Click to See Complete Forum and Search --> : Simulate click on Toolbar button programmatically
sohail_k
August 25th, 2004, 08:42 AM
Hi,
I have a VB application that contains a toolbar.
I want to write an application (using Win32 API) that will simulate a click on the VB application toolbar button.
I have enumerated all the windows and found my VB app window. Then I enumerated the child windows of VB app and got a handle to its Toolbar.
Now when I use SendMessage(toolbarHandle, TB_PRESSBUTTON,1,MAKELONG(TRUE,0));
Fails.
Also other messages to VB app toolbar fail using SendMessage.
Can someone please tell me how to do it.
Thanks in advance
JohnCz
August 25th, 2004, 09:21 AM
I would suggest mouse_event (superseded) or SendInput API (User32.dll).
sohail_k
August 25th, 2004, 10:13 AM
Thanks John,
I'll try that and let you know if it worked for me.
Bond
August 25th, 2004, 10:55 AM
I've done this a number of times:
RECT rc;
SendMessage(hToolbar, TB_GETITEMRECT, iIndex, (LPARAM) &rc);
PostMessage(hToolbar, WM_LBUTTONDOWN, NULL, MAKELPARAM(rc.left, rc.top));
(Edit: though not from VB)
kirants
August 25th, 2004, 06:57 PM
If the toolbar action results in a WM_COMMAND, why not send a WM_COMMAND to the toolbar's owner instead of sending the toolbar some mesage and then the toolbar sending a WM_COMMAND to it's owner ?
sohail_k
August 26th, 2004, 12:56 AM
Hi JohnCz,
I check SendInput API, I think it will work for me, but the problem is that I have to know the mouse co-ordinates i want to click on.
If I don't find any other way to do it then I'll use SendInput. Thanks.
Have a nice day
sohail_k
August 26th, 2004, 12:57 AM
Hi Bond,
RECT rc;
SendMessage(hToolbar, TB_GETITEMRECT, iIndex, (LPARAM) &rc);
PostMessage(hToolbar, WM_LBUTTONDOWN, NULL, MAKELPARAM(rc.left, rc.top));
doesn't work for me.
Is it because VB uses an ActiveX control????
Any idea?
jesusFernandez
December 3rd, 2007, 11:52 AM
you've got to run it in the same process, try so:
DWORD dwProcessID;
SIZE_T nNumberOfBytesRead;
GetWindowThreadProcessId((HWND)manejador, &dwProcessID);
HANDLE hProcess=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE,false,dwProcessID);
void* Pointer=VirtualAllocEx(hProcess,NULL,4096,MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);
RECT bi;
SendMessage((HWND)manejador, TB_GETITEMRECT, indiceBoton, (LPARAM) Pointer);
ReadProcessMemory(hProcess, (Pointer),&bi,sizeof(bi),&nNumberOfBytesRead);
PostMessage((HWND)manejador, WM_LBUTTONDOWN, NULL, MAKELPARAM(bi.left, bi.top));
PostMessage((HWND)manejador, WM_LBUTTONUP, NULL, MAKELPARAM(bi.left, bi.top));
Kargo
July 7th, 2010, 11:00 AM
Hi,
I dont know how to implement your code in my application.In my case the problem is i have created a add-in application with commandbar button for Outlook. Through this button click i want to execute the Dynamic CRM TrackIn button. The bellow code is working when i am using it in console application or windows application.when i am using this code in Add-In application its not getting fired. So i thought of going your way but i dont know how to use that. Can you please give me a code to reach my target.
Microsoft.Office.Interop.Outlook._Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook._Explorer oExp = oApp.ActiveExplorer();
Microsoft.Office.Core._CommandBars oCmdBars = oExp.CommandBars;
Office.CommandBar oCmdBar = oCmdBars["Microsoft Dynamics CRM "];
Office.CommandBarControls oBarCrls = oCmdBar.Controls;
Office.CommandBarButton oSendReceiveAll = (Office.CommandBarButton)oBarCrls["Tr&ack in CRM"];
oSendReceiveAll.Execute();
Please help me.
Thanks in advance
Kargo.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.