Hallo,
I am trying to display a .bmp image on the screen when I press a button. This is probably simple, but I cant get it work and I must admit that I find the msdn very confusing (although I am starting to learn my way around).
I was able to load and display the image on the screen using WM_PAINT, but then it was under my other media object (I am streaming from a web camera) and it was visible all the time.
So, is there a way to display a bmp image over all the other elements when a button is pressed?
Here is the code I am using(which do not work)
Code:
case WM_COMMAND:
{
// Check if the mouse button has been clicked
if(HIWORD(wParam) == BN_CLICKED)
{
// See if it clicked any of the buttons
if((wParam) == BUTTON_PLAY)
{
PAINTSTRUCT ps;
HBITMAP img = (HBITMAP) LoadImage(NULL, TEXT("C:\\Users\\Ole\\Documents\\frames\\animasjonsFrame_0.bmp"),
IMAGE_BITMAP,640,480,LR_LOADFROMFILE );
if(img == NULL)
MessageBox(NULL, TEXT("ERROR loading"), TEXT("Error"), MB_ICONERROR|MB_OK);
BITMAP bm;
HDC hdc = BeginPaint(hWnd, &ps);;
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, img);
GetObject(img, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
EndPaint(hWnd, &ps);
int currentTime = GetTickCount();
while(currentTime + 500 > GetTickCount());
ShowWindow(hWnd, SW_SHOW);
}
//.....
}