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));