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)));
}