使用MFC界面库LibUIDK制作超酷界面

原作者:psbeyond    源出处:CSDN    发布者:施昌权    发布类型:转载    发布日期:2008-11-13

  

LibUIDK简介:
LibUIDK是专业开发Windows平台下图形用户界面的开发包,该开发包基于Microsoft的MFC库。使用此开发工具包可轻易把美工制作的精美界面用VC实现,由于使用LibUIDK创建的所有窗口都支持控件的从控件工具栏中拖入创建,所以极大的提高了新产品的开发速度,并大大增强图形用户界面(GUI)的亲和力。LibUIDK还可以使您的软件轻松具有当今流行的换肤功能,以提高产品的竞争力。

LibUIDK的目标用户:
任何使用Microsoft Visual C++ 6.0、Microsoft Visual C++.NET的程序开发人员。

系统需求:
Win2K、WinXP、Win2003及VC++6.0或VC++.NET。

主要特点:
快速创建窗口:
  使用LibUIDK创建一个窗口与VC创建一个对话框一样方便,所见即所得的操作方式,极易上手。UIShop在设计时尽量模拟VC6.0创建一个对话框那样来创建UI窗口。

支持换肤:
  你可以为同一个应该程序创建多个不同的皮肤,每个皮肤可以有不同的外观,不同的控件布局,也就是说,同一个控件在一 套皮肤中位于窗口的左边,在另一套皮肤中可以位于窗口的右边,这样就为不规则窗口中重新布置控件的位置提供了支持。

皮肤与代码的分离:
  程序员可以不必等到美工把所有的图片全部做好就可以开始编码,在工程前期,程序员可以使用Windows自带的画图软件简单创建一些纯色的底图而在上面创建控件,等美工把图片做好后替换一下即可,不需要修改代码。并且,如果由美工使用皮肤编辑器UIShop创建皮肤,可以直接看到程序最终的效果。而不必先把图片交给程序员接入代码中编辑源工程后才能查看界面效果。

多种图像格式支持:
  LibUIDK支持多种图像格式,如bmp,jpg,png,gif等。(免费版只支持bmp)

下载:
官方网站:www.iuishop.com/download.htm
华军软件园:http://www.onlinedown.net/soft/43316.htm

使用LibUIDK开发您的程序:

说明:

使用VC的应用程序向导,你可以创建基于对话框、单文档和多文档的应用程序,具体最终的应该程序是什么样子,完全取决于CWinApp派生类中InitInstance成员函数中窗口的创建方法。对于基于对话框的工程,类似于下面的方法:

BOOL CTestPopApp::InitInstance()
{
    // Standard initialization
    // If you are not using these features and wish to reduce the size
    // of your final executable, you should remove from the following
    // the specific initialization routines you do not need.

    CTestPopDlg dlg;
    m_pMainWnd = &dlg;
    int nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
        // TODO: Place code here to handle when the dialog is
        // dismissed with OK
    }
    else if (nResponse == IDCANCEL)
    {
        // TODO: Place code here to handle when the dialog is
        // dismissed with Cancel
    }

    // Since the dialog has been closed, return FALSE so that we exit the
    // application, rather than start the application's message pump.
    return FALSE;
}

下面看看基于单文档的应用程序InitInstance成员函数的内容(创建时没有选中文档/视支持):

BOOL CTestSDIApp::InitInstance()
{
    // Standard initialization
    // If you are not using these features and wish to reduce the size
    // of your final executable, you should remove from the following
    // the specific initialization routines you do not need.

    // Change the registry key under which our settings are stored.
    // TODO: You should modify this string to be something appropriate
    // such as the name of your company or organization.
    SetRegistryKey(_T("Local AppWizard-Generated Applications"));


    // To create the main window, this code creates a new frame window
    // object and then sets it as the application's main window object.

    CMainFrame* pFrame = new CMainFrame;
    m_pMainWnd = pFrame;

    // create and load the frame with its resources

    pFrame->LoadFrame(IDR_MAINFRAME,
        WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
        NULL);


    // The one and only window has been initialized, so show and update it.
    pFrame->ShowWindow(SW_SHOW);
    pFrame->UpdateWindow();

    return TRUE;
}

可见,创建什么样的应用程序,完全取决于InitInstance的动作,是不是我们只能创建VC为我们设计好的这三种(对话框、单文档和多文档)应用程序呢? 当然不是了。不管CDialog和CFrameWnd都是直接派生自CWnd,我们可以从CWnd派生自已的窗口类,然后交由InitInstance去创建。

BOOL CTestUIApp::InitInstance()
{
    // ...

    CMainFrame* pFrame = new CMainFrame; // derive from CWnd
    m_pMainWnd = pFrame;

    CString strMyClass;
    WNDCLASS wndcls;
    memset(&wndcls, 0, sizeof(WNDCLASS));
    wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
    wndcls.lpfnWndProc = ::DefWindowProc;
    wndcls.hInstance = AfxGetInstanceHandle();
    wndcls.hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME));
    wndcls.hCursor = ::LoadCursor(NULL, IDC_ARROW);
    wndcls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wndcls.lpszMenuName = NULL;
    strMyClass = "MyClass"; // Specify your own class name
    wndcls.lpszClassName = (LPCTSTR)strMyClass;
    
    // Register the new class and exit if it fails
    if(!AfxRegisterClass(&wndcls))
    {
        TRACE("Class Registration Failed/n");
        return FALSE;
    }

    DWORD dwStyle = WS_POPUP|WS_CLIPCHILDREN|WS_SYSMENU|WS_MINIMIZEBOX;
    // change "Test" to you your application name
    m_pMainWnd->CreateEx(0, strMyClass, "Test", dwStyle, CRect(0, 0, 0, 0), NULL, NULL);

    // The one and only window has been initialized, so show and update it.
    pFrame->ShowWindow(SW_SHOW);
    pFrame->UpdateWindow();
    
    // ...
}

LibUIDK正是推荐这种应用程序创建方式。您也可以选择生成基于单文档的应用程序,然后修改成这个样子。

步骤:

1. 先使用UIShop创建应用程序的皮肤

2. 把皮肤文件夹放到应用程序可以找到的路径(相对路径)

3. 使用VC的应用程序向导创建一个基于单文档的应用程序,名字为"HelloGUI"。(去掉文档视支持,去掉所有3D特效,去掉工具栏停靠功能,因为这些将由LibUIDK支持)

4. 把LibUIDK压缩包中的Controls.h、LibUIDK.lib和UIMgr.h拷贝到源文件夹下,并在工程中加裁LibUIDK.lib。有两种方法可以加载LibUIDK.lib:

1) 在VC工程设置中加裁。打开VC,选择菜单Project/Settings,打开Project Settings对话框,选择Link选择卡, 在Object/library modules输入框中输入"LibUIDK.lib",记得在Debug版和Release版中都要设置。如下图:

2) 在源代码中, 使用pragma加载:
#pragma comment (lib, "LibUIDK.lib")

5. 要使用LibUIDK,必须设置皮肤的路径,您可以在应用程序类的初始化中设置它:

#include "UIMgr.h"
BOOL CHelloGUIApp::InitInstance()
{
    // ...

    // Init the skin path before the main window is created
    CUIMgr::SetUIPath("Sample//the.ui");

    // ...
}

6. 删除MainFrm.cpp和MainFrm.h。

7. 使用VC的类向导创建一个派生自CWnd的窗口类"CMainWnd"(类向导自动生成MainWnd.h和MainWnd.cpp,您也可以根据习惯,把类名改为CMainFrame,把生成的文件改为MainFrm.cpp和MainFrm.h),在MainWnd.h中包含头文件:

#include "Controls.h" // 定义了各个控件和CUIWnd

并修改CMainWnd的基类为CUIWnd,注意要同时修改CMainWnd的消息入口的基类也为CUIWnd,如下:

////////////////////////////////////////////////////////
// MainWnd.cpp

BEGIN_MESSAGE_MAP(CMainWnd, CUIWnd)
//{{AFX_MSG_MAP(CMainWnd)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

由于CUIWnd包含纯虚函数:
void UIName {} = 0;
所以在CMainWnd中要实现它,这个纯虚函数的作用是指定CMainWnd的UI模板,即指定它与皮肤文件中哪个窗口绑定,类似于对话框类中的:
enum { IDD = IDD_HELLOGUI_DIALOG }; // 在对话框类的头文件中,用以指定对话框模板ID
UIName函数要为定义在CUIWnd中的成员变量m_strUIWndName赋值

void UIName {} { m_strUIWndName = "Sample"; } // "Sample"为*.ui文件中创建的窗口名

8. 创建CMainWnd,并显示它.

BOOL CHelloGUIApp::InitInstance()
{
    // ...

    // Init the skin path before the main window is created
    CUIMgr::SetUIPath("Sample//the.ui");

    CMainFrame* pFrame = new CMainFrame; // derive from CWnd
    m_pMainWnd = pFrame;

    CString strMyClass;
    WNDCLASS wndcls;
    memset(&wndcls, 0, sizeof(WNDCLASS));
    wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
    wndcls.lpfnWndProc = ::DefWindowProc;
    wndcls.hInstance = AfxGetInstanceHandle();
    wndcls.hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME));
    wndcls.hCursor = ::LoadCursor(NULL, IDC_ARROW );
    wndcls.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
    wndcls.lpszMenuName = NULL;
    strMyClass = "MyClass"; // Specify your own class name
    wndcls.lpszClassName = (LPCTSTR) strMyClass;
    
    // Register the new class and exit if it fails
    if(!AfxRegisterClass(&wndcls))
    {
        TRACE("Class Registration Failed/n");
        return FALSE;
    }

    DWORD dwStyle = WS_POPUP|WS_CLIPCHILDREN|WS_SYSMENU| WS_MINIMIZEBOX ;
    // change "Test" to you your application name
    m_pMainWnd->CreateEx(0, strMyClass, "Test", dwStyle, CRect(0, 0, 0, 0), NULL, NULL);

    // The one and only window has been initialized, so show and update it.
    pFrame->ShowWindow(SW_SHOW);
    pFrame->UpdateWindow();
    
    // ...
}

9. 创建其它从CUIWnd派生的子窗口,以完成整个应用程序的GUI部分。

posted @ 2011-01-23 16:00  kevinzhwl  阅读(923)  评论(0编辑  收藏  举报