Edit Control Procedure
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!!
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]
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]
Hi there!
Heres some working code that does this
Hope that helps
Heres some working code that does this
WNDPROC DefEditProc; //Possibly global, needs to be accessed by //your edit control functionHWND 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 messagesDefEditProc= (WNDPROC)GetWindowLong(editbox,GWL_WNDPROC); //Set the edit process for the windowSetWindowLong(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 handlerdefault: return( (LRESULT)CallWindowProc((WNDPROC)DefEditProc,hwnd,message,wParam,lParam) );} return( (LRESULT)CallWindowProc((WNDPROC)DefEditProc,hwnd,message,wParam,lParam) ); }
Hope that helps
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement