Re: Custom Control - Notifcation Messages
Hi Dan,
This is the same as
struct MOUSE
{
HWND hwndFrom;
UINT idFrom;
UINT code;
UINT nFlags;
CPoint point;
};
This
struct MOUSE
{
NMHDR hdr;
UINT nFlags;
CPoint point;
};
*Note the position of hwndFrom, idFrom and code. That is the order of =
NMHDR
But, yeah. It is easier to write it the 2nd way.
Yes, but that you should not hardwire the IDs. (I'm not sure how you =
got that to work.)
At first, it was just a test, just to get it to work.
Then, knowing me, I saved the ID as a variable in my class.
Then, after further thought, I changed it to GetDlgCtrlID()
I was thinking about ID's and how they are not really reliable. 2 or =
more controls could have the same ID.
Unless, I was to use GUID's. So, I wasn't looking at the idFrom, just =
the message.
Maybe the message could be generic, like UWM_MYCONTROL
Then, I could look at the ID from to see what child control sent the =
message.
Then, I would have to cast to a child control structure to get the =
message,
Then, cast to another struct to get the actual parameters.
I suppose that is really how it should be done.
It's just a lot of work...
For example, Say My Control has several child controls.
The child controls send a parent notify message to MyControl.
Then, MyControl forwards the message to it's parent.
That is really the way it should be done.
I am kind of lazy and just do GetParent()->GetFrame()->PostMessage().
It should be GetParent()->PostMessage()
Then, in parent GetFrame()->PostMessage()
I take it you have read technical notes 61 and 62. I do believe you
should never use WM_PARENTNOTIFY as has well defined system behavior.
Yeah, I am supposed to use WM_PARENTNOTIFY.
That's what notifies the parent.
Thanks,
"Dan Bloomquist" <public21@lakeweb.com> wrote in message =
news:sqnti.13474$B25.8931@news01.roc.ny...
Nobody wrote:
Hi Scott,
Thanks for the quick response.
Your absolutely right about the Send/Post.
I just started messing around making my own notification messages.
I'm just curious as to how Notification messages actually work.
I am a bit confused about WM_PARENTNOTIFY and WM_NOTIFY.
I think I am on the right track. I just need verification.
I take it you have read technical notes 61 and 62. I do believe you
should never use WM_PARENTNOTIFY as has well defined system behavior.
Here, I have created my own notification message.
struct MOUSE
{
HWND hwndFrom;
UINT idFrom;
UINT code;
UINT nFlags;
CPoint point;
};
If you are going to write notifications, stick with the paradigm and =
use
NMHDR as the first structure member:
//notify clicks ............................
typedef struct tagCLVCLICKA
{
NMHDR hdr;
int iItem;
int iSubItem;
CPoint ptClick;
LPARAM lParam;
} CLVCLICKA, *LPCLVCLICKA;
This is so all notifications have the same signature. What if you:
BOOL CSomeCtrl::OnWndMsg( UINT message, WPARAM wParam, LPARAM lParam,
LRESULT* pResult )
{
if( message == WM_NOTIFY )
{
NMHDR& hdr= *reinterpret_cast<NMHDR*>( lParam );
...
}
return CListCtrl::OnWndMsg( message, wParam, lParam, pResult );
}
Yes, your structure would work but NMHDR sets the discipline.
Then, in OnLButtonDown, OnLButtonUp, OnMouseMove, I send a =
Notifcation message.
if(GetMouseEvents()) //If MouseEvents Notifcation Messages Enabled
{
Mouse.hwndFrom = GetSafeHwnd();
Mouse.idFrom = ID_MYCONTROL;
Mouse.code = UWM_MYCONTROL_LBUTTONDOWN;
Mouse.nFlags = nFlags;
Mouse.point = point;
GetParent()->PostMessage(WM_NOTIFY, UWM_MYCONTROL_LBUTTONDOWN, =
(LPARAM)&Mouse);
}
Is that basically how it is done?
Yes, but that you should not hardwire the IDs. (I'm not sure how you =
got
that to work.)
if( ... )
{
//Check with parent if new row is ok
MYSTRUCT nr;
nr.hdr.code= CLVN_NEWITEM;
nr.hdr.hwndFrom= GetSafeHwnd( );
nr.hdr.idFrom= GetDlgCtrlID( );
nr.iItem= iItem;
if( GetParent( )->
SendMessage(WM_NOTIFY, GetParent( )->GetDlgCtrlID( ), =
(LPARAM)&nr))
return;
InsertRowSet( ... );
...
}
Best, Dan.