Page 1 of 1

Need help "pressing" Ok-gadget in another program.

Posted: Mon Sep 12, 2005 9:00 pm
by maw
Hi!

My problem is this, I have a program running (not written by me) that opens a requester where I have to answer Ok or Cancel when closing the program. So I need some code to automatically choose Ok whenever the program opens that requester.

The problem? Sometimes the default is Ok and othertimes it's Cancel, so I can't just use PostMessage_ with #VK_Return. The requester doesnt have any keyboard shortcuts either..

Does anyone have any good ideas?

I was thinking along the lines of getting the handle of the gadget with the text Ok, but I have no idea how to enumerate gadgets in a window and could really use an example on this in that case!

I would really appreciate some help! This is driving me nuts :evil:

Posted: Mon Sep 12, 2005 9:36 pm
by dracflamloc
I believe EnumChildWindowsEx can give you the handles to gadgets.

Its in that win32 api somewhere ;)

Posted: Mon Sep 12, 2005 10:10 pm
by Paul
This might be a little more helpful to you and point you in the right direction :)

Open WordPad and type some text. Then close the application.
You will get a "WordPad" message box asking if you want to "Save Changes"
The default answer is "Yes"
Instead of answering the question, run this code.
It will find the "WordPad" messagebox, find the "No" button and press the "Spacebar" to select "No" and close the app.


Code: Select all

NewList Window()

Procedure EnumProc(hwnd,lParam) 
  AddElement(Window())
  Window()=hwnd
  ProcedureReturn 1
EndProcedure

Procedure EnumChildProc(hwnd,lParam) 
  class.s=Space(255)
  GetClassName_(hwnd,@class,255) 
  Buffer.s=Space(255)
  GetWindowText_(hwnd,@Buffer,255)

  If class="Button" And Buffer="&No"
    SetForegroundWindow_(hwnd)	
    keybd_event_(#VK_SPACE,1,0,0)
    keybd_event_(#VK_SPACE,1,#KEYEVENTF_KEYUP,0)
  EndIf

  ProcedureReturn 1
EndProcedure



FindWindow$="WordPad"
ClearList(Window())
If EnumWindows_(@EnumProc(),0)
  ForEach Window()
    Buffer.s=Space(255)
    GetWindowText_(Window(),@Buffer,255) 
    If FindString(Buffer,FindWindow$,1)
      EnumChildWindows_(Window(),@EnumChildProc(),0) 
      Break
    EndIf 
  Next
EndIf

You can also use API commands like SetWindowPos_() and SetWindowText_() to change the size, location and text of Gadgets in other apps once you have the handle... kind cool ;)

Posted: Tue Sep 13, 2005 6:32 pm
by maw
That was just what I needed, Paul!! I could kiss you!! :shock:

Well, a "Thank you very much!" will have to do :lol:

Posted: Tue Sep 13, 2005 9:59 pm
by utopiomania
Hndl = FindWindow_("SciCalc","Calculadora")
Thanks Paul, very good, Is there a way (API_)to find the localised name of hidden apps like:

(calc.exe,charmap.exe, cleanmgr.exe, clipbrd.exe, drwtsn32.exe, dxdiag.exe, eudcedit.exe, iexpress.exe,
mobsync.exe, mplay32.exe, odbcad32.exe, packager.exe, perfmon.exe, progman.exe, rasphone.exe,
regedt32.exe, shrpubw.exe, sigverif.exe, sndvol32.exe, sysedit.exe, syskey.exe, telnet.exe,
winchat.exe, msconfig.exe, etc...)

so I can use them this way ??

Posted: Wed Sep 14, 2005 3:23 am
by dagcrack
maw: why not buying the program and thats just about all? :lol: