zz使用介面庫LibUIDK製作介面

來源:互聯網
上載者:User

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建立一個對話方塊一樣方便,所見即所得 (WYSIWYG)的操作方式,極易上手。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部分。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.