|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
Thank you for yuour help, I must find the reason...
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
|
|
|
|
|
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?
"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 want to know about SQL Server and ODBC is someone who now something?
i want to make a conection with odbc (visualfoxpro database)!
please tell me a web adress where i can learn something !
thank you in advance !
Bravoone
|
|
|
|
|
Flaviu_2006 wrote: i want to make a conection with odbc (visualfoxpro database)!
Are you wanting a DSN or DSN-less connection? If the former, you'll first need to create a DSN using the ODBC Data Source applet.
"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
|
|
|
|
|
Good Morning,
I have prob with pointer, in fact my principal class has a control activeX
witch i put it like variable m_DTC so it générate a class .cpp and .h
when I try to call it into a CDialog
i do like this :
in file .h Cmyinterface (class of control activeX) I put a pointer
Cmyinterface *pdc;
and in the main class in boutton evenement i write
CexempleCDialog exple;
exple.pdc=&m_DTC;
int nreponse =exple.DoModal();
if (nreponse)
{
return;
}
I have a bug
"Exception non generated in 0x7c2090db (mfc70d.dll) in project.exe:0xC0000005: Violation of access when reading from the location 0xcccccd1c.
when i add other CDialog calling the interface i have the same prob
I hope that i exposed well my problem.
|
|
|
|
|
zizzzz wrote: exple.pdc=&m_DTC;
Can you show how m_DTC is initialized ?
Have you stepped through OnInitdialog of CexempleCDialog ?
|
|
|
|
|
in main class
DDX_Control(pDX, IDC_ITDCINTERFACECTRL1, m_DTC);
and i just put:
cont.pDTC=&m_DTC;
in the CDialog CexempleDialog i call it directly
int rvalue=pDT->name_function();
How i must initialize it ?
zzzz, zizzz
|
|
|
|
|
The first thing to do when you get such a crash is to start your debugger. You will get a lot of information (where the crash occurs exactly, what are the values of the variables and pointers, ...). It could be helpfull to see where it crashes exactly. You could also use the callstack to check in which of your functions the problem occurs.
|
|
|
|
|
Hi to everyone.
I search the internet for my problem but nothing.
I use CDatabase and CRecordset to connect to MySQL server, without any problem.
The problem is that i can't see greek characters (i see only '?') from my application.
The records in MySQL stored correctly in greek and the connection string which i use is:
mysql.OpenEx("DRIVER=MySQL ODBC 3.51 Driver;SERVER=localhost;UID=root; PWD=123456;APP=Microsoft Data Access Components;WSID=localhost;DATABASE=mybase;CHARSET=greek;")
What is wrong?
Please help me!!!
Thanks a lot!!!
|
|
|
|
|
How to set the Dialog Screen itself as a BMP (e.g. company logo),for placing various controls on it
tyyu
|
|
|
|
|
overide the WM_ERASEBKGND( OnEraseBkgnd ) message of the dialog and draw the bitmap inside it.
nave
|
|
|
|
|
arti mujumdar wrote: Dialog Screen itself as a BMP (e.g. company logo),for placing various controls on it
Use BitBlt(...) in OnEraseBkgnd().
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
arti mujumdar wrote: How to set the Dialog Screen itself as a BMP (e.g. company logo),for placing various controls on it
BEGIN_MESSAGE_MAP(CDlbClickEventDlg, CDialog)
<code> ON_WM_ERASEBKGND()</code>
END_MESSAGE_MAP()
//In .h file
BOOL OnEraseBkgnd( CDC* pDC );
// In .cpp file
BOOL CDlbClickEventDlg::OnEraseBkgnd( CDC* pDC )
{
CBitmap bmp;
bmp.LoadBitmap( IDB_BITMAP1 );
const int nSavePrevState = pDC->SaveDC();
CBrush brush;
brush.CreatePatternBrush( &bmp );
pDC->SelectObject( &brush );
CRect rcClient;
GetClientRect( &rcClient );
pDC->Rectangle( &rcClient );
pDC->RestoreDC( nSavePrevState );
return TRUE;
}
|
|
|
|
|
See
#include AtlImage.h
m_Image.Load(path of your file);
...
BOOL CAnswer::OnEraseBkgnd(CDC* pDC)
{
m_Image.BitBlt(pDC->m_hDC,0,0,m_Image.GetWidth(),m_Image.GetHeight(),0,0);
return TRUE;
}
|
|
|
|
|
Hi again,
Whats different between C++ with VC++ and VC++.Net differ with VC++.
Thanks
|
|
|
|
|
messages wrote: C++
Is a standards based language
messages wrote: VC++
Is a compiler which targets C++
messages wrote: VC++.Net
Properly, is the name of the last three compilers, in that they all target .NET. If you really mean C++/CLI, that's an extension to C++ which uses the .NET framework.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks Christian Graus
and i have a other question,
I hear that C++ will limited for write COM is it right?
and on thing VC++ or VC.NET which is better and which is easy
|
|
|
|