[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

Drawing custom form using Layered windows in MFC

Asked by exprotein in C / C++ / C# Editors and IDEs, Windows MFC Programming, C++ Programming Language

Tags: C++, MFC, Visual Studio 2005

I need to create a MFC dialog application, the dialog used a PNG for background, the borders of the image have shadows, so I need to blend it with the background screen. So far, I've successful to create a dialog using that PNG image as background by UpdateLayeredWindows. The problem is I need to draw some texts and image buttons on the dialog. I'm trying to create my own button class by extending CButton as CImageButton, and drawing my own image on the button. But I'm still not success. What I'm trying to do is using UpdateLayeredWindows in my CImageButton class whenever an image for button is set.

below is how I use UpdateLayeredWindows (I read about it in CodeProject)

Because I use PNG, so I use CImage to load it, and convert it to CBitmap.

Any advice is welcome.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
    CBitmap * bmp = CBitmap::FromHandle(m_bgImage);
 
    BITMAP bmpInfo;
    bmp->GetBitmap(&bmpInfo);
 
    ::PreMultiplyRGBChannels(*bmp, (LPBYTE)bmpInfo.bmBits);
    ModifyStyleEx(0, WS_EX_LAYERED);
 
    CDC dcMemory;
    CDC dcScreen;
    dcScreen.Attach(::GetDC(NULL));
    dcMemory.CreateCompatibleDC(&dcScreen);
    
    //m_bgImage.AlphaBlend(GetDC()->GetSafeHdc(), 0, 0);
 
    CBitmap *pOldBitmap= dcMemory.SelectObject(bmp);
 
    // get the window rectangular (we are only interested in the top left position)
    CRect rectDlg;
    GetWindowRect(rectDlg);
 
    // calculate the new window position/size based on the bitmap size
    CPoint ptWindowScreenPosition(rectDlg.TopLeft());
    //CSize szWindow(bmpInfo.bmWidth, bmpInfo.bmHeight);
    CSize szWindow(bmpInfo.bmWidth, bmpInfo.bmHeight);
 
    // Perform the alpha blend
 
    // setup the blend function
    BLENDFUNCTION blendPixelFunction= { AC_SRC_OVER, 0, PATCHER_DIALOG_CONSTANT_ALPHA, AC_SRC_ALPHA };
    CPoint ptSrc(0,0); // start point of the copy from dcMemory to dcScreen
 
    // perform the alpha blend
    BOOL bRet = UpdateLayeredWindow(&dcScreen, &ptWindowScreenPosition, &szWindow, &dcMemory,
        &ptSrc, 0, &blendPixelFunction, ULW_ALPHA);
    //::UpdateLayeredWindow(wnd, dcScreen, &ptWindowScreenPosition, &szWindow, dcMemory,
    //    &ptSrc, 0, &blendPixelFunction, ULW_ALPHA);
 
    ASSERT(bRet); // ops... something bad just occured....
 
    // clean up
    dcMemory.SelectObject(pOldBitmap);
[+][-]02/03/09 06:13 AM, ID: 23537226Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/03/09 11:48 AM, ID: 23541334Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/03/09 12:06 PM, ID: 23541546Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/03/09 08:00 PM, ID: 23544871Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: C / C++ / C# Editors and IDEs, Windows MFC Programming, C++ Programming Language
Tags: C++, MFC, Visual Studio 2005
Sign Up Now!
Solution Provided By: exprotein
Participating Experts: 2
Solution Grade: A
 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625