Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29386 Discussions

Resizing GetOpenFileName common dialog box

llynisa
Beginner
1,997 Views
I have been trying to resize the GetOpenFileName dialog box in a QuickWin
application using CVF 6.6C & W2K so that it can show more files without
manual resizing. However, when I do so, the box itself gets bigger, but its
child window showing the files actually gets smaller. I have developed a
dirty method involving resizing, closing it immediately with EndDialog and
then reopening without a hook procedure - it then gives the same larger
child window as from dragging the box larger. Does anyone know a better
way? I found that the discussion in this forum "Controlling GETOPENFILENAME dialog box position" in April 2001 provided useful background on moving.
The code that I am currently using includes:
hFrame = GetHwndQQ(QWIN$FRAMEWINDOW)
xTLHC = 0; yTLHC = 0 ! Public variables.
xWidth = 700; yHeight = 400 ! Public variables.
ofn.hwndOwner = hFrame ! Set Owner Window Handle.
ofn.Flags = OFN_ENABLEHOOK .OR. OFN_EXPLORER .OR. OFN_ENABLESIZING
ofn.lpfnHook = LOC(OpenHookProc)
if (GetOpenFileName(ofn)) then ! Resizing and delete.
ofn.Flags = OFN_FILEMUSTEXIST
if (GetOpenFileName(ofn)) then ! Opens at larger size.
............
=======================================================================
integer*4 function OpenHookProc(hWnd, Msg, WParam, lParam)
!DEC$ATTRIBUTES STDCALL:: OpenHookProc
use dfwin
implicit none
integer*4, intent(in) :: hWnd, Msg, wParam, lParam
integer*4 :: hwndPrnt, iSt
hwndPrnt = GetParent(hWnd)
iSt = SetWindowPos(hwndPrnt, NULL, xTLHC, yTLHC, xWidth, yHeight, NULL)
call EndDialog(hwndPrnt, iSt)
OpenHookProc = .TRUE.
end function OpenHookProc
=======================================================================
The notes on OFN_ENABLESIZING state that its use enables resizing using
either the mouse or keyboard. I don't know how to resize with the
keyboard - how is that effected?
Regards
Alan
0 Kudos
6 Replies
Jugoslav_Dujic
Valued Contributor II
1,997 Views

Alan, I'm in a big hurry & overloaded, so just a quick hint: you canplay with every control within the dialog within the hook. Instead of always hooking, you can simply select case (Msg). In this case, you can catch WM_SIZE (and/or WM_WINDOWPOSCHANGING) and resize/move the ListView containing the folder list. You can get its handle from the hook via GetDlgItem(GetParent(hDlg), ID) where ID is revealed using Spy++, or FindWindow by class "SysListView32". From there, you can move/size every control in the dialog normally (MoveWindow/SetWindowPos) -- that action will be performed whenever the dialog is being sized.

Hmm, I could swear that dialog with OFN_ENABLESIZING does size its listview according to the size by default? Or am I mistaken? (No time to check it out).

Jugosav

0 Kudos
llynisa
Beginner
1,997 Views

Jugoslav,

Thanks for that - BTW, I am having problems logging on, and am sending this when visiting the company where I worked before I retired. If Lexi S. from Support manages to sort me out, I will be able to respond better.

I had previously developed a method of enlarging the dialog box, getting all the child windows using EnumChildWindows and shifting down all the child windows that were below the listview. The trouble with that was that if the box was then manually resized larger, the next time GetOpenFileName was called, it produced ghost child windows. I will dig out the code for that and see if I made an error in closing things after use.

I still hope that if anyone can tell me how to enlarge the box using the keyboard, then a programmed alternative should be fairly straightforward. I too was surprised that OFN_ENABLESIZING did not allow enlargement of the listview - what is the point of it if it doesn't? Perhaps I have missed a wrinkle there.

Regards

Alan

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,997 Views
Alan,
OFN_ENABLESIZING does enable sizing of the ListView. Try it without OFN_ENABLEHOOK and resize the window manually -- the ListView is correctly scaled with the dialog.
However, I understand that this is not what you're after -- you want to do it programatically, and that's where the quirks start -- MoveWindow or SetWindowPos won't resize the ListView as well. As you discovered, you can use EnumChildWindows. However, you're erring from the start -- the hook procedure should contain a SELECT CASE(Msg) statement, and you should do the resizing/moving/Enuming only on CASE(WM_INITDIALOG). This way, you ensure it's done only once -- the way it is now, it is done zillion times per second, as the hook procedure is called very frequently with different Msg's. On CASE DEFAULT, you should return .FALSE. The Hook procedure is more or less an ordinary DialogProc.
I have a hunch that there's a simpler way than EnumChildWindows, but few initial tries failed. (e.g. manual sending of WM_SIZE). I'll let you know if I find one (when I find some time).
Jugoslav
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,997 Views

See also this thread about using "stc32"=1119 control in custom template, as well as this article-- maybe you find them helpful.

Jugoslav

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,997 Views
Alan, I asked in comp.os.ms-windows.programmer.win32 and good souls told me the simple solution (which I wouldn't call obvious) -- MoveWindow/SetWindowPos will achieve the desired effect when called after CDN_INITDONE, which is most easily achieved by posting a custom message to itself:
type(T_NMHDR):: Hdr; pointer(pHdr, Hdr)

select case(Msg)
CASE(WM_NOTIFY)
 pHdr=lParam
 IF (Hdr%Code.EQ.CDN_INITDONE) THEN
 iSt = PostMessage(hWnd, WM_USER+1, 0, 0)
 END IF
 OpenHookProc = .FALSE.
CASE(WM_USER+1)
 iSt=SetWindowPos(GetParent(hWnd),0,iX,iY,iWidth,iHeight,SWP_NOZORDER)
 OpenHookProc=.TRUE.
Jugoslav
0 Kudos
llynisa
Beginner
1,997 Views
Jugoslav,
Many thanks for that - it worked first time! If the solution was not obvious to you, it was abstruse to me. However, it is short and elegant and I recommend it to anyone. The hardest part of my routine was then to
calculate the minimum size of the listview to show all the files in a directory.
Regards
Alan
0 Kudos
Reply