wolfbartels Posted November 6, 2006 Share Posted November 6, 2006 I have a script that runs an application. This application opens a dialog of its own with 'Yes, No, Cancel'. How can I find out which button the user pressed on the dialog? All usual technics in AutoIt work only with dialogs opend by AutoIt and not by an application. Link to comment Share on other sites More sharing options...
stampy Posted November 6, 2006 Share Posted November 6, 2006 I've had to do similar things. i think i used WinActive to trap for the window then ControlGetFocus to trap for the control. Link to comment Share on other sites More sharing options...
PaulIA Posted November 6, 2006 Share Posted November 6, 2006 I've had to do similar things. i think i used WinActive to trap for the window then ControlGetFocus to trap for the control.How could you do this on a dialog? The focus is going to shift back to the parent as soon as you click any of the buttons. Auto3Lib: A library of over 1200 functions for AutoIt Link to comment Share on other sites More sharing options...
stampy Posted November 6, 2006 Share Posted November 6, 2006 How could you do this on a dialog? The focus is going to shift back to the parent as soon as you click any of the buttons.A very good point. hmmm... It's got to be possible ... everything is possible Link to comment Share on other sites More sharing options...
MHz Posted November 6, 2006 Share Posted November 6, 2006 You could send in your own MsgBox and transfer the operation clicked to the other MsgBox. This gives you the info of which button was pressed. Example Opt('WinWaitDelay', 10) ; MsgBox example from external program $line = "MsgBox(4,'msg-test','some text')" Run('"' & @AutoItExe & '" /AutoIt3ExecuteLine "' & $line & '"') ; Control MsgBox with Script MsgBox If WinWait('msg-test', '', 5) Then WinSetState('msg-test', '', @SW_HIDE) $result = MsgBox(4, '', 'Choose') WinSetState('msg-test', '', @SW_SHOW) If $result = 6 Then ControlClick('msg-test', '', 'Button1') $result = 'Yes' Else ControlClick('msg-test', '', 'Button2') $result = 'No' EndIf MsgBox(0, '', 'User clicked id: ' & $result) EndIf Link to comment Share on other sites More sharing options...
wolfbartels Posted November 6, 2006 Author Share Posted November 6, 2006 You could send in your own MsgBox and transfer the operation clicked to the other MsgBox. This gives you the info of which button was pressed.Thanks for the hint. I thought of this by myself, but hoped there would be an easier way.Wolf Bartels Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 6, 2006 Moderators Share Posted November 6, 2006 (edited) You can try the below... mind you... I haven't tested it.;Assuming the ClassNameNN's of the Dialog buttons are Button1 to Button3 ;Button1 = Yes / Button2 = No / Button3 = Cancel While 1 If _DialogDetectClick('Dialog Title', 1) Then MsgBox(64, 'Info', 'Yes was pressed') If _DialogDetectClick('Dialog Title', 2) Then MsgBox(64, 'Inof', 'No was pressed') If _DialogDetectClick('Dialog Title', 3) Then MsgBox(64, 'Info', 'Cancel was pressed') Sleep(100) WEnd Func _DialogDetectClick($hWnd, $iButton) If IsString($hWnd) Then $hWnd = WinGetHandle($hWnd) $OptMCM = Opt('MouseCoordMode', 2) Local $sPrimary = '01' If Int(RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons")) = 1 Then $sPrimary = '02' Local $aCpos = ControlGetPos($hWnd, '', 'Button' & $iButton) Local $aMpos = MouseGetPos() Opt('MouseCoordMode', $OptMCM) If Not _IsPressed($sPrimary) Then Return SetError(1, 0, 0) Return _MouseInRegion($aMpos, $aCpos) EndFunc Func _MouseInRegion($aMpos, $aCpos) If Not IsArray($aMpos) Or Not IsArray($aCpos) Then Return SetError(1, 0, 0) If $aMpos[0] >= $aCpos[0] _ And $aMpos[0] <= $aCpos[0] + $aCpos[2] _ And $aMpos[1] >= $aCpos[1] _ And $aMpos[1] <= $aCpos[1] + $aCpos[3] Then Return 1 EndIf Return SetError(2, 0, 0) EndFunc Func _IsPressed($v_R, $v_dll = 'user32.dll') $v_R = DllCall($v_dll, 'int', 'GetAsyncKeyState', 'int', '0x' & $v_R) Return (Not @error And BitAND($v_R[0], 0x8000) = 0x8000) * 1 EndFunc Edit: Forgot a return. Edit2: Decided to test it, the above works fine (had to revise it a bit). Edited November 6, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now