Page 1 of 7 123 ... LastLast
Results 1 to 10 of 70

Thread: clicking a button

  1. #1
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default clicking a button

    Quick question here. Let's assume we have a program running that has several buttons on an application. You want to automate a process without having to press that button each time. How would you go about doing it? I know there are apps that record macro's, but it just seems like they're kinda glitchy. Here is basically a psuedo code of what I'm thinking...

    shellexecute() start the application I want
    use findwindow() to make sure the process I started up above is running and found
    Once I have the process and the window, assuming I want to press the "next" button programatically how would I do that? I think there is a sendkey() function but can I do that to a specific button

    for example if strcmp on button == "Next"
    sendkey(mouse click)

    then it takes me to the next screen then I do something like
    if strcmp on button == "Continue"
    sendkey(mouse click)

    and so on. Hope this makes sense

  2. #2

  3. #3
    Über Prodigy & Developer Razo[R]apiD's Avatar
    Join Date
    May 2010
    Location
    Poland, Lublin
    Posts
    3,257

    Default

    SendMessage, PostMessage

    In Windows, button is also a window. BM_CLICK message, or WM_LBUTTONDOWN and WM_LBUTTONUP as a message.

    You should be able to find a button with FindWindow or FindWindowEx by it's class or caption.

  4. #4
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    Quick question. So here is a screenshot of 1 of the shots.Click image for larger version. 

Name:	exclaimer.png 
Views:	19 
Size:	40.3 KB 
ID:	584

    If you can see it, the left side I have to select the folder that I need to scan images from.
    The path is \\earth\corp\pics which is down the list, how can I send that as a command?

    The 2nd image is thisClick image for larger version. 

Name:	images2.png 
Views:	14 
Size:	38.2 KB 
ID:	585

    However, as you can see the path is grayed out,s o I would probably have to hook the application to modify that field or enable it correct?

    BTW, in the first image, even if I were to tab, it doesn't allow me to tab through the brower folder list section so that's not an option. I would actually have to send mouse events I would imagine to scroll through the application.

  5. #5
    Über Prodigy & Developer Razo[R]apiD's Avatar
    Join Date
    May 2010
    Location
    Poland, Lublin
    Posts
    3,257

    Default

    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    http://msdn.microsoft.com/en-us/libr...system_defined

    You can send different messages to control all WinAPI buttons/widgets/controls

  6. #6
    Über Prodigy & Developer Razo[R]apiD's Avatar
    Join Date
    May 2010
    Location
    Poland, Lublin
    Posts
    3,257

    Default

    You may be more interested in Tree View http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx than in List View

  7. #7
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    So here is a basic overview of what I have

    Code:
    	//Main handle to AD Pictures
    	HWND myTitle = FindWindowTitleContains("AD Pictures by Exclaimer");
    	HWND myClass = FindWindowClassContains("#32770");
    	HWND application = FindWindow("#32770", "AD Pictures by Exclaimer");
    	//Next button
    	HWND nextButton = FindWindow("Button", "&Next >");
    
    
    	//Import Multiple Pictures
    	HWND radio1 = FindWindow("Button", "Import Multiple Images");
    
    
    	//Handle for the SysTreeView32 Form
    	HWND TreeView = FindWindowEx(myClass, NULL, "SysTreeView32", NULL);
    
            //Start our application "AD Pictures"
    	ShellExecute(NULL, "open", "c:\\Program Files\\AD Pictures\\AD Pictures.exe", NULL, NULL, SW_SHOWNORMAL);
    
    
            if(application)
    	{
    		//MessageBox(0, "TestZZZ", "Found Window", MB_OK);
    		if(nextButton)
    		{
    			MessageBox(0, "Test1", "Found Window", MB_OK);
    			SendMessage(nextButton, BM_CLICK, 0, 0);
    		}
    		else if(radio1)
    		{
    			MessageBox(0, "Test2", "Found Window", MB_OK);
    			SendMessage(radio1, BM_CLICK, 0, 0);
    			SendMessage(nextButton, BM_CLICK, 0, 0);
    		}
    		else if(TreeView)
    		{
    			MessageBox(0, "Test3", "Found Window", MB_OK);
    			treeItem = SendMessage(TreeView, TVM_GETNEXTITEM, TVGN_ROOT, 0);
    			treeItem = SendMessage(TreeView, TVM_GETNEXTITEM, TVGN_NEXT, treeItem);
    			treeItem = SendMessage(TreeView, TVM_GETNEXTITEM, TVGN_CHILD, treeItem);
    			SendMessage(TreeView, TVM_SELECTITEM, TVGN_CARET, treeItem);
    		}
    	}
    Does this look correct? It doesn't seem to be emulating anything for me.

  8. #8
    Über Prodigy & Developer Razo[R]apiD's Avatar
    Join Date
    May 2010
    Location
    Poland, Lublin
    Posts
    3,257

    Default

    Why you try to find the buttons and window before starting the app itself? It won't work imho.

  9. #9
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    OMFG, You're right. Christ I'm an idiot. Let's pretend I didn't just do that haha. I'm so used to initializing and setting stuff globally that I forgot I'm searching for the window before actually starting the app. haha. Of course it won't work properly. Let me move the shellexecute() above and try again.

    So I made the obvious changes and I get the messagebox for Testzzz, but not any of the other window handles. ??

  10. #10
    Über Prodigy & Developer Razo[R]apiD's Avatar
    Join Date
    May 2010
    Location
    Poland, Lublin
    Posts
    3,257

    Default

    Use this: http://speedy.sh/5tcKq/EnumWnd.exe

    It will enumerate all windows titles togheter with their classes. If a Window contains some child windows, you will be able to unwrap the tree.

    After finding main app window with FindWindow, you should use FindWindowEx to search in that window for specified child elements.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •