C++ Programming
09-26-2009, 12:11 AM
Dear all,
Please help me...
I have a problem using CPaintDC class.
Global variable that I made:
CGambarDlg *pdlg;
CString tulisan;
int len;
bool upkotak;
bool ada;
int warna1,warna2;
I also made an IDEvent: IDC_counter
I made a button with function:
void CGambarDlg::OnButton1()
{
UpdateData(true);
tulisan = m_edit;
len = tulisan.GetLength();
CRect RectBackground;
RectBackground.top = 98;
RectBackground.right = 200;
RectBackground.bottom = 118;
RectBackground.left = 13;
InvalidateRect(&RectBackground, FALSE);
UpdateWindow();
upkotak = true;
ada = true;
SetTimer(IDC_counter, 1000, 0);
}
Timer function:
void CGambarDlg::OnTimer(UINT nIDEvent)
{
CRect RectBackground(150,150,220,220);
if(upkotak)
{
upkotak = false;
warna1 = 255;
warna2 = 0;
}
else
{
upkotak = true;
warna1 = 0;
warna2 = 255;
}
InvalidateRect(&RectBackground, false);
UpdateWindow();
CDialog::OnTimer(nIDEvent);
}
I make function gradasi:
// function start here
void gradasi()
{
CBrush BrushSilver;
CRect RectBackground;
CPaintDC dc(pdlg);
unsigned int red = 0;
double tambah = 5;
double warna = 0;
WORD lebar = 324;
//--------------------------first part------------------------------//
for(WORD j=1; j {
WORD y1,y2;
y1 = j;
y2 = y1+1;
warna = warna + 0.78;
red = (unsigned int) ceil(warna);
RectBackground.top = y1;
RectBackground.right = 500;
RectBackground.bottom = y2;
RectBackground.left = 0;
BrushSilver.CreateSolidBrush(RGB(0 ,0, red));
dc.FillRect(RectBackground,&BrushSilver);
BrushSilver.DeleteObject();
}
//--------------------------second part------------------------------//
// Background Text
BrushSilver.CreateSolidBrush(RGB(255,255,255));
RectBackground.top = 98;
RectBackground.right = 200;
RectBackground.bottom = 118;
RectBackground.left = 13;
dc.FillRect(RectBackground,&BrushSilver);
CFont font;
VERIFY(font.CreateFont(
24, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
"Arial")); // lpszFacename
// Text
dc.TextOut(15, 100, tulisan, len);
dc.SelectObject(&font);
font.DeleteObject();
//--------------------------third part------------------------------//
RectBackground.top = 150;
RectBackground.right = 220;
RectBackground.bottom = 220;
RectBackground.left = 150;
if(ada)
{
BrushSilver.CreateSolidBrush(RGB(warna1,warna2,0));
dc.SelectObject(&BrushSilver);
dc.Ellipse(&RectBackground);
BrushSilver.DeleteObject();
}
}
// function end here
On begin of my program, my dialog filled with gradation color from "first part" of "gradasi()".
Then from "second part" of "gradasi()" make a rectangle with words "tulisan" that have length "len".
When I clicked Button1, I want a round shape appear with blinking color. then I make a timer for switching the round color. every 1000 ms, "warna1" and "warna2" will changes.
I added a boolean variable "ada"--on "third part" of "gradasi()"-- in order to make a conditional that the round part is only reload when it is needed.
Problem that I get is:
When I click button1, error is occured. "Debug Assertion Failed!"
If I disable "third part" of "gradasi()", there is no error. But I can not make a blinking round shape.
If I disable "first part" and "second part" of "gradasi()", there is also no error. But I just have an original frame window without color gradation.
I don't know where is the application's failure.
Please help me...
Best Regards,
Eka Candra
Please help me...
I have a problem using CPaintDC class.
Global variable that I made:
CGambarDlg *pdlg;
CString tulisan;
int len;
bool upkotak;
bool ada;
int warna1,warna2;
I also made an IDEvent: IDC_counter
I made a button with function:
void CGambarDlg::OnButton1()
{
UpdateData(true);
tulisan = m_edit;
len = tulisan.GetLength();
CRect RectBackground;
RectBackground.top = 98;
RectBackground.right = 200;
RectBackground.bottom = 118;
RectBackground.left = 13;
InvalidateRect(&RectBackground, FALSE);
UpdateWindow();
upkotak = true;
ada = true;
SetTimer(IDC_counter, 1000, 0);
}
Timer function:
void CGambarDlg::OnTimer(UINT nIDEvent)
{
CRect RectBackground(150,150,220,220);
if(upkotak)
{
upkotak = false;
warna1 = 255;
warna2 = 0;
}
else
{
upkotak = true;
warna1 = 0;
warna2 = 255;
}
InvalidateRect(&RectBackground, false);
UpdateWindow();
CDialog::OnTimer(nIDEvent);
}
I make function gradasi:
// function start here
void gradasi()
{
CBrush BrushSilver;
CRect RectBackground;
CPaintDC dc(pdlg);
unsigned int red = 0;
double tambah = 5;
double warna = 0;
WORD lebar = 324;
//--------------------------first part------------------------------//
for(WORD j=1; j {
WORD y1,y2;
y1 = j;
y2 = y1+1;
warna = warna + 0.78;
red = (unsigned int) ceil(warna);
RectBackground.top = y1;
RectBackground.right = 500;
RectBackground.bottom = y2;
RectBackground.left = 0;
BrushSilver.CreateSolidBrush(RGB(0 ,0, red));
dc.FillRect(RectBackground,&BrushSilver);
BrushSilver.DeleteObject();
}
//--------------------------second part------------------------------//
// Background Text
BrushSilver.CreateSolidBrush(RGB(255,255,255));
RectBackground.top = 98;
RectBackground.right = 200;
RectBackground.bottom = 118;
RectBackground.left = 13;
dc.FillRect(RectBackground,&BrushSilver);
CFont font;
VERIFY(font.CreateFont(
24, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
"Arial")); // lpszFacename
// Text
dc.TextOut(15, 100, tulisan, len);
dc.SelectObject(&font);
font.DeleteObject();
//--------------------------third part------------------------------//
RectBackground.top = 150;
RectBackground.right = 220;
RectBackground.bottom = 220;
RectBackground.left = 150;
if(ada)
{
BrushSilver.CreateSolidBrush(RGB(warna1,warna2,0));
dc.SelectObject(&BrushSilver);
dc.Ellipse(&RectBackground);
BrushSilver.DeleteObject();
}
}
// function end here
On begin of my program, my dialog filled with gradation color from "first part" of "gradasi()".
Then from "second part" of "gradasi()" make a rectangle with words "tulisan" that have length "len".
When I clicked Button1, I want a round shape appear with blinking color. then I make a timer for switching the round color. every 1000 ms, "warna1" and "warna2" will changes.
I added a boolean variable "ada"--on "third part" of "gradasi()"-- in order to make a conditional that the round part is only reload when it is needed.
Problem that I get is:
When I click button1, error is occured. "Debug Assertion Failed!"
If I disable "third part" of "gradasi()", there is no error. But I can not make a blinking round shape.
If I disable "first part" and "second part" of "gradasi()", there is also no error. But I just have an original frame window without color gradation.
I don't know where is the application's failure.
Please help me...
Best Regards,
Eka Candra