Link to home
Start Free TrialLog in
Avatar of eklee
eklee

asked on

How to make custom UI with VC++ 5?

Hi,
   Is there a way (an easy one) to create custom User Interface for our application? For example, instead of using the standard Windows 95 application UI, I would like to create a fancy UI (kinda like WinAMP, or other Win32 MP3 players) with my own BMP file with the layout.
 
  I think I can achieve that by modifiying the .rc file, but I don't know where or how to begin.  Can anyone help me out?
Avatar of chensu
chensu
Flag of Canada image

Create a frame window without a menu, title, border or whatever you want. Here is a very simple template.

#include <afxwin.h>

//-----------------------------------------------------------------------------
class CMyApp : public CWinApp
{
    public:
        virtual BOOL InitInstance();
};
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
class CMyWnd : public CFrameWnd
{
    public:
        CMyWnd();
        inline BOOL CreateWnd();
   
    protected:
        afx_msg void OnPaint();
        afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
       
        DECLARE_MESSAGE_MAP()
};
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
inline BOOL CMyWnd::CreateWnd()
{
    RECT rcWnd;
    rcWnd.top = rcWnd.left = 0;
    rcWnd.right = 100;
    rcWnd.bottom = 100;
   
    return this->Create(NULL,      // use default class name
                        _T("My Window"),
                        WS_POPUP,
                        rcWnd);
}
//-----------------------------------------------------------------------------


CMyApp theApp;


//-----------------------------------------------------------------------------
BOOL CMyApp::InitInstance()
{
    // Create an instance of our own frame window class
    CMyWnd *pWnd = new CMyWnd;
    if (!pWnd->CreateWnd())
        return FALSE;
    pWnd->ShowWindow(SW_SHOW);
   
    m_pMainWnd = pWnd;
   
    return TRUE;
}
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CMyWnd, CFrameWnd)
    ON_WM_PAINT()
    ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
//-----------------------------------------------------------------------------
afx_msg void CMyWnd::OnPaint()
{
    CPaintDC dc(this);    // device context for painting

    // draw your window here    
}
//-----------------------------------------------------------------------------
afx_msg void CMyWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
    // action here
}
//-----------------------------------------------------------------------------

Avatar of eklee
eklee

ASKER

Yes, but how could I associate the "Close Window", "Maximize Window", "Minimize Window" buttons to what they should do?  For example, let's say my application has a circle shape, all the "Close/Max/Min Windows" buttons are at distributed in the bottom of the circle.  Let's say I have already drawn up the layout of this circle in a bmp file.

Now, how could I make my application to use my bmp file as its 'skin'? In addition to that, how can i tell my program that the "Close/Max/Min Windows" button are located at some other places, instead of at the top right (standard) position?
You can always catch the mouse messages yourself and respond to them as needed. For example, if the user clicks on your X bitmap and you want to interpret that as a close message, then all need is to PostMessage(WM_CLOSE). To minimize, you would use ShowWindow(SW_MINIMIZE), and ShowWindow(SW_MAXIMIZE) to maximize the window.
Your question is a not a hard question but is a long one and deals with many issues based on your design desions...like say if you make a custom button that say Maximizes a window....In all these cases you need to overide these messages and in some cases override them completely and deal with them yourself. You have to handle all button interactions including states of your buttons..drawing them yourself and produce messages when they are pressed.  But to answer your question one would need a clear idea of what you want to do.
Avatar of eklee

ASKER

bfwizard,
    I guess what I want to know is how could we use a custom BMP image as the appearance of our application.  For example, if we create a custom Dialog-based application, it will still be the traditional rectangle-shaped application.  Instead of this, I would like to make the application looks like whatever BMP image we use.  
    As another example, let's say I want to write a CD-jukebox application.  It is ugly if we use standard/traditional Windows' rectangle-shaped layout.  I want to make my application looks like a jukebox (I will draw it in a BMP file) and let the user interact with it (custom buttons).  How can I do this thru VC++? I know I can do this quite easily thru Delphi 3, but I don't have it, and I prefer to work with VC++ for now.
It is very easy with ActiveX controls.

In the ActiveX Control Wizard(App Wizard), check the box Window less activation and you can build your control in customized shape.
ASKER CERTIFIED SOLUTION
Avatar of chabaud
chabaud

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial