otti
asked on
Send accelerators to applications.
Hello!
I want to send i.e to Notepad the accelerator for
"Select all" (ctrl-a). How to do it ?
I tried "GetMenu" and got the handle of the menuitem and send then the WM_COMMAND message. This works fine, but i need it for differnet apps and searching everytime the handle of the menuitem is not the best way.
I'm using Delphi2.0 with WIN95 and WinNT4.0
Thanks in advance!
Bye, Sascha
I want to send i.e to Notepad the accelerator for
"Select all" (ctrl-a). How to do it ?
I tried "GetMenu" and got the handle of the menuitem and send then the WM_COMMAND message. This works fine, but i need it for differnet apps and searching everytime the handle of the menuitem is not the best way.
I'm using Delphi2.0 with WIN95 and WinNT4.0
Thanks in advance!
Bye, Sascha
ASKER
Hi Jim!
I tried it with WM_COPY too, but it only works with Notepad. It should work with all apps, like MS Outlook Express, Agent, Eduroa, InternetMail... (To get the windowhandle is not my problem)
Notepad is only one window, but i.E. Outlook Express have a MainWindow, with some child windows. Simply send the EM_SETSEL and WM_COPY message to the Handle of the child window (The control) dosen't work. I don't know why.
The best soulution for me is really send the accelerator to the main window, so i don't have to look for all child windows and search for the control which has the text i want to copy.
Any hint?
Bye, Sascha
I tried it with WM_COPY too, but it only works with Notepad. It should work with all apps, like MS Outlook Express, Agent, Eduroa, InternetMail... (To get the windowhandle is not my problem)
Notepad is only one window, but i.E. Outlook Express have a MainWindow, with some child windows. Simply send the EM_SETSEL and WM_COPY message to the Handle of the child window (The control) dosen't work. I don't know why.
The best soulution for me is really send the accelerator to the main window, so i don't have to look for all child windows and search for the control which has the text i want to copy.
Any hint?
Bye, Sascha
Different apps use different keys for select all text. Some use Ctrl+A, others (e.g. Notepad) don't have any shortcut keys, but rely on menu items only. There is no universal way of telling any given app to select all the text and copy to clipbrd.
I think that your Outlook sample wasn't working because you're sending the messages to the wrong child window. I tried it in Delphi by hardcoding the window handle (which I got using VC++ Spy++ program) and the text was selected perfectly.
JB
I think that your Outlook sample wasn't working because you're sending the messages to the wrong child window. I tried it in Delphi by hardcoding the window handle (which I got using VC++ Spy++ program) and the text was selected perfectly.
JB
ASKER
Hi Jim!
Yes op course, use differnet apps differnet accs. but i want to make userconfiguarble. The user has the choise which keystroke he want to send to the app.
The only problem is that i don't know how to send accelerators.
I'm wondering that it works at you.
I'm using Winsight to got the Windowclass of the Childwindow, i tried to send the messages to the windows with the Classname "ATH_Note", "Ath_DocHost" and "Internet Explorer_Server".
Nothing works.
To which childwindow (Windowclass) do you sent the message?
My way to get the windowhandles:
MainHandle:=FindWindowEx(0 ,0,'ATH_No te'+#0,nil );
Childhandle:=FindWindowEx( MainHandle ,0,'Ath_Do cHost'+#0, nil);
Childhandle2:=FindWindowEx (Childhand le,0,'Inte rnet Explorer_Server'+#0,nil);
SendMessage(Childhandle2,. ...)
Bye, Sascha
Yes op course, use differnet apps differnet accs. but i want to make userconfiguarble. The user has the choise which keystroke he want to send to the app.
The only problem is that i don't know how to send accelerators.
I'm wondering that it works at you.
I'm using Winsight to got the Windowclass of the Childwindow, i tried to send the messages to the windows with the Classname "ATH_Note", "Ath_DocHost" and "Internet Explorer_Server".
Nothing works.
To which childwindow (Windowclass) do you sent the message?
My way to get the windowhandles:
MainHandle:=FindWindowEx(0
Childhandle:=FindWindowEx(
Childhandle2:=FindWindowEx
SendMessage(Childhandle2,.
Bye, Sascha
Hi
I only used the FindWindow method for Notepad (in my example above). For the Outlook sample I used Spy++ to find the window handle, then I hard-coded the window handle:
var
h: THandle;
begin
h := $878; // Used Spy++ to get this handle.
SendMessage(h, EM_SETSEL, 0, 65535);
end;
This selected all the text in the outlook window.
I just did this as a test because you said that your Outlook example doesn't work. The Outlook test I did only works because I was sending the msg to the correct window, but I cheated in getting the window handle...
JB
I only used the FindWindow method for Notepad (in my example above). For the Outlook sample I used Spy++ to find the window handle, then I hard-coded the window handle:
var
h: THandle;
begin
h := $878; // Used Spy++ to get this handle.
SendMessage(h, EM_SETSEL, 0, 65535);
end;
This selected all the text in the outlook window.
I just did this as a test because you said that your Outlook example doesn't work. The Outlook test I did only works because I was sending the msg to the correct window, but I cheated in getting the window handle...
JB
ASKER
Hi!
I understand that you hardcoded the handle, but if i try this it doesen't work :-(
Winsight tells me the Windowclassname, does this Spy++, too??
If yes, please tell me the windowclassname of the handle you used. (The Windowclass is uniqe - so i can check if i used the wrong childwindowhandle).
I tried it with the window which appear if you doubleclick on a message, you too?
Bye, Sascha
If we can get this work at my computer it would be great.
I understand that you hardcoded the handle, but if i try this it doesen't work :-(
Winsight tells me the Windowclassname, does this Spy++, too??
If yes, please tell me the windowclassname of the handle you used. (The Windowclass is uniqe - so i can check if i used the wrong childwindowhandle).
I tried it with the window which appear if you doubleclick on a message, you too?
Bye, Sascha
If we can get this work at my computer it would be great.
ASKER
Adjusted points to 200
Hi
I set it to the childwindow, which has WindowClass "RichEdit20A".
JB
I set it to the childwindow, which has WindowClass "RichEdit20A".
JB
ASKER
Hi!
Winsight don't show any Windowclass called "RichEdit20A" :-((
Seems to be a really hard problem.
Winsight don't show any Windowclass called "RichEdit20A" :-((
Seems to be a really hard problem.
Mmm...
Using Spy++ I see that when you press Ctrl+A in Outlook, the parent window gets the following msgs:
WM_KEYDOWN: VK_CONTROL
WM_KEYDOWN: Ord('A')
WM_KEYUP: Ord('A')
WM_KEYUP: VK_CONTROL
But when I send these messages manually to Outlook nothing happens!! I will try more later (got a bit of work to do now) and let you know if I come up with anything...
JB
Using Spy++ I see that when you press Ctrl+A in Outlook, the parent window gets the following msgs:
WM_KEYDOWN: VK_CONTROL
WM_KEYDOWN: Ord('A')
WM_KEYUP: Ord('A')
WM_KEYUP: VK_CONTROL
But when I send these messages manually to Outlook nothing happens!! I will try more later (got a bit of work to do now) and let you know if I come up with anything...
JB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi !
I tried your source, but only notepad selects all the text if i used this source. The most other apps i tried don't.
I found the answer by myself - i used:
Handle:=GetForegroundWindo w;
PostMessage(Handle,WM_KEYD OWN,VK_CON TROL,0);
PostMessage(Handle,WM_KEYD OWN,$41,0) ;
Simple, isn't it?
But in some applications this not worked, so i tried to use the keybd_event that you have used - now everything works fine!
Thank you all for your help!
Sascha
I tried your source, but only notepad selects all the text if i used this source. The most other apps i tried don't.
I found the answer by myself - i used:
Handle:=GetForegroundWindo
PostMessage(Handle,WM_KEYD
PostMessage(Handle,WM_KEYD
Simple, isn't it?
But in some applications this not worked, so i tried to use the keybd_event that you have used - now everything works fine!
Thank you all for your help!
Sascha
Another way is to use FindWindow to get the handle of the window. You need to know the window class name and optionally the window caption too.
procedure NotepadSelectCopy;
var
hNotePad: THandle;
begin
// To send to 1st found instance of Notepad
hNotePad := FindWindow(PChar('Notepad'
// If you know the window caption (e.g. "Untitled - Notepad")you could use:
// hNotePad := FindWindow(PChar('Notepad'
if (hNotePad > 0) then begin
hNotePad := GetTopWindow(hNotePad);
if (hNotePad > 0) then begin
SendMessage(hNotePad, EM_SETSEL, 0, 65535);
SendMessage(hNotePad, WM_COPY, 0, 0);
end;
end;
end;
JB