Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / June 2005

Tip: Looking for answers? Try searching our database.

SetDialogBkColor

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sonu - 05 Jun 2005 19:15 GMT
Hi All,

Is this the only way to substitute for SetDialogBkColor??

HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CreateSolidBrush(RGB(255,0,0));
    return hbr;
}

If so, then all my controls still have a white background even though I made
them transparent!!!

Thanks for any help
Srishti
Rhett Gong [MSFT] - 06 Jun 2005 10:24 GMT
From your description, I get that you would like to transparent your
dialog's background, so I suggest you using SetLayeredWindowAttributes to
make your dialog transparent. Try add following code inside your dialog's
initialization handler to see the effect.
//---------------------------
::SetWindowLong(this->m_hWnd,
    GWL_EXSTYLE,
    ::GetWindowLong(this->m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
// Make this window 70% alpha
::SetLayeredWindowAttributes(this->m_hWnd, RGB(222,235,239), (255 * 50) /
100, LWA_ALPHA);
//------------------------------
Please let me know if my answer helps you resolve the problem. If there is
anything more I can assist you, please feel free to let me know.

Thanks,
Rhett Gong [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties and confers no rights.
Sonu - 06 Jun 2005 19:02 GMT
Hi Rhett, Thanks a lot, though that's not exactly what I wanted to do, though
it's pretty cool!! I'm sorry I wasn't clear enough.

I was porting my application form VC6.0 to VC.NET2003, and sice the function
SetDialogBkColor is obsolete in the .NET version, I was looking for the best
way to substitute for it.
Do I have to do the OnCtlColor for every Dialog box in my application or
there is a better way.
And if I have to use OnCtlColor, then as I said earlier all the other
controls (static text etc.)had a white background on a say, red dialog, I
would like to have the controls come up in the same background color as the
dialog.

Do you know know what I mean??

It's probably something really simple, but I coudn't get it to do it...
Thanks a whole lot
Srishti
"Gary Chang[MSFT]" - 07 Jun 2005 08:31 GMT
Hi Srishti,

>And if I have to use OnCtlColor, then as I said earlier all the other
>controls (static text etc.)had a white background on a say, red dialog,
>I would like to have the controls come up in the same background
>color as the dialog.

OK, if you want a red background About dialogbox with black static text
controls on it, you may declare a CBrush m_brush member varible in the
CAboutDlg class first, and in its constructor function create the red brush:

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
   m_brush .CreateSolidBrush(RGB (255, 0, 0 )) ;
}

then in its OnCtlColor handler function:

HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
   if (nCtlColor == CTLCOLOR_DLG )                                        
 
       return (HBRUSH) m_brush .GetSafeHandle ( ) ;     //set the dialog's
background brush

   if (pWnd->GetDlgCtrlID() == IDC_STATIC)
  {
     // Set the text color to red
     pDC->SetTextColor(RGB(0, 0, 0));

     // Set the background mode for text to transparent
     // so background will show thru.
     pDC->SetBkMode(TRANSPARENT);

     // Return handle to our CBrush object
     hbr = m_brush;
  }

  //for other kinds of the dialog's child controls, set their foreground
color and make their background mode to transparent as the above

  return hbr;
}

>Do I have to do the OnCtlColor for every Dialog box in my application
>or there is a better way.

AFAIK, there is no better way than the OnCtlColor in MFC 7. If all the
dialog box has the same background color and text color in your
application, I suggest you can customize a dialog class(from the CDialog)
as the above sample CAboutDlg, then use this customized dialog class as the
base class of all the other dialog classes in your project.

Thanks!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
Sonu - 07 Jun 2005 18:35 GMT
Thanks a lot Gary, that was really helpful!
Regards
Srishti

> Hi Srishti,
>
[quoted text clipped - 62 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Gary Chang[MSFT]" - 08 Jun 2005 02:56 GMT
It's OK, Srishti, we are glad to help you on this issue:)

Good Luck!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.