Вроде дошло, но скрипт зависает при выборе файла.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
DetectHiddenWindows, On
VarSetCapacity(OPENFILENAMEW, (cbOFN := A_PtrSize == 8 ? 152 : 88), 0)
NumPut(cbOFN, OPENFILENAMEW,, "UInt") ; lStructSize
NumPut(A_ScriptHwnd, OPENFILENAMEW, A_PtrSize, "Ptr") ; hwndOwner
filters := [ "Text Documents", "*.txt"
,"Test", "*.nfo"
,"All files", "*.*"]
if (IsObject(filters) && Mod(filters.MaxIndex(), 2) == 0) {
finalFilterString := ""
for _, filter in filters
finalFilterString .= Mod(A_Index, 2) ? filter . " (" : filter . ")|" . filter . "|"
while ((char := DllCall("ntdll\wcsrchr", "Ptr", &finalFilterString, "UShort", Asc("|"), "CDecl Ptr")))
NumPut(0, char+0,, "UShort")
NumPut(&finalFilterString, OPENFILENAMEW, A_PtrSize*3, "Ptr") ; lpstrCustomFilter
NumPut(1, OPENFILENAMEW, A_PtrSize*(5 + (A_PtrSize == 4)), "UInt") ; nFilterIndex
}
VarSetCapacity(vPath, (260+2)*2, 0) ; if keeping the option to select multiple files, consider raising the size
vPath .= "*.txt"
NumPut(&vPath, OPENFILENAMEW, A_PtrSize*(6 + (A_PtrSize == 4)), "Ptr") ; lpstrFile
NumPut(260, OPENFILENAMEW, A_PtrSize*(7 + (A_PtrSize == 4)), "UInt") ; nMaxFile
initialDir := A_Desktop
title := "Open"
NumPut(&initialDir, OPENFILENAMEW, A_PtrSize*(10 + (A_PtrSize == 4)), "Ptr") ; lpstrInitialDir
NumPut(&title, OPENFILENAMEW, A_PtrSize*(11 + (A_PtrSize == 4)), "Ptr") ; lpstrTitle
NumPut((cb := RegisterCallback("OFNHookProc")), OPENFILENAMEW, A_PtrSize == 8 ? 120 : 68, "Ptr")
;OFN_ENABLESIZING := 0x00800000
;OFN_EXPLORER := 0x00080000
;OFN_ALLOWMULTISELECT := 0x00000200
;OFN_ENABLEHOOK := 0x00000020
;OFN_HIDEREADONLY := 0x00000004
vOFNFlags := 0x00880024
NumPut(vOFNFlags, OPENFILENAMEW, A_PtrSize*(12 + (A_PtrSize == 4)), "UInt") ; Flags
if (DllCall("comdlg32\GetOpenFileNameW", "Ptr", &OPENFILENAMEW)) {
dirOrFile := StrGet(&vPath,, "UTF-16")
if (InStr(FileExist(dirOrFile), "D")) {
; Multiple files selected
fileNames := &vPath + (NumGet(OPENFILENAMEW, A_PtrSize == 8 ? 100 : 56, "UShort") * 2)
while (*fileNames) {
MsgBox % dirOrFile . "\" . (filename := StrGet(fileNames,, "UTF-16"))
fileNames += (DllCall("ntdll\wcslen", "Ptr", fileNames, "CDecl Ptr") * 2) + 2
}
} else {
MsgBox %dirOrFile%
}
if (ColorSelection)
MsgBox % ColorSelection
}
DllCall("GlobalFree", "Ptr", cb, "Ptr")
return
;==================================================
OFNHookProc(hdlg, uiMsg, wParam, lParam)
{
DetectHiddenWindows, On
global ColorSelection
if (uiMsg == 0x0110) { ; WM_INITDIALOG
hWndParent := DllCall("GetParent", "Ptr", hdlg, "Ptr")
ControlGet, hCtl1, Hwnd, , Static4, % "ahk_id " hWndParent
ControlGet, hCtl2, Hwnd, , ComboBox3, % "ahk_id " hWndParent
JEE_ControlGetPosClient(hWndParent, hCtl1, vPosX1, vPosY1, vPosW1, vPosH1)
JEE_ControlGetPosClient(hWndParent, hCtl2, vPosX2, vPosY2, vPosW2, vPosH2)
WinMove, % "ahk_id " hdlg, , , , , % vPosH2+15
vPosX1 += 1, vPosY1 += vPosH1+15, vPosW1 *=0.69, vPosH1 *= 5
vPosY2 += vPosH2+8
Gui, Add, Text, x%vPosX1% y%vPosY1% w%vPosW1% h%vPosH1% hWndhCtl1, &Encoding:
;note: for 'Gui, Add, DropDownList', h determines the height of the popup list not the ComboBox
Gui, Add, DropDownList, x%vPosX2% y%vPosY2% w%vPosW2% hwndhCtl2 vColorSelection, ANSI||Unicode|Unicode big endian|UTF-8
DllCall("SetParent", "Ptr", hCtl1, "Ptr", hWndParent, "Ptr")
DllCall("SetParent", "Ptr", hCtl2, "Ptr", hWndParent, "Ptr")
;resize window - including this line will not resize the window as desired
;WinMove, % "ahk_id " hWndParent, , 0, 0, 800, 600
;centre window
;WinGetPos,,, Width, Height, % "ahk_id " hWndParent
;WinMove, % "ahk_id " hWndParent,, (A_ScreenWidth/2)-(Width/2), (A_ScreenHeight/2)-(Height/2)
} else if (uiMsg == 0x004E) {
if (NumGet(lParam+0, A_PtrSize * 2, "UInt") == 4294966690) { ; CDN_FILEOK
; Gui submit
Return 1, DllCall("SetWindowLong" . (A_PtrSize = 8 ? "Ptr" : ""), Ptr, hdlg, Int, -4, Ptr, 1)
}
} else if (uiMsg == 0x0002) { ; WM_DESTROY
Gui Destroy
}
return 0
}
;==================================================
JEE_ControlGetPosClient(hWnd, hCtl, ByRef vPosX, ByRef vPosY, ByRef vPosW, ByRef vPosH)
{
VarSetCapacity(RECT, 16, 0)
DllCall("GetWindowRect", Ptr,hCtl, Ptr,&RECT)
DllCall("MapWindowPoints", Ptr,0, Ptr,hWnd, Ptr,&RECT, UInt,2)
vPosX := NumGet(RECT, 0, "Int"), vPosY := NumGet(RECT, 4, "Int")
vPosW := NumGet(RECT, 8, "Int")-vPosX, vPosH := NumGet(RECT, 12, "Int")-vPosY
return
}