MFC Dialog: How to create a non-rectangular dialog box?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: MFC Dialog: How to create a non-rectangular dialog box?

Threaded View

  1. #1
    Join Date
    Dec 2001
    Location
    Canada/Montreal
    Posts
    983

    MFC Dialog: How to create a non-rectangular dialog box?

    Q: How to create a non-rectangular dialog box?

    A: The main idea is to use the 'SetWindowRgn()' function. Adding the following lines of code just before the 'return TRUE;' of the 'OnInitDialog()' will produce a dialog box that has rounded corners:

    Code:
    BOOL CYourDialog::OnInitDialog()
    {
      CDialog::OnInitDialog();
    
      // Rest of initialization 
      // ...
    
      // Create a 'CRgn' object
      CRgn rgn;
      CRect rect;
      GetWindowRect(&rect);
      rgn.CreateRoundRectRgn(0,
                             0,
                             rect.Width(), 
                             rect.Height(),
                             30,
                             30);
    
      // Set the windows region
      SetWindowRgn(static_cast<HRGN>(rgn.GetSafeHandle()), TRUE);
    
      // Detach the 'CRgn' object from the region or else the
      // 'CRgn' destructor would close the 'HRGN' handle when 'rgn'
      // goes out of scope
      rgn.Detach(); 
    
      return TRUE;  // return TRUE  unless you set the focus
                    // to a control
    }
    You can use a region of any shape that fits into your dialog rect.


    Last edited by Andreas Masur; July 24th, 2005 at 04:26 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center