Had a quick look and i think it's because the value of the global variable "hwnd" is only set AFTER CreateWindow is finished, but WM_CREATE is called before CreateWindow is finished (i think). The functions "creatergn" and "clswin" use this global variable. This may work:
Code:
void creatergn(HWND hwnd)
{
rgnfile =FindResource(GetModuleHandle(NULL),MAKEINTRESOURCE(IDR_RGN),"BINARY");
pSkinData = (LPRGNDATA)LoadResource(NULL, rgnfile);
rgnSkin = ExtCreateRegion(NULL, SizeofResource(GetModuleHandle(NULL),rgnfile), pSkinData);
SetWindowRgn(hwnd,rgnSkin,TRUE);
}
void clswin(HWND hwnd)
{
DWORD dwStyle;
dwStyle = GetWindowLong(hwnd, GWL_STYLE);
dwStyle &= ~(WS_CAPTION|WS_SIZEBOX);
SetWindowLong(hwnd, GWL_STYLE, dwStyle);
InvalidateRect(hwnd, NULL, TRUE);
SetWindowPos(hwnd, NULL, 0,0,504,360, SWP_NOMOVE|SWP_NOZORDER);
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
static BOOL regned =FALSE;
switch (message)
{
case WM_CREATE:
creatergn(hwnd);
clswin(hwnd);
loadbitmap();
return 0 ;
case WM_LBUTTONDOWN:
SendMessage(hwnd, WM_NCLBUTTONDOWN,HTCAPTION,0);
break;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
skinme(ps.hdc);
SetBkMode(ps.hdc,TRANSPARENT);
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
case WM_CLOSE:
DeleteDC(bitdc);
DeleteObject(rgnSkin);
FreeResource(pSkinData);
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
You need to ask yourself if it's necessary to use these global variables.