Dialog question

Dialog question

I want to display a dialog and then display text to show the progress of an application. On completion, I want to press the 'Exit' button and the dialog is cleared.

I want to do this using Windows API calls.

How do I do this?

Normally I would display a dialog, and press 'Start' button to start the application, then on completion, press the 'Exit' button to clear the dialog.

Thanks,
David

4 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

I prefer to spawn a worker thread for longish calculations. See ThreadDlg sample as a starting point. It lacks "callback" feature you need (updating of an UI element such as a progress bar or a text box) but that would be easy to add.

In another application, a worker thread is started on startup of a dialog. The thread calls the routine StepProgress for every while, which steps the progress bar and updates status bar with progress info; also, it checks whether the user pressed "Stop" button:

LOGICAL FUNCTION StepProgress(szMsg)

USE DFWIN
USE HANDLES, ONLY: hProgress, hStatus, hEvent

IMPLICIT NONE

INTEGER::         iSt
CHARACTER(*)::    szMsg

iSt=SendMessage(hProgress,PBM_STEPIT,0,0)
IF (LEN(szMsg).GT.1) THEN
      iSt=SendMessage(hStatus,SB_SETTEXT,1,LOC(szMsg))
END IF
IF (WaitForSingleObject(hEvent, 0).EQ.WAIT_OBJECT_0) THEN
      StepProgress=.TRUE.
ELSE
      StepProgress=.FALSE.
END IF

END SUBROUTINE StepProgress

It is called like:

IF (StepProgress("Calculating Topology..."C)) THEN
   CALL CloseAndDeallocate()
   RETURN
END IF

Jugoslav

Jugoslav
www.xeffort.com

I shouldn't admit this but threads frighten me.

I have this code working and it doesn't use threads, its nearly there.
I press OK to start, do the processing, then press OK to finish.
I could easily miss out the OK to finish by rearranging the code.
But I want to miss out the OK to start, do the processing then have an OK to finish.

Maybe there is a way to make it think that OK has been pressed?

Regards,

David

case (WM_SHOWWINDOW)
 finished=.FALSE.
 iret=SetDlgItemText(hWnd,IDC_STATIC1,'Start'c)

case (WM_COMMAND)
 Select case (LoWord(wParam))
  case (IDOK)			! OK pressed
   if (not(finished)) then	! start
    lret=EnableWindow(hOK,.FALSE.)
    iret=SetDlgItemText(hWnd,IDC_STATIC1,'Processing'c)
    ! do process
    iret=SetDlgItemText(hWnd,IDC_STATIC1,'Finished'c)
    AutoProc = 1
    finished=.TRUE.
    lret=EnableWindow(hOK,.TRUE.)
    return
   else			! finshed
    lret=EndDialog(hWnd,1)
    AutoProc = 1
   end if
  end select
end select

I must admit I don't follow you completely. If you want the calculation to start immediately, why not put it in WM_INITDIALOG? Ah, I see -- in that case you won't see the dialog until the calculaton is over, because...

...when your program is single-threaded, it can do only one statement at a time. Since it is performing calculation, it cannot process messages, including WM_PAINT, so this means it will be effectively stuck. That is the case with your actual code also -- to see what I mean, try inserting few Sleep() calls within calculation (to simulate it's lasting longer than it is), run the calculation, and in the meantime switch to another application and back ("Alt-tabbing").

So, to overcome this, you should either:
- Create the worker thread as I described
- Use method described here. Essentially, it's about running a "mini" message loop periodically while doing the calculation.

Jugoslav

Jugoslav
www.xeffort.com

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen