MINIGUI 中主窗口、控件(即子窗口)的理解

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 中得到的结果:

143018_6bsR_1756851.jpg

转载于:https://my.oschina.net/fengyeshangqing/blog/467307

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值