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

progress bar

dan789
Beginner
1,523 Views

Dear colleagues,

I have written a Windows dialog-based application on the basis of the Whizzy example from the CVF 6.5 samples. I am performing sophisticated calculations described by my own subroutine, and want that each time my subroutine calculates a new point the progress bar in the dialog box be updated. However this does not happen: the progress bar first shows 0%, then (when ALL the calculations are finished) it is changed to 100%. (I am also unable to change any of the static text controls of the dialog until the program stops). Could you please help me to get it working smoothly? Here is my code for the progress bar:

Code:
retlog = DlgSet(dlg, IDC_PROGRESS, 0, DLG_RANGEMIN) 
retlog = DlgSet(dlg, IDC_PROGRESS, 500, DLG_RANGEMAX) 
retlog = DlgSet(dlg, IDC_PROGRESS, 0) 
do i = 1, 500 
   retlog = DlgSet(dlg, IDC_PROGRESS, i) 
   call PointCalc(i,[other parameters]) 
enddo 

Message Edited by Dan789 on 04-19-2005 10:20 AM

0 Kudos
11 Replies
Paul_Curtis
Valued Contributor I
1,523 Views
Here is how you run a progress bar in a Windows application.
First, get the handle to the progressbar control within its parent dialog, hwnd:
hwpb = GetDlgItem (hwnd, IDC_MY_BAR)
rval = SendMessage (hwpb, PBM_SETRANGE, 0, MakeLong(0, maxsteps))
rval = SendMessage (hwpb, PBM_SETPOS, 0, 0) ! start at 0
rval = SendMessage (hwpb, PBM_SETSTEP, 1, 0) ! 1 unit steps
Then, youshow progress by incrementing the bar displayfor each iteration of your loop or whatever:
DO iter = 1, maxsteps
... your code ...
rval = SendMessage (hwpb, PBM_STEPIT, 0, 0)
END DO
0 Kudos
dan789
Beginner
1,523 Views
Hmm Thats what Ive got after this:

Compiling Fortran...

Error: This name does not have a type, and must have an explicit type. [GETDLGITEM]

Error: This name does not have a type, and must have an explicit type. [SENDMESSAGE]

Message Edited by Dan789 on 04-19-2005 01:50 PM

0 Kudos
Paul_Curtis
Valued Contributor I
1,523 Views
Well, the obvious stuff (type defines, includes, etc.) was left unstated in my code sample. GetDlgIgem is a standard Win32 API function, residing in USER32.lib, one of the standard Win32 component collections. My code simply INCLUDEs modules IFWIN and IFWINTY, which in turn include the relevent interface block for GetDlgItem (and every other Win32 API function you might need). If you search for GetDlgItem in the set of include files, the interface is found in USER32.f90, which you can open to inspect the arguments and calling convention for F90. Searching for GetDlgItem in the VS help immediately produces the complete documentation for this function (in a C context); you could also recover the same information by a search of the MSDN website.
0 Kudos
anthonyrichards
New Contributor III
1,523 Views
In otherwords, trying to update progress within a callback, even using 'dlgflush' does not work, when the computations are being done in a callback in the same thread. You have to go directly to the dialog control using SendMessage or SendDlgItemMessage. Thanks for the code Paul, it solves my similar problem trying to update edit boxes in a loop.
0 Kudos
dan789
Beginner
1,523 Views
Yes, this helps. I proceed a little bit:) That's what I've got after adding the "use user32" line:
Compiling Fortran...
Error: This name does not have a type, and must have an explicit type. [MAKELONG]
PS.I didn't find any "ifwin" files. Only dfwin, msfwin, etc in the include directory
0 Kudos
anthonyrichards
New Contributor III
1,523 Views
You are using CVF, so add USE DFWIN, which includes calls to USE USER32, which contains the interface block for SendMessage.
0 Kudos
anthonyrichards
New Contributor III
1,523 Views
MAKELONG(0,NUMBER) takes a 16-bit integer and makes it 32-bit, with NUMBER in the lowest 16-bits. I guess you could just make NUMBER a 4-byte integer and use it instead of MAKELONG(...).
0 Kudos
dan789
Beginner
1,523 Views
Yes, thanks, USE DFWIN works Ok.

But after this there is still something missing:

Compiling Fortran...

Warning: Variable HWND is used before its value has been defined.

In fact, HWND (which is used in the first line of the code kindly provided by Paul-Curtis)has not been defined in my program. My dialog was initialized by

recursive subroutine DoDialog( dlgParent, id, callbacktype )

without any handlers

0 Kudos
anthonyrichards
New Contributor III
1,523 Views
Your callback routines, attached to controls in your dialog 'dlgParent',should typically begin something like
SUBROUTINE ComputeSub( dlg, id, callbacktype )
!DEC$ ATTRIBUTES DEFAULT :: ComputeSub
use dflib
use dfwin
use dflogm
use Yourglobals
implicit none
type (dialog) dlg
integer id, callbacktype
The handle you want is given by dlg%hWnd in the dialog type 'dlg' given as the first argument in the callback routine. This is the windows handle to the dialog box that 'owns' the controls you want to send messages to.'Dlg' will be identical to dlgParent if the callback is attached to controls in dlgParent. So, wherever you see 'hWnd' in the example code given by Paul Curtis, just substitute 'dlg%hWnd'.
0 Kudos
dan789
Beginner
1,523 Views
nope, there is nothing like this in the program code
I have attached a file of the sample provided with CVF. I have greatly modified this code, but I didn't introduce new structures there.
btw. I have an idea why it's impossble to change the dialog controls while the calculations are running. I think it deals with the modal/non-modal use of the dialog.
0 Kudos
dan789
Beginner
1,523 Views
Wow! it works:) I have a nicely working progress bar!
Thank you, guys!
0 Kudos
Reply