MINI GUI 上的helloworld 程序

/* 
** $Id: helloworld.c,v 1.25 2005/02/01 09:42:31 clear Exp $
**
** Listing 2.1
**
** helloworld.c: Sample program for MiniGUI Programming Guide
**      The first MiniGUI application.
**
** Copyright (C) 2004 Feynman Software.
**
** License: GPL
*/

#include <stdio.h>
#include <string.h>

#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/mywindows.h>

static const char* en_text = "If you see this text, MiniGUI on this board is OK now.";
static char msg_text [256];
static RECT msg_rc = {10, 50, 300, 80};

static const char* syskey = "";

static int last_key = -1;
static int last_key_count = 0;

static int HelloWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
    RECT rc;
    syskey = "";

    switch (message) {
        case MSG_CREATE:
            strcpy (msg_text, "No message so far.");
            break;

        case MSG_TIMER:
            printf ("Timer expired, current tick count: %ul\n", GetTickCount ());
            sprintf (msg_text, "Timer expired, current tick count: %ul.", GetTickCount ());
            InvalidateRect (hWnd, &msg_rc, TRUE);
            break;
            
        case MSG_LBUTTONDOWN:
            printf ("The left button pressed.\n");
            strcpy (msg_text, "The left button pressed.");
            InvalidateRect (hWnd, &msg_rc, TRUE);
            break;

        case MSG_LBUTTONUP:
            printf ("The left button released.\n");
            strcpy (msg_text, "The left button released.");
            InvalidateRect (hWnd, &msg_rc, TRUE);
            break;

        case MSG_PAINT:
            KillTimer (hWnd, 100);
            SetTimer (hWnd, 100, 500);
            printf ("BeginPaint.\n");
            hdc = BeginPaint (hWnd);
#if 1
            rc.left = 10; rc.top = 10;
            rc.right = 300; rc.bottom = 40;
            printf ("DrawText1.\n");
            DrawText (hdc, en_text, -1, &rc, DT_LEFT | DT_WORDBREAK);
            printf ("DrawText2.\n");
            DrawText (hdc, msg_text, -1, &msg_rc, DT_LEFT | DT_WORDBREAK);
#else
            TextOut (hdc, 10, 10, en_text);
            TextOut (hdc, 10, 50, msg_text);
#endif
            EndPaint (hWnd, hdc);
            printf ("EndPaint.\n");
            return 0;

        case MSG_SYSKEYDOWN:
            syskey = "sys";
        case MSG_KEYDOWN:
            if(last_key == wParam)
                last_key_count++;
            else
            {
                last_key = wParam;
                last_key_count = 1;
            }
            printf ("The %d %skey pressed %d times.\n", wParam, syskey, last_key_count);
            sprintf (msg_text, "The %d %skey pressed %d times", wParam, syskey, last_key_count);
            InvalidateRect (hWnd, &msg_rc, TRUE);
            return 0;

        case MSG_KEYUP:
            printf ("The %d key released.\n", wParam);
            sprintf (msg_text, "The %d key released", wParam);
            InvalidateRect (hWnd, &msg_rc, TRUE);
            return 0;

        case MSG_CLOSE:
            KillTimer (hWnd, 100);
            DestroyMainWindow (hWnd);
            PostQuitMessage (hWnd);
            return 0;
    }

    return DefaultMainWinProc(hWnd, message, wParam, lParam);
}

#ifdef _MISC_MOUSECALIBRATE
static void mouse_calibrate (void)
{
    POINT src_pts [5] = {{5, 10}, {600, 20}, {620, 450}, {20, 470}, {310, 234}};
    POINT dst_pts [5] = {{0, 0}, {639, 0}, {639, 479}, {0, 479}, {320, 240}};

    SetMouseCalibrationParameters (src_pts, dst_pts);
}
#else /* _MISC_MOUSECALIBRATE */
static void mouse_calibrate (void)
{
    /* do nothing */
}
#endif /* !_MISC_MOUSECALIBRATE */

int MiniGUIMain (int argc, const char* argv[])
{
    MSG Msg;
    HWND hMainWnd;
    MAINWINCREATE CreateInfo;

#ifdef _LITE_VERSION
    SetDesktopRect(0, 0, 1024, 768);
#endif

    mouse_calibrate ();

    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);
    printf ("The main window created.\n");
    
    if (hMainWnd == HWND_INVALID)
        return -1;

    ShowWindow(hMainWnd, SW_SHOWNORMAL);
    printf ("The main window showed.\n");

    while (GetMessage(&Msg, hMainWnd)) {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    MainWindowThreadCleanup (hMainWnd);

    return 0;
}

#ifndef _LITE_VERSION
#include <minigui/dti.c>
#endif


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值