For the last day or so I've been struggling to display a bitmap on a Window that I have created using the WINAPI C++. I started off using Loadbitmap(), but that was giving me problems in that the bitmap would never load because I had issues with resource handling (Dev C++). Now I'm using Loadimage() and I'm able to load the bitmap but it is not displayed in the window!? Here is the code I am using:
Most of the code in WM_PAINT was centred around me using Loadbitmap() before I gave up and I figured it could still be used for Loadimage(). Maybe this is causing the problem?Code:LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hDC, MemDCExercising; PAINTSTRUCT Ps; HBITMAP bmpExercising; BITMAP bm; switch (message) /* handle the messages */ { case WM_CREATE: bmpExercising = (HBITMAP) LoadImage( hInst, "C:\\test.bmp", IMAGE_BITMAP ,0 ,0 ,LR_LOADFROMFILE); if(bmpExercising == NULL) MessageBox(hwnd, "Could not load Exercise!", "Error", MB_OK | MB_ICONEXCLAMATION); break; case WM_DESTROY: PostQuitMessage (0); break; case WM_PAINT: hDC = BeginPaint(hwnd, &Ps); MemDCExercising = CreateCompatibleDC(hDC); SelectObject(MemDCExercising, bmpExercising); GetObject(bmpExercising, sizeof(bm), &bm); BitBlt(hDC, 10, 10,bm.bmWidth, bm.bmHeight, MemDCExercising, 0, 0, SRCCOPY); DeleteDC(MemDCExercising); DeleteObject(bmpExercising); EndPaint(hwnd, &Ps); break; default: return DefWindowProc (hwnd, message, wParam, lParam); }
In the long run I am hoping to change the picture displayed in the Window using data I receive from a winsock server as an argument as to which picture is shown. Can anyone see any potential difficulties with this? Thanks a lot.




Reply With Quote