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

Please help with simple dialog box control and floating menus.

chandrika
Beginner
1,121 Views
Dear Members,
I am a first time user of visual fortran. I am currently attempting to write a GUI. I would like to be able to select an option from a floating menu that I get when I right click on the window. I have so far been able to obtain the menu upon right clicking but I cannot select an option. The code that I am using is as follows:

case (WM_RBUTTONDOWN)
iret = SetCapture(hWnd)
pt%x = INT4(LOWORD(lparam))
pt%y = INT4(HIWORD(lparam))
hMenu = LoadMenu (ghInstance, LOC("Floating"C))
hMenuTrackPopup = GetSubMenu (hMenu, 0)
if(option1 .eq. true) then
!code
endif
if(option2 .eq. true) then
!code
endif
bret = ClientToScreen (hwnd, pt)
bret = TrackPopupMenu (hMenuTrackPopup, 0,&
pt%x, pt%y, 0, hwnd, NULL_RECT)
bret = DestroyMenu (hMenu)
MainWndProc = 0
return
Also, I am trying to enable a button in a dialog box only when text in entered in an edit box within the dialog box. This effort has been a dismal failure. I am using the following code to initialise the dialog box
retlog = dlgset(dlg, IDCancel, .true. , dlg_enable )
retint = DlgModal( dlg )
and I have set the button to disabled. Iam trying to use the control index dlg_clicked to call
dlgset( dlg, IDC_Button1, .true. , dlg_enable)
and enable the button.
I have also created the dialog box using
DialogBoxParam(hinstance, lpTemplate,...)

but I still cannot do what I wish.
Any assistance with these issues will be greatly appreciated
Regards
Chandrika
0 Kudos
7 Replies
anthonyrichards
New Contributor III
1,121 Views
If you look at the Help for TRACKPOPUPMENU, you will see that you must set various flags as the second argument if you want the function to return the menu selection value. e.g. if you use
integer iflags
...
...
iflags=IOR(TPM_RETURNCMD, TPM_RIGHTBUTTON)
bret = TrackPopupMenu (hMenuTrackPopup, iflags, &
pt%x, pt%y, 0, hwnd, NULL_RECT)
then the menu selection can be made with either left or right mouse buttons,
because of the TPM_RIGHTBUTTON flag,and the value will be returned to 'bret', because of the TPM_RETURNCMD flag. Other flags, which should be combined using IOR, are available for positioning the pop-up menu relative to the X and Y values. The flags are defined in DFWINTY, so make sure you USE DFWINTY in the function containing the above code. From the Help:

"Use the following bit flag constants to determine the user selection without having to set up a parent window for the menu.

ValueMeaningTPM_NONOTIFYIf this flag is set, the function does not send notification messages when the user clicks on a menu item.TPM_RETURNCMDIf this flag is set, the function returns the menu item identifier of the user's selection in the return value.

Use one of the following bit flag constants to specify which mouse button the shortcut menu tracks.

ValueMeaningTPM_LEFTBUTTONIf this flag is set, the user can select menu items with only the left mouse button.TPM_RIGHTBUTTONIf this flag is set, the user can select menu items with both the left and right mouse buttons."

0 Kudos
anthonyrichards
New Contributor III
1,121 Views
Regarding your dialog callback problem, you should have something like:
retlog = dlgset(dlg, IDCancel, .true. , dlg_enable )
retlog = dlgsetsub(dlg, IDC_EDIT, EditboxSub)
retlog = dlgsetsub(dlg, IDC_BUTTON, ButtonSub)
retlog = dlgset(dlg, IDC_BUTTON, .false. , dlg_enable )

retint = DlgModal( dlg )
Then, in the callback EditboxSub, when you detect IDC_EDIT,
you can do the following:
retlog = dlgset(dlg, IDC_BUTTON, .true. , dlg_enable )
You can then, if you want, simulate clicking the button using
CALL ButtonSub(dlg, IDC_BUTTON, dlg_clicked)

Do not forget to add INCLUDE "RESOURCE,FD" to make the

control codes available.

(I have sometimes had problems, I do not know why,with the compiler not finding the correct DLGSET function corresponding to the type of the quantity being 'set', so you may have to use DLGSETLOG when setting the button state, to get rid of error messages).


0 Kudos
chandrika
Beginner
1,121 Views
Dear Mr.Richards
Thank you so much for your advice. I 've implemented your first suggestion to call the following subroutine from the right click menu. The subroutine is being called and the dialog box is being initialised successfully, this I know from the beep, however I cannot see it on my screen. Please enlighten me as to my errors in this regard.
The code that I am using is shown below,
subroutine NewMthdDlg
use dflogm
use dfwin
implicit none
include 'resource.fd'
integer retint, iret
logical retlog
type (dialog) dlg
external EditBoxSub
retlog = DlgInit( IDD_DIALOG4, dlg )
if ( retlog .eq. .true. ) then
iret = beep(1000,200)
retlog = dlgsetsub(dlg, IDC_EDIT1, EditBoxSub)

end if

call dlguninit (dlg)
end subroutine NewMthdDlg

subroutine EditBoxSub (dlg, id, callbacktype )
!DEC$ ATTRIBUTES DEFAULT :: EditboxSub
use dflogm
include 'RESOURCE.FD'
type (dialog) dlg
integer id, callbacktype
logical retlog
retlog = dlgset(dlg, IDC_BUTTON1, .true. , dlg_enable )
end subroutine EditBoxSub
0 Kudos
anthonyrichards
New Contributor III
1,121 Views
You appear to have omitted
iret = DlgModal(Dlg)
which is essential to display the dialog...so try
retlog = dlgsetsub(dlg, IDC_EDIT1, EditBoxSub
iret = DlgModal(Dlg)
Hope this helps

0 Kudos
chandrika
Beginner
1,121 Views
Dear Mr Richards,
Yes it worked !!! Also, I have noticed that ' Dlginit ', does not return to the dialog box, if I require this handle, how may I obtain it? Consider the case where I want to re-position the dialogbox in the window, I can get its position using 'GetWindowRect' and I can use 'SetWindowPos' to specify the new position, however both these functions require the dialog box handle as an input argument...
Thank you for everything
Regards
Chandrika
0 Kudos
anthonyrichards
New Contributor III
1,121 Views
You will find derived-type DIALOG in DFLOGM.F90 which is in the DF98 /INCLUDE/ folder:
type, public :: dialog
sequence
integer dlgid
integer hwnd! 0 if dialog is not displayed
!private
integer retval
logical dirty! prevents unwanted callbacks when dlg values are changed
logical mutexflush
logical comboupdate
integer dlginitcallback
integer NumControls
type (ControlType), pointer, dimension(:) :: list
end type
When you initialise the dialog, the function DLGINIT(IDD_DIALOG, dlg) populates the variable 'dlg' which is defined as TYPE(DIALOG) in your code.
You will therefore always find the handle to the dialog by specifying dlg%hwnd.
As long as you have access to 'dlg' (which is supplied as the first argument to all your
call back routines), then you will always have access to the dialog's window handle.
0 Kudos
chandrika
Beginner
1,121 Views
Dear Mr Richards,
Thank you for your help, your patience and guidance has contributed significantly to my competence with this facet of CVF, thank you sir...
ps did you see my post on MDIs :)
Best Regards
Chandrika
0 Kudos
Reply