Win32 API Custom Classes

Started by
1 comment, last by PaladinOfKaos 13 years, 8 months ago
I'm creating my own classes for windows in Win32 API and I now wonder what approach I should be taking for the message procedures.

I thought I'd have some functions like OnButtonDown() but how would I make this happen? Should the message procedure be hidden from the user of the classes so they should only be concerned about the OnButtonDown() functions? What are some good approaches accomplishing this? Is it a good idea at all?

These classes would be used for my editor and I'm using Object Oriented Programming, if that's any use for anyone.

Feedback would be much appreciated.
Advertisement
Hi. I have developed a GUI framework for win32. As you might imagine there are a number of different ways to implement the message handling code.

This is how I do it in C++

LRESULT CALLBACK QdWndProc ( HWND hwnd, UINT message,	WPARAM wParam, LPARAM lParam ){	QdWindowPrivate * p_QdWindowPrivate = reinterpret_cast<QdWindowPrivate *> (		::GetWindowLong ( hwnd, GWL_USERDATA ) ) ;	return p_QdWindowPrivate->WndProc ( hwnd, message, wParam, lParam ) ;}/**************************************************************************************************************************************************************/LRESULT QdWindowPrivate::WndProc ( HWND hwnd, UINT message,	WPARAM wParam, LPARAM lParam ){	switch ( message ) {	HANDLE_MSG ( hwnd, WM_CREATE, virtual_wm_create ) ;	HANDLE_MSG ( hwnd, WM_SIZE, virtual_wm_size ) ;	HANDLE_MSG ( hwnd, WM_PAINT, virtual_wm_paint ) ;		HANDLE_MSG ( hwnd, WM_COMMAND, virtual_wm_command ) ;	HANDLE_MSG ( hwnd, WM_DESTROY, virtual_wm_destroy ) ;	HANDLE_MSG ( hwnd, WM_NCDESTROY, wm_ncdestroy ) ;... ...	return ::DefWindowProc ( hwnd, message, wParam, lParam ) ;}


Basically I store a pointer to the C++ base object in the window GWL_USERDATA.
Then I derive all my windows from QdWindowPrivate and override the virtual functions as I need.
In this case WndProc is not virtual because I don't think there is need for a derived class to override it. So yes WndProc can be "hidden".
GetWindowLong is obsolete: it returns a 32-bit value even on win64. If you're storing pointers, you should use GetWindowLongPtr

This topic is closed to new replies.

Advertisement