Pelles C forum

C language => Work in progress => Topic started by: czerny on August 12, 2014, 03:23:32 pm

Title: Only Message Crackers
Post by: czerny on August 12, 2014, 03:23:32 pm
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.
Title: Re: Only Message Crackers
Post by: 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
 
Title: Re: Only Message Crackers
Post by: DMac on August 13, 2014, 05:41:29 pm
I prefer to use message crackers whenever I can to reduce the size of callback procedures and compartmentalize code.

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:
Code: [Select]
    //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.
Code: [Select]
...
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
Title: Re: Only Message Crackers
Post by: JohnF on August 14, 2014, 07:38:03 am
David, I was thinking something like this

Code: [Select]
case WM_LBUTTONDOWN:
  return OnLButtonDown(hwnd, LOWORD(lParam), HIWORD(lParam), &bInPosition, &bDoCapture);

I prefer to do it myself. :)

John
Title: Re: Only Message Crackers
Post by: czerny on August 14, 2014, 09:46:38 am
Code: [Select]
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.
Title: Re: Only Message Crackers
Post by: JohnF on August 14, 2014, 10:43:30 am
Code: [Select]
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
Title: Re: Only Message Crackers
Post by: czerny on August 14, 2014, 08:48:39 pm
I don't mind the work!
:)