I have tried to build an example window project without any case statements.
I have not used prototypes for all the functions 'func_OnSomething' because of the extra effort.
This is only a starting point!
I am sure there are lots of improvements and pitfalls, I would like to here from.
The only pitfall I can think of is you might occasionally want to pass extra variables. The message crackers don't allow for that. Unless there is a way to do it that I'm not aware of.
John
I prefer to use message crackers whenever I can to reduce the size of callback procedures and compartmentalize code.
Quote from: JohnF on August 13, 2014, 08:55:55 AM
The only pitfall I can think of is you might occasionally want to pass extra variables. The message crackers don't allow for that. Unless there is a way to do it that I'm not aware of.
John
If I wish to send a message with my own arguments I find the FORWARD macros helpful. They ensure that the format of data attached to a message is correct for that message. For example:
//Update the fields
FORWARD_WM_CHAR(g_lpInst->hwndCtl1, VK_RETURN, 0, SNDMSG);
FORWARD_WM_CHAR(g_lpInst->hwndCtl2, VK_RETURN, 0, SNDMSG);
//Trigger refresh
FORWARD_WM_COMMAND(GetParent(hwnd), GetDlgCtrlID(hwnd), hwnd, LBN_SELCHANGE, SNDMSG);
When it comes to handling my own messages though, I take a mixed approach since I don't care to define message crackers for them.
...
HANDLE_MSG(hwnd, WM_SIZE, Grid_OnSize);
HANDLE_MSG(hwnd, WM_VSCROLL, Grid_OnVScroll);
//
//Begin Grid specific messages
//
case SG_ADDCOLUMN:
return Grid_OnAddColumn(hwnd, wParam, lParam) - 1; // don't include row header column
case SG_ADDROW:
return Grid_OnAddRow(hwnd, wParam, lParam) - 1; //don't include the column header row
...
David M
David, I was thinking something like this
case WM_LBUTTONDOWN:
return OnLButtonDown(hwnd, LOWORD(lParam), HIWORD(lParam), &bInPosition, &bDoCapture);
I prefer to do it myself. :)
John
Quote from: JohnF on August 14, 2014, 07:38:03 AM
case WM_LBUTTONDOWN:
return OnLButtonDown(hwnd, LOWORD(lParam), HIWORD(lParam), &bInPosition, &bDoCapture);
But this is as much work as to write a own cracker macro. And window local parameters can be hold in a structure which adress can be stored in wc.cbWndExtra or in GWLP_USERDATA if the control is not our own.
Quote from: czerny on August 14, 2014, 09:46:38 AM
Quote from: JohnF on August 14, 2014, 07:38:03 AM
case WM_LBUTTONDOWN:
return OnLButtonDown(hwnd, LOWORD(lParam), HIWORD(lParam), &bInPosition, &bDoCapture);
But this is as much work as to write a own cracker macro. And window local parameters can be hold in a structure which adress can be stored in wc.cbWndExtra or in GWLP_USERDATA if the control is not our own.
I don't mind the work!
John