Jump to content
  • Advertisement
Sign in to follow this  

Win32 API Custom Classes

This topic is 3005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post

Link to post
Share on other sites
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".

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!