WIN32自绘按钮,求大神解答问题
以下是我自己写的Button类,但是自绘效果是有了,点击按钮没反应,是不是主窗口没收到消息呢?怎么解决//创建按钮
void cbutton::CreateButton(HWND hWnd, HINSTANCE hInstance, int hB_x, int hB_y, int hB_w, int hB_h, int ID)
{
//创建按钮
hButton = CreateWindow(
L"button",
L" ",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW,
hB_x,
hB_y,
hB_w,
hB_h,
hWnd,
(HMENU) ID,
hInstance,
NULL);
w = hB_w;
h = hB_y;
SetWindowLong(hButton, GWL_WNDPROC, (LONG)ButtonProc);
}
//(静态)按钮窗口过程处理函数
LRESULT cbutton::ButtonProc(HWND hbwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
cbutton *athis = (cbutton*)GetWindowLong(hbwnd, GWL_USERDATA);
athis->hButton=hbwnd;
switch (msg)
{
PAINTSTRUCT ps;
HBITMAP hb;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
b_hdc = BeginPaint(hbwnd, &ps); //开始绘图
b_mdc = CreateCompatibleDC(b_hdc); //兼容DC
//加载图片
hb = (HBITMAP)LoadImage(NULL, FileName, IMAGE_BITMAP,
0, 0, LR_LOADFROMFILE);
SelectObject(b_mdc, hb);
//贴图
BitBlt(b_hdc, 0, 0, w ,h, b_mdc, 0, 0, SRCCOPY);
EndPaint(hbwnd, &ps); //结束绘图
w = 0;
h = 0;
DeleteObject(b_hdc);
DeleteObject(b_mdc);
memset(FileName, '\0', sizeof(FileName));
break;
}
return DefWindowProc(hbwnd,msg,wParam,lParam);
}