- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does anyone know how to control the position on the screen where the Getopenfilename and Getsavefilename common dialog boxes open?
They always appear at the top left of the parent window, and are sometimes obscured by other dialogs. I would like to specify a diferent location.
Thanks in advance
Tony Richards
They always appear at the top left of the parent window, and are sometimes obscured by other dialogs. I would like to specify a diferent location.
Thanks in advance
Tony Richards
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jugoslav Dujic kindly provided the following solution of opening an invisible pop-up window in the required location, to which the getopenfilename window is attached. The pop-up window must then be destroyed.
iX=200
iY=300
hFrame=GetHwndQQ(QWIN$FRAMEWINDOW)
hInst=GetWindowLong(hFrame,GWL_HINSTANCE)
hDummy=CreateWindow("Edit"C,""C,WS_POPUP,iX,iY,10,10,hFrame,NULL,hInst,NULL)
! build the OPENFILENAME structure
Ofn%hwndOwner=hDummy
Ofn%hInstance=0
(snip)
bOK=GetOpenFileName(Ofn)
iSt=DestroyWindow(hDummy)
iX=200
iY=300
hFrame=GetHwndQQ(QWIN$FRAMEWINDOW)
hInst=GetWindowLong(hFrame,GWL_HINSTANCE)
hDummy=CreateWindow("Edit"C,""C,WS_POPUP,iX,iY,10,10,hFrame,NULL,hInst,NULL)
! build the OPENFILENAME structure
Ofn%hwndOwner=hDummy
Ofn%hInstance=0
(snip)
bOK=GetOpenFileName(Ofn)
iSt=DestroyWindow(hDummy)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I try the solution with the GetHwndQQ, but I can not get it work. I assume this solution does not work in a Win32-application.
I use in a Win32-application a somewhat longer way via a hook procedure. I tried this in the Cmndlg example (..DF98AdvancedWind32Cmndlg). I add in the hook procedure (FileOpenHookProc in file Cmndlg8.f90) the case WM_INITDIALOG and insert in that case a call to SetWindowPos:
stat = SetWindowPos(hDlg, HWND_TOP, ixpos, iypos, 0, 0 , SWP_NOSIZE)
in which (ixpos, iypos) is the new window position.
And this will do the job. The hook procedure in the example can be activated via the menu: "Options" and "Using a hook".
Guus
I use in a Win32-application a somewhat longer way via a hook procedure. I tried this in the Cmndlg example (..DF98AdvancedWind32Cmndlg). I add in the hook procedure (FileOpenHookProc in file Cmndlg8.f90) the case WM_INITDIALOG and insert in that case a call to SetWindowPos:
stat = SetWindowPos(hDlg, HWND_TOP, ixpos, iypos, 0, 0 , SWP_NOSIZE)
in which (ixpos, iypos) is the new window position.
And this will do the job. The hook procedure in the example can be activated via the menu: "Options" and "Using a hook".
Guus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your solution is cleaner, Guus -- that's the way it was intended to do it.
My solution is somewhat dirty but shorter -- GetHWNDQQ is used only
to obtain frame window handle for creation of Edit box; in Win32, just replace it with handle of the frame window (even NULL should work).
Jugoslav
My solution is somewhat dirty but shorter -- GetHWNDQQ is used only
to obtain frame window handle for creation of Edit box; in Win32, just replace it with handle of the frame window (even NULL should work).
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using VF 5.0D on WIn NT.
I have tried Guus's method using
stat = SetWindowPos(hDlg, HWND_TOP, ixpos, iypos, 0, 0 , SWP_NOSIZE)
in a hook procedure obtained in the same way (from CMNDLG8.f90). I find that the Open File dialog window POSITION cannot be changed UNLESS the Flags element of the OPENFILENAME structure DOES NOT contain OFN_EXPLORER. I get a different-style dialog than that obtained with the OFN_EXPLORER flag set, with a network button and with a directory tree-structure in the right-hand box.
I have tried Guus's method using
stat = SetWindowPos(hDlg, HWND_TOP, ixpos, iypos, 0, 0 , SWP_NOSIZE)
in a hook procedure obtained in the same way (from CMNDLG8.f90). I find that the Open File dialog window POSITION cannot be changed UNLESS the Flags element of the OPENFILENAME structure DOES NOT contain OFN_EXPLORER. I get a different-style dialog than that obtained with the OFN_EXPLORER flag set, with a network button and with a directory tree-structure in the right-hand box.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tony,
You are right. I was not aware of the OFN_EXPLORER flag. I tried to find any handle to set the position, but I lost my way in the help information.
Probably the method of Jugoslav will work for such a dialog type.
Guus
You are right. I was not aware of the OFN_EXPLORER flag. I tried to find any handle to set the position, but I lost my way in the help information.
Probably the method of Jugoslav will work for such a dialog type.
Guus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've just dig this out of documentation: (see OFNHookProc, which refers to OFN_EXPLORER style and, contrary, OFNHookProcOldStyle, which refers to the situation when it's not defined):
hdlg
Handle to the child dialog box of the Open or Save As dialog box. Use the GetParent function to get the handle to the Open or Save As dialog box window....
If you provide a hook procedure for an Explorer-style common dialog box, the system creates a dialog box that is a child of the default dialog box. The hook procedure acts as the dialog procedure for the child dialog. This child dialog is based on the template you specified in the OPENFILENAME structure, or it is a default child dialog if no template is specified.
Thus, the correct usage for OFN_EXPLORER seems to be:
I tried it and it worked.
Jugoslav
hdlg
Handle to the child dialog box of the Open or Save As dialog box. Use the GetParent function to get the handle to the Open or Save As dialog box window....
If you provide a hook procedure for an Explorer-style common dialog box, the system creates a dialog box that is a child of the default dialog box. The hook procedure acts as the dialog procedure for the child dialog. This child dialog is based on the template you specified in the OPENFILENAME structure, or it is a default child dialog if no template is specified.
Thus, the correct usage for OFN_EXPLORER seems to be:
INTEGER,PARAMETER:: OFN_EXPLORER = #00080000 TYPE(T_OPENFILENAME):: Ofn ... Ofn%Flags= OFN_FILEMUSTEXIST.OR.OFN_HIDEREADONLY.OR.OFN_EXPLORER.OR. & OFN_PATHMUSTEXIST.OR.OFN_ENABLEHOOK ... !================================================= INTEGER FUNCTION OpenHookProc(hWnd,Msg,wParam,lParam) !DEC$ATTRIBUTES STDCALL:: OpenHookProc USE DFWIN IMPLICIT NONE INTEGER:: hWnd,Msg,wParam,lParam INTEGER:: iSt SELECT CASE(Msg) CASE(WM_INITDIALOG) iSt=SetWindowPos(GetParent(hWnd),0,75,75,0,0,SWP_NOSIZE.OR.SWP_NOZORDER) OpenHookProc=.TRUE. CASE DEFAULT OpenHookProc=.FALSE. END SELECT END FUNCTION OpenHookProc
I tried it and it worked.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK Yugoslav, the "Getparent(hwnd)" is the clue. You are right, it is in the documentation, but to translate it in statements is an other thing. There you need the eye of the master.
Guus
Guus

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page