LaneH Posted January 9, 2015 Posted January 9, 2015 (edited) I am making a script to accompany the program Microstation that will open up a file in a new instance. Microstation's internal File Open dialog has the word "Open - " followed by the current directory. This directory in the title stays current as you navigate to the file of your choosing. The only way I could think to replicate this was with @WorkingDir and AdlibRegister but to my understanding an open dialog disallows AdlibRegister #include <FileConstants.au3> Func WorkingDir () Global $WorkingDir=@WorkingDir EndFunc WinActivate("[CLASS:MstnTop; INSTANCE:1]", "") WorkingDir() $file=FileOpenDialog("Open - "&$WorkingDir,@WorkingDir, "All (*.*)",$FD_FILEMUSTEXIST + $FD_PATHMUSTEXIST) If $file="" Then Exit Else WinActivate("[CLASS:MstnTop; INSTANCE:1]", "") Send("{ENTER}") Send("newsession "&$file&"{ENTER}") EndIf I don't have the AdlibRegister command in the above code because it wasn't working anyway. It is the reason I made defining $WorkingDir a function though. Is there a simple line I can throw in here to keep @WorkingDir fresh or is this not possible? Thanks Edited January 9, 2015 by LaneH
MyEarth Posted January 10, 2015 Posted January 10, 2015 Take a look here: '?do=embed' frameborder='0' data-embedContent>> Add this line: WinSetTitle($hWndFrom, "", @WorkingDir) Under the Case $CDN_FOLDERCHANGE
LaneH Posted January 12, 2015 Author Posted January 12, 2015 That resulted in the same thing I was getting with my own code. A static window title of the working directory upon opening. Doesn't change as directory does. expandcollapse popup; _FileDialogsEx.au3 example #1: ; create big resizeable file open dialog, defaulting to thumbnails view ; demonstrates how to set size/position of dialog window, how to set default view mode for listview. #include <WindowsConstants.au3> #include <WinAPI.au3> #include "_FileDialogsEx.au3" Global $f_CDN_Start = 1 $Return = _FileOpenDialogEx("Open - "&@WorkingDir, @WorkingDir, "All Files (*.*)", BitOR($OFN_ENABLESIZING,$OFN_ALLOWMULTISELECT), "", 0, "_OFN_HookProc") If @error Then ConsoleWrite('No file selected.' & @CRLF) Else ConsoleWrite($Return & @CRLF) EndIf Func _OFN_HookProc($hWnd, $Msg, $wParam, $lParam) Switch $Msg Case $WM_NOTIFY Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate("hwnd hWndFrom;int idFrom;int code", $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iIDFrom = DllStructGetData($tNMHDR, "idFrom") $iCode = DllStructGetData($tNMHDR, "code") Switch $iCode Case $CDN_INITDONE Case $CDN_FOLDERCHANGE WinSetTitle($hWndFrom, "", @WorkingDir) If $f_CDN_Start Then;if executing first time Local $hODLV = _FindWindowEx($hWndFrom, 0, "SHELLDLL_DefView", "") If $hODLV <> 0 Then DllCall('user32.dll','int','SendMessage','hwnd',$hODLV,'uint',$WM_COMMAND,'wparam',$ODM_VIEW_THUMBS,'lparam',0) EndIf WinMove($hWndFrom, "", 0,0, 800,600, 0) $f_CDN_Start = 0;to make sure these tweaks happens only once. EndIf Case $CDN_SELCHANGE Case $CDN_FILEOK EndSwitch Case Else EndSwitch EndFunc Func _FindWindowEx($hWndParent,$hWndChildAfter,$sClassName,$sWinTitle="") Local $aRet = DllCall('user32.dll','hwnd','FindWindowEx', 'hwnd', $hWndParent,'hwnd',$hWndChildAfter,'str',$sClassName,'str',$sWinTitle) If $aRet[0] = 0 Then ConsoleWrite('_FindWindowEx() Error : ' & _WinAPI_GetLastErrorMessage()) Return $aRet[0] EndFunc Exit Did I not do what you meant?
TouchOdeath Posted January 13, 2015 Posted January 13, 2015 I think what your asking is you want the fileopen dialog title to change as you navigate through directories. If this is the case then ya AdlibRegister wouldn't work because FileOpenDialog pauses the script until a file is picked. In this case you have two options: 1. You can do a search for multithread and make a multithread application 2. The easier approach would be to create a seperate autoit program to monitor the FileOpenDialog window, probably use WingetText along with AutoItSetOption("WinDetectHiddenText", 1), and then use WinSetTitle as suggested by MyEarth.
MyEarth Posted January 13, 2015 Posted January 13, 2015 (edited) This is an alternative, work for me like my first does: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIComboBoxEx.au3> Global $hOTitle, $hCTitle, $hITitle = "[CLASS:#32770;TITLE:" & @WindowsDir & "]" $hGUI = GUICreate("MY_GUI", 200, 110, -1, -1) $hButton = GUICtrlCreateButton("FileOpenDialog", 52, 40, 100, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $hButton _FileOpenDialog() EndSwitch _ChangeTitle() WEnd GUIDelete($hGUI) Func _FileOpenDialog() Run(@AutoItExe & ' /AutoIt3ExecuteLine "' & "FileOpenDialog(@WindowsDir, @WindowsDir & '\', 'Images (*.jpg;*.bmp)', 1 + 4, '', WinGetHandle('MY_GUI', ''))" & '"') WinWait($hITitle) Return 1 EndFunc ;==>_FileOpenDialog Func _ChangeTitle() If WinExists($hITitle, "") Then $hCTitle = _OpenSaveDialog_GetPath_ComboMode($hITitle) If $hOTitle <> $hCTitle Then WinSetTitle($hOTitle, "", $hCTitle) $hOTitle = $hCTitle $hITitle = "[CLASS:#32770;TITLE:" & $hCTitle & "]" EndIf EndIf EndFunc Func _OpenSaveDialog_GetPath_ComboMode($sTitle = "[CLASS:#32770]") ; by MrCreator Local $sRet_Path = "", $hCombo, $iIndex, $sCurrent_Text $hCombo = ControlGetHandle($sTitle, "", "ComboBox1") $iIndex = _GUICtrlComboBoxEx_GetCurSel($hCombo) For $i = $iIndex To 0 Step -1 $sCurrent_Text = "" _GUICtrlComboBoxEx_GetItemText($hCombo, $i, $sCurrent_Text) If StringRegExp($sCurrent_Text, "(?i)[a-z]:") Then $sRet_Path = StringRegExpReplace($sCurrent_Text, "(?i).*([a-z]):\).*", "\1") & ":\" & $sRet_Path If StringLen($sRet_Path) = 3 Then Return $sRet_Path ; Addition for C:\ MyEarth Return StringRegExpReplace($sRet_Path, "\\$", "") EndIf $sRet_Path = $sCurrent_Text & "\" & $sRet_Path Next $sCurrent_Text = "" _GUICtrlComboBoxEx_GetItemText($hCombo, $iIndex, $sCurrent_Text) If $sCurrent_Text = "" Then Return SetError(1, 0, "") Return $sCurrent_Text EndFunc ;==>_OpenSaveDialog_GetPath_ComboMode Edited January 13, 2015 by MyEarth
LaneH Posted January 13, 2015 Author Posted January 13, 2015 MyEarth, are you testing these before you post? That code results in a static title as well. Are you understanding what I'm trying to do here? TouchODeath, thanks for the suggestions. Was definitely hoping for a simpler solution, but I suppose a more difficult one is more fun to accomplish. I'll post how I eventually achieve this if and when I can.
johnmcloud Posted January 13, 2015 Posted January 13, 2015 (edited) Maybe he use a different OS then you? Try this: Func _ChangeTitle() If WinExists($hITitle, "") Then ;~ $hCTitle = _OpenSaveDialog_GetPath_ComboMode($hITitle) $hCTitle = ControlGetText($hITitle, "", "[CLASS:ToolbarWindow32; INSTANCE:2]") ConsoleWrite($hCTitle) If $hOTitle <> $hCTitle Then WinSetTitle($hOTitle, "", $hCTitle) $hOTitle = $hCTitle $hITitle = "[CLASS:#32770;TITLE:" & $hCTitle & "]" EndIf EndIf EndFunc If you have a x64 don't forget to run the script as x64 EDIT: Also _FileDialogsEx work fine on my x64 W7 ( only if run it with 32Bit version ) the title change everytime i'll navigate into a new folder and i prefer that instead of the second example but both work. Edited January 13, 2015 by johnmcloud
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