How could I create similar structure to handle Win32 Messages like it is in MFC?
In MFC;
BEGIN_MESSAGE_MAP(CSkinCtrlTestDlg, CDialog)
//{{AFX_MSG_MAP(CSkinCtrlTestDlg)
ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
ON_BN_CLICKED(IDC_DEFAULTSKIN, OnChangeSkin)
ON_WM_DRAWITEM()
ON_WM_MEASUREITEM()
ON_WM_COMPAREITEM()
ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_MESSAGE_MAP macro handles this behaviour. What to do for pure Win32?
Here is a breif summary of the code I use to do this in the Zeus programmer’s editor:
Step 1: Define a couple of message structure to hold the Windows message details:
Step 2: Define a base window class with a few special methods:
Step 3: Define a few macros to do the dispatching of the Windows messages:
Step 4: Define the dispatcher method:
Step 5: Define the static window procedure method (NOTE: this method will need to be used as the Window procedure of the window class when the class is first registered):
Now, using this base class it is possible to define a new window class that will look like this:
Edit: How this code works.
The secret to understanding how this code works is to remember the wndProc in the xWindow class is nothing but a Win32 Window procedure passed to RegisterClassEx when the Win32 Window is registered.
Now if you look at the wndProc code you will see it does a bit of setting up and checking but generally it does nothing more than send the Windows message to the dispatch method.
The dispatch method is even simpler as it does nothing more than pack the Windows message into an easy to move structure and then sends it off to the dispatchToMsgMap method.
Now look at the MyWindow class an you will see this code:
This code is just using the macros defined earlier. If you take a close look at these macros you will see the code above is in fact creating a dispatchToMsgMap method. This is the exact same dispatchToMsgMap method that was called by the dispatch method.
I know this method of handling Windows messages does work as I use this exact same approach in the Zeus for Windows editor.