I have a user's choice which is set as recent files:
$loc = FileSelectFolder("Choose file location...", "\")
$file = FileOpenDialog("Choose file...", $loc, "Jar Files (*.jar*)")
GUICtrlCreateMenuItem($file, $recentfilesmenu)
I have tried to get the information from it through:
IniWrite("C:\Config.ini", "Recent", "Recent", GUICtrlRead($recentfilesmenu))
But it only gives me the number 68. Where is my mistake?
The number 68 is the controlID of the menu.
You need to use _GUICtrlMenu_GetItemText to read the text of the menu item:
#include <GUIConstantsEx.au3>
#include <GuiMenu.au3>
$hGui = GUICreate('Read Menu Item', 400, 300)
$mnuFile = GUICtrlCreateMenu('&File')
$mnuFileExit = GUICtrlCreateMenuItem('Exit', $mnuFile)
GUISetState()
; read the text of the menu item
$hMenu = _GUICtrlMenu_GetMenu($hGui)
$sText = _GUICtrlMenu_GetItemText($hMenu, $mnuFileExit, False)
MsgBox(0, 'Menu item text', $sText)
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Or $msg = $mnuFileExit Then ExitLoop
WEnd
This outputs: Exit
Update
To pick up Matt's suggestion you can also make use of the advanced parameter for GUICtrlRead which is much shorter:
IniWrite("C:\Config.ini", "Recent", "Recent", GUICtrlRead($recentfilesmenu, 1))
Related
I try to automate procedures in my Oracle MiddleWare Environment and when I get to the bottom of it, where I should click "Run" button (in Cyrrilic), I can't do this with Send, or Control, or Mouse. However, it is third level of the submenu, all other levels work (I know the usual problems with Frames, but it works for other levels, than why?))
The summary from Info is below:
Window <<<<
Title: My Window
Class: SunAwtFrame
Position: 0, 0
Size: 820, 660
Style: 0x16CF0000
ExStyle: 0x00000100
Handle: 0x00171058
Control <<<<
Class:
Instance:
ClassnameNN:
Name:
Advanced (Class):
ID:
Text:
Position:
Size:
ControlClick Coords:
Style:
ExStyle:
Handle: 0x000910F4
Mouse <<<<
Position: 448, 427
Cursor ID: 0
Color: 0xC0FFFF
StatusBar <<<<
ToolsBar <<<<
Visible Text <<<<
Hidden Text <<<<
Local $sLogin = InputBox("Security Check", "Enter your login", "")
Local $sPasswd = InputBox("Security Check", "Enter your password.", "","-")
$oIE = _IECreate("https://******************",0,0,1,1)
$oLinks = _IETagNameGetCollection($oIE, "input")
For $oLink In $oLinks
If String($oLink.type) = "button" And String($oLink.value) = "RUN" Then
_IEAction($oLink, "click")
ExitLoop
EndIf
Next
_IELoadWait($oIE, 1000)
Sleep(15000)
_WinWaitActivate("Oracle Fusion Middleware Forms Services","")
Send($sLogin)
Send("{TAB}")
Send($sPasswd)
Send("{TAB}")
Send("{SHIFTDOWN}prod{SHIFTUP}9{ENTER}")
_WinWaitActivate("My Window","")
Send("{TAB}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}
{DOWN}{UP}{RIGHT}{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{DOWN}{DOWN}{RIGHT}{DOWN}
{DOWN}{DOWN}{DOWN}{DOWN}{RIGHT}{DOWN}{DOWN}{DOWN}{DOWN}{ENTER}")
*//And here it stops working without any error.//
Send("03/01/2019")
Send("{TAB}{TAB}{TAB}")
MouseMove(268,363,25)
MouseClick("primary")
Please note that I cannot change anything at all in Oracle MiddleWare environment or on the server side.
To answer this for your class SunAwtFrame the question is too unclear. But your code has some issues.
_WinWaitActivate() with Sleep(15000) isn't necessary because you can use WinWaitActive($sTitle, $sText, $iTimeout) with a timeout of 15 seconds as third parameter.
Your problem for the stopping should be the line 21. You can not add a new line within a function parameter without using of & _ at the end of the line. Use a function like _sendKeystrokesSeveralTimes() to avoid such long parameter values.
You also could shorten your MouseMove() and then MouseClick() action by doing MouseClick('left', 268, 363) to the target mouse position.
Here a reworked version of your code:
#include-once
#include <IE.au3>
Global $sLogin = InputBox('Security Check', 'Enter your login', '')
Global $sPasswd = InputBox('Security Check', 'Enter your password.', '', '-')
Global $oIE = _IECreate('https://******************', 0, 0, 1, 1)
Global $oLinks = _IETagNameGetCollection($oIE, 'input')
Func _clickButtonRun()
For $oLink In $oLinks
If String($oLink.type) == 'button' And String($oLink.value) == 'RUN' Then
_IEAction($oLink, 'click')
ExitLoop
EndIf
Next
EndFunc
Func _sendKeystrokesSeveralTimes($sKey, $iHowOften = 1)
For $i = 1 To $iHowOften Step 1
Send($sKey)
Sleep(200) ; to increase the robustness wait a bit between each input/send
Next
EndFunc
_clickButtonRun()
_IELoadWait($oIE, 1000)
WinWaitActive('Oracle Fusion Middleware Forms Services', '', 15)
_sendKeystrokesSeveralTimes($sLogin)
_sendKeystrokesSeveralTimes('{TAB}')
_sendKeystrokesSeveralTimes($sPasswd)
_sendKeystrokesSeveralTimes('{TAB}')
_sendKeystrokesSeveralTimes('PROD9')
_sendKeystrokesSeveralTimes('{ENTER}')
WinWaitActive('My Window', '', 5)
_sendKeystrokesSeveralTimes('{TAB}')
_sendKeystrokesSeveralTimes('{DOWN}', 11)
_sendKeystrokesSeveralTimes('{UP}')
_sendKeystrokesSeveralTimes('{RIGHT}')
_sendKeystrokesSeveralTimes('{DOWN}', 4)
_sendKeystrokesSeveralTimes('{RIGHT}')
_sendKeystrokesSeveralTimes('{DOWN}', 2)
_sendKeystrokesSeveralTimes('{RIGHT}')
_sendKeystrokesSeveralTimes('{DOWN}', 5)
_sendKeystrokesSeveralTimes('{RIGHT}')
_sendKeystrokesSeveralTimes('{DOWN}', 4)
_sendKeystrokesSeveralTimes('{ENTER}')
_sendKeystrokesSeveralTimes('03/01/2019')
_sendKeystrokesSeveralTimes('{TAB}', 3)
MouseClick('left', 268, 363)
I am having trouble with the code I am writing. I have a table which lists staff member details. I am trying to have an email address copy to the clipboard when you select a record and right click. I have the following code:
#include <GUIConstantsEx.au3>
#include <mssql.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
global $title = "E-Mail address lookup"
global $name = InputBox($title,"Please type the name of the person you wish to find")
global $sqlCon = _MSSQL_Con("server", "username", "password", "directory-plus")
global $result = _MSSQL_GetRecord($sqlCon, "autoit_view","*", "WHERE cn LIKE '%" & StringStripWS($name,3) & "%'")
if StringLen(StringStripWS($name,3)) < 1 then
MsgBox(0, $title, "Name cannot be empty")
Else
Global $rset = UBound($result) - 1
Global $ControlID = GUICreate($title, 500, 150)
Global $idListview = GUICtrlCreateListView("Deparment|E-Mail Address|Name|Telephone Number", 10, 10, 480, 150)
for $count = 1 to $rset step 1
GUICtrlCreateListViewItem($result[$count][0] & "|" & $result[$count][2] & "|" & $result[$count][1] & "|" & $result[$count][2], $idListview)
if MouseClick($MOUSE_CLICK_RIGHT)==1 Then
ClipPut($result[$count][2])
EndIf
Next
GUISetState(#SW_SHOW)
GUISetState()
While 1
Global $Msg = GUIGetMsg()
Switch $Msg
Case -3, $ControlID
Exit
EndSwitch
WEnd
EndIf
I would have thought my IF statement within the for loop would do the trick but, when I run my code, it just copies whatever is in email address column in the last row when in fact I want it to copy the email address when you right click on a particular row but I'm not sure how to do it.
Your code has two major problems. The first is that MouseClick() doesn't check for the mouse button being pressed, but instead sends a mouse button click. Since sending a mouse button click is going to succeed, MouseClick($MOUSE_CLICK_RIGHT)==1 will evaluate to true. For each list view item you create, you are putting the email address on the clipboard.
The second problem is that the if statement is in the wrong place. It's executed just after you create each list view item.
Instead, change your While statement as follows
While 1
Global $Msg = GUIGetMsg()
Switch $Msg
Case -3, $ControlID
Exit
case $GUI_EVENT_SECONDARYDOWN
$selecteditem=StringSplit(GUICtrlRead(GUICtrlRead($idListview)),"|")
if #error=0 and $selecteditem[0]>1 Then
ClipPut($selecteditem[2])
EndIf
EndSwitch
WEnd
I am working on a project, in which I decided I should have history of previously searched stuff (since it's an app with which you can search stuff), so I have been thinking that I could just create the context menu or regular menu, that I could somehow force to activate on a button click or by using accelerators.
Now, I haven't been able to figure out how to make that work.
First I tried the GuiCtrlSetState() function, which didn't seem to work (I tried show and focus), then I tried accelerators and they didn't do anything.
So I'm wondering is there any way I can make the context menu or regular menu pop up on button press/click or key press (with accelerators)?
So what I'm basically trying to do is some sort of a pop-up, you click on a button or press a key to trigger the context menu or regular menu to open.
I know I could be old school and use a new GUI or just a combo box for the history or anything but I kinda want this, if there's any way to do so.
Any help, or an alternative way of doing the same thing appreciated.
Here's the testing code in which I was trying to make the test button trigger and activate the context menu, and I have tried the same with the regular
menu:
#NoTrayIcon
#include <GUIConstantsEx.au3>
GUICreate("test123")
$but = guictrlcreatebutton("test", -1, -1, -1)
$xt = GUICtrlCreateContextMenu("test context menu")
GUICtrlCreateMenuItem("test1", $xt)
GUICtrlCreateMenuItem("test2", $xt)
GUISetState(#SW_MAXIMIZE)
While 1
$msg = GUIGetMsg()
If $msg = $but Then
GUICtrlSetState($xt, $GUI_FOCUS)
EndIf
Sleep(5)
WEnd
If you check the help file under GUICtrlCreateContextMenu:
; right click on gui to bring up context Menu.
; right click on the "ok" button to bring up a controll specific context menu.
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
GUICreate("My GUI Context Menu", 300, 200)
Local $idContextmenu = GUICtrlCreateContextMenu()
Local $idNewsubmenu = GUICtrlCreateMenu("new", $idContextmenu)
Local $idNewsubmenuText = GUICtrlCreateMenuItem("text", $idNewsubmenu)
Local $idButton = GUICtrlCreateButton("OK", 100, 100, 70, 20)
Local $idButtoncontext = GUICtrlCreateContextMenu($idButton)
Local $idMenuAbout = GUICtrlCreateMenuItem("About button", $idButtoncontext)
Local $idMenuOpen = GUICtrlCreateMenuItem("Open", $idContextmenu)
Local $idMenuSave = GUICtrlCreateMenuItem("Save", $idContextmenu)
GUICtrlCreateMenuItem("", $idContextmenu) ; separator
Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu)
GUISetState(#SW_SHOW)
; Loop until the user exits.
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $idButton
MsgBox($MB_SYSTEMMODAL, "Button Clicked", 'OK')
Case $idMenuAbout
MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'About')
Case $idMenuOpen
MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Open')
Case $idMenuSave
MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Save')
Case $idMenuInfo
MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Info')
Case $idNewsubmenuText
MsgBox($MB_SYSTEMMODAL, "SubMenu Selected", 'Text')
EndSwitch
WEnd
GUIDelete()
EndFunc ;==>Example
I have a GUI that records the list of all the chm in a folder. When 'RUN' button is clicked, it will open the first chm in the list until so on. Then I have created a function that should expand the tree.
My problem is my function, it works until MsgBox() and stops there. When I ran my program there is no error indicated.
#include <GuiConstantsEx.au3>
#include <GuiListBox.au3>
#include <GuiTreeView.au3>
#include <File.au3>
#include <Array.au3>
;GUI
$guiTitle = "Automation"
GUICreate($guiTitle, 250, 430)
Global $hWnd = ControlGetHandle("[CLASS:HH Parent;TITLE:AutoIt Help]", "", "[CLASS:SysTreeView32; INSTANCE:1]")
Global $hChild = _GUICtrlTreeView_GetFirstChild($hWnd, 0)
Local $source = InputBox("Source Folder","Please enter the source folder","")
;InputBox
If #error = 1 Then
Exit
EndIf
If #error = 4 Then
Exit
;GUI_List
Else
$add = GUICtrlCreateButton("Show", 10, 53, 230, 20)
$picList = GUICtrlCreateList("", 10, 78, 230, 300)
$run = GUICtrlCreateButton("Run", 170, 385, 70, 30)
GUISetState(#SW_SHOW)
While 1
$msg = GUIGetMsg()
Switch $msg
;add
Case $add
Global $FileList = _FileListToArray($source, "*.chm")
If #error = 1 Then
MsgBox(0, "", "No Files Found.")
Exit
EndIf
If #error = 4 Then
MsgBox(0, "", "No Files Found.")
Exit
EndIf
For $i = 1 To $FileList[0] ;List_IFIX Pictures
GUICtrlSetData($picList, $FileList[$i])
Next
;run
Case $run
If _GUICtrlListBox_GetCount($picList) = 0 Then
MsgBox(0, "", "No Files Found.")
Else
For $i = 1 To $FileList[0]
If Not WinExists("AutoIT Help]") Then
ShellExecute($source & "\" & $FileList[1])
_Expand($hWnd, $hChild)
EndIf
Next
EndIf
;exit
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
EndIf
And here is my function:
Func _Expand($hWnd, $hChild)
WinWaitActive("AutoIT Help")
MsgBox(0,"","Expand")
While 1
$hChild = _GUICtrlTreeView_GetNextChild($hWnd, $hChild)
If _GUICtrlTreeView_GetText($hWnd, $hChild) = "Tutorials" Then ExitLoop
WEnd
_GUICtrlTreeView_Expand(ControlGetHandle("[CLASS:HH Parent;TITLE:AutoIt Help]","", "[CLASS:SysTreeView32; INSTANCE:1]"),$hchild, True)
EndFunc
Lots of problems with the code.
Check your titles! In two cases you have got the window title spelt incorrectly in your example. AutoIt is spelt with a lowercase t, and window title matching is case sensitive unless you set an option otherwise.
If "Tutorials" is not found then you will loop forever. You should add a check after _GUICtrlTreeView_GetNextChild to see if you've reached the end of the treeview.
But the real problem with your code is that you are setting $hWnd and $hChild at the beginning of the code, before you run the process that creates the window. As a result, the window is not found, and so $hWnd will always be NULL when you call _Expand.
This sort of question is not encouraged on stackoverflow. We like questions which will be useful to other people in the future rather than help with specific code. Before asking questions like this in the future, please try and debug the problem yourself. You could add ConsoleWrite statements through the code showing variable values, which would have shown you that $hWnd didn't have a handle value when you enter expand, from there it is obvious.
Here is my code:
#include <GUIConstantsEx.au3>
GUICreate( "Main", 1200, 700 )
$viewer = ObjCreate( "Shell.Explorer.2" )
GUICtrlCreateObj( $viewer, 5, 5, 1000, 690 )
$viewer.navigate( "url_for_website" )
GUISetState( #SW_SHOW )
$running = 1
While $running
$event = GUIGetMsg()
Switch $event
Case $GUI_EVENT_CLOSE
$running = 0
EndSwitch
WEnd
How would I go about finding user input fields with the code above? A push in the right direction would be very helpful!
This should help you out with understanding as this is a great script for IE. Also, it should give you an idea on how to go about implementing what you'd like to do:: http://www.autoitscript.com/forum/files/file/227-ieau3/