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
PhilHoYou 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