How to display CStatic
-
I have an MFC application (VS 2003 Std). There is a dialog window with CStaticText. For example: CStatic lblRecno; I want to change the colour of the CStaticText. I am using the OnCtlColor function: HBRUSH DlgBackup::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = NULL; /* if(pWnd->GetDlgCtrlID() == IDC_STATIC_LP) or */ if( nCtlColor == CTLCOLOR_STATIC ) { pDC->SetTextColor(clBlack); pDC->SetBkMode(TRANSPARENT); hbr = (HBRUSH) GetStockObject( NULL_BRUSH ); } else { hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); } return hbr; } To this place is OK. Now I am changeing the lblRecno value in the while loop: int lp = 0; CString newTxt = ""; while(...) { ++lp; bewTxt.Format("%d", lp); lblRecno.SetWindowText(newTxt); } But the new value lblRecno is displaying in the place of the previous value, an so on. I think I should to use the WM_ERASEBKGND, but I don't know how to do it. Can you help me. Regards mwgomez Poland
-
I have an MFC application (VS 2003 Std). There is a dialog window with CStaticText. For example: CStatic lblRecno; I want to change the colour of the CStaticText. I am using the OnCtlColor function: HBRUSH DlgBackup::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = NULL; /* if(pWnd->GetDlgCtrlID() == IDC_STATIC_LP) or */ if( nCtlColor == CTLCOLOR_STATIC ) { pDC->SetTextColor(clBlack); pDC->SetBkMode(TRANSPARENT); hbr = (HBRUSH) GetStockObject( NULL_BRUSH ); } else { hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); } return hbr; } To this place is OK. Now I am changeing the lblRecno value in the while loop: int lp = 0; CString newTxt = ""; while(...) { ++lp; bewTxt.Format("%d", lp); lblRecno.SetWindowText(newTxt); } But the new value lblRecno is displaying in the place of the previous value, an so on. I think I should to use the WM_ERASEBKGND, but I don't know how to do it. Can you help me. Regards mwgomez Poland
-
What you want actually to show the static text one after another. If you just place a while loop you can see that last value only. Try with a timer updating the window text in regular intervals say 1 sec Rinu Raj
No it doesn't work. Please try it. I don't create CStatic it my sorce code, it is on the dialog window. I am setting the new Value by lblRecno.SetWindowText(...) I am setting the CStatic colour by OnCtlColor(...) and the TIMER void CDemoDlg::OnTimer(UINT nIDEvent) { lblLP.Invalidate(); CDialog::OnTimer(nIDEvent); } Regards mwgomez
-
No it doesn't work. Please try it. I don't create CStatic it my sorce code, it is on the dialog window. I am setting the new Value by lblRecno.SetWindowText(...) I am setting the CStatic colour by OnCtlColor(...) and the TIMER void CDemoDlg::OnTimer(UINT nIDEvent) { lblLP.Invalidate(); CDialog::OnTimer(nIDEvent); } Regards mwgomez
-
inside the timer do void CDemoDlg::OnTimer(UINT nIDEvent) { static int lp = 0; CString newTxt = ""; ++lp; newTxt.Format("%d", lp); lblRecno.SetWindowText(newTxt); } then Start the timer in the initdialog Rinu Raj
I think there is steel something wrong. Please look at my source code. My dialog window is MOkno.h public: CStatic lblRecno; // for displaying recno CButton btnStart; // button Start int iLicznik; // increment variable CString newTxt; // new value of the text = iLicznik as a Text MOkno.cpp: BOOL MOkno::OnInitDialog() { CDialog::OnInitDialog(); // TODO: SetTimer(ID_TIMER1, 1000, NULL); // my Timer is running every 1 s return TRUE; } HBRUSH MOkno::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr; if(nCtlColor == CTLCOLOR_STATIC ) { pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(clBlue); hbr = (HBRUSH) GetStockObject( NULL_BRUSH ); } else { hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); } return hbr; } void MOkno::OnClose() { KillTimer(ID_TIMER1); CDialog::OnClose(); } On the dialog window tehre is a Start button. When user click on the button: void MOkno::OnBnClickedButtonStart() { iLicznik = 0; newTxt = ""; // suppose: It is a database, and I am reading records // and display the current recno number for(iLicznik = 1; iLicznik <= 1000; iLicznik++) { newTxt.Format("%d", iLicznik); } } void MOkno::OnTimer(UINT nIDEvent) { CDialog::OnTimer(nIDEvent); lblRecno.SetWindowText(newTxt); } Regards mwgomez
-
I think there is steel something wrong. Please look at my source code. My dialog window is MOkno.h public: CStatic lblRecno; // for displaying recno CButton btnStart; // button Start int iLicznik; // increment variable CString newTxt; // new value of the text = iLicznik as a Text MOkno.cpp: BOOL MOkno::OnInitDialog() { CDialog::OnInitDialog(); // TODO: SetTimer(ID_TIMER1, 1000, NULL); // my Timer is running every 1 s return TRUE; } HBRUSH MOkno::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr; if(nCtlColor == CTLCOLOR_STATIC ) { pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(clBlue); hbr = (HBRUSH) GetStockObject( NULL_BRUSH ); } else { hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); } return hbr; } void MOkno::OnClose() { KillTimer(ID_TIMER1); CDialog::OnClose(); } On the dialog window tehre is a Start button. When user click on the button: void MOkno::OnBnClickedButtonStart() { iLicznik = 0; newTxt = ""; // suppose: It is a database, and I am reading records // and display the current recno number for(iLicznik = 1; iLicznik <= 1000; iLicznik++) { newTxt.Format("%d", iLicznik); } } void MOkno::OnTimer(UINT nIDEvent) { CDialog::OnTimer(nIDEvent); lblRecno.SetWindowText(newTxt); } Regards mwgomez
There are some problems in your code You may modify code like this void MOkno::OnBnClickedButtonStart() { SetTimer( ...) // Set the timer here not in the oninitdialog } void MOkno::OnTimer(UINT nIDEvent) { static int i =0; newTxt.Format( "%d", ++i ); lblRecno.SetWindowText(csTex); CDialog::OnTimer(nIDEvent); } Rinu Raj
-
There are some problems in your code You may modify code like this void MOkno::OnBnClickedButtonStart() { SetTimer( ...) // Set the timer here not in the oninitdialog } void MOkno::OnTimer(UINT nIDEvent) { static int i =0; newTxt.Format( "%d", ++i ); lblRecno.SetWindowText(csTex); CDialog::OnTimer(nIDEvent); } Rinu Raj
-
I think there is steel something wrong. Please look at my source code. My dialog window is MOkno.h public: CStatic lblRecno; // for displaying recno CButton btnStart; // button Start int iLicznik; // increment variable CString newTxt; // new value of the text = iLicznik as a Text MOkno.cpp: BOOL MOkno::OnInitDialog() { CDialog::OnInitDialog(); // TODO: SetTimer(ID_TIMER1, 1000, NULL); // my Timer is running every 1 s return TRUE; } HBRUSH MOkno::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr; if(nCtlColor == CTLCOLOR_STATIC ) { pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(clBlue); hbr = (HBRUSH) GetStockObject( NULL_BRUSH ); } else { hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); } return hbr; } void MOkno::OnClose() { KillTimer(ID_TIMER1); CDialog::OnClose(); } On the dialog window tehre is a Start button. When user click on the button: void MOkno::OnBnClickedButtonStart() { iLicznik = 0; newTxt = ""; // suppose: It is a database, and I am reading records // and display the current recno number for(iLicznik = 1; iLicznik <= 1000; iLicznik++) { newTxt.Format("%d", iLicznik); } } void MOkno::OnTimer(UINT nIDEvent) { CDialog::OnTimer(nIDEvent); lblRecno.SetWindowText(newTxt); } Regards mwgomez
Your code is doing exactly what it is supposed to do. Paint-related messages are low priority so they do not get handled if other, high-priority messages are in the queue. This is why you do not see the
lblRecno
control being updated until the end. Lose the timer stuff and try:void MOkno::OnBnClickedButtonStart()
{
for(int iLicznik = 1; iLicznik <= 1000; iLicznik++)
{
CString newTxt;
newTxt.Format("%d", iLicznik);
lblRecno.SetWindowText(newTxt);
}
}I just tried this (using 10000) and it worked fine.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
-
I have an MFC application (VS 2003 Std). There is a dialog window with CStaticText. For example: CStatic lblRecno; I want to change the colour of the CStaticText. I am using the OnCtlColor function: HBRUSH DlgBackup::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = NULL; /* if(pWnd->GetDlgCtrlID() == IDC_STATIC_LP) or */ if( nCtlColor == CTLCOLOR_STATIC ) { pDC->SetTextColor(clBlack); pDC->SetBkMode(TRANSPARENT); hbr = (HBRUSH) GetStockObject( NULL_BRUSH ); } else { hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); } return hbr; } To this place is OK. Now I am changeing the lblRecno value in the while loop: int lp = 0; CString newTxt = ""; while(...) { ++lp; bewTxt.Format("%d", lp); lblRecno.SetWindowText(newTxt); } But the new value lblRecno is displaying in the place of the previous value, an so on. I think I should to use the WM_ERASEBKGND, but I don't know how to do it. Can you help me. Regards mwgomez Poland
gomez_a wrote:
But the new value lblRecno is displaying in the place of the previous value, an so on.
Of course. What are you expecting it to do? :confused:
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb