AutoHotkey Community

It is currently May 26th, 2012, 11:47 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: September 13th, 2006, 12:48 am 
Offline

Joined: November 17th, 2005, 10:14 pm
Posts: 196
Location: Leicester, UK
Hello

I recently found myself needing to find the full path of a folder in an Open/Save dialogue. Searching the forum brought up nothing and was a big disappointment as it mean't that I had to figure it out for myself. :)

The way that I did it is very crude, but it works (not exactly under the hood).

Happy path getting!
Code:
#O::
wClass = ahk_class #32770
Loop {
   ControlFocus ComboBox1, %wClass%
   ControlGetText DirName, ComboBox1, %wClass%
   StringRight Root, DirName, 4
   StringRight End, Root, 2
   StringLeft Start, Root, 1
   If (Start = "(") and (End = ":)")
   {
      StringLeft Tmp, Root, 2
      StringRight Letter, Tmp, 1
      DirPath = %Letter%:\%DirPath%
      MsgBox The full path of this folder is:- `n" %DirPath% "
      ControlSetText Edit1, %DirPath%, %wClass%
      ControlSend Edit1, {Enter}, %wClass%
      Break
      }
   DirPath = %DirName%\%DirPath%
   ControlFocus SysListView321, %wClass%
   ControlSend SysListView321, {Bs}, %wClass%
   }
DirPath =
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2006, 12:53 am 
Offline

Joined: September 3rd, 2006, 5:34 am
Posts: 601
Location: Iowa, U.S.
Good script, but may I suggest putting this in the script forum?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2006, 8:26 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
You didn't search well. You have it in my Favmenu code. You also have function how to recognise only Open/Save dialogs somewhere in the Scripts, with the example.

Your recognition of window is not good. Hundreeds of windows have 32770 class.

Addapt this code:

Code:
FavMenu_IsOpenSave(dlg)
{
   global FavMenu_dlgInput, FavMenu_dlgType
   
   FavMenu_dlgType =

   toolbar := FavMenu_FindWindowExID(dlg, "ToolbarWindow32", 0x440)   ;windows XP
   if (toolbar = "0")
    toolbar := FavMenu_FindWindowExID(dlg, "ToolbarWindow32", 0x001)  ;windows 2k
   
   combo  := FavMenu_FindWindowExID(dlg, "ComboBoxEx32", 0x47C) ; comboboxex field
   button := FavMenu_FindWindowExID(dlg, "Button", 0x001)      ; second button
   
   edit := FavMenu_FindWindowExID(dlg, "Edit", 0x480)         ; edit field
   
   if (toolbar && (combo || edit) && button)
   {
      FavMenu_dlgInput   := combo + edit
      FavMenu_dlgType      := "OpenSave"
      return 1
   }

   return FavMenu_IsOffice03(dlg)
}

You can return 0 isted dark blue code. Office dialogs are not standard, but story for itself.

GetPath requires RemoteBufffer class, you have it in a scripts.
Code:
FavMenu_DialogGetPath_OS()
{
   global Favmenu_dlgHwnd

   WM_USER = 0x400
   CDM_FIRST := WM_USER + 100
   CDM_GETFOLDERPATH := CDM_FIRST + 0x0002

   bufID := RemoteBuf_Open(Favmenu_dlgHwnd, 256)
   adr := RemoteBuf_GetAdr(bufID)
   SendMessage CDM_GETFOLDERPATH, 256, adr,, ahk_id %Favmenu_dlgHwnd%
   textSize := errorlevel
   if (textSize <= 0)
      return

   VarSetCapacity(buf, 256, 0)
   RemoteBuf_Read(bufID, buf, 256)
   RemoteBuf_Close(bufID)

   VarSetCapacity(ansiString, textSize, 0)
   
   ;Check if Windows returned unicode string. Sine drive letter is first char, it will be ANSI
   ; so unicode can be check by comparing next char to 0
   if *(&buf+1) = 0
         return FavMenu_GetAnsiStringFromUnicodePointer(&buf)
   else   return buf
   
}


Credits for GetAnsiStringFromUnicodePointer go to PhilHo

You can go without RemoteBuffer, similar to what you did, but anyway your code is still not god, since it will workeonly for hard disk, not in Virtual Folders, like My Documents etc.... this code will handle some virtual folders good. My Docs is very important since mass of users keep its data in it (not me)

Code:
;Old implementation of DialogGetPath witch doesn't use Remote Buffer but
; have problem with some virtual folders, like Desktop..
;--------------------------------------------------------------------------
; my recent documents
; desktop
;   my documents
;      <path of any depth>
;   my computer
;     <list of root's - must contain ":" in the name>
;       <path of any depth>
;   my network places
;       IGNORE THIS
;   <desktop folders>
;   ....             IGNORE DESKTOP FOLDERS FOR NOW
;   <desktop folders>
;--------------------------------------------------------------------------
FavMenu_DialogGetPath_OS2()
{
   global FavMenu_dlgHWND, CB_GETLBTEXT

   md := Favmenu_GetSFLabel("My Documents")
   mc := Favmenu_GetSFLabel("My Computer")
   np := Favmenu_GetSFLabel("My Network Places")


;take curently displayed item
   ControlGetText name, ComboBox1, ahk_id %FavMenu_dlgHWND%

;return if shell folder itself is selected
   if (name = md)
      return FavMenu_ConvertPseudoPath("%$PERSONAL%")

   if ( name = mc )
      return ":My Computer"
   
   if (name = np)
      return ":Desktop OR My Network Places"

   StringGetPos idx, name, :
   if !ErrorLevel
   {
      StringMid path, name, idx, 2
      return path
   }
   
;get all combo items
   VarSetCapacity(txt, 256)
   loop
   {
      txt =
      SendMessage, CB_GETLBTEXT, A_Index-1, &txt, ComboBox1, ahk_id %FavMenu_dlgHWND%
      aFolders_%A_Index% = %msg%%txt%

      StringGetPos idx, txt, :
      if !Errorlevel
         root := true

      if (txt = "") or (txt = name)
      {
         aFolders_count := A_Index
         break
      }
   }

;I got the names, find the path, by walking up
   path := name
   loop
   {
      aFolders_count -= 1
      if (aFolders_count = 0)
         return ":"

      folder := aFolders_%aFolders_count%
      if (folder = np)
         return ":Desktop OR My Network Places"

      
      if (root)
         StringGetPos idx, folder,:
      else
         StringGetPos idx, folder, %md%
      

      if (ErrorLevel)
          path = %folder%\%path%
      else
      {
         if (root)
         {
             StringMid drv, folder, idx, 2
             path = %drv%\%path%   
         }
         else path := FavMenu_ConvertPseudoPath("%$PERSONAL%") . "\" . path
         
         break
      }      
   }
   return path
}


Used Functions:


Code:
;------------------------------------------------------------------------------------------------
;Get localised string for virtual folder supplied as an argument on English
;
FavMenu_GetSFLabel( sFolder )
{
   if (sFolder = "My Documents")
      return   Favmenu_GetResString("{450D8FBA-AD25-11D0-98A8-0800361B1103}")
   
   if (sFolder = "My Computer")
      return   Favmenu_GetResString("{20D04FE0-3AEA-1069-A2D8-08002B30309D}")

   if (sFolder = "My Network Places" )
      return   Favmenu_GetResString("{208D2C60-3AEA-1069-A2D7-08002B30309D}")
}

;--------------------------------------------------------------------------

FavMenu_GetResString( p_clsid )
{
   key = SOFTWARE\Classes\CLSID\%p_clsid%
   RegRead res, HKEY_LOCAL_MACHINE, %key%, LocalizedString
   
;get dll and resource id
   StringGetPos idx, res, -, R
    StringMid, resID, res, idx+2, 256
   StringMid, resDll, res, 2, idx - 2
   resDll := FavMenu_ExpandEnvVars(resDll)
   
;get string from resource
   VarSetCapacity(buf, 256)
   hDll := DllCall("LoadLibrary", "str", resDll)
   Result := DllCall("LoadString", "uint", hDll, "uint", resID, "str", buf, "int", 128)

   return buf
}
;------------------------------------------------------------------------------------------------
; Iterate through controls with the same class, find the one with ctrlID and return its handle
; Used for finding a specific control on a dialog

FavMenu_FindWindowExID(dlg, className, ctrlId)
{
   local ctrl, id

   ctrl = 0
   Loop
   {
      ctrl := DllCall("FindWindowEx", "uint", dlg, "uint", ctrl, "str", className, "uint", 0 )
      if (ctrlId = "0")
      {
         return ctrl
      }

      if (ctrl != "0")
      {
         id := DllCall( "GetDlgCtrlID", "uint", ctrl )
         if (id = ctrlId)
            return ctrl            
      }
      else
         return 0
   }
}



Check out the Favmenu to see how it works

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 30th, 2008, 11:09 pm 
Offline

Joined: November 8th, 2004, 12:46 am
Posts: 1271
Is there an alternative way to get the path to CDM_GETFOLDERPATH? I tried this method with a number of programs and most don't seem to create the dialog with the OFN_EXPLORER flag, so the message fails.

The CB_GETLBTEXT method only works when the dialog is first called. I want to be able to change directories and still be able to get the path. I'm using the clipboard method which works but isn't ideal.

Code:
#IfWinActive #32770
   #E::   
   ControlGetFocus, control
   ControlFocus, SysListView321
   Send {Space} ; select
   Clipsaved := ClipboardAll
   Clipboard =
   Send ^c
   Clipwait   
   SplitPath, Clipboard,, dir ; get dir
   Clipboard := Clipsaved
   Clipsaved =
   ControlFocus, %control%
   Run, explorer /e`, %dir%   
   Return
#IfWinActive

_________________
"Anything worth doing is worth doing slowly." - Mae West
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], oldbrother, Rajat and 60 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group