Show information in modeless dialog while main program is running

Show information in modeless dialog while main program is running

Hi,This is the first time I am using modeless dialogs. I have problem showingstatic text within a modeless dialog while the main program is running. The programshown below is adapted from a modal dialog.================================================program running
use ifwin
use iflogm
use kernel32
implicit double precision (a-h,o-z)
type (t_memorystatus) mymemory
include 'resource.fd'
type (dialog) dlg
logical lret
integer iret
character*256 itram_c, dlg_text
c
call globalmemorystatus(mymemory)
itram=mymemory.dwtotalphys/1048576
c
write (*,*) itram
if(.not.dlginit(idd_dialog1,dlg))then
write (*,*) "error: resource not found"
else
write(itram_c, *) itram
dlg_text = "total physical ram : "//trim(adjustl(itram_c))
+ //" mb"
lret = dlgset( dlg, idc_static1, dlg_text )
c iret = dlgmodal(dlg)
iret = dlgmodeless(dlg)
call dlguninit(dlg)
endif
do icount=1,100000
print *, icount
enddo
end
================================================When Iinsert the following after "iret = DlgModeless(dlg)", the main program halted. What could be the problem with the code?================================================! Read and process messages
do while( GetMessage (mesg, NULL, 0, 0) )if ( DlgIsDlgMessage(mesg) .EQV. .FALSE. )thenlret = TranslateMessage( mesg )ret = DispatchMessage( mesg ) end if
end do================================================

14 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

In the code you posted, you have not used DlgSetSub to connect any control in your dialog with any callback routine. If you have specified a default control in the dialog (usually an'IDOK' button by default), as soon as you select any control and press , the default control will be activated and default message handling will result in the dialog exiting, I think.

My intent was to allow the program to go on running even after the modeless dialog was shown. The close button in the attached project (modeless.zip)will be used to close the modeless dialog butshould not affect the running program. The modeless dialog was initiated to present some information whilethe program was running.From the code below, the program halted when the modeless dialog was shown and "Ctrl-C" is required to terminate the program which wasn't the intent. How do I go about it?

================================================

program running
use ifwin
use iflogm
use kernel32
implicit double precision (a-h,o-z)
type (t_memorystatus) mymemory
include 'resource.fd'
type (dialog) dlg
type (t_msg) mesg
logical lret
integer iret
character*256 itram_c, dlg_text
c
call globalmemorystatus(mymemory)
itram=mymemory.dwtotalphys/1048576
c
write (*,*) itram
if(.not.dlginit(idd_dialog1,dlg))then
write (*,*) "error: resource not found"
else
write(itram_c, *) itram
lret = dlginit(idd_dialog1,dlg)
dlg_text = "Total physical ram : "//trim(adjustl(itram_c))
+ //" MB"
lret = dlgset( dlg, idc_static1, dlg_text )
c iret = dlgmodal(dlg)
iret = dlgmodeless(dlg)
do while( GetMessage (mesg, NULL, 0, 0) )
if (dlgisdlgmessage(mesg) .eqv. .false.) then
lret = TranslateMessage( mesg )
ret = DispatchMessage( mesg )
end if
end do

call dlguninit(dlg)
endif

do icount=1,100000
print *, icount
enddo
c

================================================

The following is an edited version of your code, which does what you want by adding a callback routine to deal with the IDCLOSE button and send a WM_QUIT message to the dialog's message queue (I use CVF, so actually had to changeUSE IFWIN to USE DFWIN and USE IFLOGM to USE DFLOGM to test it, but I assume if it works under CVF, it will work with IVF)

(P.S. I note that IDCLOSE does not occur in RESOURCE.FD, so it must be a globally defined value. I always like to define my own values, so that I retain full control and know which 'CLOSE' button I am dealing with at any time.)

Code:

      program running
      use ifwin
      use iflogm
      use kernel32
      implicit double precision (a-h,o-z)
      type (t_memorystatus) mymemory
      include 'resource.fd' 
      type (dialog) dlg
      type (t_msg)  mesg
      logical lret
      integer iret
      character*256 itram_c, dlg_text
c Define callback routine as EXTERNAL
 external DialogQuit
c
      call globalmemorystatus(mymemory)
      itram=mymemory.dwtotalphys/1048576
c
      write (*,*) itram
      if(.not.dlginit(idd_dialog1,dlg))then
         write (*,*) "error: resource not found"
      else
         write(itram_c, *) itram
         lret = dlginit(idd_dialog1,dlg)
         dlg_text = "Total physical ram : "//trim(adjustl(itram_c))
     +            //" MB"
         lret = dlgset( dlg, idc_static1, dlg_text )
c         iret = dlgmodal(dlg)
c
c Assign a callback routine DialogQuit to the CLOSE button
c
  lret = DlgSetSub(dlg, IDCLOSE,DialogQuit)
         iret = dlgmodeless(dlg)
         do while( GetMessage (mesg, NULL, 0, 0) )
            if (dlgisdlgmessage(mesg) .eqv. .false.) then
               lret = TranslateMessage( mesg )
               ret  = DispatchMessage( mesg )
            end if
         end do

         call dlguninit(dlg)
      endif

      do icount=1,100000
      print *, icount
      enddo
c
      end
c************************************************************
c
c Callback subroutine DialogQuit
c Function: To post a WM_QUIT message to the dialog's
c message queue when the CLOSE button is pressed
c
c**********************************************************
 SUBROUTINE DialogQuit( dlg, id, callbacktype )
