Home > Software engineering >  MFC threads access form control problem!
MFC threads access form control problem!

Time:09-17

Simple dialog countdown procedure, form only Static Text (ID: IDC_STATIC1) and Progress Control two controls, the countdown 60 seconds!
The Static Text display number 60,59,58... .
The Progress shows Progress Control

In the thread, use the
The CWnd * h_d2=AfxGetApp () - & gt; GetMainWnd ();
H_d2 - & gt; GetDlgItem (IDC_STATIC1) - & gt; SetWindowTextW (_T (" countdown: ")) to update the Static Text normal
But using h_d2 - & gt; GetDlgItem (IDC_PROGRESS1) - & gt; SetRange (0 ') cannot, can you tell me, what reason?

Small white just contact MFC consult!

CodePudding user response:

Let dialog to update data, not in a thread interface

CodePudding user response:

GetDlgItem (IDC_PROGRESS1) - & gt; SetRange (0 '); In the dialog initialization

CodePudding user response:

refer to the second floor schlafenhamster response:
GetDlgItem (IDC_PROGRESS1) - & gt; SetRange (0 '); In the dialog initialization


Why is the Static Text can be used directly?

CodePudding user response:

The progress bar to use SetPos (x)
H_d2 - & gt; GetDlgItem (IDC_PROGRESS1) - & gt; SetPos (now);
SetRange (0 '); Is to initialize!

CodePudding user response:

reference 4 floor schlafenhamster response:
progress bar with SetPos (x)
H_d2 - & gt; GetDlgItem (IDC_PROGRESS1) - & gt; SetPos (now);
SetRange (0 '); Is to initialize!

Basic I will, of the progress bar is in the use of h_d2 - & gt; GetDlgItem (IDC_PROGRESS1) - & gt; SetPos (3) when the tip can't find the definition,

CodePudding user response:

CWnd * h_d2
Should be CYourDlg *
CYourDlg * h_d2=(CYourDlg *) AfxGetApp () - & gt; GetMainWnd ();

CodePudding user response:

reference kyosuke kanou 1/f, 1989 response:
let dialog to update data, not in a thread interface

CodePudding user response:

refer to 6th floor schlafenhamster response:
CWnd * h_d2
Should be CYourDlg *
CYourDlg * h_d2=(CYourDlg *) AfxGetApp () - & gt; GetMainWnd ();

Have already done
  • Related