設置窗口及按鈕背景圖片

first, register a window class:

    WNDCLASSEX wcex = { sizeof(wcex) };
    wcex.style            = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc      = _WndProc;
    wcex.hInstance        = _hInst;
    wcex.hIcon            = NULL;
    wcex.hCursor          = LoadCursor(NULL, IDC_ARROW);
    //wcex.hbrBackground    = (HBRUSH)(COLOR_WINDOW + 1);
    //set window background image
    HBITMAP image;
     image = LoadBitmap(g_hinst, MAKEINTRESOURCE(IDB_BITMAP_IMAGE));
     wcex.hbrBackground = (HBRUSH)CreatePatternBrush(image);

     wcex.lpszClassName    = c_szClassName;
     return RegisterClassEx(&wcex)

then, create the windows:

 _hWnd = CreateWindowEx(
        WS_EX_TOPMOST|WS_EX_LAYERED, 
        c_szClassName, 
        c_szDisconnected, 
        WS_DLGFRAME,
        x, y, width, height,  
        NULL,
        NULL, _hInst, NULL);

the above text in red  are how to set window background picture. My focus is the first parameter of  LoadBItmap fucntion, g_inst.

ref to a network resource here:

http://blog.youkuaiyun.com/sandro_zhang/article/details/6837662

,the g_inst parameter is replaced by (HINSTANCE)GetModuleHandle(NULL). 

this may be ok , but not for my case.

In my code, the window is created in dll, so the g_inst is in 

STDAPI_(BOOL) DllMain(__in HINSTANCE hinstDll, __in DWORD dwReason, __in void *),

yes, it is the hinstaDll ,the DLL module instance.


 How about to create Button? the code is below:

 _hWndButton = CreateWindow(L"Button", L"xxx", 
                             WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 
                             x,y , width, height, 
                             _hWnd, 
                             NULL,
                             _hInst,
                             NULL);


then to set button background picture:

HBITMAP image;
 image = LoadBitmap(g_hinst,MAKEINTRESOURCE(IDB_TILE_IMAGE));
::SendMessage(_hWndButton,BM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)(image));


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值