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

Everything else that doesn't fall into one of the other PB categories.
maw

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

Post 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:
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

I believe EnumChildWindowsEx can give you the handles to gadgets.

Its in that win32 api somewhere ;)
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post 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 ;)
Image Image
maw

Post 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:
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post 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 ??
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

maw: why not buying the program and thats just about all? :lol:
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Post Reply