Software Archive
Read-only legacy content
17061 Discussions

How do i bring a dialog box to the foreground

Intel_C_Intel
Employee
807 Views
Hello,

I'm using DVF 6.0 and i've build a Fortran windows application (although i don't use Win32 API functions). The application opens a dialog box at startup. After this, it is possible to open a second dialog box by clicking on a control button in the dialog box. Now i want to switch between the first and second dialog box with the help of the mouse. When i click on the first dialog box, this box becomes active but the second dialog box remains to the foreground, not the first dialog box. So, if the boxes overlap, i can't work with the first dialog box anymore.
Does anyone know what i've done wrong? Below, a simplified version of my code is listed.

integer(4) function ShowDialog(iM1,iM2,iM3,iM4) 
!DEC$ IF DEFINED(_X86_) 
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_WinMain@16' :: ShowDialog 
!DEC$ ELSE 
!DEC$ ATTRIBUTES STDCALL, ALIAS : 'WinMain' :: ShowDialog 
!DEC$ ENDIF 
use dfwin 
use dflogm 
implicit none 
integer(4) iM1,iM2,iM3,iM4 
include "resource.fd" 
 
type (dialog) dFirst 
external eCallback 
integer(4) iRet 
logical lRet 
 
lRet = dlginit(idd_dialog1,dFirst) 
lRet = dlgsetsub(dFirst,idc_button,eCallback,dlg_clicked) 
iRet = dlgmodal(dFirst) 
 
ShowDialog = 0 
end function ShowDialog 
 
Subroutine eCallback(dFirst,iID,iCallbacktype) 
use dflogm 
implicit none 
include "resource.fd" 
 
! global 
type (dialog) dFirst 
integer(4) iID,iCallbacktype 
! local 
type (dialog) dSecond 
logical lRet 
 
lRet = dlginit(idd_dialog2,dSecond) 
lRet = dlgmodeless(dSecond) 
 
end Subroutine eCallback
0 Kudos
5 Replies
Intel_C_Intel
Employee
807 Views
Hi Bruce,

I am afraid I have no solution for you - if indeed one exists.
However I do know that you can't use dlgmodeless in a QuickWin application
(lRet = dlgmodeless(dSecond))

Lars
0 Kudos
Jugoslav_Dujic
Valued Contributor II
807 Views
By default, if you don't specify dialog's parent (owner) window in call to DlgModeless, the existing dialog is taken as parent, causing it to always lie underneath the modeless dialog. There's an optional argument to DlgModeless where you can specify the parent window -- if you specify 0, desktop is the parent. Try:
 
lRet = DlgModeless(dSecond, hwndParent=0) 


HTH

Jugoslav
0 Kudos
Intel_C_Intel
Employee
807 Views
Jugoslav,

When i implement the code lRet = DlgModeless(dSecond, hwndParent=0), not the desktop becomes the parent window, but the second dialog box.
What goes wrong?

Bruce
0 Kudos
Jugoslav_Dujic
Valued Contributor II
807 Views
I pasted your code in a simple workspace with addition of hwndParent=0 and it seems to work, in the sense that you can freely switch between two dialogs using the mouse and the second does not always overlap the first. It's not 100% clear to me what you want to obtain: if you want that dFirst keeps the focus after clicking the idc_button, just add the following line at the end of eCallback:

 
use dfwin 
... 
iSt = SetFocus(dFirst%hWnd) 


Also, you can play with window-positioning functions. The following piece of code in eCallback will move dSecond so that it appears next to the right border of dFirst:

 
type (t_rect) rect 
... 
lRet = dlgmodeless(dSecond) 
... 
lRet = GetWindowRect(dFirst%hWnd,Rect) 
lRet = SetWindowPos(dSecond%hWnd,0,Rect%Right,Rect%Top,0,0,SWP_NOZORDER.OR.SWP_NOSIZE) 


HTH

Jugoslav
0 Kudos
Intel_C_Intel
Employee
807 Views
Jugoslav,

The problem seems to be partly solved: When I add hwndParent=0 in my original code (not the simplified version at the Fortran Forum site), everything works OK.
I don't understand though why it doesn't work with the simplified version.

But never mind, my program is fixed so I can move on. Thanks !!!

Bruce
0 Kudos
Reply