How can i show my button bitmap picture?

I want to add a pic in my button.I tried this.But it doesn't work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <windows.h>
HBITMAP hBmp;
HWND button;
LRESULT CALLBACK P(HWND A,UINT B,WPARAM C,LPARAM D){
        switch(B){
                  case WM_CREATE:
                      button= CreateWindow("button","Button Pic",WS_CHILD|WS_VISIBLE|BS_BITMAP,30,75,75,25,A,(HMENU)hBmp,NULL,NULL);
                SendMessage(
            (HWND)button,
            (UINT) BM_SETIMAGE,
            (WPARAM) IMAGE_BITMAP,
            (LPARAM) hBmp
            );
                  break;
                  case 0x2:
                       PostQuitMessage(0);
                       break;
                       default:
                       return DefWindowProc(A,B,C,D);
                  }
                  return 0;
        }
        char title[]="Button Pic";
int WINAPI WinMain(HINSTANCE A,HINSTANCE B,LPSTR C,int d){
    hBmp=(HBITMAP)LoadImage(NULL,"C:\\exam.bmp",IMAGE_ICON,32,32,LR_LOADFROMFILE);
    HWND E;
    MSG F;
    WNDCLASS G={0};
    G.hInstance=A;
    G.lpszClassName=title;
    G.lpfnWndProc=P;
    G.hbrBackground=GetSysColorBrush(COLOR_3DFACE);
    RegisterClass(&G);
    CreateWindow(G.lpszClassName,title,0xcf0000|WS_VISIBLE,50,150,600,450,0,0,A,0);
    while(GetMessage(&F,NULL,0,0)){
            TranslateMessage(&F);
            DispatchMessage(&F);
            }
            return F.wParam;
    }
What if you specify IMAGE_BITMAP instead of IMAGE_ICON on line 25?
Yes.I tried.But it doesn't work.
Your code works for me. You should check hBmp:
25
26
27
28
29
 hBmp=(HBITMAP)LoadImage(NULL,"C:\\exam.bmp",IMAGE_ICON,32,32,LR_LOADFROMFILE);
if(hBmp==NULL)
  {
      MessageBox(0,"Could not open bitmap file","Error",48);
  }

Last edited on
I can not work.I use Dev-C++
Topic archived. No new replies allowed.