Reputation: 83
The bitmap will not display when the left mouse button is clicked. I'm using visual c++ express
HDC DC, memDC;
switch(message) {
case WM_CREATE:
hBit1 = LoadBitmap(hInst, "C:\New folder (2)\MyBP1.bmp");
break;
case WM_LBUTTONDOWN:
DC = GetDC(hwnd);
memDC = CreateCompatibleDC(DC);
SelectObject (memDC, hBit1);
BitBlt(DC, LOWORD(lParam), HIWORD(lParam), 27, 59, memDC, 0, 0, SRCCOPY);
ReleaseDC(hwnd, DC);
DeleteDC(memDC);
break;
I'm not sure exactly whats wrong with the code. Theres no errors displayed in visual c++ express If the code is all wrong would someone point me in the right direction
Upvotes: 1
Views: 649
Reputation: 490728
LoadBitmap
is only for loading bitmaps that are stored as resources in your executable or a DLL.
To load a bitmap from a BMP file, you want to use LoadImage
with the LR_LOADFROMFILE
flag, something like this:
bmp = (HBITMAP)LoadImage(0, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
As an aside, you probably don't really want to do the displaying directly in response to WM_LBUTTONDOWN
. Instead, you normally want to record the position, possibly set a flag to indicate that the bitmap should be displayed, and call InvalidateRect
to invalidate your client rectangle -- then do the actual drawing in response to WM_PAINT
.
Upvotes: 6