EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control

  1. #1
    Join Date
    Apr 2013
    Location
    Prague / Cracow
    Posts
    47

    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
    .

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,517

    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

  3. #3
    Join Date
    Apr 2013
    Location
    Prague / Cracow
    Posts
    47

    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.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,517

    Re: EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control

    Quote Originally Posted by berkov View Post
    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

  5. #5
    Join Date
    Apr 2013
    Location
    Prague / Cracow
    Posts
    47

    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!!

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,517

    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

  7. #7
    Join Date
    Apr 2013
    Location
    Prague / Cracow
    Posts
    47

    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.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,517

    Re: EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control

    Quote Originally Posted by berkov View Post
    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

  9. #9
    Join Date
    Apr 2013
    Location
    Prague / Cracow
    Posts
    47

    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!

  10. #10
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,039

    Re: EN_UPDATE / EN_CHANGE how to use Notyfication Code - validation on control

    Quote Originally Posted by berkov View Post
    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.
    Quote Originally Posted by berkov View Post
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center