Click here to Skip to main content
15,902,198 members
Articles / Desktop Programming / MFC

A cool skin GUI with shadow border

Rate me:
Please Sign up or sign in to vote.
1.13/5 (16 votes)
25 May 2008CPOL2 min read 61.4K   8.5K   47   7
A cool skin GUI with shadow border; display images (supports many formats) on dialogs, buttons, listboxes.

vietdoor_cool_skin_dialog.PNG

Picture 1: A cool skinnable dialog - can display images on a listbox

Introduction

This is a code to program a great GUI. We can load an image to a combobox, button, or a dialog. It uses the CxImage library to load an image, so it can support all formats of images.

In this code, we also use a shadow border for the dialog, which I got from here. You can also make a special effect on the dialog when it is displayed, which I got from here.

Using the code

How to display a background image on a dialog

First, include FXDialog.h/.cpp. Then, create a dialog like CFXGUIDlg and inherit CFXDialog. You must go to the resource of the dialog, and set the properties of the dialog: border = none, so this dialog will be removed the title bar, and you must implement a code to do this; see Move dialog by mouse.

Add code as below:

C++
OnInitDialog 
{
    ....

    SetImage(PATH_IMAGE_GALLERY_MEDIA_MAIN_BG); // Set background image
    SetSizeFollowImage(this); // Update size

    ...
}

BOOL CFXGUIDlg::OnEraseBkgnd(CDC* pDC)
{
    CFXDialog::OnEraseBkgnd(pDC);
    return TRUE;          
}

To create a dialog of any shape, set the region of dialog as below. You must create a template image which has two colors, like black and white (black color is a transparent part of the dialog, the white color the visible part of the dialog). This SetRgn function will make this transparent dialog at an area with the back color of the template image. You need to include the region.hpp/.cpp files. The BitmapToRegion function will be based on a template image to create any region for the dialog.

C++
OnInitDialog 
{
    ...
    SetRgn(PATH_IMAGE_GALLERY_MEDIA_MAIN_TEMPLATE, this, false);
    // Set region of dialog 
    ...
}

To move the dialog by mouse:

C++
#define CY_TITLEBAR 35
void CFXGUIDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
    // TODO: Add your message handler code here and/or call default
    if(point.y > CY_TITLEBAR)
        return;
    // This code to move window when press left button any where on dialog
    PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));

    CDialog::OnLButtonDown(nFlags, point);
}

Create a shadow for the dialog:

C++
BOOL CFXGUIApp::InitInstance()
{
    ...
    CWndShadow::Initialize(AfxGetInstanceHandle());
    ...
}

OnInitDialog 
{
    ...
    CreateShadow(GetSafeHwnd());
    ...
}

void OnShowWindow(BOOL bShow, UINT nStatus) 
{
    CDialog::OnShowWindow(bShow, nStatus);
    
    // TODO: Add your message handler code here    
    static bool bFirstTime = true;
    if (bFirstTime)
    {
        bFirstTime = false;
        AnimationWindow(m_hWnd, 1200, AW_BLEND);
        UpdateShadow();        
    }
}

To use the button and combobox, we can use the FXButton and FXComboBox classes. You must go to the resources and check the style of the button to "Owner draw".

C++
CFXGUIDlg::CFXGUIDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CFXGUIDlg::IDD, pParent)
    , CFXDialog()
    , m_cBtnClose(PATH_IMAGE_GALLERY_MEDIA_BTN_CLOSE, 
                  PATH_IMAGE_GALLERY_MEDIA_BTN_CLOSE_OVER)
    , m_cBtnBrowser(PATH_IMAGE_GALLERY_MEDIA_BTN_BROWSER_NORMAL, 
                    PATH_IMAGE_GALLERY_MEDIA_BTN_BROWSER_OVER, true)
    , m_cCmbPath(PATH_IMAGE_GALLERY_MEDIA_CMB_PATH_PULL_NORMAL)
    , m_cCmbViewStype(PATH_IMAGE_GALLERY_MEDIA_CMB_PATH_PULL_NORMAL)
{
    ...
}

To use a listbox, we can use the FXListBox class, and we also use FXExplorer to imitate Windows Explorer. It is really cool to integrate this control to manage files/folders into your project.

History

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Vietnam Vietnam
Bachelor of Natural Science University, HCMC VietNam

Comments and Discussions

 
QuestionDemo image Pin
Phuc Dam15-Apr-12 16:30
Phuc Dam15-Apr-12 16:30 
AnswerRe: Demo image Pin
James Duy Trinh (VietDoor)15-Apr-12 16:54
James Duy Trinh (VietDoor)15-Apr-12 16:54 
Generalvery cool buy very sloow Pin
huangzongwu16-Oct-09 2:51
huangzongwu16-Oct-09 2:51 
GeneralNeed more "meat" in this article. PinPopular
James R. Twine17-Apr-08 2:44
James R. Twine17-Apr-08 2:44 
   IMHO, you need to put more "meat" into this article.  It is little more than a screenshot and a couple of archives.

   It would be a good idea to put some details into the article.  For example, explain how you use the region functions to get the desired results.  How do you generate the shadow and/or skin appearance?

   Simply looking through your code is not enough - your particular coding style may or may not be well understood by someone looking to learn something from you.

   Peace!

-=- James
Please rate this message - let me know if I helped or not!<hr></hr>If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles



GeneralRe: Need more "meat" in this article. Pin
James Duy Trinh (VietDoor)17-Apr-08 22:11
James Duy Trinh (VietDoor)17-Apr-08 22:11 
AnswerRe: Need more "meat" in this article. Pin
James R. Twine18-Apr-08 2:52
James R. Twine18-Apr-08 2:52 
GeneralRe: Need more "meat" in this article. Pin
James Duy Trinh (VietDoor)19-Apr-08 6:14
James Duy Trinh (VietDoor)19-Apr-08 6:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.