Posts: 763
Threads: 261
Joined: Jul 2012
Is it possible to get the path of a file from any dialogbox that has 'save as' in its window title name above (top left).
Example
other example, if image above isn't displayed:
http://www.blackice.com/images/SaveAsDialog.png
In these examples the dropdownlistbox in the top of the 'save as' dialogbox shows a tree based folder structure where I can't 'get' the path.
If you do a 'save as' in notepad then the top of the 'save as' dialogbox shows a directory path which you can grab:
http://www.tannerwilliamson.com/wp-cont ... rt_two.png
Posts: 12,051
Threads: 140
Joined: Dec 2002
I did not find a reliable way.
On XP should work CDM_GETFILEPATH message, used with __ProcessMemory. Not tested. On Windows 7 does not work.
Other way - get current directory of the process. The dialog sometimes changes current directory, but only sometimes. Not useful.
Posts: 763
Threads: 261
Joined: Jul 2012
Posts: 1,058
Threads: 367
Joined: Oct 2007
Dear Gintaras,
Could you please give an example with CDM_GETFILEPATH message ?
Thanks, Best regards
Posts: 12,051
Threads: 140
Joined: Dec 2002
Function GetPathInOpenSaveDialog
;/
function hwnd [str&sFolder] [str&sFilename]
;Gets folder path and/or filename from an Open or Save As dialog box.
;Error if fails.
;hwnd - handle of the dialog box.
;sFolder - variable that receives current folder.
;sFilename - variable that receives filename. Note that it is raw text of the File name edit box and therefore can be anything.
;REMARKS
;Tested on Windows 7, 8 and XP. May not work on future Windows versions. On XP fails with some dialogs (depends on style).
;EXAMPLE
;int w=win("Open" "#32770")
;str sFolder sFilename
;GetPathInOpenSaveDialog w sFolder sFilename
;out F"{sFolder}\{sFilename}"
if(!IsWindow(hwnd)) end ERR_WINDOW
if _winnt>=6
,Acc a; int c
,if &sFolder
,,c=child("" "Breadcrumb Parent" hwnd)
,,if(c) c=child("" "ToolbarWindow32" c)
,,if(!c) end ERR_FAILED
,,a.Find(c "TOOLBAR" "" "" 0x1005)
,,_s=a.Name
,,int i=find(_s ": "); if(i<0) end ERR_FAILED ;;"Address: ..."
,,sFolder.get(_s i+2)
,if &sFilename
,,c=child("" "Edit" hwnd 0x400 "id=1148") ;;Open
,,if(!c) c=child("" "ComboBox" hwnd 0x400 "cclass=Edit") ;;Save As
,,a.Find(c "TEXT" "" "" 0x1005)
,,sFilename=a.Value
else
,__ProcessMemory m.Alloc(hwnd 1000)
,int n
,if &sFolder
,,n=SendMessageW(hwnd CDM_GETFOLDERPATH 500 m.address); if(n<1) end ERR_FAILED
,,m.ReadStr(sFolder n*2 0 1)
,if &sFilename
,,n=SendMessageW(hwnd CDM_GETSPEC 500 m.address); if(n<1) end ERR_FAILED
,,m.ReadStr(sFilename n*2 0 1)
err+ end _error
Posts: 1,058
Threads: 367
Joined: Oct 2007
Dear Gintaras,
Tested. Perfect! Extremely useful.
I am really indebted.
Best regards
Posts: 1,058
Threads: 367
Joined: Oct 2007
Dear Gintaras,
I have some problems when using this macro, namely :
(a) when opening file in MS-Word-2000 it fails on :
n=SendMessageW(hwnd CDM_GETFOLDERPATH 500 m.address); if(n<1) end ERR_FAILED
(b) when opening file in Acrobat Reader you get values with ireggular characters, probably different code set.
Could you please advise? Furthrmore, could you please comment on the way to get current directory of the process, as advised earlier in the post?
Many thanks, Best Regards.
Posts: 12,051
Threads: 140
Joined: Dec 2002
From CDM_GETFOLDERPATH reference in MSDN:
Quote:The dialog box must have been created with the OFN_EXPLORER flag; otherwise, the message fails.
Probably created without this flag. I don't know how to get path then.
Macro get other process string from PEB - command line, current directory etc
;http://wj32.org/wp/2009/01/24/howto-get-the-command-line-of-processes/
int w=win("Save As" "#32770")
__ProcessMemory m.Alloc(w 1000)
PROCESS_BASIC_INFORMATION pbi
if(NtQueryInformationProcess(m.hprocess 0 &pbi sizeof(pbi) 0)) ret
byte* pp
m.ReadOther(&pp pbi.PebBaseAddress+16 4)
;out pp
UNICODE_STRING us
m.ReadOther(&us pp+0x24 8) ;;current directory
;m.ReadOther(&us pp+0x40 8) ;;command line
;m.ReadOther(&us pp+0x38 8) ;;image path
out us.Length
BSTR b.alloc(us.Length)
m.ReadOther(b.pstr us.Buffer us.Length*2)
out b
;note: this code is only for 32-bit. Tested only on Windows 7.
|