MINIGUI 中大体分为 主窗口、控件(即子窗口),而其他的一些都属于这两类,如对话框属于主窗口,按键等属于控件
对于主窗口、控件的理解,根据以下程序和效果图,更容易明白。
#include <stdio.h> #include <stdlib.h> #include <minigui/common.h> #include <minigui/minigui.h> #include <minigui/gdi.h> #include <minigui/window.h> #include <minigui/control.h> /* 函数原型: HWND GUIAPI CreateWindow(class_name, caption, style, id, x, y, w, h, parent, add_data) */ #define IDC_STATIC1 100 #define IDC_STATIC2 150 #define IDC_BUTTON1 110 #define IDC_BUTTON2 120 #define IDC_EDIT1 130 #define IDC_EDIT2 140 static int CreateWindow_s(HWND hWnd) { HWND hStaticWnd1, hStaticWnd2, hButton1, hButton2, hEdit1, hEdit2; //创建一个静态框 hStaticWnd1 = CreateWindow(CTRL_STATIC, "This is a static control", WS_CHILD | SS_NOTIFY | SS_SIMPLE | WS_VISIBLE | WS_BORDER, IDC_STATIC1, 10, 10, 180, 300, hWnd, 0); //在 hStaticWnd1 中创建两个按钮控件 hButton1 = CreateWindow(CTRL_BUTTON, "Button1", WS_CHILD | BS_PUSHBUTTON |WS_VISIBLE, IDC_BUTTON1, 20, 20, 80, 20, hStaticWnd1, 0); hButton2 = CreateWindow(CTRL_BUTTON, "Button2", WS_CHILD |BS_PUSHBUTTON | WS_VISIBLE, IDC_BUTTON2, 20, 50, 80, 20, hStaticWnd1, 0); //在 hStaticWnd1 中创建一个编辑框控件 hEdit1 = CreateWindow(CTRL_EDIT, "Edit box 1", WS_CHILD | WS_VISIBLE | WS_BORDER, IDC_EDIT1, 20, 80, 100, 24, hStaticWnd1, 0); //在 hStaticWnd1 中创建一个静态框 hStaticWnd2 hStaticWnd2 = CreateWindow(CTRL_STATIC, "This is child static control", WS_CHILD | SS_NOTIFY | SS_SIMPLE | WS_VISIBLE | WS_BORDER, IDC_STATIC2, 20, 110, 150, 50, hStaticWnd1, 0); //在 hStaticWnd2 中创建一个编辑框控件 hEdit2,这时, hEdit2 是 hStaticWnd1 的孙窗口 hEdit2 = CreateWindow(CTRL_EDIT, "Edit Box 2", WS_CHILD | WS_VISIBLE | WS_BORDER, IDC_EDIT2, 0, 20, 100, 24, hStaticWnd2, 0); return 0; } static int HelloWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam) { switch (message) { case MSG_CREATE: CreateWindow_s(hWnd); return 0; case MSG_DESTROY: DestroyAllControls (hWnd); return 0; case MSG_CLOSE: DestroyMainWindow (hWnd); PostQuitMessage (hWnd); return 0; } return DefaultMainWinProc(hWnd, message, wParam, lParam); } int MiniGUIMain (int argc, const char* argv[]) { MSG Msg; HWND hMainWnd; MAINWINCREATE CreateInfo; CreateInfo.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION; CreateInfo.dwExStyle = WS_EX_NONE; CreateInfo.spCaption = "Hello, world"; CreateInfo.hMenu = 0; CreateInfo.hCursor = GetSystemCursor(0); CreateInfo.hIcon = 0; CreateInfo.MainWindowProc = HelloWinProc; CreateInfo.lx = 0; CreateInfo.ty = 0; CreateInfo.rx = 320; CreateInfo.by = 240; CreateInfo.iBkColor = COLOR_lightwhite; CreateInfo.dwAddData = 0; CreateInfo.hHosting = HWND_DESKTOP; hMainWnd = CreateMainWindow (&CreateInfo); if (hMainWnd == HWND_INVALID) return -1; ShowWindow(hMainWnd, SW_SHOWNORMAL); while (GetMessage(&Msg, hMainWnd)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } MainWindowThreadCleanup (hMainWnd); return 0; }
下图是在 Ubuntu 中得到的结果: