Application of large-scale periodic tasks using Dialog-based MFC application

In an MFC application for one document (SDI) or multiple documents (MDI), I created an application timer in the view. The timer will be a checkmark while the application is running, and will cause some periodic actions.

How can I do the same with a Dialog-based MFC application?

  • Should I create a Thread Timer (SetTimer with NULL HWND) and pass a callback function to it?
  • Should I create workflows? My experience with other projects was that when I tried to display some feedback GUI from threads other than the GUI / worker, I needed to deploy my own delegation / team template and the "invoke invoker" / command invoker. A worker thread will send a message (I think using a message is safer than directly calling a function when working across a thread boundary, CMIIW) to a UI thread. and the UI thread will be "invoice" / command invoker. Failing to do this and making sure that windows / dialogs have the correct parent will cause bizzare behavior, such as an application, to suddenly disappear into the background; Window / Dialog, which is displayed behind the current window / dialog and causes the current window to be unresponsive / non-attached. Probably,I was doing something wrong, but there were so many problems working with threads.

Are there better methods for doing this?

+3
source share
4 answers

The timer also works in the dialog application as an SDI or MDI application. OTOH, timers (mostly) remain from 16-bit Windows. If you want to do things periodically, a workflow is usually the best way to do this (and yes, Windows Mobile supports multiple threads).

: ( ) . , . - MFC , .

+1

MFC , , , , . DoModal(), , .

, - . , , .

- .

0

IMO, , . , , , MFC , .

, , ( KISS)

SetTimer , .

- CWinApp ( - )

static void CALLBACK OnTimer(HWND, UINT, UINT, DWORD);

InitInstance SetTimer(0, [eventid], [time period], OnTimer);

OnTimer CWinApp AfxGetApp() theApp, .

0

: .

MFC Dialog . , CWinApp. InitInstance() CDialog:: DoModal(). , .

, CWinApp , WM_TIMER.

.

  • . , , .

  • , .. Create() DoModal(). Create() ( ). CWinApp . , CWinApp . ( , ).

  • mesage CWinApp. , .

  • You can create a dedicated timer thread. You will probably do this from the CWinApp class before it creates a dialog, but other strategies are possible.

How does any of these patterns sound like they fit your needs? If not, perhaps you can explain your needs in more detail, and we can come up with something suitable.

0
source

Source: https://habr.com/ru/post/1730498/


All Articles