-
April 20th, 2013, 06:18 PM
#1
EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control
hey ho!
I've got a Dialog with various Controls on it. Just for the need of this example, let's say we talk about:
#define IDC_example 1001
IDC_example to EDITTEXT.
The Dialog where this Control is on is processed by:
BOOL CALLBACK DlgProcModalless( HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam )
I woudl like to have possibility to correct the user's entry on this Control, let's say, so that the program automatically changes user's entry from "x" to "z" and would not allow to enter e.g. "a".
MSDN says:
EN_UPDATE
WPARAM wParam;
LPARAM lParam;
Parameters
wParam - The LOWORD contains the identifier of the edit control. The HIWORD specifies the notification code.
lParam - A handle to the edit control.
But how can i get it work for my particular example of DlgProcModalless?
I've started typing the code (I don't even know if what i've typed so far is correct):
BOOL CALLBACK DlgProcModalless( HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam )
{
switch( Msg ) {
case EN_UPDATE:
{
switch(LOWORD(lParam))
{
case 1001: //lub IDC_przyklad:
// here is the validation, however when i put the MessageBox just to find out if this part of code is called at all, unfortunatelly i've learnt that no pop-up message appears while modyfying the EDITTEXT example.
I quite understand the use of notification codes but only up to the lParam / wParam level, but how to get to LOWORD, HIWORD...?
In this particular example how to get the HWND to the particular Control and how to find out that the user typed e.g. "x" from the keyboard?
woudl be grateful for help!
cheers
berkov
.
-
April 21st, 2013, 02:52 AM
#2
Re: EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control
You missed the important part of MSDN article EN_UPDATE notification code:
The parent window of the edit control receives this notification code through a WM_COMMAND message.
So you have to handle WM_COMMAND messsage, then check the notification code (HIWORD of its WPARAM parameter) to be EN_UPDATE, then do what you want to...
Victor Nijegorodov
-
April 21st, 2013, 05:12 AM
#3
Re: EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control
Hi
I just realized so i made the following:
BOOL CALLBACK DlgProcModalless( HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam )
{
switch( Msg )
{
case WM_COMMAND:
{
switch( LOWORD( wParam ) )
{
case IDC_save: somesavingcode(); break;
case IDC_cancel: DestroyWindow( hwnd ); break;
case IDC_example: {
if( HIWORD( wParam ) == EN_UPDATE )
{ MessageBox( 0, "EN_UPDATE!", 0, 0 ); } else { MessageBeep(0); }
} break;
}
}
break;
default: return FALSE;
}
return TRUE;
}
And when i execute the program i only get the system beep when updating the IDC_example control but never get the MessageBox, and i should be getting the MessageBox coz the HIWORD( wParam ) should pass the EN_UPDATE notification.... but apparently it passes something else, why?
and can i check on debug mode what is the notification passed if not EN_UPDATE?
btw. i checked with EN_CHANGE and the result is exactly the same as with EN_UPDATE.
-
April 21st, 2013, 05:42 AM
#4
Re: EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control
Originally Posted by berkov
And when i execute the program i only get the system beep when updating the IDC_example control but never get the MessageBox, and i should be getting the MessageBox coz the HIWORD( wParam ) should pass the EN_UPDATE notification.... but apparently it passes something else, why?
and can i check on debug mode what is the notification passed if not EN_UPDATE?
You should never call MessageBox from within the window procedure for debugging purposes. Use OutputDebugString instead.
Or just set a breakpoint on the line with somesavingcode();:
Code:
case WM_COMMAND:
{
switch( HIWORD( wParam ) )
{
case EN_UPDATE:
if(LOWORD(wParam ) == IDC_example)
{
somesavingcode();
}
break;
}
break;
}
and start debugger (F5)
Victor Nijegorodov
-
April 21st, 2013, 06:23 AM
#5
Re: EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control
Brilliant!
Seems to be working.
case WM_COMMAND:
{
switch( LOWORD( wParam ) )
{
case IDC_save: {somesavingcode} break;
case IDC_cancel: DestroyWindow(hwnd); break;
}
switch( HIWORD( wParam ) )
{
case EN_UPDATE: if(LOWORD(wParam ) == IDC_example) {MessageBeep(0);} break; //i finally get the beep!!!!!!
}
}break;
Thanks a lot!!
-
April 21st, 2013, 06:30 AM
#6
Re: EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control
Please, use Code tags while posting code snippets! Read Announcement: Before you post....
Never put more than one statement in a line. It is hard to read and hard (if not say impossible) to debug!
Victor Nijegorodov
-
April 21st, 2013, 06:34 AM
#7
Re: EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control
i checked my previous code and it also works as well
The problem was that IDC_example cannot be a COMBOBOX but EDIT.
This notification does not work with COMBOBOXES.
-
April 21st, 2013, 06:37 AM
#8
Re: EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control
Originally Posted by berkov
i checked my previous code and it also works as well
The problem was that IDC_example cannot be a COMBOBOX but EDIT.
This notification does not work with COMBOBOXES.
There is a CBN_EDITUPDATE notification sent when the edit control portion of a combo box is about to display altered text.
Victor Nijegorodov
-
April 21st, 2013, 07:05 AM
#9
Re: EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control
OK,, thanks for this info., guess i might need to use it for combo!
-
April 22nd, 2013, 10:16 AM
#10
Re: EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control
Originally Posted by berkov
The problem was that IDC_example cannot be a COMBOBOX but EDIT.
Of course it cannot. Did you read EN_UPDATE notification code?
From MSDN:
Sent when an edit control is about to redraw itself.
Originally Posted by berkov
This notification does not work with COMBOBOXES.
As long as the notification is sent by EDIT control, COMBOBOX just doesn't send it. You definitely miss some very basic principles of Windows programming. I would recommend to start with reading Petzold's Programming Windows. A.S.A.P.
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|