!DEC$ ATTRIBUTES DEFAULT :: DialogQuit

 use user32
 use iflogm

 implicit none

 include 'resource.fd'

 type (dialog) dlg
 integer id, callbacktype, lret

 if (id.eq.IDCLOSE) then
  Call PostQuitMessage(0)
 return
 endif
!
 END SUBROUTINE DialogQuit

By the way, the simple problem you have could easily be done using MessageBox (which requires

null (i.e. CHAR(0) )-terminated strings for the message and the message box title..

For example

lret =MessageBox( null,TRIM(ADJUSTL(dlg_text))//char(0), 'Memory Status'c, MB_OK)

Message Edited by anthonyrichards on 03-20-200603:05 AM

Thanks for your quick reply. Both the modeless dialog and MessageBox optionsare very close but did not achieve my intent. I am trying to allow the program to run without the need for user inteference.In the dialog box option, I tried to do away with the callback andIDCLOSE to create a temporary onscreen notice.In a MessageBox option, the userclicks "OK" and the message box disappears. Only then, the program will continue.I can't readily make timed messages boxes or other windows which disappear automatically after a short while. These would be very useful for various warning messages or notices. Is there any other functions that can achieve this property.Thanks in advance for advice.

Here is the code fora solution, which uses SetTimer to get a timer to send WM_TIMER messages to a TimerProc every (in this case) 3000 milliseconds. When the TimerProc receives the message, it then sendsa command to the dialog to close by mimicing the pressing of the CLOSE button, using the commandshbutt= GetDlgItem(hwnd,IDC_CLOSE)lret=SendMessage (Hwnd, WM_COMMAND, makewparam(IDC_CLOSE,BN_CLICKED), hbutt )
Note that I have changed the ID of the CLOSE button to IDC_CLOSE (hence the inclusion of the resource file MODELESS.RC and the header files RESOURCE.FD and RESOURCE.H).
By changing the elapsed time programmed for the timer, you can control the time the dialog is displayed. I note that, although the dialog is automatically exited and the later computations proceed ok (i.e.the printing of 1000 lines), the dialog box window remains visible until the printing ceases, when it finally disappears.p.s. I have just found that addinglret=DestroyWindow(dlg%hwnd)
before the DlgUninit statement makes the window disappear immediately....p.p.s Warning: I forgot to change back to USE IFORT and USE IFLOGM from USE DFLIB and USE DFLOGM...

Message Edited by anthonyrichards on 03-21-200603:55 AM

Message Edited by anthonyrichards on 03-21-200606:14 AM

Thanks for your thorough explanation. I viewed your attachment but the code is exactly the same as the one I had posted earlier. I was trying to reconstruct as you had mentioned in the post but was getting some warnings from the compiler. Could you repost your attachment, please?===========================================C:Documents and SettingshongshDesktopModeless1Modeless.f(46) : Warning: The data type of the actual argument does not match the definition. [1001]
C:Documents and SettingshongshDesktopModeless1Modeless.f(46) : Warning: The data type of the actual argument does not match the definition. [0]
===========================================

Apologies for the mix-up, I had two ZIPs with the same name, the one you posted and the one I made up. Here is the new one, with the 'USEDFLIB', DFLOGM and DFWIN changed to 'USE IFLIB' etc.. I hope that is correct for you. Otherwise those sort of corrections should be easliy managed.p.s. I have made the FORTRAN file free-format, with an F90 extension, which I find more convenient. Regards

Message Edited by anthonyrichards on 03-22-200601:30 AM

Thanks a lot! The program is working as intended. I will try to figure out why I keep getting the following warningmessages:

================================================

C:Documents and SettingshongshDesktopModelessModeless.f90(99) : Warning: The data type of the actual argument does not match the definition. [1001]
C:Documents and SettingshongshDesktopModelessModeless.f90(99) : Warning: The data type of the actual argument does not match the definition. [0]

================================================

In CVF, clicking on the compiler warning/error messages directs you to the line in the code causing the warning/error. Does not doing this point you to where the compiler thinks there may be a problem?Note that '1001' is the value assigned to the parameter IDC_CLOSE in RESOURCE.FD in my code. Look for where IDC_CLOSE is used as an argument in the code. MAKEWPARAM uses it, and it expects two 16-bit integers to make into a 32-bit integer. Maybe the default is IDC_CLOSE is stored as a 32-bit integer, and the INTEL compiler warns about this, whereas the CVF compiler does not. There should be no problem with this though, because it is only a warning.The warning about the '0' being possibly misused as an argument could apply to several calls, for example GetMessage and PostQuitMessage.I think the compiler chould be more helpful in this respect. I am glad that the code works in spite of this. regards.

Oh yes... the compiler indicate both warnings to be on line 99 [Modeless.f90(99)] which is the following:lret=SendMessage (Hwnd, wm_command, makewparam(IDC_CLOSE,BN_CLICKED), hbutt )I am figuring out why.

...and you will probably find that the parameter BN_CLICKED is defined = 0, so the messages are probably that these parameters are by default INTEGER*4, whereas MAKEWPARAM expects INTEGER*2 arguments....

You could try using MAKEWPARAM( INT2(IDC_CLOSE),INT2(BN_CLICKED) ) and see if this works and makes the warnings go away...

Yes, the warnings went away. Thanks a lot! You are a great help.

Leave a Comment

Please sign in to add a comment. Not a member? Join today