0

I am trying to capture a screen and assign it to some sort of control so I can click the picture and retrieve the coordinates at which the picture was clicked. How would I go about doing this? Im trying to assign a bitmap to a static control, and when the user clicks on the image, i retrieve mouse coordinates and subtract the offsetted borders. Im using a static control since it has SS_Notify.

But here the picture isnt even to be able to be displayed on the frame? What would i do to fix this code?

            static HDC handle_MemoryDC;
    static HDC handle_ScreenDC;
    //BITMAP bitmap;
    static HBITMAP handle_Bitmap;
    static int x, y;


    case WM_CREATE:{

    CreateWindowEx(NULL, "STATIC", "", SS_BITMAP|WS_VISIBLE|WS_CHILD, 500,300, 640 ,360 , hwnd, HMENU(IDCSTATIC_BITMAP), GetModuleHandle(NULL), NULL);

    handle_ScreenDC = GetDC(NULL);
    handle_MemoryDC = CreateCompatibleDC(handle_ScreenDC);



     x = GetDeviceCaps(handle_ScreenDC, HORZRES);
     y = GetDeviceCaps(handle_ScreenDC, VERTRES);

    handle_Bitmap = CreateCompatibleBitmap(handle_ScreenDC, 640, 360);

    SelectObject(handle_MemoryDC, handle_Bitmap);
    StretchBlt(handle_MemoryDC, 0, 0, 640, 360, handle_ScreenDC, 0, 0, x, y, SRCCOPY);



    SendDlgItemMessage(hwnd, IDCSTATIC_BITMAP, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)handle_Bitmap);
Kelvin
  • 233
  • 1
  • 4
  • 13

1 Answers1

0

It looks like you are trying to send message to menu (IDCSTATIC_BITMAP), instead of static control. Try to use

SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)handle_Bitmap);
ovk
  • 2,318
  • 1
  • 23
  • 30
  • I'mean use HWND returned from CreateWindowEx. I.e.: HWND hStaticWnd = CreateWindowEx(NULL, "STATIC", "", SS_BITMAP|WS_VISIBLE|WS_CHILD, 500,300, 640 ,360 , hwnd, HMENU(IDCSTATIC_BITMAP), GetModuleHandle(NULL), NULL); and then SendMessage(hStaticWnd , STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)handle_Bitmap); – ovk Apr 23 '13 at 06:48
  • Doesnt work. Ive tried that. SendDlgItem message achieves similar thing. Ive tried SendMessage(GetDlgItem(hwnd, IDCSTATIC).... And your solution ive just tried. Nothing is showing on the static. I know that ive done the GDI part correctly because i can paint my window correctly. I just cant inject the image into a static control. I want to be able to click the picture and get the coordinates which i clicked it. – Kelvin Apr 23 '13 at 06:51
  • Are you sure that you see your static control in your main window (for example you may add some text on it and see if it will appear)? – ovk Apr 23 '13 at 07:09
  • yes I do see text when i remove ss_bitmap and i add some text – Kelvin Apr 23 '13 at 07:10
  • Ok, the last thing I can suggest is to do following: HBITMAP hOldBmp = SelectObject(handle_MemoryDC, handle_Bitmap); and after StretchBlt: handle_Bitmap = (HBITMAP)SelectObject(handle_MemoryDC, hOldBmp); – ovk Apr 23 '13 at 07:25
  • Ive noticed that when using SendDlgItemMessage error code returns as 1421 control id not found. Yet ive defined it in preprocessor.... – Kelvin Apr 23 '13 at 07:25
  • Just send message directly to HWND of your static control. – ovk Apr 23 '13 at 07:27
  • When i use the return value of createwindowex i get a error 1400: ERROR_INVALID_WINDOW_HANDLE 1400 (0x578) Invalid window handle. – Kelvin Apr 23 '13 at 07:32