Archived

This topic is now archived and is closed to further replies.

Edit Control Procedure

This topic is 5171 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I''ve been trying for quite a while to implement a callback function for an edit control, so I can do stuff on mouse clicks and key presses, just like you use when you create a window[LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)]. The problem is that the edit class is already registered, and so you can''t set the callback function. (I''m using CreateWindowEx to create the edit box with the classname as "EDIT") I''ve tried sub/superclassing, but it''s too messy and too dangerous(could crash the system if you don''t get to "un"subclass). I''ve tried getting the EDIT class info, and registering my own class based off of it, but was getting errors that didn''t make sense("The system cannot find the file specified" when calling CreateWindowEx with the new registered class). Does anyone know of a better way to go about doing this? I don''t want to use MFC as I am learning the Windows API, and want to stick with it. I am using Dev-c++ if that makes a difference(don''t think so). Thanks a bunch! CD Jesus is Lord!!

Share this post


Link to post
Share on other sites
Subclassing is quite safe, if you do instance subclassing. Just use SetWindowLong (windowHandle, GWL_WNDPROC, myWindowProcedure);.

Global subclassing (using SetClassLong) is more difficult and may hook into other aspects of your app that you don't expect.

For more info: check msdn.



[edited by - Kippesoep on October 15, 2003 5:47:42 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi there!

Heres some working code that does this


WNDPROC DefEditProc; //Possibly global, needs to be accessed by
//your edit control function


HWND editbox=CreateWindowEx(WS_EX_CLIENTEDGE, RICHEDIT_CLASS ,
"", WS_CHILD | WS_VISIBLE |
ES_MULTILINE |ES_READONLY|WS_VSCROLL ,
0, 0, rcClient.right, rcClient.bottom,
windowhwnd,(HMENU)NULL, hInst, NULL);


//store the current edit process in this variable, you will call
//this for your unhandled messages
DefEditProc= (WNDPROC)GetWindowLong(editbox,GWL_WNDPROC);
//Set the edit process for the window
SetWindowLong(editbox, GWL_WNDPROC,(long)MyEditProc);

LRESULT APIENTRY MyEditProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

switch(message)
{
//send unhandled messages to the default editcontrol handler
default:
return( (LRESULT)CallWindowProc((WNDPROC)DefEditProc,hwnd,message,wParam,lParam) );
}
return( (LRESULT)CallWindowProc((WNDPROC)DefEditProc,hwnd,message,wParam,lParam) );

}

Hope that helps

Share this post


Link to post
Share on other sites