CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Jan 2010
    Posts
    76

    Peek Message help

    ok so I have a text box that I need to detect if any characters inside it has been changed.

    I keep reading into it and everything I see has to do with PeekMessage.

    I tried some eaxmples and is having no luck.


    How can I get the messages from another control within my app like a edit box or a listbox

    thanks

    I know I ask for alot. but there is barely anything out there for API's. I keep finding MFC examples v_v

    thanks again

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Peek Message help

    Why PeekMessage? Can't you just check for EN_CHANGE or EN_UPDATE notification to the parent?

  3. #3
    Join Date
    Jan 2010
    Posts
    76

    Re: Peek Message help

    How would I be able to do that?


    I have a command open with my app to debug it and stuff and my text box when I do something other then giving it focus, it doesn't show up under my main form procedures.

  4. #4
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Peek Message help

    OK, I assume your not using MFC (because of the comment in the OP), so what are you using? The above makes little sense.

  5. #5
    Join Date
    Jan 2010
    Posts
    76

    Re: Peek Message help

    Just the basics. Like the getmessage dispatch message,etc.

    I have a function called Procedures that gets the messages of the main window and what ever it is such as menu clicks,button clicks, takes care of that. I just need to get the messages for other controls such as a edit box.

    I can't find anything on it besides PeekMessage or MFC.

  6. #6
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Peek Message help

    I still don't get it. Do you have a message loop? Just handle WM_NOTIFY and check for EN_CHANGE.

  7. #7
    Join Date
    Jan 2010
    Posts
    76

    Re: Peek Message help

    Quote Originally Posted by hoxsiew View Post
    I still don't get it. Do you have a message loop? Just handle WM_NOTIFY and check for EN_CHANGE.


    well I tried that and it didn't work

    this is what I have:

    Code:
    /*--*/LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){// Gets the Application Procedure
    /*|-*/
                  
    
         
        
    /*|-*//*--*/switch(msg){// Switch Message base on Application Message
    /*|-*//*|-*/
    
                case WM_MOUSEMOVE:
                       //if(lParam==(int)rtfctl){
                         
                         // }
                          break;
    /*|-*//*|-*/case WM_COMMAND:// Gets which command is in use
    
                   
    /*|-*//*|-*/   /*--*/switch(wParam){// Gets the sub command is in use
    /*|-*//*|-*/   /*|-*/case ID_FILE_NEW: // File New command activated   
    /*|-*//*|-*/   /*|-*/break;
    /*|-*//*|-*/   /*|-*/case ID_FILE_OPEN:// File Open command activated
    /*|-*//*|-*/   /*|-*/        DestroyWindow(hwnd);// This was here for a test/debug. Remove when this control gets used
    /*|-*//*|-*/   /*|-*/break;
    /*|-*//*|-*/   /*|-*/case ID_FILE_SAVE: // This was here for a test/debug. Remove when this control gets used
    /*|-*//*|-*/   /*|-*/
    /*|-*//*|-*/   /*|-*/break; 
    /*|-*//*|-*/   /*|-*/case ID_FILE_SAVEAS:// Save As command activated              
    /*|-*//*|-*/   /*|-*/break; 
    /*|-*//*|-*/   /*|-*/case ID_FILE_PRINT:// File Print command activated
    /*|-*//*|-*/   /*|-*/break; 
    /*|-*//*|-*/   /*|-*/case ID_FILE_PRINTPREVIEW:// File Print Preview command activated
    /*|-*//*|-*/   /*|-*/break; 
    /*|-*//*|-*/   /*|-*/case ID_FILE_IMPORT://File Import command activated
    /*|-*//*|-*/   /*|-*/break; 
    /*|-*//*|-*/   /*|-*/case ID_FILE_RECENT://command activated
    /*|-*//*|-*/   /*|-*/break; 
    /*|-*//*|-*/   /*|-*/case ID_FILE_EXIT:// Exit command activated
    /*|-*//*|-*/   /*|-*/DestroyWindow(hwnd);// Exits the main program
    /*|-*//*|-*/   /*|-*/break; 
    /*|-*//*|-*/   /*|-*/case ID_INSERT_NEWFORM://command activated
                       
    /*|-*//*|-*/   /*|-*/break;                         
    
    /*|-*//*|-*/   /*|-*/           //break;                          
    /*|-*//*|-*/   /*--*/}
    /*|-*//*|-*/  
    
    /*|-*//*|-*/break;
    /*|-*//*|-*/case WM_SIZE:// Resize Message
               #include "sizectrls.h"
               break;
               case WM_NOTIFY:
                          switch(lParam){
                          case EN_CHANGE:
                          MessageBox(0,"test","test",MB_OK);
                          break;                    
                                                      }
    /*|-*//*|-*/break;
    /*|-*//*|-*/case WM_CLOSE:// Close message
    /*|-*//*|-*/DestroyWindow(hwnd);// Exits the main program
    /*|-*//*|-*/break;
    /*|-*//*|-*/case WM_DESTROY:// Terminate Message
    /*|-*//*|-*/PostQuitMessage(0);// Terminates the main program
    /*|-*//*|-*/default:
    /*|-*//*|-*/return DefWindowProc(hwnd, msg, wParam, lParam);//Returns the defualt Messages to the main program
    /*|-*//*--*/}
    /*|-*/return 0;
    /*|-*/}
    Last edited by Senith; February 24th, 2010 at 10:51 PM.

  8. #8
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Peek Message help

    Sorry, it's been a while since I worked with windows at the API level. The correct method is to handle WM_COMMAND and check for your control ID, then handle its notifications there. Something like this:

    Code:
    HWND m_hEdit;
    #define ID_EDIT1 1001
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
      int wmId, wmEvent;
      PAINTSTRUCT ps;
      HDC hdc;
      int i;
    
      switch (message)
      {
      case WM_CREATE:
        m_hEdit=CreateWindow(L"EDIT",L"Test",WS_BORDER|WS_VISIBLE|WS_CHILD|WS_TABSTOP|WS_GROUP,10,10,100,15,hWnd,(HMENU)ID_EDIT1,hInst,0);
        break;
      case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        switch (wmId)
        {
        case ID_EDIT1:
          switch(wmEvent){
            case EN_CHANGE:
            //handle change here
              break;
          }
          break;
        default:
          return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
      case WM_DESTROY:
        PostQuitMessage(0);
        break;
      default:
        return DefWindowProc(hWnd, message, wParam, lParam);
      }
      return 0;
    }

  9. #9
    Join Date
    Jan 2010
    Posts
    76

    Re: Peek Message help

    ok that works for the edit box control that you have included with your code.

    but it won't work for the richedit control though

    Code:
    rtfctl = CreateWindow("RICHEDIT","text",WS_BORDER|WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOHSCROLL|WS_VSCROLL|WS_HSCROLL|WS_GROUP,40,30,300,300,MAINSS,(HMENU)ID_EDIT1,hInstance,0);
    I think richedit hates me or something lol.

    Thanks for posting that code btw. It will help me out with other controls too

  10. #10
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Peek Message help

    Rich edit has an event mask that you have to enable for events.

    Add these lines:

    Code:
      rtfctl = CreateWindow("RICHEDIT","text",WS_BORDER|WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOHSCROLL|WS_VSCROLL|WS_HSCROLL|WS_GROUP,40,30,300,300,MAINSS,(HMENU)ID_EDIT1,hInstance,0);
      LRESULT mask=SendMessage(rtfctl,EM_GETEVENTMASK,0,0);
      mask|=ENM_CHANGE;
      SendMessage(rtfctl,EM_SETEVENTMASK,0,(LPARAM)mask);
    
    There's a bunch of other ENM_xxx mask values too. See:

    http://msdn.microsoft.com/en-us/libr...66(VS.85).aspx

  11. #11
    Join Date
    Jan 2010
    Posts
    76

    Re: Peek Message help

    Thank you that works!

    Thanks I appreciate it.

    also what does the "crosses initialization of `int whileline' " mean in DEV?

  12. #12
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Peek Message help

    I don't know. WHat do you mean by "DEV"?

  13. #13
    Join Date
    Jan 2010
    Posts
    76

    Re: Peek Message help

    Dev C++ by Bloodshed I believe.

    I keep getting a lot of these in my projects once in a while.

  14. #14
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Peek Message help

    I've never used DevC++ nor have I seen a warning like that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured