mfc >> OnPaint Problem

by QWRhbQ » Wed, 22 Mar 2006 05:08:29 GMT

Dear everyone:

I am creating an IE browser using the microsoft web browser activeX control.
After placing the microsoft web browser in a dialog box, i am trying to draw
some ellipses on top of it.

Those ellipses disappear if the dialog box in minimised/maximised or if
another window is placed on top of the dialog.

Can some one help me solving this problem? Thank you

Here is some code:

bool drawings = false;
void CPaintNightMareDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting

if(drawings == TRUE){
drawShapes(dc); // this is a call to the drawShapes method
}

if (IsIconic())
{
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()),
0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}


// process user event click
void CPaintNightMareDlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
CClientDC dc(this);
drawShapes(dc);
drawings = TRUE;
UpdateWindow();
}

// this method starts the drawing of shapes
void CPaintNightMareDlg::drawShapes(CDC& dc)
{
int xCentre, yCentre;
int xMax = GetSystemMetrics(SM_CXSCREEN);
int yMax = GetSystemMetrics(SM_CYSCREEN);

for(int index = 0; index < 20; index ++ ){
xCentre = getRandom(0, 1000);
yCentre = getRandom(0, 700);
dc.Ellipse(xCentre + 25, yCentre + 20, xCentre - 25, yCentre - 20);
dc.TextOut(xCentre -10, yCentre-10, "A test");
}
}

// this method returns a random number between min and max
int CPaintNightMareDlg::getRandom(int min, int max)
{
if(min > max){
swap(min, max);
}
int range = max - min + 1;
return (min + int(range * rand()/(RAND_MAX + 1.0)));
}



Similar Threads

1. GDI Onpaint Problem/Question in Custom control - CSharp/C#

2. OnPaint() Problem

What do you mean by win32 application and using CToolBar. Why this
choice? Whats wrong in using MFC's CFrameWnd. You dont need to use
doc-view architecture. Toolbar (actually all CControlBar derived
objects) occupy the client area of Mainframe. That may be one of the
issues. Either way, I would simply use a default non-doc-view app and
start from there.

--------------
Ajay Kalra
 XXXX@XXXXX.COM 

3. OnPaint() problem

4. how to solve this OnPaint problem ? ( about remote screen transmit )

i want to abtain remote screen capture on the pc in LAN.
i was suggested to transmit the changed parts only to save the bandwidth.
so i divide the screen into 10*10 parts. and now , i need to display the
remote screen on my own form. my method is use this:

Graphics c = this.createGraphics();
c.drawImage(imageparts,xcoodinary,ycoodinary);// imageparts is ONE part
                                              // of the screen  (1/100)

whenever i receive a imageparts, i use the code above to draw the changed
screen parts on a FORM. the code seems to work well.In the first time,i
should call this code 100 times to get the original screen.after then , i
could only call this code several times.

but now ,when the FORM is changed or covered by other windows , with the
repaint result ,the image  disappeared or changed into a wrong display.

So i should put the code above into OnPaint method. but the code above only
redraws the changed parts of the remote screen, the others disappeared.

How can i redraw the previous unchanged image already on the FORM ? OR are
there other methods to solve this problem ?

THX!



5. overidding onPaint textbox to make lines causes problems - CSharp/C#

6. Problem with OnPaint in custom label control

Hi there

I have a custom label control (GradientLabel) which enherits from Label and 
basically just paints the background of a label in a gradient.

In my code I have the following for the overidden OnResize event:

protected override void OnPaint(PaintEventArgs e)
{
    Graphics g = e.Graphics;
    using (LinearGradientBrush br = new LinearGradientBrush(e.ClipRectangle, 
color1, color2, gradient_mode))
    {
        g.FillRectangle(br, e.ClipRectangle);
    }
    base.OnPaint(e);
}

(The Color1 and Color2 and gradient_mode are set using properties to get the 
designtime representation to work)

Now the odd part is this. I have two different machines, a desktop and a 
laptop, both running .NET 2.0. On my desktop there is no problem when I 
resize the control and the gradient follows nicely, also when I maximize the 
window etc.
On my laptop however, everything works except when I maximize the form in 
which the label resides. The gradient simply cuts off and starts over where 
the form was maximized from.
I have tried overriding a lot of different events, including the forms own 
OnResize event and then through that calling the labels Refresh() method, 
but no luck.

What is the problem? I suspect it for being a machine specific problem, but 
it would be nice if I somehow could get a reason :)

Another problem is when I drag another window across the label. It then 
won't repaint itself. How do I get it to do that?

Sincerely
Kenneth, Denmark 


7. [issue] overidding onPaint textbox to make lines causes problems - CSharp/C#

8. OnPaint handler problem

Hi All,
Can somebody explain me this?

I have a dialog box with a static control on it.
CStatic c_ImgArea;  //declared in header file

//--------------
void CMyDlg::DrawCurrentImg(){
	read a bitmap and store it in a memory DC
	c_ImgArea->GetClientRect(&rectStaticClient);
	InvalidateRect(&rectStaticClient);
	UpdateWindow();
	
}

void CMyDlg::OnPaint()
{
	CPaintDC dcDlg(this); 
	dcDlg.BitBlt(iOffsetX, iOffsetY, m_Size.cx, m_Size.cy, &m_dcMem,
iSourceX, iSourceY, SRCCOPY);
	CDialog::OnPaint();
}

//---------------

the above piece of code does'nt work and I did'nt get a image in my
static box

//--------------
void CMyDlg::DrawCurrentImg(){
	
	read a bitmap and store it in a memory DC
	c_ImgArea->GetClientRect(&rectStaticClient);
	InvalidateRect(&rectStaticClient);
	UpdateWindow();
	
}

void CMyDlg::OnPaint()
{
	CPaintDC dcDlg(this); 
	CPaint dcStatic(c_ImgArea);
	dcStatic.BitBlt(iOffsetX, iOffsetY, m_Size.cx, m_Size.cy, &m_dcMem,
iSourceX, iSourceY, SRCCOPY);
	
	CDialog::OnPaint();
}

//---------------
This thing works and I get a image in my static control.
Here, I have created the device context for static control and dialog
both and doing my blitting with static control
and it works.

Why I does'nt get a image when I am using dc for dialog in OnPaint()? 

thanks
Rachel