How to extend the all edit-like control in my code? Any idea?
-
I want to add a item to the right-click popup menu wherever the edit-lick control, which can belong to any program instance. I thought there are two ways maybe, one is change the registry, like some "shell extending" articles in codeproject; two is hooking. But I never touch those two domain before. Can you give me some suggestions? I've got the base info of hooking, but have no good info or source-code of mouse hooking. I have no info of registry. Thanks ahead! with Best Regards, Kamp Huang:)
-
I want to add a item to the right-click popup menu wherever the edit-lick control, which can belong to any program instance. I thought there are two ways maybe, one is change the registry, like some "shell extending" articles in codeproject; two is hooking. But I never touch those two domain before. Can you give me some suggestions? I've got the base info of hooking, but have no good info or source-code of mouse hooking. I have no info of registry. Thanks ahead! with Best Regards, Kamp Huang:)
You can do that with local superclassing. Subclassing is where you replace the windowproc of a window or control after it is created. Local Superclassing is where you register a new class in your process that has the same name as one of the controls that have already been defined. When windows attempts to create a new control that has been superclasses, it will look in the local class definitions before it looks in the global definitions. Here is an example of the code that you can add to make it so that every time that you hit a key in the edit box, a beep will sound. You can make the changes to do what you need to do.
WNDPROC lpfnEditClassProc = NULL;
LRESULT CALLBACK LocalEdit_WndProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
if (msg == WM_CHAR ) {
MessageBeep(-1);
}
return CallWindowProc(lpfnEditClassProc, hwnd, msg, wParam, lParam);
}BOOL CreateLocalEditClass()
{
WNDCLASS wc;if ( lpfnEditClassProc == NULL ) {
GetClassInfo(NULL, "Edit", &wc);
lpfnEditClassProc = (WNDPROC) wc.lpfnWndProc;
wc.lpfnWndProc = LocalEdit_WndProc;
wc.lpszClassName = "Edit";
wc.hInstance = _hInstance;
if (!RegisterClass(&wc))
return FALSE;return TRUE;
}
}void DeleteLocalEditClass()
{
if ( lpfnEditClassProc != NULL ) {
UnregisterClass("Edit", _hInstance);
lpfnEditClassProc = NULL;
}
}If you need to change every edit control in windows to do what you want, you can look into global superclassing, but this is generally not a good idea.
-
You can do that with local superclassing. Subclassing is where you replace the windowproc of a window or control after it is created. Local Superclassing is where you register a new class in your process that has the same name as one of the controls that have already been defined. When windows attempts to create a new control that has been superclasses, it will look in the local class definitions before it looks in the global definitions. Here is an example of the code that you can add to make it so that every time that you hit a key in the edit box, a beep will sound. You can make the changes to do what you need to do.
WNDPROC lpfnEditClassProc = NULL;
LRESULT CALLBACK LocalEdit_WndProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
if (msg == WM_CHAR ) {
MessageBeep(-1);
}
return CallWindowProc(lpfnEditClassProc, hwnd, msg, wParam, lParam);
}BOOL CreateLocalEditClass()
{
WNDCLASS wc;if ( lpfnEditClassProc == NULL ) {
GetClassInfo(NULL, "Edit", &wc);
lpfnEditClassProc = (WNDPROC) wc.lpfnWndProc;
wc.lpfnWndProc = LocalEdit_WndProc;
wc.lpszClassName = "Edit";
wc.hInstance = _hInstance;
if (!RegisterClass(&wc))
return FALSE;return TRUE;
}
}void DeleteLocalEditClass()
{
if ( lpfnEditClassProc != NULL ) {
UnregisterClass("Edit", _hInstance);
lpfnEditClassProc = NULL;
}
}If you need to change every edit control in windows to do what you want, you can look into global superclassing, but this is generally not a good idea.
Oh! :-D New idea! I never thought of that before! But I really need to detect every edit-like controls to get the user selected text. I found that there are some many edit-like control with various class-name. Can I superclassing without specified a class-name? I wondered that. Hooking maybe the best way to do the tast. Thanks anyway!:)