Click here to Skip to main content
15,919,132 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please l need help on how i can send message to case WM_NOTIFY in my program. l want when a button is clicked(as in the case WM_COMMAND below), the SendMessage function activates case WM_NOTIFY so that the codes inside the WM_NOTIFY case will run.
l had tried my best but l only get unhandled exception error messages.
snippet below;
C++
case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
		{
		case IDC_NEXTBTN:
			QueNo++;
			SendMessage(hWnd,WM_NOTIFY,(int)IDC_NEXTBTN,(NMHDR)lParam);//here l cast wparam to int and wparam to (NMHDR) according to msdn for WM_NOTIFY
			break;
......


while in WM_NOTIFY, i have

C++
case WM_NOTIFY:
		{
		
		if(lpnmhdr->code==TCN_SELCHANGE||lpnmhdr->hwndFrom==NextBtn){
			
.....
}

Or is there any other way l can implement it.
Thanks everyone

What I have tried:

C
SendMessage(hWnd,WM_NOTIFY,(int)IDC_NEXTBTN,(NMHDR)lParam)
Posted
Updated 21-Feb-16 11:20am
v2
Comments
Richard MacCutchan 21-Feb-16 7:43am    
And what happens?
Member 12139442 21-Feb-16 8:00am    
It doesn't work and VC++ breaks at the if statement line and gives me unhandled exception.
Richard MacCutchan 21-Feb-16 8:18am    
Probably because you are casting one object to another unrelated type. You cannot cast the lparam sent to WM_COMMAND to a NMHDR structure. You need to create a proper header structure and populate its member variables before passing it in to the notify code.
Kornfeld Eliyahu Peter 21-Feb-16 7:47am    
It seems that your params are invalid...
The first should ahve the control id of the event source, and the second a structure of NMHDR...While the low word of wParam may(!) be the control id lParam never will be a NMHDR structure...but zero or window handle...
Member 12139442 21-Feb-16 8:01am    
I also had tried parsing the window handled as well as 0, but no avail. VC++ breaks at the if statement line and gives me unhandled exception.

Quote:
the SendMessage function activates case WM_NOTIFY so that the codes inside the WM_NOTIFY case will run.

I won't do that. Instead I would factor out 'the code inside the WM_NOTIFY case' as a function and call directly such a function.
 
Share this answer
 
C#
case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
		{
		case IDC_NEXTBTN:
			QueNo++;
			NMHDR nmh;
			nmh.code = NM_CLICK;    // Message type defined by control.
			nmh.idFrom =IDC_NEXTBTN;
			nmh.hwndFrom = NextBtn;
			SendMessage(GetParent(NextBtn),	WM_NOTIFY, nmh.idFrom, (LPARAM)&nmh);
			
			break;

Based on the link given by Konfeld.
And many thanks to all of you who contributed.
@CPallini: l would have but it wouldn't be much better than as l wanted.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900