Hi,
Im trying to create my own custom control class, and im have a few problems with the Main and Proc functions, heres the code i use:
Code:
class aButton
{
public:
void Create(//params here);
private:
void Main();
WNDPROC Proc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
};
void aButton::Create(//params here)
{
DWORD dwThread;
m_hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Main, NULL, 0, &dwThread);
}
void aButton::Main()
{
MSG Message;
WNDCLASS Window = {0};
Window.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
Window.hIcon = LoadIcon(NULL, IDI_APPLICATION);
Window.hCursor = LoadCursor(NULL, IDC_ARROW);
Window.hInstance = m_hInstance;
Window.lpfnWndProc = Proc;
Window.lpszClassName = "aButton";
Window.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&Window);
m_hButton = CreateWindow("aButton",
"",
WS_CHILD,
0,
0,
0,
0,
m_hParent,
0,
m_hInstance,
0);
ShowWindow(m_hButton, SW_SHOW);
UpdateWindow(m_hButton);
while (GetMessage(&Message, NULL, 0, 0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
UnregisterClass("aButton", m_hInstance);
}
WNDPROC aButton::Proc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message)
{
//Handle all messages (paint msgs, mouse msgs.. etc)
default: return (WNDPROC)DefWindowProc(hWnd, Message, wParam, lParam);
}
return (WNDPROC)0;
}
anyway, when i try to compile, i get 2 errors:
Code:
D:\Programming\C++\aButton.cpp(86) : error C2440: '=' : cannot convert from 'long (__stdcall *(__thiscall aButton::*)(struct HWND__ *,unsigned int,unsigned int,long))(struct HWND__ *,unsigned int,unsigned int,long)' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'
D:\Programming\C++\aButton.cpp(74) : error C2440: 'type cast' : cannot convert from '' to 'unsigned long (__stdcall *)(void *)'
None of the functions with this name in scope match the target type
Basically, im trying to handle all the messages for my custom control in 1 class.. is there an easier way? or a different way? if so, please let me know
thanks