Click to See Complete Forum and Search --> : Peek Message help


Senith
February 24th, 2010, 01:42 AM
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

hoxsiew
February 24th, 2010, 07:34 AM
Why PeekMessage? Can't you just check for EN_CHANGE or EN_UPDATE notification to the parent?

Senith
February 24th, 2010, 10:52 AM
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.

hoxsiew
February 24th, 2010, 12:56 PM
OK, I assume your not using MFC (because of the comment in the OP), so what are you using? The above makes little sense.

Senith
February 24th, 2010, 05:46 PM
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.

hoxsiew
February 24th, 2010, 09:11 PM
I still don't get it. Do you have a message loop? Just handle WM_NOTIFY and check for EN_CHANGE.

Senith
February 24th, 2010, 09:47 PM
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:


/*--*/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;
/*|-*/}

hoxsiew
February 25th, 2010, 08:25 AM
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:


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;
}

Senith
February 25th, 2010, 11:16 AM
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


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 :D

hoxsiew
February 25th, 2010, 12:42 PM
Rich edit has an event mask that you have to enable for events.

Add these lines:


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/library/bb774366(VS.85).aspx

Senith
February 25th, 2010, 02:58 PM
Thank you that works! :D

Thanks I appreciate it.

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

hoxsiew
February 25th, 2010, 03:02 PM
I don't know. WHat do you mean by "DEV"?

Senith
February 25th, 2010, 03:20 PM
Dev C++ by Bloodshed I believe.

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

hoxsiew
February 25th, 2010, 04:02 PM
I've never used DevC++ nor have I seen a warning like that.