Import
This commit is contained in:
+14
-1
@@ -18,4 +18,17 @@ foreach (item IN LISTS TEST_SOURCES)
|
||||
message(STATUS "[${PROJECT_NAME}] TEST UNIT: ${TestUnit} - ${item}")
|
||||
add_executable(${TestUnit} ${item})
|
||||
target_link_libraries(${TestUnit} PRIVATE ${PROJECT_NAME})
|
||||
endforeach ()
|
||||
endforeach ()
|
||||
|
||||
file(GLOB GUI_TEST_SOURCES ${SOURCE_DIR}/GUITest/*.t.c)
|
||||
foreach (item IN LISTS GUI_TEST_SOURCES)
|
||||
get_filename_component(TestUnit ${item} NAME_WLE)
|
||||
message(STATUS "[${PROJECT_NAME}] TEST UNIT: ${TestUnit} - ${item}")
|
||||
add_executable(${TestUnit} WIN32 ${item})
|
||||
target_include_directories(${TestUnit} PUBLIC ${SOURCE_DIR}/GUITest)
|
||||
target_link_libraries(${TestUnit} PRIVATE ${PROJECT_NAME})
|
||||
endforeach ()
|
||||
|
||||
target_sources(Resource.t PRIVATE GUITest/Resource.rc)
|
||||
target_sources(Snake.t PRIVATE GUITest/Snake.rc)
|
||||
target_sources(SimpFont.t PRIVATE GUITest/SimpFont.rc)
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -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 |
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#include "c_WinGuiApp.h"
|
||||
#include "c_WinGUI.h"
|
||||
#include "c_WinGuiUtil.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <c_WinApp.h>
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
@@ -17,29 +21,28 @@ static int yVal = 30;
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
static BOOL MainWindow_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct){
|
||||
c_WinGUI_EventHandlerDef(WM_CREATE, KeyMouse_OnCreate){
|
||||
c_WinGuiUtil_MoveWindowToScreenCenter(hwnd);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void MainWindow_OnDestroy(HWND hwnd){
|
||||
c_WinGUI_EventHandlerDef(WM_DESTROY, KeyMouse_OnDestroy){
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
|
||||
static void MainWindow_OnPaint(HWND hwnd){
|
||||
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",
|
||||
}
|
||||
"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);
|
||||
@@ -54,7 +57,7 @@ static void MainWindow_OnPaint(HWND hwnd){
|
||||
EndPaint(hwnd, &PaintStruct);
|
||||
}
|
||||
|
||||
static void MainWindow_OnChar(HWND hwnd, UINT ch, int cRepeat){
|
||||
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 "
|
||||
@@ -65,15 +68,15 @@ static void MainWindow_OnChar(HWND hwnd, UINT ch, int cRepeat){
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
static void MainWindow_OnKey(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT flags){
|
||||
c_WinGUI_EventHandlerDef(WM_KEYDOWN, KeyMouse_OnKey){
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size =0;
|
||||
if(fDown){
|
||||
if(fBool){
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_KEYDOWN ==> vk = %c, fDown = %d, cRepeat = %d, flags = %d "
|
||||
, vk
|
||||
, fDown
|
||||
, fBool
|
||||
, cRepeat
|
||||
, flags
|
||||
);
|
||||
@@ -81,7 +84,7 @@ static void MainWindow_OnKey(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT f
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_KEYUP ==> vk = %c, fDown = %d, cRepeat = %d, flags = %d "
|
||||
, vk
|
||||
, fDown
|
||||
, fBool
|
||||
, cRepeat
|
||||
, flags
|
||||
);
|
||||
@@ -92,16 +95,16 @@ static void MainWindow_OnKey(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT f
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
static void MainWindow_OnSysKey(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT flags){
|
||||
c_WinGUI_EventHandlerDef(WM_SYSKEYDOWN, KeyMouse_OnSysKey){
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size = 0;
|
||||
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
|
||||
if(fDown){
|
||||
if(fBool){
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_SYSKEYDOWN ==> vk = %d, fDown = %d, cRepeat = %d, flags = %d "
|
||||
, vk
|
||||
, fDown
|
||||
, fBool
|
||||
, cRepeat
|
||||
, flags);
|
||||
|
||||
@@ -111,7 +114,7 @@ static void MainWindow_OnSysKey(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UIN
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_SYSKEYUP ==> vk = %d, fDown = %d, cRepeat = %d, flags = %d "
|
||||
, vk
|
||||
, fDown
|
||||
, fBool
|
||||
, cRepeat
|
||||
, flags);
|
||||
|
||||
@@ -123,7 +126,7 @@ static void MainWindow_OnSysKey(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UIN
|
||||
}
|
||||
|
||||
|
||||
static void MainWindow_OnLButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags){
|
||||
c_WinGUI_EventHandlerDef(WM_LBUTTONDOWN, KeyMouse_OnLButtonDown){
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size =0;
|
||||
@@ -150,7 +153,7 @@ static void MainWindow_OnLButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y,
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
static void MainWindow_OnLButtonUp(HWND hwnd, int x, int y, UINT keyFlags){
|
||||
c_WinGUI_EventHandlerDef(WM_LBUTTONUP, KeyMouse_OnLButtonUp){
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size =0;
|
||||
@@ -168,7 +171,7 @@ static void MainWindow_OnLButtonUp(HWND hwnd, int x, int y, UINT keyFlags){
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
static void MainWindow_OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags){
|
||||
c_WinGUI_EventHandlerDef(WM_MOUSEMOVE, KeyMouse_OnMouseMove){
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size =0;
|
||||
@@ -198,7 +201,8 @@ static void MainWindow_OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags){
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
static void MainWindow_OnRButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags){
|
||||
c_WinGUI_EventHandlerDef(WM_RBUTTONDOWN, KeyMouse_OnRButtonDown)
|
||||
{
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size =0;
|
||||
@@ -226,7 +230,7 @@ static void MainWindow_OnRButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y,
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
static void MainWindow_OnRButtonUp(HWND hwnd, int x, int y, UINT keyFlags){
|
||||
c_WinGUI_EventHandlerDef(WM_RBUTTONUP, KeyMouse_OnRButtonUp){
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size =0;
|
||||
@@ -243,26 +247,75 @@ static void MainWindow_OnRButtonUp(HWND hwnd, int x, int y, UINT keyFlags){
|
||||
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_WinGuiApp_EventBegin(WndProc)
|
||||
c_WinGuiApp_OnEvent(WM_CREATE, MainWindow_OnCreate)
|
||||
c_WinGuiApp_OnEvent(WM_CHAR, MainWindow_OnChar)
|
||||
c_WinGuiApp_OnEvent(WM_KEYDOWN, MainWindow_OnKey)
|
||||
c_WinGuiApp_OnEvent(WM_KEYUP, MainWindow_OnKey)
|
||||
c_WinGuiApp_OnEvent(WM_SYSKEYDOWN, MainWindow_OnSysKey)
|
||||
c_WinGuiApp_OnEvent(WM_SYSKEYUP, MainWindow_OnSysKey)
|
||||
c_WinGuiApp_OnEvent(WM_MOUSEMOVE, MainWindow_OnMouseMove)
|
||||
c_WinGuiApp_OnEvent(WM_LBUTTONDBLCLK, MainWindow_OnLButtonDown)
|
||||
c_WinGuiApp_OnEvent(WM_LBUTTONDOWN, MainWindow_OnLButtonDown)
|
||||
c_WinGuiApp_OnEvent(WM_LBUTTONUP, MainWindow_OnLButtonUp)
|
||||
c_WinGuiApp_OnEvent(WM_DESTROY, MainWindow_OnDestroy)
|
||||
c_WinGuiApp_OnEvent(WM_PAINT, MainWindow_OnPaint)
|
||||
c_WinGuiApp_OnEvent(WM_RBUTTONDBLCLK, MainWindow_OnRButtonDown)
|
||||
c_WinGuiApp_OnEvent(WM_RBUTTONDOWN, MainWindow_OnRButtonDown)
|
||||
c_WinGuiApp_OnEvent(WM_RBUTTONUP, MainWindow_OnRButtonUp)
|
||||
c_WinGuiApp_EventEnd
|
||||
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()
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
@@ -293,16 +346,36 @@ static HWND Create(HINSTANCE hInstance, int nCmdShow){
|
||||
// CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
NULL, NULL, hInstance, NULL);
|
||||
if(!hWindow) return NULL;
|
||||
c_WinGuiApp.hMainWindow = hWindow;
|
||||
ShowWindow(hWindow, nCmdShow);
|
||||
UpdateWindow(hWindow);
|
||||
return hWindow;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
|
||||
c_WinGuiApp_Main(Register, Create)
|
||||
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;
|
||||
}
|
||||
@@ -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*/
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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*/
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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*/
|
||||
@@ -0,0 +1,3 @@
|
||||
Body BITMAP body.bmp
|
||||
Head BITMAP head.bmp
|
||||
Hundred BITMAP hundred.bmp
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
@@ -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;
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
@@ -0,0 +1,3 @@
|
||||
#include <c_WinApp.h>
|
||||
|
||||
c_WinApp_t WinApp={0};
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#ifndef INCLUDED_C_WINAPP_H
|
||||
#define INCLUDED_C_WINAPP_H
|
||||
|
||||
#ifndef INCLUDED_C_WINGUI_H
|
||||
#include <c_WinGUI.h>
|
||||
#endif /*INCLUDED_C_WINGUI_H*/
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
typedef struct {
|
||||
HINSTANCE hInstance;
|
||||
HWND hwnd;
|
||||
}c_WinApp_t;
|
||||
|
||||
extern c_WinApp_t WinApp;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
static void c_WinApp_Init(HINSTANCE hInstance, HWND hwnd) {
|
||||
WinApp.hInstance = hInstance;
|
||||
WinApp.hwnd = hwnd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /*INCLUDED_C_WINAPP_H*/
|
||||
@@ -0,0 +1 @@
|
||||
#include <c_WinGUI.h>
|
||||
+451
@@ -0,0 +1,451 @@
|
||||
#ifndef INCLUDED_C_WINGUI_H
|
||||
#define INCLUDED_C_WINGUI_H
|
||||
|
||||
#ifndef INCLUDED_WINDOWS_H
|
||||
#define INCLUDED_WINDOWS_H
|
||||
#include <windows.h>
|
||||
#endif /*INCLUDED_WINDOWS_H*/
|
||||
|
||||
#ifndef INCLUDED_WINDOWSX_H
|
||||
#define INCLUDED_WINDOWSX_H
|
||||
#include <windowsx.h>
|
||||
#endif /*INCLUDED_WINDOWSX_H*/
|
||||
|
||||
#ifndef INCLUDED_C_WINAPP_H
|
||||
#include <c_WinApp.h>
|
||||
#endif /*INCLUDED_C_WINAPP_H*/
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
#define c_WinGUI_EventFn_WM_COMPACTING(fn) \
|
||||
void fn(HWND hwnd, UINT compactRatio)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_WININICHANGE(fn) \
|
||||
void fn(HWND hwnd, LPCTSTR lpszSectionName)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SYSCOLORCHANGE(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_QUERYNEWPALETTE(fn) \
|
||||
WINBOOL fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_PALETTEISCHANGING(fn) \
|
||||
void fn(HWND hwnd, HWND hwndPaletteChange)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_PALETTECHANGED(fn) \
|
||||
void fn(HWND hwnd, HWND hwndPaletteChange)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_FONTCHANGE(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SPOOLERSTATUS(fn) \
|
||||
void fn(HWND hwnd, UINT status, int cJobInQueue)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_DEVMODECHANGE(fn) \
|
||||
void fn(HWND hwnd, LPCTSTR lpszDeviceName)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_TIMECHANGE(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_POWER(fn) \
|
||||
void fn(HWND hwnd, int code)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_QUERYENDSESSION(fn) \
|
||||
WINBOOL fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_ENDSESSION(fn) \
|
||||
void fn(HWND hwnd, WINBOOL fEnding)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_QUIT(fn) \
|
||||
void fn(HWND hwnd, int exitCode)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SYSTEMERROR(fn) \
|
||||
void fn()
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CREATE(fn) \
|
||||
WINBOOL fn(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_NCCREATE(fn) \
|
||||
WINBOOL fn(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_DESTROY(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_NCDESTROY(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SHOWWINDOW(fn) \
|
||||
void fn(HWND hwnd, WINBOOL fShow, UINT status)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SETREDRAW(fn) \
|
||||
void fn(HWND hwnd, WINBOOL fRedraw)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_ENABLE(fn) \
|
||||
void fn(HWND hwnd, WINBOOL fEnable)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SETTEXT(fn) \
|
||||
void fn(HWND hwnd, LPCTSTR lpszText)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_GETTEXT(fn) \
|
||||
int fn(HWND hwnd, int cchTextMax, LPTSTR lpszText)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_GETTEXTLENGTH(fn) \
|
||||
int fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_WINDOWPOSCHANGING(fn) \
|
||||
WINBOOL fn(HWND hwnd, LPWINDOWPOS lpwpos)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_WINDOWPOSCHANGED(fn) \
|
||||
void fn(HWND hwnd, const LPWINDOWPOS lpwpos)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MOVE(fn) \
|
||||
void fn(HWND hwnd, int x, int y)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SIZE(fn) \
|
||||
void fn(HWND hwnd, UINT state, int cx, int cy)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CLOSE(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_QUERYOPEN(fn) \
|
||||
WINBOOL fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_GETMINMAXINFO(fn) \
|
||||
void fn(HWND hwnd, LPMINMAXINFO lpMinMaxInfo)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_PAINT(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_ERASEBKGND(fn) \
|
||||
WINBOOL fn(HWND hwnd, HDC hdc)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_ICONERASEBKGND(fn) \
|
||||
WINBOOL fn(HWND hwnd, HDC hdc)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_NCPAINT(fn) \
|
||||
void fn(HWND hwnd, HRGN hrgn)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_NCCALCSIZE(fn) \
|
||||
UINT fn(HWND hwnd, WINBOOL fCalcValidRects, NCCALCSIZE_PARAMS * lpcsp)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_NCHITTEST(fn) \
|
||||
UINT fn(HWND hwnd, int x, int y)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_QUERYDRAGICON(fn) \
|
||||
HICON fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_DROPFILES(fn) \
|
||||
void fn(HWND hwnd, HDROP hdrop)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_ACTIVATE(fn) \
|
||||
void fn(HWND hwnd, UINT state, HWND hwndActDeact, WINBOOL fMinimized)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_ACTIVATEAPP(fn) \
|
||||
void fn(HWND hwnd, WINBOOL fActivate, DWORD dwThreadId)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_NCACTIVATE(fn) \
|
||||
WINBOOL fn(HWND hwnd, WINBOOL fActive, WPARAM hwndActDeact, LPARAM fMinimized)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SETFOCUS(fn) \
|
||||
void fn(HWND hwnd, HWND hwndOldFocus)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_KILLFOCUS(fn) \
|
||||
void fn(HWND hwnd, HWND hwndNewFocus)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_KEYDOWN(fn) \
|
||||
void fn(HWND hwnd, UINT vk, WINBOOL fBool, int cRepeat, UINT flags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_KEYUP(fn) \
|
||||
void fn(HWND hwnd, UINT vk, WINBOOL fBool, int cRepeat, UINT flags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CHAR(fn) \
|
||||
void fn(HWND hwnd, TCHAR ch, int cRepeat)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_DEADCHAR(fn) \
|
||||
void fn(HWND hwnd, TCHAR ch, int cRepeat)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SYSKEYDOWN(fn) \
|
||||
void fn(HWND hwnd, UINT vk, WINBOOL fBool, int cRepeat, UINT flags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SYSKEYUP(fn) \
|
||||
void fn(HWND hwnd, UINT vk, WINBOOL fBool, int cRepeat, UINT flags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SYSCHAR(fn) \
|
||||
void fn(HWND hwnd, TCHAR ch, int cRepeat)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SYSDEADCHAR(fn) \
|
||||
void fn(HWND hwnd, TCHAR ch, int cRepeat)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MOUSEMOVE(fn) \
|
||||
void fn(HWND hwnd, int x, int y, UINT keyFlags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_LBUTTONDOWN(fn) \
|
||||
void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_LBUTTONDBLCLK(fn) \
|
||||
void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_LBUTTONUP(fn) \
|
||||
void fn(HWND hwnd, int x, int y, UINT keyFlags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_RBUTTONDOWN(fn) \
|
||||
void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_RBUTTONDBLCLK(fn) \
|
||||
void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_RBUTTONUP(fn) \
|
||||
void fn(HWND hwnd, int x, int y, UINT keyFlags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MBUTTONDOWN(fn) \
|
||||
void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MBUTTONUP(fn) \
|
||||
void fn(HWND hwnd, int x, int y, UINT keyFlags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MOUSEWHEEL(fn) \
|
||||
void fn(HWND hwnd, int xPos, int yPos, int zDelta, UINT fwKeys)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_NCMOUSEMOVE(fn) \
|
||||
void fn(HWND hwnd, int x, int y, UINT codeHitTest)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_NCLBUTTONDOWN(fn) \
|
||||
void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_NCLBUTTONUP(fn) \
|
||||
void fn(HWND hwnd, int x, int y, UINT codeHitTest)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_NCRBUTTONDOWN(fn) \
|
||||
void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_NCRBUTTONUP(fn) \
|
||||
void fn(HWND hwnd, int x, int y, UINT codeHitTest)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_NCMBUTTONDOWN(fn) \
|
||||
void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_NCMBUTTONUP(fn) \
|
||||
void fn(HWND hwnd, int x, int y, UINT codeHitTest)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MOUSEACTIVATE(fn) \
|
||||
int fn(HWND hwnd, HWND hwndTopLevel, UINT codeHitTest, UINT msg)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CANCELMODE(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_TIMER(fn) \
|
||||
void fn(HWND hwnd, UINT id)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_INITMENU(fn) \
|
||||
void fn(HWND hwnd, HMENU hMenu)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_INITMENUPOPUP(fn) \
|
||||
void fn(HWND hwnd, HMENU hMenu, UINT item, WINBOOL fSystemMenu)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MENUSELECT(fn) \
|
||||
void fn(HWND hwnd, HMENU hmenu, UINT item, HMENU hmenuPopup, UINT flags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MENUCHAR(fn) \
|
||||
DWORD fn(HWND hwnd, UINT ch, UINT flags, HMENU hmenu)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_COMMAND(fn) \
|
||||
void fn(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_HSCROLL(fn) \
|
||||
void fn(HWND hwnd, HWND hwndCtl, UINT code, int pos)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_VSCROLL(fn) \
|
||||
void fn(HWND hwnd, HWND hwndCtl, UINT code, int pos)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CUT(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_COPY(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_PASTE(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CLEAR(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_UNDO(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_RENDERFORMAT(fn) \
|
||||
HANDLE fn(HWND hwnd, UINT fmt)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_RENDERALLFORMATS(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_DESTROYCLIPBOARD(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_DRAWCLIPBOARD(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_PAINTCLIPBOARD(fn) \
|
||||
void fn(HWND hwnd, HWND hwndCBViewer, const LPPAINTSTRUCT lpPaintStruct)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SIZECLIPBOARD(fn) \
|
||||
void fn(HWND hwnd, HWND hwndCBViewer, const LPRECT lprc)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_VSCROLLCLIPBOARD(fn) \
|
||||
void fn(HWND hwnd, HWND hwndCBViewer, UINT code, int pos)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_HSCROLLCLIPBOARD(fn) \
|
||||
void fn(HWND hwnd, HWND hwndCBViewer, UINT code, int pos)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_ASKCBFORMATNAME(fn) \
|
||||
void fn(HWND hwnd, int cchMax, LPTSTR rgchName)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CHANGECBCHAIN(fn) \
|
||||
void fn(HWND hwnd, HWND hwndRemove, HWND hwndNext)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SETCURSOR(fn) \
|
||||
WINBOOL fn(HWND hwnd, HWND hwndCursor, UINT codeHitTest, UINT msg)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SYSCOMMAND(fn) \
|
||||
void fn(HWND hwnd, UINT cmd, int x, int y)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MDICREATE(fn) \
|
||||
HWND fn(HWND hwnd, LPMDICREATESTRUCT lpmcs)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MDIDESTROY(fn) \
|
||||
void fn(HWND hwnd, HWND hwndDestroy)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MDIACTIVATE(fn) \
|
||||
void fn(HWND hwnd, WINBOOL fActive, HWND hwndActivate, HWND hwndDeactivate)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MDIRESTORE(fn) \
|
||||
void fn(HWND hwnd, HWND hwndRestore)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MDINEXT(fn) \
|
||||
HWND fn(HWND hwnd, HWND hwndCur, WINBOOL fPrev)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MDIMAXIMIZE(fn) \
|
||||
void fn(HWND hwnd, HWND hwndMaximize)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MDITILE(fn) \
|
||||
WINBOOL fn(HWND hwnd, UINT cmd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MDICASCADE(fn) \
|
||||
WINBOOL fn(HWND hwnd, UINT cmd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MDIICONARRANGE(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MDIGETACTIVE(fn) \
|
||||
HWND fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MDISETMENU(fn) \
|
||||
HMENU fn(HWND hwnd, WINBOOL fRefresh, HMENU hmenuFrame, HMENU hmenuWindow)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CHILDACTIVATE(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_INITDIALOG(fn) \
|
||||
WINBOOL fn(HWND hwnd, HWND hwndFocus, LPARAM lParam)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_NEXTDLGCTL(fn) \
|
||||
HWND fn(HWND hwnd, HWND hwndSetFocus, WINBOOL fNext)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_PARENTNOTIFY(fn) \
|
||||
void fn(HWND hwnd, UINT msg, HWND hwndChild, UINT idChild)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_ENTERIDLE(fn) \
|
||||
void fn(HWND hwnd, UINT source, HWND hwndSource)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_GETDLGCODE(fn) \
|
||||
UINT fn(HWND hwnd, LPMSG lpmsg)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CTLCOLORMSGBOX(fn) \
|
||||
HBRUSH fn(HWND hwnd, HDC hdc, HWND hwndChild)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CTLCOLOREDIT(fn) \
|
||||
HBRUSH fn(HWND hwnd, HDC hdc, HWND hwndChild)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CTLCOLORLISTBOX(fn) \
|
||||
HBRUSH fn(HWND hwnd, HDC hdc, HWND hwndChild)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CTLCOLORBTN(fn) \
|
||||
HBRUSH fn(HWND hwnd, HDC hdc, HWND hwndChild)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CTLCOLORDLG(fn) \
|
||||
HBRUSH fn(HWND hwnd, HDC hdc, HWND hwndChild)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CTLCOLORSCROLLBAR(fn) \
|
||||
HBRUSH fn(HWND hwnd, HDC hdc, HWND hwndChild)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CTLCOLORSTATIC(fn) \
|
||||
HBRUSH fn(HWND hwnd, HDC hdc, HWND hwndChild)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_SETFONT(fn) \
|
||||
void fn(HWND hwnd, HFONT hfont, WINBOOL fRedraw)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_GETFONT(fn) \
|
||||
HFONT fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_DRAWITEM(fn) \
|
||||
void fn(HWND hwnd, const DRAWITEMSTRUCT * lpDrawItem)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_MEASUREITEM(fn) \
|
||||
void fn(HWND hwnd, MEASUREITEMSTRUCT * lpMeasureItem)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_DELETEITEM(fn) \
|
||||
void fn(HWND hwnd, const DELETEITEMSTRUCT * lpDeleteItem)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_COMPAREITEM(fn) \
|
||||
int fn(HWND hwnd, const COMPAREITEMSTRUCT * lpCompareItem)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_VKEYTOITEM(fn) \
|
||||
int fn(HWND hwnd, UINT vk, HWND hwndListBox, int iCaret)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CHARTOITEM(fn) \
|
||||
int fn(HWND hwnd, UINT ch, HWND hwndListBox, int iCaret)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_QUEUESYNC(fn) \
|
||||
void fn(HWND hwnd)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_COMMNOTIFY(fn) \
|
||||
void fn(HWND hwnd, int cid, UINT flags)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_DISPLAYCHANGE(fn) \
|
||||
void fn(HWND hwnd, UINT bitsPerPixel, UINT cxScreen, UINT cyScreen)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_DEVICECHANGE(fn) \
|
||||
WINBOOL fn(HWND hwnd, UINT uEvent, DWORD dwEventData)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_CONTEXTMENU(fn) \
|
||||
void fn(HWND hwnd, HWND hwndContext, UINT xPos, UINT yPos)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_COPYDATA(fn) \
|
||||
WINBOOL fn(HWND hwnd, HWND hwndFrom, PCOPYDATASTRUCT pcds)
|
||||
|
||||
#define c_WinGUI_EventFn_WM_HOTKEY(fn) \
|
||||
void fn(HWND hwnd, int idHotKey, UINT fuModifiers, UINT vk)
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
#define c_WinGUI_EventMapBegin(fn) \
|
||||
static LRESULT CALLBACK fn(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){ \
|
||||
switch (msg){
|
||||
|
||||
#define c_WinGUI_EventMap(message, fn) \
|
||||
case message: return HANDLE_##message(hwnd, wParam, lParam, fn)
|
||||
|
||||
#define c_WinGUI_EventMapEnd() \
|
||||
default: return DefWindowProc(hwnd, msg, wParam, lParam); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define c_WinGUI_EventHandlerDef(message, fn) \
|
||||
static c_WinGUI_EventFn_##message(fn)
|
||||
|
||||
#define c_WinGUI_Main() \
|
||||
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
||||
|
||||
#endif /*INCLUDED_C_WINGUI_H*/
|
||||
@@ -1,5 +0,0 @@
|
||||
#include <c_WinGuiApp.h>
|
||||
|
||||
c_WinGuiApp_t c_WinGuiApp = {0};
|
||||
|
||||
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
#ifndef INCLUDED_C_WINGUIAPP_H
|
||||
#define INCLUDED_C_WINGUIAPP_H
|
||||
|
||||
#ifndef INCLUDED_WINDOWS_H
|
||||
#define INCLUDED_WINDOWS_H
|
||||
#include <windows.h>
|
||||
#endif /*INCLUDED_WINDOWS_H*/
|
||||
|
||||
#ifndef INCLUDED_WINDOWSX_H
|
||||
#define INCLUDED_WINDOWSX_H
|
||||
#include <windowsx.h>
|
||||
#endif /*INCLUDED_WINDOWSX_H*/
|
||||
|
||||
#ifndef INCLUDED_STRING_H
|
||||
#define INCLUDED_STRING_H
|
||||
#include <string.h>
|
||||
#endif /*INCLUDED_STRING_H*/
|
||||
|
||||
#ifndef INCLUDED_STDLIB_H
|
||||
#define INCLUDED_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif /*INCLUDED_STDLIB_H*/
|
||||
|
||||
#ifndef INCLUDED_STDIO_H
|
||||
#define INCLUDED_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif /*INCLUDED_STDIO_H*/
|
||||
|
||||
#ifndef INCLUDED_TIME_H
|
||||
#define INCLUDED_TIME_H
|
||||
#include <time.h>
|
||||
#endif /*INCLUDED_TIME_H*/
|
||||
|
||||
#ifndef INCLUDED_STDINT_H
|
||||
#define INCLUDED_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif /*INCLUDED_STDINT_H*/
|
||||
|
||||
#ifndef INCLUDED_STDBOOL_H
|
||||
#define INCLUDED_STDBOOL_H
|
||||
#include <stdbool.h>
|
||||
#endif /*INCLUDED_STDBOOL_H*/
|
||||
|
||||
#ifndef INCLUDED_STDATOMIC_H
|
||||
#define INCLUDED_STDATOMIC_H
|
||||
#include <stdatomic.h>
|
||||
#endif /*INCLUDED_STDATOMIC_H*/
|
||||
|
||||
#ifndef INCLUDED_STDDEF_H
|
||||
#define INCLUDED_STDDEF_H
|
||||
#include <stddef.h>
|
||||
#endif /*INCLUDED_STDDEF_H*/
|
||||
|
||||
#ifndef INCLUDED_INTTYPES_H
|
||||
#define INCLUDED_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif /*INCLUDED_INTTYPES_H*/
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
typedef struct {
|
||||
HINSTANCE hInstance;
|
||||
HWND hMainWindow;
|
||||
}c_WinGuiApp_t;
|
||||
|
||||
typedef bool (*c_WinGuiApp_fRegister_t)(HINSTANCE hInstance);
|
||||
typedef HWND (*c_WinGuiApp_fCreate_t)(HINSTANCE hInstance, int nCmdShow);
|
||||
|
||||
extern c_WinGuiApp_t c_WinGuiApp;
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
#define c_WinGuiApp_Main(fRegister, fCreate) \
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow){ \
|
||||
MSG Msg; \
|
||||
if(!hPrevInstance){ \
|
||||
c_WinGuiApp.hInstance = hInstance; \
|
||||
if(!fRegister(hInstance)){ \
|
||||
return FALSE; \
|
||||
} \
|
||||
} \
|
||||
c_WinGuiApp.hMainWindow = fCreate(hInstance, nCmdShow); \
|
||||
if(!c_WinGuiApp.hMainWindow){ \
|
||||
return FALSE; \
|
||||
} \
|
||||
while(GetMessage(&Msg, NULL, 0, 0)){ \
|
||||
TranslateMessage(&Msg); \
|
||||
DispatchMessage(&Msg); \
|
||||
} \
|
||||
return Msg.wParam; \
|
||||
}
|
||||
|
||||
#define c_WinGuiApp_OnEvent(msg, handler) case msg: return HANDLE_##msg(hWnd, wParam, lParam, handler);
|
||||
|
||||
#define c_WinGuiApp_EventBegin(name) \
|
||||
static LRESULT CALLBACK name(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam){ \
|
||||
switch (Message) {
|
||||
|
||||
|
||||
#define c_WinGuiApp_EventEnd\
|
||||
default: \
|
||||
return DefWindowProc(hWnd, Message, wParam, lParam); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
#endif /*INCLUDED_C_WINGUIAPP_H*/
|
||||
@@ -1,70 +0,0 @@
|
||||
#include "c_WinGuiApp.h"
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
#define MAIN_WINDOW_CLASSNAME "c_WinGuiApp_Main"
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
static void MainWindow_OnDestroy(HWND hwnd){
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
|
||||
static void MainWindow_OnPaint(HWND hwnd){
|
||||
PAINTSTRUCT PaintStruct;
|
||||
HDC hdc = BeginPaint(hwnd, &PaintStruct);
|
||||
TextOutA(hdc, 10, 10, "Hello", 5);
|
||||
EndPaint(hwnd, &PaintStruct);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
c_WinGuiApp_EventBegin(WndProc)
|
||||
c_WinGuiApp_OnEvent(WM_DESTROY, MainWindow_OnDestroy)
|
||||
c_WinGuiApp_OnEvent(WM_PAINT, MainWindow_OnPaint)
|
||||
c_WinGuiApp_EventEnd
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
|
||||
|
||||
static bool Register(HINSTANCE hInstance){
|
||||
WNDCLASS WndClass;
|
||||
WndClass.lpszClassName = MAIN_WINDOW_CLASSNAME;
|
||||
WndClass.style = CS_HREDRAW | CS_VREDRAW;
|
||||
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,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
NULL, NULL, hInstance, NULL);
|
||||
if(!hWindow) return NULL;
|
||||
c_WinGuiApp.hMainWindow = hWindow;
|
||||
ShowWindow(hWindow, nCmdShow);
|
||||
UpdateWindow(hWindow);
|
||||
return hWindow;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
|
||||
c_WinGuiApp_Main(Register, Create)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user