Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

dialog boxes - understanding required

michael_green
Beginner
1,055 Views
There is a lot I don't understand about WIN32, dialog boxes, and DFLOGM. I have a dialog box which has, among many other things, 3 pairs of radio buttons. The first of each pair is checked "group" and the second is not. If I use the following code in the dlg proc:

select case(message)
   case(WM_INITDIALOG)
      call CenterWindow(hDlg,GetWindow(hDlg,GW_OWNER))
      OverlayDlgProc = 1
      return

the dialog, and in particular, the radio buttons work fine, except that none of the radio buttons is on when the dialog first appears. However, with the following version:

use dflogm
implicit none
type (dialog) dlg

dlg.hwnd = hDlg

select case(message)
   case(WM_INITDIALOG)
      bret = DlgInit(IDD_overlay,dlg)
      call CenterWindow(hDlg,GetWindow(hDlg,GW_OWNER))
      bret = DlgSet(dlg,IDC_optheme,'qtest')
      OverlayDlgProc = 1
      return

the radio buttons work perfectly. This surprises me because the statement
bret = DlgSet(dlg,IDC_optheme,'qtest')
is quite irrelevant as far as the radio buttons are concerned, yet it appears necessary, as do the other extra bits and pieces. Please could someone explain what's going on here.

With many thanks

Mike
0 Kudos
2 Replies
Jugoslav_Dujic
Valued Contributor II
1,055 Views
You're toying with fire here. I can tell you what's going on, but that's not the way to do it. You're loading the Dlg structure to memory using DlgInit, and then fill in Dlg%hWnd. In this way, the Dlg structure is "almost" valid, but DialogProc is yours, not the one within DFLOGM. Now, take a look at source of DFLOGM.f90: when you call DlgSetChar, it calls DlgFlush at the end to synchronize dialog appearance with contents of Dlg structure. It calls Data2Dialog, which within CASE(ctrl_radiobutton) ultimately calls:
dummyi = DlgSendMessage( hwndControl, BM_SETCHECK, &
log2int( dlg % list(index) % logvalue(2) ), 0 )
The variable in question is by default initialized to .TRUE. in DlgInit for the first radio button. So, it "magically works".

Do not fiddle with DFLOGM once you wrote your own DialogProc and invoked it with DialogBox(Indirect) API. Instead, initialize your controls using native APIs -- mostly Send(DlgItem)Message. So, the "real" solution is to
SendDlgItemMessage(hDlg,IDC_FIRSTRADIO,BM_SETCHECK,BST_CHECKED,0)
on WM_INITDIALOG. There's also CheckRadioButton API (which is actually just a wrapper around BM_SETCHECK).

Most of your DialogProc will contain calls to SendDlgItemMessage, which is (more or less) what DlgSet/DlgGet do. Although the number of message symbolic names is big, they're systematized rather consistently: for example, BM_ are button messages, EM_ edit box messages, CB_ combobox etc. And you can always refer to source of DFLOGM.f90 (particularly Data2Dialog and Dialog2Data) to find out how it's implemented there -- just don't USE it. You might get away with it, as in this case, but IMO you're asking for trouble.

Jugoslav
0 Kudos
michael_green
Beginner
1,055 Views
Thankyou, Jugoslav, I am beginning to see the light now.

Mike
0 Kudos
Reply