/*
** $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
MINI GUI 上的helloworld 程序
最新推荐文章于 2024-06-13 17:42:15 发布