Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Since using forums in my early days 10 years ago in CompuServe, one had to log back on and sometimes wait days for a response. Now I get a response e-mailed to me which I can click a link and go right back to exactly where My post was..."

Geography

Where in the world do Tek-Tips members come from?

Windows Graphics problem, HRGN region repainting problem

vvozar (Programmer)
5 Mar 11 12:12
Hello,

   The issue is related to Windows GDI, actually about repainting "framed" regions (HRGN framed with "FrameRgn" function)
   I'm making application using BCB including VCL library. I put TImage component/object on an empty form and loaded proper bitmap image to Picture property of that image.
   Then i wrote form's method that paints a frame around 'img':

CODE

void __fastcall drawFrame()
{
 rgb = 0x00ffeeff; // light gray RGB color code

 // creating region on image area, 26 is width of caption in pixels
 // frame will be 4 pixels width around image

 rgn = CreateRoundRectRgn(form->Left + img1->Left + 2,
  form->Top + 26 + img1->Top + 2,
  form->Left + img1->Left + img1->Width + 11,
  form->Top + 26 + img1->Top + img1->Height + 11,
  4 , 4);

 hdc = GetDC(hWnd);
 brush = CreateSolidBrush(rgb);
 FrameRgn(hdc, rgn, brush, 4, 4);
 ReleaseDC(hWnd,hdc);
 DeleteObject(rgn);
}
Wanting always to have frame around my image, i am calling this method in OnPaint event.

CODE

void __fastcall TfrmMainForm::FormPaint(TObject *Sender)
{
    drawFrame();
}
When OnPaint event occurs everything is repainted fine, except in one situation. When my forms window is not top most (i drag some other opened window above it - like windows explorer), those region frame around image is being redrawed on top of the foreground window. I understand that it is normal because of the nature of an OnPaint event, but don't know the way to avoid this situation.
I mean, how to disable that repainting regions frame on top of foreground window - window that's not my applications window?

Appreciate any help or advice.
vvozar (Programmer)
9 Mar 11 6:32
Instead of using regions, device contexts and brushes, i will draw directly on the form.
I've changed code in drawFrame() method to:

CODE

void __fastcall TfrmMainForm::drawFrame()
{
        form->Canvas->Pen->Style = psSolid;
        form->Canvas->Pen->Width = 4;
        form->Canvas->Pen->Color = clLtGray;
        form->Canvas->Brush->Style = bsClear;
        form->Canvas->Rectangle(
          img->Left - 2,
          img->Top  - 2,
          img->Left + img->Width + 2,
          img->Top  + img->Height + 2
          );
}
This way it draws directly on forms canvas, and requires less memory management (allocating and freeing) comparing to using regions and brushes.
To be able to draw directly on a form, FormStyle must be set either to fsNormal or fsStayOnTop.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close