C++按钮类问题
WIN32编程
想写个按钮类,但是按钮类的消息函数无法响应,我吧按钮类放在客户去(为了好看),猜测是不是被主窗体覆盖了,得不到消息?怎么解决,正在学C++,我还是想用类的方法实现自定义按钮。
#include "StdAfx.h"
#include "ButtonX.h"
#include"resource.h"
LRESULT CALLBACK Button_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
ATOM Button_RegisterClass(HINSTANCE hInst);
CButtonX::CButtonX(HWND hwnd,int ID_B)
{
extern HINSTANCE hInst;
B_hInst=hInst;
Father_Hwnd=hwnd;;
ID_Button=ID_B;
// 执行应用程序初始化:
Button_RegisterClass(B_hInst);
if (!b_InitInstance (ID_B))
{
MessageBox(NULL,_T("按钮加载失败!"),_T("错误"),MB_OK);
return;
}
}
CButtonX::~CButtonX(void)
{
}
LRESULT CALLBACK Button_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_LBUTTONDOWN:
MessageBox(NULL,_T("1"),_T("1"),MB_OK);
return 0;
case WM_CREATE:
MessageBox(NULL,_T("1"),_T("1"),MB_OK);
return 0;
case WM_COMMAND:
MessageBox(NULL,_T("1"),_T("1"),MB_OK);
return 0;
case WM_PAINT:
MessageBox(NULL,_T("1"),_T("1"),MB_OK);
return 0;
case WM_KEYUP:
MessageBox(NULL,_T("1"),_T("1"),MB_OK);
break;
}
return DefWindowProc (hWnd, uMsg, wParam, lParam);
}
ATOM Button_RegisterClass(HINSTANCE hInst)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style= CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;
wcex.lpfnWndProc= Button_WndProc;
wcex.cbClsExtra= 0;
wcex.cbWndExtra= 0;
wcex.hInstance= hInst;
wcex.hIcon= LoadCursor(hInst,MAKEINTRESOURCE(IDB_MinButton));
wcex.hCursor= LoadCursor(hInst,MAKEINTRESOURCE(IDB_MinButton));
wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName= NULL;
wcex.lpszClassName= _T("Button");
//wcex.hIconSm= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
BOOL CButtonX::b_InitInstance(int ID_Button)
{
extern HINSTANCE hInst;
int Wide=GetSystemMetrics(SM_CXFULLSCREEN);//屏幕宽度
int Hight=GetSystemMetrics(SM_CYFULLSCREEN);//屏幕高度
ButtonHwnd=
CreateWindow(
_T("Button"),
_T("-"),
WS_VISIBLE | WS_CHILD | BS_OWNERDRAW,
Wide/2-768/2,
Hight/2-480/2,
39,
39,
Father_Hwnd,
(HMENU)ID_Button,
hInst,
NULL);
if (!ButtonHwnd)
{
MessageBox(NULL,_T("创建按钮失败!"),_T("错误!"),MB_OK);
return FALSE;
}
ShowWindow(ButtonHwnd,SW_SHOWNORMAL);
UpdateWindow( ButtonHwnd);
return TRUE;
}
我还想把图片加载到按钮上,一般怎么做? C++?WIN32?
[解决办法]
在主窗口里面默认转消息函数里,把消息抛进来!