This commit is contained in:
2026-07-28 14:17:49 +08:00
parent a68366efb2
commit a222cf81bb
28 changed files with 2421 additions and 231 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

+23
View File
@@ -0,0 +1,23 @@
Brahma
by Ralph Waldo Emerson
If the red slayer think he slays,
Or if the slain think he is slain,
They know not well the subtle ways
I keep, and pass, and turn again.
Far or forgot to me is near;
Shadow and sunlight are the same;
The vanished gods to me appear;
And one to me are shame and fame.
They reckon ill who leave me out;
When me they fly, I am the wings;
I am the doubter and the doubt,
And I the hymn the Brahmin sings.
The strong gods pine for my abode,
And pine in vain the sacred Seven;
But thou, meek lover of the good!
Find me, and turn thy back on heaven.
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

+86
View File
@@ -0,0 +1,86 @@
#include "c_WinApp.h"
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define WINDOW_CLASS_NAME "WinGUI.Main"
c_WinGUI_EventHandlerDef(WM_DESTROY, Main_Destroy) {
PostQuitMessage(0);
}
c_WinGUI_EventHandlerDef(WM_CREATE, Main_Create) {
return TRUE;
}
c_WinGUI_EventMapBegin(WndProc)
c_WinGUI_EventMap(WM_DESTROY, Main_Destroy);
c_WinGUI_EventMap(WM_CREATE, Main_Create);
c_WinGUI_EventMapEnd()
static
BOOL Register(HINSTANCE hInstance) {
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = WINDOW_CLASS_NAME;
return RegisterClass(&WndClass);
}
static
HWND Create(HINSTANCE hInstance, int nCmdShow) {
HWND hwnd = CreateWindow(WINDOW_CLASS_NAME, WINDOW_CLASS_NAME,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL
);
if (hwnd == NULL) {
return NULL;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return hwnd;
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
c_WinGUI_Main(){
MSG msg;
if (!hPrevInstance) {
if (!Register(hInstance)) {
return FALSE;
}
}
WinApp.hInstance = hInstance;
HWND MainHwnd = Create(hInstance, nShowCmd);
if (!MainHwnd) {
return FALSE;
}
WinApp.hwnd = MainHwnd;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
+381
View File
@@ -0,0 +1,381 @@
#include "c_WinGUI.h"
#include "c_WinGuiUtil.h"
#include <stdio.h>
#include <c_WinApp.h>
/* -------------------------------------------------------------------------------------------------------------- */
/* */
#define MAIN_WINDOW_CLASSNAME "KeyMouse"
/* -------------------------------------------------------------------------------------------------------------- */
/* */
#define DIRECTION_SIZE 100
static char Directions[DIRECTION_SIZE];
static int xVal = 10;
static int yVal = 30;
/* -------------------------------------------------------------------------------------------------------------- */
/* */
c_WinGUI_EventHandlerDef(WM_CREATE, KeyMouse_OnCreate){
c_WinGuiUtil_MoveWindowToScreenCenter(hwnd);
return TRUE;
}
c_WinGUI_EventHandlerDef(WM_DESTROY, KeyMouse_OnDestroy){
PostQuitMessage(0);
}
c_WinGUI_EventHandlerDef(WM_PAINT, KeyMouse_OnPaint){
PAINTSTRUCT PaintStruct;
RECT Rect;
HDC hdc = BeginPaint(hwnd, &PaintStruct);
static char* Message[]={
"WM_CHAR",
"WM_KEY",
"WM_SYSKEY",
"WM_MOUSEMOVE",
"WM_MOUSEDOWN",
"WM_MOUSEUP",
};
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
HFONT OldFont = SelectFont(hdc, GetStockObject(OEM_FIXED_FONT));
GetClientRect(hwnd, &Rect);
DrawText(hdc, "MOUSE AND KEYBOARD DEMONSTRATION", -1, &Rect, DT_CENTER);
Rect.top = 20;
Rect.bottom = 40;
DrawText(hdc, "(Try experimenting with mouse and keyboard)", -1, &Rect, DT_CENTER);
SelectFont(hdc, OldFont);
for(int i=0; i<sizeof(Message)/sizeof(Message[0]); i++){
TextOut(hdc, xVal, yVal + (20 * (i+1)), Message[i], strlen(Message[i]));
}
EndPaint(hwnd, &PaintStruct);
}
c_WinGUI_EventHandlerDef(WM_CHAR, KeyMouse_OnChar){
char s[100];
HDC hdc = GetDC(hwnd);
int size = snprintf(s, sizeof(s)/sizeof(s[0]), "WM_CHAR ==> Ch = %c, cRepeat = %d "
, ch
, cRepeat);
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
TextOut(hdc, xVal, yVal + 20, s, size);
ReleaseDC(hwnd, hdc);
}
c_WinGUI_EventHandlerDef(WM_KEYDOWN, KeyMouse_OnKey){
char s[100];
HDC hdc = GetDC(hwnd);
int size =0;
if(fBool){
size = snprintf(s, sizeof(s)/sizeof(s[0])
, "WM_KEYDOWN ==> vk = %c, fDown = %d, cRepeat = %d, flags = %d "
, vk
, fBool
, cRepeat
, flags
);
}else{
size = snprintf(s, sizeof(s)/sizeof(s[0])
, "WM_KEYUP ==> vk = %c, fDown = %d, cRepeat = %d, flags = %d "
, vk
, fBool
, cRepeat
, flags
);
}
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
TextOut(hdc, xVal, yVal + 40, s, size);
ReleaseDC(hwnd, hdc);
}
c_WinGUI_EventHandlerDef(WM_SYSKEYDOWN, KeyMouse_OnSysKey){
char s[100];
HDC hdc = GetDC(hwnd);
int size = 0;
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
if(fBool){
size = snprintf(s, sizeof(s)/sizeof(s[0])
, "WM_SYSKEYDOWN ==> vk = %d, fDown = %d, cRepeat = %d, flags = %d "
, vk
, fBool
, cRepeat
, flags);
TextOut(hdc, xVal, yVal + 60, s, size);
FORWARD_WM_SYSKEYDOWN(hwnd, vk, cRepeat, flags, DefWindowProc);
}else{
size = snprintf(s, sizeof(s)/sizeof(s[0])
, "WM_SYSKEYUP ==> vk = %d, fDown = %d, cRepeat = %d, flags = %d "
, vk
, fBool
, cRepeat
, flags);
TextOut(hdc, xVal, yVal + 60, s, size);
FORWARD_WM_SYSKEYUP(hwnd, vk, cRepeat, flags, DefWindowProc);
}
ReleaseDC(hwnd, hdc);
}
c_WinGUI_EventHandlerDef(WM_LBUTTONDOWN, KeyMouse_OnLButtonDown){
char s[100];
HDC hdc = GetDC(hwnd);
int size =0;
if(fDoubleClick){
size = snprintf(s, sizeof(s)/sizeof(s[0])
, "WM_LBUTTONDBLCLK ==> Db = %d, x = %d, y = %d, flags = %d "
, fDoubleClick
, x
, y
, keyFlags
);
}else{
size = snprintf(s, sizeof(s)/sizeof(s[0])
, "WM_LBUTTONDOWN ==> Db = %d, x = %d, y = %d, flags = %d "
, fDoubleClick
, x
, y
, keyFlags
);
}
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
TextOut(hdc, xVal, yVal + 100, s, size);
ReleaseDC(hwnd, hdc);
}
c_WinGUI_EventHandlerDef(WM_LBUTTONUP, KeyMouse_OnLButtonUp){
char s[100];
HDC hdc = GetDC(hwnd);
int size =0;
size = snprintf(s, sizeof(s)/sizeof(s[0])
, "WM_LBUTTONUP ==> x = %d, y = %d, flags = %d "
, x
, y
, keyFlags
);
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
TextOut(hdc, xVal, yVal + 120, s, size);
ReleaseDC(hwnd, hdc);
}
c_WinGUI_EventHandlerDef(WM_MOUSEMOVE, KeyMouse_OnMouseMove){
char s[100];
HDC hdc = GetDC(hwnd);
int size =0;
size = snprintf(s, sizeof(s)/sizeof(s[0])
, "WM_MOUSEMOVE ==> x = %d, y = %d, flags = %d "
, x
, y
, keyFlags
);
if((keyFlags & MK_CONTROL) == MK_CONTROL){
SetTextColor(hdc, RGB(0, 0, 255));
}
if((keyFlags & MK_LBUTTON) == MK_LBUTTON){
SetTextColor(hdc, RGB(0, 255, 0));
}
if((keyFlags & MK_RBUTTON) == MK_RBUTTON){
SetTextColor(hdc, RGB(255, 0, 0));
}
if((keyFlags & MK_SHIFT) == MK_SHIFT){
SetTextColor(hdc, RGB(255, 0, 255));
}
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
TextOut(hdc, xVal, yVal + 80, s, size);
ReleaseDC(hwnd, hdc);
}
c_WinGUI_EventHandlerDef(WM_RBUTTONDOWN, KeyMouse_OnRButtonDown)
{
char s[100];
HDC hdc = GetDC(hwnd);
int size =0;
if(fDoubleClick){
size = snprintf(s, sizeof(s)/sizeof(s[0])
, "WM_RBUTTONDBLCLK ==> Db = %d, x = %d, y = %d, flags = %d "
, fDoubleClick
, x
, y
, keyFlags
);
c_WinGuiUtil_MoveWindowToScreenCenter(hwnd);
}else{
size = snprintf(s, sizeof(s)/sizeof(s[0])
, "WM_RBUTTONDOWN ==> Db = %d, x = %d, y = %d, flags = %d "
, fDoubleClick
, x
, y
, keyFlags
);
}
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
TextOut(hdc, xVal, yVal + 140, s, size);
ReleaseDC(hwnd, hdc);
}
c_WinGUI_EventHandlerDef(WM_RBUTTONUP, KeyMouse_OnRButtonUp){
char s[100];
HDC hdc = GetDC(hwnd);
int size =0;
size = snprintf(s, sizeof(s)/sizeof(s[0])
, "WM_RBUTTONUP ==> x = %d, y = %d, flags = %d "
, x
, y
, keyFlags
);
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
TextOut(hdc, xVal, yVal + 160, s, size);
ReleaseDC(hwnd, hdc);
}
c_WinGUI_EventHandlerDef(WM_MBUTTONDOWN, KeyMouse_OnMButtonDown) {
char s[100];
HDC hdc = GetDC(hwnd);
int size =0;
if(fDoubleClick){
size = snprintf(s, sizeof(s)/sizeof(s[0])
, "WM_MBUTTONDBLCLK ==> Db = %d, x = %d, y = %d, flags = %d "
, fDoubleClick
, x
, y
, keyFlags
);
}else{
size = snprintf(s, sizeof(s)/sizeof(s[0])
, "WM_MBUTTONDOWN ==> Db = %d, x = %d, y = %d, flags = %d "
, fDoubleClick
, x
, y
, keyFlags
);
}
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
TextOut(hdc, xVal, yVal + 180, s, size);
ReleaseDC(hwnd, hdc);
}
c_WinGUI_EventHandlerDef(WM_MBUTTONUP, KeyMouse_OnMButtonUp){
char s[100];
HDC hdc = GetDC(hwnd);
int size =0;
size = snprintf(s, sizeof(s)/sizeof(s[0])
, "WM_MBUTTONUP ==> x = %d, y = %d, flags = %d "
, x
, y
, keyFlags
);
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
TextOut(hdc, xVal, yVal + 160, s, size);
ReleaseDC(hwnd, hdc);
}
/* -------------------------------------------------------------------------------------------------------------- */
/* */
c_WinGUI_EventMapBegin(WndProc)
c_WinGUI_EventMap(WM_CREATE, KeyMouse_OnCreate);
c_WinGUI_EventMap(WM_CHAR, KeyMouse_OnChar);
c_WinGUI_EventMap(WM_KEYDOWN, KeyMouse_OnKey);
c_WinGUI_EventMap(WM_KEYUP, KeyMouse_OnKey);
c_WinGUI_EventMap(WM_SYSKEYDOWN, KeyMouse_OnSysKey);
c_WinGUI_EventMap(WM_SYSKEYUP, KeyMouse_OnSysKey);
c_WinGUI_EventMap(WM_MOUSEMOVE, KeyMouse_OnMouseMove);
c_WinGUI_EventMap(WM_LBUTTONDBLCLK, KeyMouse_OnLButtonDown);
c_WinGUI_EventMap(WM_LBUTTONDOWN, KeyMouse_OnLButtonDown);
c_WinGUI_EventMap(WM_LBUTTONUP, KeyMouse_OnLButtonUp);
c_WinGUI_EventMap(WM_DESTROY, KeyMouse_OnDestroy);
c_WinGUI_EventMap(WM_PAINT, KeyMouse_OnPaint);
c_WinGUI_EventMap(WM_RBUTTONDBLCLK, KeyMouse_OnRButtonDown);
c_WinGUI_EventMap(WM_RBUTTONDOWN, KeyMouse_OnRButtonDown);
c_WinGUI_EventMap(WM_RBUTTONUP, KeyMouse_OnRButtonUp);
c_WinGUI_EventMap(WM_MBUTTONDOWN, KeyMouse_OnMButtonDown);
c_WinGUI_EventMap(WM_MBUTTONDBLCLK, KeyMouse_OnMButtonDown);
c_WinGUI_EventMap(WM_MBUTTONUP, KeyMouse_OnMButtonUp);
c_WinGUI_EventMapEnd()
/* -------------------------------------------------------------------------------------------------------------- */
/* */
static bool Register(HINSTANCE hInstance){
WNDCLASS WndClass;
WndClass.lpszClassName = MAIN_WINDOW_CLASSNAME;
WndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
WndClass.cbWndExtra = 0;
WndClass.cbClsExtra = 0;
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = WndProc;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
WndClass.lpszMenuName = NULL;
return (RegisterClass(&WndClass)!=0);
}
static HWND Create(HINSTANCE hInstance, int nCmdShow){
HWND hWindow = CreateWindowEx(0, MAIN_WINDOW_CLASSNAME, MAIN_WINDOW_CLASSNAME,
WS_OVERLAPPEDWINDOW,
800, 600,
800, 300,
// CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if(!hWindow) return NULL;
ShowWindow(hWindow, nCmdShow);
UpdateWindow(hWindow);
return hWindow;
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
c_WinGUI_Main() {
MSG msg;
if (!hPrevInstance) {
if (!Register(hInstance)) {
return FALSE;
}
}
HWND MainHwnd = Create(hInstance, nShowCmd);
if (!MainHwnd) {
return FALSE;
}
c_WinApp_Init(hInstance, MainHwnd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
+13
View File
@@ -0,0 +1,13 @@
#ifndef INCLUDED_RESOURCE_H
#define INCLUDED_RESOURCE_H
/* ------------------------------------------------------------------------------------------------------------------ */
/* COMMAND */
#define CM_ABOUT 1001
#define CM_BITMAP 1002
#define CM_BRAHMIN 1003
#define CM_WOODNOTES 1004
#define CM_SEASHORE 1005
#endif /*INCLUDED_RESOURCE_H*/
+123
View File
@@ -0,0 +1,123 @@
#include "windows.h"
#include "Resource.h"
Menu MENU
BEGIN
POPUP "Poems"
BEGIN
MENUITEM "Bitmap", CM_BITMAP
MENUITEM "Brahmin", CM_BRAHMIN
MENUITEM "Woodnotes", CM_WOODNOTES
MENUITEM "SeaShore", CM_SEASHORE
END
MENUITEM "&About", CM_ABOUT
END
Icon ICON Emerson.ico
Cursor CURSOR Emerson.cur
Brahma CUSTOM Brahma.txt
Bitmap BITMAP Bitmap.bmp
About DIALOG 18, 18, 141, 58
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Dialog"
BEGIN
PUSHBUTTON "OK", IDOK, 5, 39, 132, 12, WS_CHILD|WS_VISIBLE|WS_TABSTOP
CTEXT "Emerson Example", -1, 1, 9, 140, 8, WS_CHILD|WS_VISIBLE|WS_GROUP
CTEXT "Copyright (c) World Community, Inc.", -1, 1, 23, 140, 10, WS_CHILD|WS_VISIBLE|WS_GROUP
END
STRINGTABLE
BEGIN
0, "Woodnotes (Part 1)"
1, "by Ralph Waldo Emerson"
2, ""
3, "When the pine tosses its cones"
4, "To the song of its waterfall tones,"
5, "Who speeds to the woodland walks?"
6, "To birds and trees who talks?"
7, "Caesar of his leafy Rome,"
8, "There the poet is at home."
9, "He goes to the river-side,"
10, "Not hook nor line hath he;"
11, "He stands in the meadows wide,"
12, "Nor gun nor scythe to see."
13, "Sure some god his eye enchants;"
14, "What he knows nobody wants,"
15, "In the wood he travels glad,"
16, "Without better fortune had,"
17, "Melancholy without bad."
18, "Knowledge this man prizes best"
19, "Seems, fantastic to the rest:"
20, "Pondering shadows, colors, clouds,"
21, "Grass-bunds and caterpillar-shrouds,"
22, "Boughs on which the wild bees settle,"
23, "Tints that spot the violet's petal,"
24, "Why nature loves the number five,"
25, "And why the star-form she repeats:"
26, "Lover of all things alive,"
27, "Wonderer at all he meets,"
28, "Wonderer chiefly at himself"
29, "Who can tell him what he is?"
30, "Or how meet in human elf"
31, "Coming and past eternities?"
32, "Brahma"
33, "by Ralph Waldo Emerson"
34, ""
35, "If the red slayer think he slays"
36, "Or if the slain think he is slain,"
37, "They know not well the subtle ways"
38, "I keep and pass and turn again."
39, ""
40, "Far or forget to me is near;"
41, "Shadow and sunlight are the same;"
42, "The vanished gods to me appear;"
43, "And one to me are shame and fame."
44, ""
45, "They reckon ill who leave me out"
46, "When me they fly, I am the wings;"
47, "I am the doubter and the doubt,"
48, "And I the hymn the Brahmin sings."
49, ""
50, "The strong gods pine for my abode,"
51, "And pine in vain the sacred Seven;"
52, "But thou, meek lover of the good!"
53, "Find me, and turn thy back on heaven."
64, "SeaShore"
65, "by Ralph Waldo Emerson"
66, ""
67, "I heard or seemed to hear the chiding Sea"
68, "Say, Pilgrim, why so late and slow to come?"
69, "Am I not always here, thy summer home?"
70, "Is not my voice thy music, morn and eve?"
71, "My breath thy healthful climate in the heats,"
72, "My trouch thy antidote, my bay thy bath?"
73, "Was ever couch magnificent as mine?"
74, "Lie on the warm rock-ledges, and there learn"
75, "A little but suffices like a town."
76, "I make your sculptured architecture vain,"
77, "Vain beside mine. I drive my wedges home,"
78, "And carve the coastwise mountain into caves."
79, "Lo! here is ROme, and Nineveh and Thebes,"
80, "Kannak and Pyramid and Giant's Stairs"
81, "Half piled or prostrate; and my newest slab"
82, "Older than all thy race."
83, ""
84, "Behold the Sea,"
85, "The opaline, the plentiful and strong,"
86, "Yet beautiful as is the rose in June,"
87, "Fresh as the trickling rainbow of July;"
88, "Sea full of food, the nourisher of kinds,"
89, "Purger of earth, and medicine of men;"
90, "Creating a sweet climate by my breath,"
91, "Washing out harms and griefs from memory,"
92, "And, in my mathe matic ebb and flow,"
93, "Giving a hint of that which changes not."
94, "Rich ar the sea-gods: who gives gifts but they?"
95, "They grape the sea for pearls, but more than pearls:"
96, "They pluck force thence, and give it to the wise."
97, "For every wave is wealth to Daedalus,"
98, "Wealth to the cunning artist who can work"
99, "This matchless strength. Where shall he find, 0 waves!"
100, "A load your Atlas shoulders cannot lift?"
END
+305
View File
@@ -0,0 +1,305 @@
#include "c_WinApp.h"
#include "Resource.h"
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define MAIN_WINDOW_CLASSNAME "Resource.Main"
static HANDLE hResource;
static HBITMAP hTheBitmap;
static int ScrollWidth;
static int MaxLines = 21;
static int Start = 0;
static int TextHeight=0;
static int PageSize = 3;
static int nPosition = 0;
static BOOL bDrawBitmaps = TRUE;
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
static void NotYetAvailable(HWND hwnd) {
MessageBox(hwnd, "Not Yet Available!", "Under Construction", MB_OK);
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
BOOL CALLBACK AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_INITDIALOG: {
return TRUE;
}
case WM_COMMAND: {
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
}
return FALSE;
}
c_WinGUI_EventHandlerDef(WM_CREATE, Main_Create) {
TEXTMETRIC TextMetric;
hTheBitmap = LoadBitmap(WinApp.hInstance, "Bitmap");
if (!hTheBitmap) {
MessageBox(hwnd, "No Bitmap", "Fatal Error", MB_OK);
return FALSE;
}
hResource = LoadResource(WinApp.hInstance, FindResource(WinApp.hInstance, "Brahma", "CUSTOM"));
HDC PaintDC = GetDC(hwnd);
GetTextMetrics(PaintDC, &TextMetric);
ReleaseDC(hwnd, PaintDC);
TextHeight = TextMetric.tmHeight + TextMetric.tmExternalLeading;
SetScrollRange(hwnd, SB_VERT, 0, -1, FALSE);
return TRUE;
}
c_WinGUI_EventHandlerDef(WM_DESTROY, Main_Destroy) {
FreeResource(hResource);
DeleteBitmap(hTheBitmap);
PostQuitMessage(0);
}
c_WinGUI_EventHandlerDef(WM_COMMAND, Main_Command) {
switch (id) {
case CM_ABOUT: {
FARPROC AboutBox = MakeProcInstance((FARPROC)AboutDlgProc, WinApp.hInstance);
DialogBox(WinApp.hInstance, "About", hwnd, (DLGPROC)AboutBox);
FreeProcInstance(AboutBox);
break;
}
case CM_BITMAP: {
bDrawBitmaps = TRUE;
SetScrollRange(hwnd, SB_VERT, 0, -1, FALSE);
InvalidateRect(hwnd, NULL, TRUE);
break;
}
case CM_BRAHMIN: {
Start = 32;
MaxLines = 22;
SetScrollRange(hwnd, SB_VERT, 0, MaxLines-1, FALSE);
InvalidateRect(hwnd, NULL, TRUE);
bDrawBitmaps = FALSE;
break;
}
case CM_WOODNOTES: {
Start = 0;
MaxLines = 32;
SetScrollRange(hwnd, SB_VERT, 0, MaxLines-1, FALSE);
InvalidateRect(hwnd, NULL, TRUE);
bDrawBitmaps = FALSE;
break;
}
case CM_SEASHORE: {
Start = 64;
MaxLines = 37;
SetScrollRange(hwnd, SB_VERT, 0, MaxLines-1, FALSE);
InvalidateRect(hwnd, NULL, TRUE);
bDrawBitmaps = FALSE;
break;
}
}
}
c_WinGUI_EventHandlerDef(WM_PAINT, Main_Paint) {
PAINTSTRUCT PaintStruct;
int NumImages = 15;
char s[101];
int Y = 0;
HDC PaintDC = BeginPaint(hwnd, &PaintStruct);
SetBkMode(PaintDC, TRANSPARENT);
if (bDrawBitmaps) {
HDC BitmapDC = CreateCompatibleDC(PaintDC);
HBITMAP oldBitmap = SelectBitmap(BitmapDC, hTheBitmap);
for (int i=0; i<NumImages; i++) {
for (int j=0; j<NumImages; j++) {
BitBlt(PaintDC, i*66, j*66, 64, 64, BitmapDC, 0, 0, SRCCOPY);
}
}
SelectBitmap(BitmapDC, oldBitmap);
DeleteDC(BitmapDC);
}else {
for (int i=nPosition; i<MaxLines; i++) {
LoadString(WinApp.hInstance, i+Start, s, 100);
TextOut(PaintDC, 1, Y, s, strlen(s));
Y+=TextHeight;
}
}
EndPaint(hwnd, &PaintStruct);
#if 0
PAINTSTRUCT PaintStruct;
RECT Rect;
HDC PaintDC = BeginPaint(hwnd, &PaintStruct);
SetBkMode(PaintDC, TRANSPARENT);
char *Poem = (char *) LockResource(hResource);
GetClientRect(hwnd, &Rect);
Rect.left += 10;
Rect.top += 10;
DrawText(PaintDC, Poem, -1, &Rect, DT_EXTERNALLEADING);
GlobalUnlock(hResource);
EndPaint(hwnd, &PaintStruct);
#endif
}
c_WinGUI_EventHandlerDef(WM_KEYDOWN, Main_Key) {
switch (vk) {
case VK_HOME: {
SendMessage(hwnd, WM_VSCROLL, SB_TOP, 0L);
break;
}
case VK_DOWN: {
SendMessage(hwnd, WM_VSCROLL, SB_LINEDOWN, 0L);
break;
}
case VK_UP: {
SendMessage(hwnd, WM_VSCROLL, SB_LINEUP, 0L);
break;
}
case VK_PRIOR: {
SendMessage(hwnd, WM_VSCROLL, SB_PAGEUP, 0L);
break;
}
case VK_NEXT: {
SendMessage(hwnd, WM_VSCROLL, SB_PAGEDOWN, 0L);
break;
}
}
}
c_WinGUI_EventHandlerDef(WM_VSCROLL, Main_VScroll) {
int SrcMove = 0;
int Temp;
int i;
switch (code) {
case SB_TOP: {
nPosition = 0;
break;
}
case SB_BOTTOM: {
nPosition = MaxLines;
break;
}
case SB_LINEUP: {
if (nPosition>0) {
nPosition -= 1;
SrcMove = TextHeight;
}
break;
}
case SB_LINEDOWN: {
if (nPosition < MaxLines) {
nPosition +=1;
SrcMove = -TextHeight;
}
break;
}
case SB_PAGEUP: {
if ((nPosition - PageSize) > 0) {
for (i=0; i<PageSize; i++) {
SendMessage(hwnd, WM_VSCROLL, SB_LINEUP, 0L);
}
}
break;
}
case SB_PAGEDOWN: {
if ((nPosition + PageSize) < MaxLines) {
for (i=0; i<PageSize; i++) {
SendMessage(hwnd, WM_VSCROLL, SB_LINEDOWN, 0L);
}
}
break;
}
case SB_THUMBTRACK: {
Temp = nPosition;
nPosition = pos;
SrcMove = (Temp - nPosition) * TextHeight;
break;
}
case SB_THUMBPOSITION: {
nPosition = pos;
break;
}
}
nPosition = max(0, min(nPosition, MaxLines-1));
SetScrollPos(hwnd, SB_VERT, nPosition, TRUE);
ScrollWindow(hwnd, 0, SrcMove, NULL, NULL);
}
c_WinGUI_EventMapBegin(WndProc)
c_WinGUI_EventMap(WM_DESTROY, Main_Destroy);
c_WinGUI_EventMap(WM_CREATE, Main_Create);
c_WinGUI_EventMap(WM_COMMAND, Main_Command);
c_WinGUI_EventMap(WM_PAINT, Main_Paint);
c_WinGUI_EventMap(WM_KEYDOWN, Main_Key);
c_WinGUI_EventMap(WM_VSCROLL, Main_VScroll);
c_WinGUI_EventMapEnd()
static bool Register(HINSTANCE hInstance){
WNDCLASS WndClass;
WndClass.lpszClassName = MAIN_WINDOW_CLASSNAME;
WndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
WndClass.cbWndExtra = 0;
WndClass.cbClsExtra = 0;
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = WndProc;
WndClass.hIcon = LoadIcon(hInstance, "Icon"); /* Icon Resource */
WndClass.hCursor = LoadCursor(hInstance, "Cursor"); /* Cursor Resource */
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
WndClass.lpszMenuName = "Menu"; /* Menu Resource */
return (RegisterClass(&WndClass)!=0);
}
static HWND Create(HINSTANCE hInstance, int nCmdShow){
HWND hWindow = CreateWindowEx(0, MAIN_WINDOW_CLASSNAME, MAIN_WINDOW_CLASSNAME,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if(!hWindow) return NULL;
ShowWindow(hWindow, nCmdShow);
UpdateWindow(hWindow);
return hWindow;
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
c_WinGUI_Main() {
MSG msg;
if (!hPrevInstance) {
if (!Register(hInstance)) {
return FALSE;
}
}
WinApp.hInstance = hInstance;
HWND MainHwnd = Create(hInstance, nShowCmd);
if (!MainHwnd) {
return FALSE;
}
WinApp.hwnd = MainHwnd;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
+16
View File
@@ -0,0 +1,16 @@
#ifndef INCLUDED_SIMPFONT_H
#define INCLUDED_SIMPFONT_H
#define CM_INFO 100
#define CM_ROMAN 101
#define CM_SWISS 102
#define CM_SYMBOL 103
#define CM_ANSI_FIXED_FONT 201
#define CM_ANSI_VAR_FONT 202
#define CM_DEVICE_DEFAULT_FONT 203
#define CM_OEM_FIXED_FONT 204
#define CM_SYSTEM_FONT 205
#define CM_SYSTEM_FIXED_FONT 206
#endif /*INCLUDED_SIMPFONT_H*/
+21
View File
@@ -0,0 +1,21 @@
#include "SimpFont.h"
Menu MENU
BEGIN
MENUITEM "Font Info", CM_INFO
POPUP "TrueType"
BEGIN
MENUITEM "Roman", CM_ROMAN
MENUITEM "Swiss", CM_SWISS
MENUITEM "Symbol", CM_SYMBOL
END
POPUP "StockFonts"
BEGIN
MENUITEM "Ansi Fixed", CM_ANSI_FIXED_FONT
MENUITEM "Ansi Var", CM_ANSI_VAR_FONT
MENUITEM "Device", CM_DEVICE_DEFAULT_FONT
MENUITEM "OEM Fixed", CM_OEM_FIXED_FONT
MENUITEM "System", CM_SYSTEM_FONT
MENUITEM "System Fixed", CM_SYSTEM_FIXED_FONT
END
END
+320
View File
@@ -0,0 +1,320 @@
#include <stdio.h>
#include "SimpFont.h"
#include "c_WinApp.h"
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define WINDOW_CLASS_NAME "SimpFont.Main"
static LOGFONT LogFont;
static HFONT TheFont;
static char aFaceName[80];
static TEXTMETRIC TextMets;
static char* FontChoice[]={
"Times New Roman",
"Arial",
"Symbol",
"StockFont"
};
typedef enum {
Roman, Swiss, Symbol, StockFont
}TChoice;
static TChoice Choice;
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
static HFONT GetFont(int Escapement, char* Name) {
memset(&LogFont, 0, sizeof(LOGFONT));
LogFont.lfHeight = 37;
LogFont.lfWeight = 400;
LogFont.lfEscapement = Escapement;
LogFont.lfItalic = 1;
LogFont.lfUnderline = 1;
LogFont.lfOutPrecision = OUT_STROKE_PRECIS;
LogFont.lfClipPrecision = CLIP_STROKE_PRECIS;
LogFont.lfQuality = DEFAULT_QUALITY;
strcpy(LogFont.lfFaceName, Name);
if (TheFont) {
DeleteFont(TheFont);
}
TheFont = CreateFontIndirect(&LogFont);
return TheFont;
}
static char* GetType(char* s) {
strcpy(s, "Font Type:");
if ((TextMets.tmPitchAndFamily & TMPF_FIXED_PITCH)==0) {
strcat(s, "Default<>");
}
if ((TextMets.tmPitchAndFamily & TMPF_FIXED_PITCH)==TMPF_FIXED_PITCH) {
strcat(s, "Fixed<>");
}
if ((TextMets.tmPitchAndFamily & TMPF_VECTOR)==TMPF_VECTOR) {
strcat(s, "Vector<>");
}
if ((TextMets.tmPitchAndFamily & TMPF_TRUETYPE)==TMPF_TRUETYPE) {
strcat(s, "TrueType<>");
}
if ((TextMets.tmPitchAndFamily & TMPF_DEVICE)==TMPF_DEVICE) {
strcat(s, "Device<>");
}
if (strlen(s) > 99) {
s[strlen(s) - 3 ] = '\0';
}
return s;
}
static char* GetFamily(char* s) {
int R = TextMets.tmPitchAndFamily & 0xF0;
strcpy(s, "Family:");
if (R==FF_DONTCARE) strcat(s, "Don't Care or don't know");
if (R==FF_ROMAN) strcat(s, "Roman");
if (R==FF_SWISS) strcat(s, "Swiss");
if (R==FF_MODERN) strcat(s, "Modern");
if (R==FF_SCRIPT) strcat(s, "Script");
if (R==FF_DECORATIVE) strcat(s, "Decorative");
return s;
}
static char* GetCharSet(char* s) {
strcpy(s, "Char Set:");
if (TextMets.tmCharSet==ANSI_CHARSET) {
strcat(s, "Ansi");
}
if (TextMets.tmCharSet==DEFAULT_CHARSET) {
strcat(s, "Default");
}
if (TextMets.tmCharSet==SYMBOL_CHARSET) {
strcat(s, "Symbol");
}
if (TextMets.tmCharSet==OEM_CHARSET) {
strcat(s, "OEM");
}
return s;
}
static char* GetFontString(char* s, TEXTMETRIC TextMetric, char* FaceName) {
char szType[99];
char szFamily[99];
char szCharSet[99];
TextMets = TextMetric;
GetType(szType);
GetFamily(szFamily);
GetCharSet(szCharSet);
sprintf(s, "Font:%s\n"
"Height: %d\n"
"Ascent: %d\n"
"Descent: %d\n"
"AveCharW: %d\n"
"MaxCharW: %d\n"
"Weight: %d\n"
"Italic: %hd\n"
"Underlined: %d\n"
"%s\n"
"%s\n"
"%s", FaceName,
TextMets.tmHeight,
TextMets.tmAscent,
TextMets.tmDescent,
TextMets.tmAveCharWidth,
TextMets.tmMaxCharWidth,
TextMets.tmWeight,
TextMets.tmItalic,
TextMets.tmUnderlined,
szType,
szFamily,
szCharSet
);
return s;
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
c_WinGUI_EventHandlerDef(WM_DESTROY, Main_Destroy) {
if (TheFont) {
DeleteFont(TheFont);
}
PostQuitMessage(0);
}
c_WinGUI_EventHandlerDef(WM_CREATE, Main_Create) {
GetFont(0, "New Times Roman");
return TRUE;
}
c_WinGUI_EventHandlerDef(WM_COMMAND, Main_Command) {
char s[500];
switch (id) {
case CM_INFO: {
GetFontString(s, TextMets, aFaceName);
MessageBox(hwnd, s, "Font Info", MB_OK);
break;
}
case CM_ROMAN: {
Choice = Roman;
InvalidateRect(hwnd, NULL, TRUE);
break;
}
case CM_SWISS: {
Choice = Swiss;
InvalidateRect(hwnd, NULL, TRUE);
break;
}
case CM_SYMBOL: {
Choice = Symbol;
InvalidateRect(hwnd, NULL, TRUE);
break;
}
case CM_ANSI_FIXED_FONT: {
if (TheFont) DeleteFont(TheFont);
TheFont = GetStockFont(ANSI_FIXED_FONT);
Choice = StockFont;
InvalidateRect(hwnd, NULL, TRUE);
break;
}
case CM_ANSI_VAR_FONT: {
if (TheFont) DeleteFont(TheFont);
TheFont = GetStockFont(ANSI_VAR_FONT);
Choice = StockFont;
InvalidateRect(hwnd, NULL, TRUE);
break;
}
case CM_DEVICE_DEFAULT_FONT: {
if (TheFont) DeleteFont(TheFont);
TheFont = GetStockFont(DEVICE_DEFAULT_FONT);
Choice = StockFont;
InvalidateRect(hwnd, NULL, TRUE);
break;
}
case CM_OEM_FIXED_FONT: {
if (TheFont) DeleteFont(TheFont);
TheFont = GetStockFont(OEM_FIXED_FONT);
Choice = StockFont;
InvalidateRect(hwnd, NULL, TRUE);
break;
}
case CM_SYSTEM_FONT: {
if (TheFont) DeleteFont(TheFont);
TheFont = GetStockFont(SYSTEM_FONT);
Choice = StockFont;
InvalidateRect(hwnd, NULL, TRUE);
break;
}
case CM_SYSTEM_FIXED_FONT: {
if (TheFont) DeleteFont(TheFont);
TheFont = GetStockFont(SYSTEM_FIXED_FONT);
Choice = StockFont;
InvalidateRect(hwnd, NULL, TRUE);
break;
}
}
}
c_WinGUI_EventHandlerDef(WM_PAINT, Main_Paint) {
PAINTSTRUCT PaintStruct;
HFONT OldFont;
HDC PaintDC = BeginPaint(hwnd, &PaintStruct);
if (Choice==StockFont) {
OldFont = SelectFont(PaintDC, TheFont);
GetTextFace(PaintDC, sizeof(aFaceName), aFaceName);
GetTextMetrics(PaintDC, &TextMets);
SetTextColor(PaintDC, RGB(rand() % 255, rand()%255, rand()%255));
TextOut(PaintDC, 10, 10, aFaceName, strlen(aFaceName));
TextOut(PaintDC, 10, 30, "Stock Fonts", 11);
TextOut(PaintDC, 10, 50, "Ten Letters", 11);
SelectFont(PaintDC, OldFont);
}else {
for (int i=0; i<=3; i++) {
TheFont = GetFont(900 * i, FontChoice[Choice]);
OldFont = SelectFont(PaintDC, TheFont);
SetTextColor(PaintDC, RGB(rand() % 255, rand()%255, rand()%255));
TextOut(PaintDC, 200, 200, "Ahoy!", 5);
GetTextFace(PaintDC, sizeof(aFaceName), aFaceName);
GetTextMetrics(PaintDC, &TextMets);
SelectFont(PaintDC, OldFont);
}
TextOut(PaintDC, 10, 10, aFaceName, strlen(aFaceName));
}
EndPaint(hwnd, &PaintStruct);
}
c_WinGUI_EventMapBegin(WndProc)
c_WinGUI_EventMap(WM_CREATE, Main_Create);
c_WinGUI_EventMap(WM_DESTROY, Main_Destroy);
c_WinGUI_EventMap(WM_COMMAND, Main_Command);
c_WinGUI_EventMap(WM_PAINT, Main_Paint);
c_WinGUI_EventMapEnd()
static
BOOL Register(HINSTANCE hInstance) {
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = GetStockBrush(WHITE_BRUSH);
WndClass.lpszMenuName = "Menu";
WndClass.lpszClassName = WINDOW_CLASS_NAME;
return RegisterClass(&WndClass);
}
static
HWND Create(HINSTANCE hInstance, int nCmdShow) {
HWND hwnd = CreateWindow(WINDOW_CLASS_NAME, WINDOW_CLASS_NAME,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL
);
if (hwnd == NULL) {
return NULL;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return hwnd;
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
c_WinGUI_Main(){
MSG msg;
if (!hPrevInstance) {
if (!Register(hInstance)) {
return FALSE;
}
}
WinApp.hInstance = hInstance;
HWND MainHwnd = Create(hInstance, nShowCmd);
if (!MainHwnd) {
return FALSE;
}
WinApp.hwnd = MainHwnd;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
+23
View File
@@ -0,0 +1,23 @@
#ifndef INCLUDED_SNAKE_H
#define INCLUDED_SNAKE_H
#include <windows.h>
typedef struct {
int Size;
int StartCol;
int StartRow;
int MaxCols;
int MaxRows;
div_t NumXSects;
div_t NumYSects;
HBITMAP hHeadBitmap;
HBITMAP hBodyBitmap;
HBITMAP hOneHundredBitmap;
}SnakeApp_t;
#define SNAKE_MAIN_WINDOW_CLASS "Snake.Main"
#define SNAKE_GAME_WINDOW_CLASS "Snake.Game"
#endif /*INCLUDED_SNAKE_H*/
+3
View File
@@ -0,0 +1,3 @@
Body BITMAP body.bmp
Head BITMAP head.bmp
Hundred BITMAP hundred.bmp
+530
View File
@@ -0,0 +1,530 @@
#include "Snake.h"
#include "c_WinGUI.h"
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define WINDOW_CLASS_NAME SNAKE_MAIN_WINDOW_CLASS
#define BORDERSIZE 15
#define MAXSECTIONS 1024
#define MAXPRIZES 512
typedef enum {
Left,
Right,
Up,
Down,
TDir_Num
}TDir;
typedef struct {
BOOL DirChange;
TDir Dir;
TDir OldDir;
int SecNun;
int Row;
int Col;
int OldRow;
int OldCol;
}TSectInfo;
typedef struct {
TDir Dir;
BOOL SectChangeDir[256];
int TurnCol;
int TurnRow;
}TTurn;
typedef struct {
BOOL Exists;
int Value;
int Col;
int Row;
}TPrize;
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
static HWND hGameWindow;
static SnakeApp_t SnakeApp;
static BOOL NewSect;
static int VK_P = 112;
static unsigned int SnakeTimer = 1;
static long TotalClicks = 0;
static int Sections;
static int NumPrizes;
static TPrize Prizes[MAXPRIZES];
static TSectInfo SectInfo[MAXSECTIONS];
static TTurn TurnList[25];
static int NumTurns;
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
static
BOOL SetupWindow(HWND hWindow) {
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* Main Window */
c_WinGUI_EventHandlerDef(WM_DESTROY, Main_Destroy) {
if (SnakeApp.hHeadBitmap) {
DeleteObject(SnakeApp.hHeadBitmap);
}
if (SnakeApp.hBodyBitmap) {
DeleteObject(SnakeApp.hBodyBitmap);
}
if (SnakeApp.hOneHundredBitmap) {
DeleteObject(SnakeApp.hOneHundredBitmap);
}
PostQuitMessage(0);
}
c_WinGUI_EventHandlerDef(WM_CREATE, Main_Create) {
memset(&SnakeApp, 0, sizeof(SnakeApp_t));
SnakeApp.Size = 32;
SnakeApp.hHeadBitmap = LoadBitmap(WinApp.hInstance, "Head");
if (!SnakeApp.hHeadBitmap) {
MessageBox(hwnd, "No head", "Fatal Error", MB_OK);
return FALSE;
}
SnakeApp.hBodyBitmap = LoadBitmap(WinApp.hInstance, "Body");
if (!SnakeApp.hBodyBitmap) {
MessageBox(hwnd, "No body", "Fatal Error", MB_OK);
return FALSE;
}
SnakeApp.hOneHundredBitmap = LoadBitmap(WinApp.hInstance, "Hundred");
if (!SnakeApp.hOneHundredBitmap) {
MessageBox(hwnd, "No hundred", "Fatal Error", MB_OK);
return FALSE;
}
int CXFull = GetSystemMetrics(SM_CXSCREEN);
int CYFull = GetSystemMetrics(SM_CYSCREEN);
SnakeApp.NumXSects = div(CXFull, SnakeApp.Size);
SnakeApp.MaxCols = (SnakeApp.NumXSects.quot-1)*SnakeApp.Size;
int BoardWidth = CXFull - SnakeApp.MaxCols;
div_t StartC = div(BoardWidth, 2);
SnakeApp.StartCol = StartC.quot;
SnakeApp.NumYSects = div(CYFull, SnakeApp.Size);
SnakeApp.MaxRows = (SnakeApp.NumYSects.quot-1)*SnakeApp.Size;
BoardWidth = CYFull - SnakeApp.MaxRows;
StartC = div(BoardWidth, 2);
SnakeApp.StartRow = StartC.quot;
hGameWindow = CreateWindow(SNAKE_GAME_WINDOW_CLASS,
"Game Window",
WS_CHILD | WS_VISIBLE,
SnakeApp.StartCol, SnakeApp.StartRow,
SnakeApp.MaxCols, SnakeApp.MaxRows,
hwnd, NULL, WinApp.hInstance, NULL);
return TRUE;
}
c_WinGUI_EventHandlerDef(WM_SIZE, Main_Size) {
if (hGameWindow) {
MoveWindow(hGameWindow, 0, 0, cx, cy, TRUE);
RECT Rect;
GetClientRect(hGameWindow, &Rect);
int CXFull = Rect.right - Rect.left;
int CYFull = Rect.bottom - Rect.top;
SnakeApp.NumXSects = div(CXFull, SnakeApp.Size);
SnakeApp.MaxCols = (SnakeApp.NumXSects.quot-1)*SnakeApp.Size;
int BoardWidth = CXFull - SnakeApp.MaxCols;
div_t StartC = div(BoardWidth, 2);
SnakeApp.StartCol = StartC.quot;
SnakeApp.NumYSects = div(CYFull, SnakeApp.Size);
SnakeApp.MaxRows = (SnakeApp.NumYSects.quot-1)*SnakeApp.Size;
BoardWidth = CYFull - SnakeApp.MaxRows;
StartC = div(BoardWidth, 2);
SnakeApp.StartRow = StartC.quot;
}
}
c_WinGUI_EventMapBegin(WndProc)
c_WinGUI_EventMap(WM_DESTROY, Main_Destroy);
c_WinGUI_EventMap(WM_CREATE, Main_Create);
c_WinGUI_EventMap(WM_SIZE, Main_Size);
c_WinGUI_EventMapEnd()
/* ------------------------------------------------------------------------------------------------------------------ */
/* GAME */
static void InitializeSections(void);
static void SetColRow(void) {
int i;
for (i=0; i<=Sections; i++) {
SectInfo[i].OldCol = SectInfo[i].Col;
SectInfo[i].OldRow = SectInfo[i].Row;
switch (SectInfo[i].Dir) {
case Up: {
SectInfo[i].Row-=SnakeApp.Size;
break;
}
case Down:{
SectInfo[i].Row+=SnakeApp.Size;
break;
}
case Left: {
SectInfo[i].Col-=SnakeApp.Size;
break;
}
case Right: {
SectInfo[i].Col+=SnakeApp.Size;
break;
}
}
}
for (i = Sections; i>0; i--) {
if (SectInfo[i-1].DirChange) {
SectInfo[i].DirChange = TRUE;
SectInfo[i].Dir = SectInfo[i-1].Dir;
SectInfo[i-1].DirChange = FALSE;
}
}
}
static void SetNewTurnSection(void) {
for (int i=1; i<=Sections; i++) {
if (TurnList[NumTurns].SectChangeDir[i]==TRUE) {
break;
}
TurnList[NumTurns].SectChangeDir[i] = FALSE;
i++;
TurnList[NumTurns].SectChangeDir[i] = TRUE;
}
}
static void Boom(HWND hwnd) {
memset(SectInfo, 0, sizeof(SectInfo));
Sections = 0;
NumPrizes = 0;
for (int i=0; i<10; i++) {
MessageBeep(-1);
}
InitializeSections();
InvalidateRect(hwnd, NULL, TRUE);
}
static void WhiteOut(HWND hwnd, int i) {
HDC PaintDC = GetDC(hwnd);
HDC MemDC = CreateCompatibleDC(PaintDC);
HBITMAP SaveBmp = SelectBitmap(MemDC, SnakeApp.hOneHundredBitmap);
BitBlt(PaintDC, Prizes[i].Col, Prizes[i].Row, 32, 32, MemDC, 0, 0, SRCINVERT);
SelectObject(MemDC, SaveBmp);
DeleteDC(MemDC);
ReleaseDC(hwnd, PaintDC);
}
static void CheckForCollision(HWND hwnd) {
if (SectInfo[0].Col<0) Boom(hwnd);
if (SectInfo[0].Row<0) Boom(hwnd);
if (SectInfo[0].Col + SnakeApp.Size > SnakeApp.MaxCols) Boom(hwnd);
if (SectInfo[0].Row + SnakeApp.Size > SnakeApp.MaxRows) Boom(hwnd);
for (int i=1; i<=Sections; i++) {
if (SectInfo[i].Col == SectInfo[0].Col && SectInfo[i].Row == SectInfo[0].Row) {
Boom(hwnd);
}
}
for (int i=0; i<=NumPrizes; i++) {
if (Prizes[i].Exists) {
if (((SectInfo[0].Row >= Prizes[i].Row) &&
(SectInfo[0].Row <=Prizes[i].Row + (SnakeApp.Size-1)))&&
((SectInfo[0].Col >=Prizes[i].Col) &&
(SectInfo[0].Col <=Prizes[i].Col + (SnakeApp.Size-1)))) {
Prizes[i].Exists = FALSE;
WhiteOut(hwnd, i);
}
}
}
}
static void InitializeSections(void) {
int i;
int StartCol;
int StartRow;
Sections = 5;
StartCol = SnakeApp.Size * 3;
StartRow = SnakeApp.Size * 3;
for (i=0; i<=Sections; i++) {
SectInfo[i].Dir = Right;
SectInfo[i].DirChange = FALSE;
SectInfo[i].Col = StartCol - (SnakeApp.Size * i);
SectInfo[i].Row = StartRow;
SectInfo[i].OldCol = SectInfo[i].Col;
SectInfo[i].OldRow = SectInfo[i].Row;
}
NewSect = FALSE;
}
static void GetOldDir(TDir NewDir) {
TurnList[NumTurns].Dir = NewDir;
TurnList[NumTurns].SectChangeDir[1] = TRUE;
SectInfo[0].OldDir = SectInfo[0].Dir;
SectInfo[0].Dir = NewDir;
SectInfo[0].DirChange = TRUE;
TurnList[0].TurnCol = SectInfo[0].Col;
TurnList[0].TurnRow = SectInfo[0].Row;
}
static void MoveBitmap(HWND hwnd) {
SetColRow();
HDC DC = GetDC(hwnd);
HDC PicDC = CreateCompatibleDC(DC);
CheckForCollision(hwnd);
HBITMAP OldBmp = SelectBitmap(PicDC, SnakeApp.hHeadBitmap);
BitBlt(DC, SectInfo[0].OldCol, SectInfo[0].OldRow, SnakeApp.Size, SnakeApp.Size, PicDC, 0, 0, SRCINVERT);
BitBlt(DC, SectInfo[0].Col, SectInfo[0].Row, SnakeApp.Size, SnakeApp.Size, PicDC, 0, 0, SRCINVERT);
SelectObject(PicDC, OldBmp);
OldBmp = SelectBitmap(PicDC, SnakeApp.hBodyBitmap);
BitBlt(DC, SectInfo[1].Col, SectInfo[1].Row, SnakeApp.Size, SnakeApp.Size, PicDC, 0, 0, SRCINVERT);
BitBlt(DC, SectInfo[Sections].Col, SectInfo[Sections].Row, SnakeApp.Size, SnakeApp.Size, PicDC, 0, 0, SRCINVERT);
if (NewSect) {
BitBlt(DC, SectInfo[Sections].Col, SectInfo[Sections].Row, SnakeApp.Size, SnakeApp.Size, PicDC, 0, 0, SRCINVERT);
NewSect = FALSE;
}
SelectObject(PicDC, OldBmp);
SectInfo[0].DirChange = FALSE;
DeleteDC(PicDC);
ReleaseDC(hwnd, DC);
SetNewTurnSection();
}
static void SetSections(void) {
Sections++;
SectInfo[Sections].Dir = SectInfo[Sections-1].Dir;
SectInfo[Sections].DirChange = FALSE;
switch (SectInfo[Sections].Dir) {
case Left: {
SectInfo[Sections].Col = SectInfo[Sections-1].Col + SnakeApp.Size;
SectInfo[Sections].Row = SectInfo[Sections-1].Row;
break;
}
case Right: {
SectInfo[Sections].Col = SectInfo[Sections-1].Col - SnakeApp.Size;
SectInfo[Sections].Row = SectInfo[Sections-1].Row;
break;
}
case Up: {
SectInfo[Sections].Col = SectInfo[Sections-1].Col;
SectInfo[Sections].Row = SectInfo[Sections-1].Row + SnakeApp.Size;
break;
}
case Down: {
SectInfo[Sections].Col = SectInfo[Sections-1].Col;
SectInfo[Sections].Row = SectInfo[Sections-1].Row - SnakeApp.Size;
break;
}
}
SectInfo[Sections].OldCol = SectInfo[Sections-1].Col;
SectInfo[Sections].OldRow = SectInfo[Sections-1].Row;
}
static void SetPrizes(void) {
NumPrizes++;
Prizes[NumPrizes].Exists = TRUE;
Prizes[NumPrizes].Row = (rand() % SnakeApp.NumYSects.quot) * SnakeApp.Size;
Prizes[NumPrizes].Col = (rand() % SnakeApp.NumXSects.quot) * SnakeApp.Size;
}
c_WinGUI_EventHandlerDef(WM_CREATE, Game_Create) {
if (!SetTimer(hwnd, SnakeTimer, 125, NULL)) {
MessageBox(hwnd, "No Timers Available", "Snake Info", MB_OK);
return FALSE;
}
NumPrizes = 0;
InitializeSections();
return TRUE;
}
c_WinGUI_EventHandlerDef(WM_DESTROY, Game_Destroy) {
KillTimer(hwnd, SnakeTimer);
}
c_WinGUI_EventHandlerDef(WM_CHAR, Game_Char) {
if (ch==VK_P) {
KillTimer(hwnd, SnakeTimer);
}
}
c_WinGUI_EventHandlerDef(WM_KEYDOWN, Game_Key) {
switch (vk) {
case VK_DOWN: {
GetOldDir(Down);
break;
}
case VK_UP: {
GetOldDir(Up);
break;
}
case VK_LEFT: {
GetOldDir(Left);
break;
}
case VK_RIGHT: {
GetOldDir(Right);
break;
}
}
MoveBitmap(hwnd);
}
c_WinGUI_EventHandlerDef(WM_PAINT, Game_Paint) {
PAINTSTRUCT PaintStruct;
HDC DC = BeginPaint(hwnd, &PaintStruct);
HDC PicDC = CreateCompatibleDC(DC);
// Draw Head
HBITMAP OldMap = SelectBitmap(PicDC, SnakeApp.hHeadBitmap);
BitBlt(DC, SectInfo[0].Col, SectInfo[0].Row, SnakeApp.Size, SnakeApp.Size, PicDC, 0, 0, SRCINVERT);
SelectObject(PicDC, OldMap);
// Draw Body
OldMap = SelectBitmap(PicDC, SnakeApp.hBodyBitmap);
for (int i=1; i<=Sections; i++) {
BitBlt(DC, SectInfo[i].Col, SectInfo[i].Row, SnakeApp.Size, SnakeApp.Size, PicDC, 0, 0, SRCINVERT);
}
SelectObject(PicDC, OldMap);
DeleteDC(PicDC);
EndPaint(hwnd, &PaintStruct);
SectInfo[0].DirChange = FALSE;
}
c_WinGUI_EventHandlerDef(WM_TIMER, Game_Timer) {
HBITMAP SaveBmp;
SetFocus(hwnd);
if (id==SnakeTimer) {
MoveBitmap(hwnd);
TotalClicks++;
if ((TotalClicks%10)==0) {
SetSections();
SetPrizes();
HDC PaintDC = GetDC(hwnd);
HDC PicDC = CreateCompatibleDC(PaintDC);
NewSect = TRUE;
SaveBmp = SelectBitmap(PicDC, SnakeApp.hOneHundredBitmap);
BitBlt(PaintDC, Prizes[NumPrizes].Col,
Prizes[NumPrizes].Row,
32, 32, PicDC, 0, 0, SRCINVERT);
SelectObject(PicDC, SaveBmp);
DeleteDC(PicDC);
ReleaseDC(hwnd, PaintDC);
}
}
}
c_WinGUI_EventMapBegin(GameWndProc)
c_WinGUI_EventMap(WM_CREATE, Game_Create);
c_WinGUI_EventMap(WM_DESTROY, Game_Destroy);
c_WinGUI_EventMap(WM_CHAR, Game_Char);
c_WinGUI_EventMap(WM_KEYDOWN, Game_Key);
c_WinGUI_EventMap(WM_PAINT, Game_Paint);
c_WinGUI_EventMap(WM_TIMER, Game_Timer);
c_WinGUI_EventMapEnd()
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
static
BOOL Register(HINSTANCE hInstance) {
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = GetStockBrush(GRAY_BRUSH);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = WINDOW_CLASS_NAME;
RegisterClass(&WndClass);
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = GameWndProc;
WndClass.hIcon = NULL;
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = GetStockBrush(WHITE_BRUSH);
WndClass.lpszClassName = SNAKE_GAME_WINDOW_CLASS;
return RegisterClass(&WndClass);
}
static
HWND Create(HINSTANCE hInstance, int nCmdShow) {
HWND hwnd = CreateWindow(WINDOW_CLASS_NAME,
"A Snake and it's Tail",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL
);
if (hwnd == NULL) {
return NULL;
}
nCmdShow = SW_SHOWMAXIMIZED;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return hwnd;
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
c_WinGUI_Main(){
MSG msg;
if (!hPrevInstance) {
if (!Register(hInstance)) {
return FALSE;
}
}
WinApp.hInstance = hInstance;
HWND MainHwnd = Create(hInstance, nShowCmd);
if (!MainHwnd) {
return FALSE;
}
WinApp.hwnd = MainHwnd;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
+254
View File
@@ -0,0 +1,254 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAX_LINE_LEN 2048
#define MAX_PARAMS 16
#define MAX_NAME_LEN 64
typedef struct {
char type[MAX_NAME_LEN];
char name[MAX_NAME_LEN];
} ParamInfo;
// 辅助函数:去除两端空格
void trim(char *str) {
char *end;
while (isspace((unsigned char)*str)) str++;
if (*str == 0) return;
end = str + strlen(str) - 1;
while (end > str && isspace((unsigned char)*end)) end--;
*(end + 1) = '\0';
memmove(str - (str - (str + (isspace((unsigned char)*str) ? 1 : 0))), str, strlen(str) + 1);
}
// 辅助函数:精准提取类型强转
// 例如:"(int)(short)LOWORD(lParam)" -> 提取出 "int"
// 如果只是 "(hwnd)",由于 hwnd 是变量名而非合法类型,会通过 default_name 转换成 "HWND"
void extract_first_type(const char *src, char *dest, const char *default_name) {
dest[0] = '\0';
const char *p = src;
// 跳过前面的空格
while (*p && isspace((unsigned char)*p)) p++;
if (*p == '(') {
p++; // 进入第一个左括号
int i = 0;
while (*p && *p != ')') {
dest[i++] = *p++;
}
dest[i] = '\0';
trim(dest);
}
// 关键修正:如果提取出来的“类型”和变量名一样(例如把 (hwnd) 误判为类型为 hwnd),或者为空
// 则通过名字来给它赋予 Windows 标准类型
if (strlen(dest) == 0 || strcmp(dest, default_name) == 0 || strcmp(dest, "fn") == 0) {
if (strstr(default_name, "hwnd")) strcpy(dest, "HWND");
else if (strstr(default_name, "lParam")) strcpy(dest, "LPARAM");
else if (strstr(default_name, "wParam")) strcpy(dest, "WPARAM");
else if (strstr(default_name, "vk")) strcpy(dest, "UINT");
else strcpy(dest, "int"); // 默认兜底
}
}
// 核心解析函数
void process_macros(const char *handle_line, const char *forward_line) {
char msg_name[MAX_NAME_LEN] = {0};
char return_type[MAX_NAME_LEN] = {0};
// 1. 提取 MsgName
char *msg_pos = strstr(handle_line, "HANDLE_WM_");
if (!msg_pos) return;
msg_pos += 10;
int len = 0;
while (isalnum((unsigned char)msg_pos[len]) || msg_pos[len] == '_') {
msg_name[len] = msg_pos[len];
len++;
}
msg_name[len] = '\0';
// 2. 提取 FORWARD_WM_xxx 宏括号定义中的所有参数名
char forward_search[MAX_NAME_LEN + 20];
sprintf(forward_search, "FORWARD_WM_%s(", msg_name);
char *f_param_start = strstr(forward_line, forward_search);
if (!f_param_start) return;
f_param_start += strlen(forward_search);
char f_params_buf[MAX_LINE_LEN] = {0};
int f_len = 0;
int f_depth = 1;
// 严格按括号匹配提取参数声明区间,避免被后续宏体干扰
while (f_param_start[f_len] && f_depth > 0) {
if (f_param_start[f_len] == '(') f_depth++;
if (f_param_start[f_len] == ')') f_depth--;
if (f_depth > 0) {
f_params_buf[f_len] = f_param_start[f_len];
f_len++;
}
}
f_params_buf[f_len] = '\0';
// 切分 FORWARD 宏头部的参数名
char f_param_names[MAX_PARAMS][MAX_NAME_LEN];
int f_param_count = 0;
// 修正点:手动切分逗号,不使用会破坏内部状态的 strtok
char *f_ptr = f_params_buf;
char *f_comma;
while ((f_comma = strchr(f_ptr, ',')) != NULL && f_param_count < MAX_PARAMS) {
*f_comma = '\0';
trim(f_ptr);
if (strcmp(f_ptr, "fn") != 0 && strlen(f_ptr) > 0) {
strcpy(f_param_names[f_param_count++], f_ptr);
}
f_ptr = f_comma + 1;
}
trim(f_ptr);
if (strcmp(f_ptr, "fn") != 0 && strlen(f_ptr) > 0) {
strcpy(f_param_names[f_param_count++], f_ptr);
}
// 3. 解析 return_type
char *fn_pos = strstr(forward_line, "(fn)");
if (fn_pos) {
char *search_start = strstr(forward_line, forward_search);
if (search_start) {
char *body_start = strchr(search_start, ')');
if (body_start && body_start < fn_pos) {
char return_buf[MAX_LINE_LEN] = {0};
strncpy(return_buf, body_start + 1, fn_pos - (body_start + 1));
return_buf[fn_pos - (body_start + 1)] = '\0';
extract_first_type(return_buf, return_type, "");
}
}
}
if (strlen(return_type) == 0 || strcmp(return_type, "void") == 0) {
strcpy(return_type, "void");
}
// 4 & 5 & 6. 解析 HANDLE_WM_xxx 中 fn(...) 内部调用
char *fn_call = strstr(handle_line, "(fn)(");
if (!fn_call) fn_call = strstr(handle_line, "fn(");
ParamInfo final_params[MAX_PARAMS];
int final_param_count = 0;
if (fn_call) {
if (strncmp(fn_call, "(fn)(", 5) == 0) {
fn_call += 5; // 移动到 (fn)( 之后的具体参数部分
} else {
fn_call += 3; // 移动到 fn( 之后的具体参数部分
}
// 匹配提取出整个括号内的参数段表达式
char h_body_buf[MAX_LINE_LEN] = {0};
int h_depth = 1;
int h_idx = 0;
while (fn_call[h_idx] && h_depth > 0) {
if (fn_call[h_idx] == '(') h_depth++;
if (fn_call[h_idx] == ')') h_depth--;
if (h_depth > 0) {
h_body_buf[h_idx] = fn_call[h_idx];
h_idx++;
}
}
h_body_buf[h_idx] = '\0';
// 核心修正:按照外层零嵌套深度的逗号切分出各个独立的传参表达式
char *expressions[MAX_PARAMS];
int exp_count = 0;
char *start = h_body_buf;
int depth_count = 0;
for (int i = 0; h_body_buf[i] != '\0'; i++) {
if (h_body_buf[i] == '(') depth_count++;
else if (h_body_buf[i] == ')') depth_count--;
else if (h_body_buf[i] == ',' && depth_count == 0) {
h_body_buf[i] = '\0';
expressions[exp_count++] = start;
start = &h_body_buf[i + 1];
}
}
expressions[exp_count++] = start;
// 根据表达式与 FORWARD 的名字进行最终映射与插入
int f_idx = 0;
for (int i = 0; i < exp_count; i++) {
trim(expressions[i]);
if (strlen(expressions[i]) == 0) continue;
// 4. 对 HANDLE_WM_xxx 中 TRUE 所在位置,直接生成 fBool 参数名插入
if (strcmp(expressions[i], "TRUE") == 0 || strcmp(expressions[i], "FALSE") == 0) {
strcpy(final_params[final_param_count].name, "fBool");
strcpy(final_params[final_param_count].type, "WINBOOL");
final_param_count++;
} else {
if (f_idx < f_param_count) {
strcpy(final_params[final_param_count].name, f_param_names[f_idx]);
// 5 & 6. 提取每个参数对应的真实强转类型
char parsed_type[MAX_NAME_LEN] = {0};
extract_first_type(expressions[i], parsed_type, f_param_names[f_idx]);
strcpy(final_params[final_param_count].type, parsed_type);
final_param_count++;
f_idx++;
}
}
}
}
// 7. 生成格式化内容输出
printf("#define c_WinGUI_EventFn_WM_%s(fn) \\\n %s fn(", msg_name, return_type);
for (int i = 0; i < final_param_count; i++) {
printf("%s %s", final_params[i].type, final_params[i].name);
if (i < final_param_count - 1) {
printf(", ");
}
}
printf(")\n\n");
}
int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "使用方法: %s <windowsx.h 路径>\n", argv[0]);
return 1;
}
FILE *fp = fopen(argv[1], "r");
if (!fp) {
perror("打不开文件");
return 1;
}
char line[MAX_LINE_LEN];
char cached_handle[MAX_LINE_LEN] = {0};
char current_msg[MAX_NAME_LEN] = {0};
while (fgets(line, sizeof(line), fp)) {
line[strcspn(line, "\r\n")] = 0;
if (strstr(line, "#define HANDLE_WM_")) {
strcpy(cached_handle, line);
char *p = strstr(line, "HANDLE_WM_") + 10;
int idx = 0;
while (isalnum((unsigned char)p[idx]) || p[idx] == '_') {
current_msg[idx] = p[idx];
idx++;
}
current_msg[idx] = '\0';
}
else if (strstr(line, "#define FORWARD_WM_")) {
if (strlen(current_msg) > 0 && strstr(line, current_msg)) {
process_macros(cached_handle, line);
cached_handle[0] = '\0';
current_msg[0] = '\0';
}
}
}
fclose(fp);
return 0;
}
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

+86
View File
@@ -0,0 +1,86 @@
#include "c_WinApp.h"
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define WINDOW_CLASS_NAME "WinGUI.Main"
c_WinGUI_EventHandlerDef(WM_DESTROY, Main_Destroy) {
PostQuitMessage(0);
}
c_WinGUI_EventHandlerDef(WM_CREATE, Main_Create) {
return TRUE;
}
c_WinGUI_EventMapBegin(WndProc)
c_WinGUI_EventMap(WM_DESTROY, Main_Destroy);
c_WinGUI_EventMap(WM_CREATE, Main_Create);
c_WinGUI_EventMapEnd()
static
BOOL Register(HINSTANCE hInstance) {
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = WINDOW_CLASS_NAME;
return RegisterClass(&WndClass);
}
static
HWND Create(HINSTANCE hInstance, int nCmdShow) {
HWND hwnd = CreateWindow(WINDOW_CLASS_NAME, WINDOW_CLASS_NAME,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL
);
if (hwnd == NULL) {
return NULL;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return hwnd;
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
c_WinGUI_Main(){
MSG msg;
if (!hPrevInstance) {
if (!Register(hInstance)) {
return FALSE;
}
}
WinApp.hInstance = hInstance;
HWND MainHwnd = Create(hInstance, nShowCmd);
if (!MainHwnd) {
return FALSE;
}
WinApp.hwnd = MainHwnd;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB