20070723 minigui demo
http://www.yippeesoft.com

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

#include <minigui/common.h>   /* 包括MiniGUI 常用的宏以及数据类型的定义 */
#include <minigui/minigui.h>  /* 包含了全局的和通用的接口函数以及某些杂项函数的定义 */
#include <minigui/gdi.h>   /* 包含了 MiniGUI 绘图函数的接口定义 */
#include <minigui/window.h>   /* 包含了窗口有关的宏、数据类型、数据结构定义以及函数接口声明 */
#include <minigui/control.h>  /* 包含了 libminigui 中所有内建控件的接口定义 */
#include <minigui/mgext.h>
#include <string.h>
#include <fcntl.h> 
#include <time.h>
#include <pthread.h>

#define IDOK   100 //定义控件ID号

static DLGTEMPLATE DlgFirstRun = &leftsign;           //定义主窗体模板,DLGTEMPLATE为结构
 WS_BORDER &line; WS_CAPTION,                //窗体风格(宏的含义参看)
  WS_EX_NONE,                            //扩展风格(与窗体风格同,见windows.h)
  0, 0, 320, 240,                //面板范围 
  "caption",                   //caption内容        
  0, 0,                    //图标,菜单  
  1, NULL,                //本面板控件数量,控件列表指针
  0&rightsign;;                                     //一直为0就好了
 
 
 static CTRLDATA CtrlFirstRun[] = &leftsign;          //控件列表CTRLDATA为结构
  &leftsign;
   CTRL_BUTTON,                     //种类(编程指南51页)
                WS_VISIBLE &line;  WS_TABSTOP,//风格
                40, 150, 95, 28,              //范围
                IDOK,                         //控件ID号
                "Ok",                  //内容
                0                           //一直为0就好了
  &rightsign;  
 &rightsign;;
 //面板回调函数(几个开关语句的嵌套)
 static int DialogBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
 &leftsign;                                         //作为面板回调函数的参数时,wparam传的是控件ID。
  switch (message)
  &leftsign;
  case MSG_INITDIALOG:        //初始化
   break;
   
  case MSG_COMMAND:               //命令
            switch (wParam)                 //以控件ID号区分
            &leftsign;
   case IDOK:
    PostQuitMessage (hDlg);
    break;
            &rightsign;
   
   break;
           
        &rightsign;
  return DefaultDialogProc (hDlg, message, wParam, lParam);//返回总是这句
 &rightsign;
 int MiniGUIMain (int argc, const char* argv[])
 &leftsign;
  DlgFirstRun.controls = CtrlFirstRun;    //将控件与窗体关联起来
  DialogBoxIndirectParam (&DlgFirstRun, HWND_DESKTOP, DialogBoxProc, 0L);
  //创建窗体,我们将在下面分析
  return 0;
  
  
 &rightsign;

 ~~~~~~~~

 #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 = &leftsign;10, 50, 300, 80&rightsign;;

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)
&leftsign;
    HDC hdc;
    RECT rc;
    syskey = "";

    switch (message) &leftsign;
        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 &line; DT_WORDBREAK);
            printf ("DrawText2.\\n");
            DrawText (hdc, msg_text, -1, &msg_rc, DT_LEFT &line; 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
            &leftsign;
                last_key = wParam;
                last_key_count = 1;
            &rightsign;
            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;
    &rightsign;

    return DefaultMainWinProc(hWnd, message, wParam, lParam);
&rightsign;

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

    SetMouseCalibrationParameters (src_pts, dst_pts);
&rightsign;
#else /* _MISC_MOUSECALIBRATE */
static void mouse_calibrate (void)
&leftsign;
    /* do nothing */
&rightsign;
#endif /* !_MISC_MOUSECALIBRATE */

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

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

    mouse_calibrate ();

    CreateInfo.dwStyle = WS_VISIBLE &line; WS_BORDER &line; 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)) &leftsign;
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    &rightsign;

    MainWindowThreadCleanup (hMainWnd);

    return 0;
&rightsign;

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

历史博文

标签:, ,
四月 22, 2008 at 2:38 下午 by yippee 1,022 次
Category: Info
Tags: , ,