Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4dbe30afd1 | ||
|
|
f4261c0f8b | ||
|
|
0bcc77f741 | ||
|
|
dcd71cc7ed | ||
|
|
390da594c7 | ||
|
|
8cc5ecdc46 | ||
|
|
8bd6453415 | ||
|
|
a222cf81bb | ||
|
|
a68366efb2 | ||
|
|
f945901c18 |
@@ -19,3 +19,24 @@ foreach (item IN LISTS TEST_SOURCES)
|
||||
add_executable(${TestUnit} ${item})
|
||||
target_link_libraries(${TestUnit} PRIVATE ${PROJECT_NAME})
|
||||
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)
|
||||
target_sources(FontsExp.t PRIVATE GUITest/FontsExp.rc GUITest/FontStr.c)
|
||||
set_target_properties(Faith.t PROPERTIES WIN32_EXECUTABLE FALSE)
|
||||
set_target_properties(Console.t PROPERTIES WIN32_EXECUTABLE FALSE)
|
||||
target_sources(WinStyle.t PRIVATE GUITest/WinStyle.rc)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
#include "c_WinGuiApp.h"
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
#define MAIN_WINDOW_CLASSNAME "EasyText"
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
#define DIRECTION_SIZE 100
|
||||
|
||||
static char Directions[DIRECTION_SIZE];
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
static BOOL MainWindow_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct){
|
||||
char* msg = "Try resizing this window.";
|
||||
strcpy(Directions, msg);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void MainWindow_OnDestroy(HWND hwnd){
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
|
||||
static void MainWindow_OnPaint(HWND hwnd){
|
||||
PAINTSTRUCT PaintStruct;
|
||||
RECT Rect;
|
||||
HDC hdc = BeginPaint(hwnd, &PaintStruct);
|
||||
SetBkMode(hdc, TRANSPARENT);
|
||||
TextOut(hdc, 10, 10, Directions, lstrlen(Directions));
|
||||
GetClientRect(hwnd, &Rect);
|
||||
DrawText(hdc, "The middle of the road", -1, &Rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
|
||||
EndPaint(hwnd, &PaintStruct);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
c_WinGuiApp_EventBegin(WndProc)
|
||||
c_WinGuiApp_OnEvent(WM_CREATE, MainWindow_OnCreate)
|
||||
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)
|
||||
|
||||
|
||||
|
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.
|
||||
@@ -0,0 +1,83 @@
|
||||
#include "c_WinUI_Console.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static void HandleMouse(MOUSE_EVENT_RECORD Event) {
|
||||
char s[150];
|
||||
snprintf(s, sizeof(s)/sizeof(s[0]), "Buttons: %lu, X:%2lu Y:%2lu\n", Event.dwButtonState,
|
||||
Event.dwMousePosition.X, Event.dwMousePosition.Y);
|
||||
c_WinUI_Console_GotoXY(0, 0);
|
||||
c_WinUI_Console_WriteStr(s);
|
||||
}
|
||||
|
||||
static void HandleKey(KEY_EVENT_RECORD Event) {
|
||||
char s[100];
|
||||
snprintf(s, sizeof(s)/sizeof(s[0]), "You pressed: %c", Event.uChar);
|
||||
c_WinUI_Console_GotoXY(0, 1);
|
||||
c_WinUI_Console_WriteStr(s);
|
||||
snprintf(s, sizeof(s)/sizeof(s[0]), "Virtual Key: %3d", Event.wVirtualKeyCode);
|
||||
c_WinUI_Console_GotoXY(0, 2);
|
||||
c_WinUI_Console_WriteStr(s);
|
||||
}
|
||||
|
||||
static void SayGoodBye(void) {
|
||||
char s[100];
|
||||
c_WinUI_Console_ClearScreen();
|
||||
printf("Enter Your name:");
|
||||
gets(s);
|
||||
printf("\nGoodbye %s\n", s);
|
||||
}
|
||||
|
||||
static void InitConsoleInput(void) {
|
||||
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
if (hIn == INVALID_HANDLE_VALUE) return;
|
||||
|
||||
DWORD mode;
|
||||
// 1. 获取当前控制台的输入模式
|
||||
if (GetConsoleMode(hIn, &mode)) {
|
||||
|
||||
// 2. 启用鼠标输入
|
||||
mode |= ENABLE_MOUSE_INPUT;
|
||||
|
||||
// 3. 禁用快速编辑模式(非常关键!如果不禁用,鼠标事件会被控制台自身拦截用于复制文本)
|
||||
mode &= ~ENABLE_QUICK_EDIT_MODE;
|
||||
|
||||
// 4. 启用扩展属性(如果要修改 QUICK_EDIT,必须同时带上这个标志)
|
||||
mode |= ENABLE_EXTENDED_FLAGS;
|
||||
|
||||
// 5. 应用新模式
|
||||
SetConsoleMode(hIn, mode);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv){
|
||||
DWORD Result;
|
||||
INPUT_RECORD Buffer;
|
||||
|
||||
InitConsoleInput();
|
||||
|
||||
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
|
||||
c_WinUI_Console_ClearScreen();
|
||||
c_WinUI_Console_GotoXY(0, 24);
|
||||
|
||||
c_WinUI_Console_WriteStr("Move mouse, press keys, double click to Exit...");
|
||||
|
||||
do {
|
||||
ReadConsoleInput(hIn, &Buffer, 1, &Result);
|
||||
|
||||
if (Buffer.EventType == KEY_EVENT) {
|
||||
HandleKey(Buffer.Event.KeyEvent);
|
||||
}
|
||||
|
||||
if (Buffer.EventType == MOUSE_EVENT) {
|
||||
HandleMouse(Buffer.Event.MouseEvent);
|
||||
}
|
||||
}while (!(Buffer.EventType==MOUSE_EVENT && Buffer.Event.MouseEvent.dwEventFlags==DOUBLE_CLICK));
|
||||
|
||||
SayGoodBye();
|
||||
|
||||
getchar();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
@@ -0,0 +1,21 @@
|
||||
#include <c_WinUI_Console.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define ALT1 (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY)
|
||||
|
||||
int main(int argc, char** argv){
|
||||
int i;
|
||||
SetConsoleTitle("Emily Dickinson Console");
|
||||
c_WinUI_Console_ClearScreen();
|
||||
|
||||
c_WinUI_Console_WriteXY(0, 1, "Faith is a fine invention.", ALT1);
|
||||
c_WinUI_Console_WriteXY(0, 2, "For gentlemen who see;", ALT1);
|
||||
c_WinUI_Console_WriteXY(0, 3, "But microscopes are prudent", ALT1);
|
||||
c_WinUI_Console_WriteXY(0, 4, "In an emergency!", ALT1);
|
||||
|
||||
getchar();
|
||||
// system("pause");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
#include <FontStr.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static char TheFaceName[80];
|
||||
|
||||
char* GetType(char* s, TEXTMETRIC TextMetrics) {
|
||||
if (!s) return NULL;
|
||||
strcpy(s, "Font Type:");
|
||||
if ((TextMetrics.tmAveCharWidth & TMPF_FIXED_PITCH)==TMPF_FIXED_PITCH) {
|
||||
strcat(s, "Fixed<>");
|
||||
}
|
||||
if ((TextMetrics.tmAveCharWidth & TMPF_VECTOR)==TMPF_VECTOR) {
|
||||
strcat(s, "Vector<>");
|
||||
}
|
||||
if ((TextMetrics.tmAveCharWidth & TMPF_TRUETYPE)==TMPF_TRUETYPE) {
|
||||
strcat(s, "TrueType<>");
|
||||
}
|
||||
if ((TextMetrics.tmAveCharWidth & TMPF_DEVICE)==TMPF_DEVICE) {
|
||||
strcat(s, "Device<>");
|
||||
}
|
||||
if (strlen(s) > 11) {
|
||||
int len = strlen(s);
|
||||
s[len - 3]='\0';
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
char* GetFamily(char* s, TEXTMETRIC TextMetrics) {
|
||||
int R = TextMetrics.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;
|
||||
}
|
||||
|
||||
char* GetCharSet(char* s, TEXTMETRIC TextMetrics) {
|
||||
strcpy(s, "Char Set:");
|
||||
if (TextMetrics.tmCharSet==ANSI_CHARSET) {
|
||||
strcat(s, "Ansi");
|
||||
}
|
||||
if (TextMetrics.tmCharSet==DEFAULT_CHARSET) {
|
||||
strcat(s, "Default");
|
||||
}
|
||||
if (TextMetrics.tmCharSet==SYMBOL_CHARSET) {
|
||||
strcat(s, "Symbol");
|
||||
}
|
||||
if (TextMetrics.tmCharSet==OEM_CHARSET) {
|
||||
strcat(s, "OEM");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
char* GetFontString(char* s, int s_len, TEXTMETRIC TextMetric, char* FaceName) {
|
||||
if (!s || !FaceName) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char szType[99];
|
||||
char szFamily[99];
|
||||
char szCharSet[99];
|
||||
|
||||
GetType(szType, TextMetric);
|
||||
GetFamily(szFamily, TextMetric);
|
||||
GetCharSet(szCharSet, TextMetric);
|
||||
|
||||
snprintf(s, s_len, "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,
|
||||
TextMetric.tmHeight,
|
||||
TextMetric.tmAscent,
|
||||
TextMetric.tmDescent,
|
||||
TextMetric.tmAveCharWidth,
|
||||
TextMetric.tmMaxCharWidth,
|
||||
TextMetric.tmWeight,
|
||||
TextMetric.tmItalic,
|
||||
TextMetric.tmUnderlined,
|
||||
szType, szFamily, szCharSet
|
||||
);
|
||||
return s;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef INCLUDED_FONTSTR_H
|
||||
#define INCLUDED_FONTSTR_H
|
||||
|
||||
#ifndef INCLUDED_WINDOWS_H
|
||||
#define INCLUDED_WINDOWS_H
|
||||
#include <windows.h>
|
||||
#endif /*INCLUDED_WINDOWS_H*/
|
||||
|
||||
#ifndef INCLUDED_STRING_H
|
||||
#define INCLUDED_STRING_H
|
||||
#include <string.h>
|
||||
#endif /*INCLUDED_STRING_H*/
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
|
||||
char* GetFontString(char* s, int s_len, TEXTMETRIC TextMetric, char* FaceName);
|
||||
|
||||
#endif /*INCLUDED_FONTSTR_H*/
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef INCLUDED_FONTSEXP_H
|
||||
#define INCLUDED_FONTSEXP_H
|
||||
|
||||
#define WM_STARTFONTS (WM_USER +0)
|
||||
#define WM_NEWFONT (WM_USER +1)
|
||||
|
||||
#define ID_LISTBOX 1
|
||||
#define CM_INFO 101
|
||||
|
||||
|
||||
|
||||
#endif /*INCLUDED_FONTSEXP_H*/
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "FontsExp.h"
|
||||
|
||||
Menu MENU
|
||||
BEGIN
|
||||
MENUITEM "&Info", CM_INFO
|
||||
END
|
||||
@@ -0,0 +1,262 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "c_WinApp.h"
|
||||
#include "FontsExp.h"
|
||||
#include "FontStr.h"
|
||||
#include "c_WinUI_Toast.h"
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
typedef struct {
|
||||
int Count;
|
||||
HWND hWindow;
|
||||
}ENUMSTRUCT;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
static TEXTMETRIC TextMetrics;
|
||||
static char aTextFace[80];
|
||||
|
||||
static HFONT TheFont;
|
||||
static LPLOGFONT TheLogFont;
|
||||
|
||||
static HWND hFontList;
|
||||
static HWND hAlphaEdit;
|
||||
static HWND hTrueType;
|
||||
static HWND hNumFonts;
|
||||
static HWND hFontName;
|
||||
static HWND ButtonWindows[3];
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
#define WINDOW_CLASS_NAME "FontsExp.Main"
|
||||
|
||||
|
||||
static
|
||||
int CALLBACK DescribeFontCallback(LPENUMLOGFONT lpnlf, LPNEWTEXTMETRIC lpntm, int FontType, ENUMSTRUCT FAR * lpData);
|
||||
|
||||
|
||||
static void HandleMetrics(TEXTMETRIC TextMetrics) {
|
||||
if ((TextMetrics.tmPitchAndFamily & TMPF_TRUETYPE) == TMPF_TRUETYPE) {
|
||||
SendMessage(ButtonWindows[0], BM_SETCHECK, 1, 0);
|
||||
}else {
|
||||
SendMessage(ButtonWindows[0], BM_SETCHECK, 0, 0);
|
||||
}
|
||||
|
||||
if ((TextMetrics.tmWeight > 600)) {
|
||||
SendMessage(ButtonWindows[1], BM_SETCHECK, 1, 0);
|
||||
}else {
|
||||
SendMessage(ButtonWindows[1], BM_SETCHECK, 0, 0);
|
||||
}
|
||||
|
||||
if ((TextMetrics.tmItalic)) {
|
||||
SendMessage(ButtonWindows[2], BM_SETCHECK, 1, 0);
|
||||
}else {
|
||||
SendMessage(ButtonWindows[2], BM_SETCHECK, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void ShowTheFont(HWND hwnd) {
|
||||
// FONTENUMPROC lpfnEnumProc;
|
||||
ENUMSTRUCT EnumStruct;
|
||||
char lpszBuffer[150];
|
||||
HFONT SaveIt;
|
||||
char* Alpha="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
HDC DC = GetDC(hwnd);
|
||||
|
||||
LRESULT Index = SendMessage(hFontList, LB_GETCURSEL, 0, 0);
|
||||
SendMessage(hFontList, LB_GETTEXT, (WPARAM)Index, (LPARAM)(lpszBuffer));
|
||||
// lpfnEnumProc = (FONTENUMPROC)MakeProcInstance((FARPROC)DescribeFontCallback, WinApp.hInstance);
|
||||
EnumStruct.Count = 0;
|
||||
EnumStruct.hWindow = hwnd;
|
||||
// EnumFontFamilies(DC, lpszBuffer, lpfnEnumProc, (LONG)&EnumStruct);
|
||||
EnumFontFamilies(DC, lpszBuffer, (FONTENUMPROC)DescribeFontCallback, (LPARAM)&EnumStruct);
|
||||
if (TheFont) {
|
||||
SaveIt = SelectFont(DC, TheFont);
|
||||
}
|
||||
GetTextMetrics(DC, &TextMetrics);
|
||||
HandleMetrics(TextMetrics);
|
||||
GetTextFace(DC, 150, aTextFace);
|
||||
if (TheFont) {
|
||||
SelectFont(DC, SaveIt);
|
||||
}
|
||||
ReleaseDC(hwnd, DC);
|
||||
SendMessage(hFontName, WM_SETTEXT, 0, (LPARAM)&lpszBuffer);
|
||||
SendMessage(hFontName, WM_SETFONT, (WPARAM)TheFont, 0);
|
||||
|
||||
SendMessage(hAlphaEdit, WM_SETTEXT, 0, (LPARAM)Alpha);
|
||||
SendMessage(hAlphaEdit, WM_SETFONT, (WPARAM)TheFont, 0);
|
||||
|
||||
c_WinUI_Toast_Show(WinApp.hInstance, TEXT("Ñ¡ÖÐ×ÖÌå"), lpszBuffer, 2000);
|
||||
}
|
||||
|
||||
static
|
||||
BOOL CALLBACK FontCallback(const LOGFONT * lpelf, const TEXTMETRIC* lpntm, DWORD FontType, ENUMSTRUCT FAR * lpData) {
|
||||
SendMessage(lpData->hWindow, LB_ADDSTRING, 0, (LPARAM)lpelf->lfFaceName);
|
||||
lpData->Count++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static
|
||||
int CALLBACK DescribeFontCallback(LPENUMLOGFONT lpnlf, LPNEWTEXTMETRIC lpntm, int FontType, ENUMSTRUCT FAR * lpData) {
|
||||
SendMessage(lpData->hWindow, WM_NEWFONT, 0, (LPARAM)&lpnlf->elfLogFont);
|
||||
return 1;
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_DESTROY, Main_Destroy) {
|
||||
if (TheFont) {
|
||||
DeleteObject(TheFont);
|
||||
}
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_CREATE, Main_Create) {
|
||||
static char* Titles[] = {"TrueType", "Heavy", "Italic"};
|
||||
hFontList = CreateWindow("listbox", NULL, WS_CHILD | WS_VISIBLE | LBS_STANDARD,
|
||||
9, 30, 201, 180,
|
||||
hwnd, (HMENU)(ID_LISTBOX), WinApp.hInstance, NULL);
|
||||
hNumFonts = CreateWindow("static", NULL,
|
||||
WS_CHILD | WS_VISIBLE | WS_BORDER,
|
||||
10, 10, 200, 20,
|
||||
hwnd, (HMENU)(-1), WinApp.hInstance, NULL);
|
||||
hFontName = CreateWindow("edit", NULL,
|
||||
WS_CHILD | ES_LEFT | WS_VISIBLE | WS_BORDER | ES_READONLY,
|
||||
260, 10, 850, 70,
|
||||
hwnd, (HMENU)(-1), WinApp.hInstance, NULL);
|
||||
hAlphaEdit = CreateWindow("edit", NULL,
|
||||
WS_CHILD | ES_LEFT | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL | ES_MULTILINE | WS_HSCROLL ,
|
||||
260, 90, 850, 70,
|
||||
hwnd, (HMENU)(-1), WinApp.hInstance, NULL);
|
||||
for (int i=0; i<3; i++) {
|
||||
ButtonWindows[i] = CreateWindow("button", Titles[i],
|
||||
WS_CHILD|WS_VISIBLE|BS_CHECKBOX,
|
||||
260 + (i*125), 180, 100, 35,
|
||||
hwnd, (HMENU)(-1), WinApp.hInstance, NULL);
|
||||
}
|
||||
TheFont = 0;
|
||||
PostMessage(hwnd, WM_STARTFONTS, 0, 0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_COMMAND, Main_Command) {
|
||||
char s[500];
|
||||
switch (id) {
|
||||
case ID_LISTBOX: {
|
||||
if (codeNotify==LBN_SELCHANGE) {
|
||||
ShowTheFont(hwnd);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CM_INFO: {
|
||||
GetFontString(s, sizeof(s), TextMetrics, aTextFace);
|
||||
MessageBox(hwnd, s, "Info", MB_OK);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_USERDEFINED, Main_StartFonts) {
|
||||
char s[100];
|
||||
HDC DC = GetDC(hwnd);
|
||||
// FONTENUMPROC lpfnEnumProc = (FONTENUMPROC) MakeProcInstance((FARPROC)FontCallback, WinApp.hInstance);
|
||||
ENUMSTRUCT EnumStruct;
|
||||
EnumStruct.Count = 0;
|
||||
EnumStruct.hWindow = hFontList;
|
||||
// EnumFontFamilies(DC, NULL, lpfnEnumProc, (LONG)&EnumStruct);
|
||||
// FreeProcInstance(lpfnEnumProc);
|
||||
EnumFontFamilies(DC, NULL, (FONTENUMPROC)FontCallback, (LPARAM)&EnumStruct);
|
||||
ReleaseDC(hwnd, DC);
|
||||
|
||||
snprintf(s, sizeof(s), "There are %d fonts available", EnumStruct.Count);
|
||||
SetWindowText(hNumFonts, s);
|
||||
SetFocus(hFontList);
|
||||
SendMessage(hFontList, LB_SETCURSEL, 0, 0);
|
||||
ShowTheFont(hwnd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_USERDEFINED, Main_NewFont) {
|
||||
if (TheFont) {
|
||||
DeleteObject(TheFont);
|
||||
}
|
||||
TheLogFont = (LPLOGFONT) lParam;
|
||||
TheFont = CreateFontIndirect(TheLogFont);
|
||||
return 1;
|
||||
}
|
||||
|
||||
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_UDEventMap(WM_STARTFONTS, Main_StartFonts);
|
||||
c_WinGUI_UDEventMap(WM_NEWFONT, Main_NewFont);
|
||||
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 = "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,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;
|
||||
}
|
||||
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
@@ -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,165 @@
|
||||
#include "c_WinApp.h"
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
#define WINDOW_CLASS_NAME "SysInfo.Main"
|
||||
|
||||
#define KB 1024
|
||||
#define MB ((size_t)((size_t)KB*1024))
|
||||
#define GB ((size_t)((size_t)MB*1024))
|
||||
#define TB ((size_t)((size_t)GB*1024))
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
static HWND EditWin;
|
||||
|
||||
static LPSTR GetSysInfo(LPSTR s) {
|
||||
SYSTEM_INFO SystemInfo;
|
||||
MEMORYSTATUS MStatus;
|
||||
char Temp1[500];
|
||||
char Temp2[500];
|
||||
char CR[3]={13, 10, 0};
|
||||
GetSystemInfo(&SystemInfo);
|
||||
snprintf(Temp1, sizeof(Temp1), "%sOEM ID:%ld %s"
|
||||
"Page Size %ld %s"
|
||||
"MinAppAddress: %"PRIu64" %s"
|
||||
"MaxAppAddress: %"PRIu64" %s"
|
||||
"Active Processor Mask: %"PRIX64" %s"
|
||||
"Number of Processors: %ld %s"
|
||||
"Processor Type: %ld %s"
|
||||
"Allocation Granularity: %ld %s %s",
|
||||
CR, SystemInfo.dwOemId, CR,
|
||||
SystemInfo.dwPageSize, CR,
|
||||
SystemInfo.lpMinimumApplicationAddress, CR,
|
||||
SystemInfo.lpMaximumApplicationAddress, CR,
|
||||
SystemInfo.dwActiveProcessorMask, CR,
|
||||
SystemInfo.dwNumberOfProcessors, CR,
|
||||
SystemInfo.dwProcessorType, CR,
|
||||
SystemInfo.dwAllocationGranularity, CR, CR
|
||||
);
|
||||
MStatus.dwLength = sizeof(MStatus);
|
||||
GlobalMemoryStatus(&MStatus);
|
||||
snprintf(Temp2, sizeof(Temp2), "%sMemory Load: %ld %s"
|
||||
"Total Physical: %"PRIu64"GB %s"
|
||||
"Available Physical: %"PRIu64"GB %s"
|
||||
"Total Page File: %"PRIu64" %s"
|
||||
"Available Page File: %"PRIu64" %s"
|
||||
"Total Virtual: %"PRIu64"TB %s"
|
||||
"Available Virtual: %"PRIu64"TB",
|
||||
CR, MStatus.dwMemoryLoad, CR,
|
||||
MStatus.dwTotalPhys/GB, CR,
|
||||
MStatus.dwAvailPhys/GB, CR,
|
||||
MStatus.dwTotalPageFile, CR,
|
||||
MStatus.dwAvailPageFile, CR,
|
||||
MStatus.dwTotalVirtual/TB, CR,
|
||||
MStatus.dwAvailVirtual/TB
|
||||
);
|
||||
strcpy(s, "SYSTEM INFO");
|
||||
strcat(s, Temp1);
|
||||
strcat(s, "MEMORY STATUS");
|
||||
strcat(s, Temp2);
|
||||
return s;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_DESTROY, Main_Destroy) {
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_CREATE, Main_Create) {
|
||||
char s[1000];
|
||||
EditWin = CreateWindow("edit", "Original Text",
|
||||
WS_CHILD|WS_VISIBLE|WS_BORDER|WS_VSCROLL|ES_READONLY|ES_LEFT|ES_AUTOVSCROLL|ES_MULTILINE,
|
||||
0, 0, 0, 0,
|
||||
hwnd, (HMENU)0, lpCreateStruct->hInstance, NULL);
|
||||
GetSysInfo(s);
|
||||
SetWindowText(EditWin, s);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_SIZE, Main_Size) {
|
||||
if (EditWin) {
|
||||
SetWindowPos(EditWin, NULL, 0, 0, cx, cy, SWP_NOZORDER);
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef INCLUDED_WINSTYLE_H
|
||||
#define INCLUDED_WINSTYLE_H
|
||||
|
||||
#define CM_ARRANGE 1
|
||||
#define CM_WHISTLE 2
|
||||
#define CM_EXIT 3
|
||||
#define CM_HELP 4
|
||||
#define CM_BLUE 101
|
||||
#define CM_RED 102
|
||||
#define CM_GREEN 103
|
||||
#define CM_SPECIAL1 104
|
||||
#define CM_SPECIAL2 105
|
||||
#define CM_SPECIAL3 106
|
||||
|
||||
#endif /*INCLUDED_WINSTYLE_H*/
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "WinStyle.h"
|
||||
|
||||
Menu MENU
|
||||
BEGIN
|
||||
MENUITEM "E&xit", CM_EXIT
|
||||
MENUITEM "&Arrange", CM_ARRANGE
|
||||
MENUITEM "&Whistle", CM_WHISTLE
|
||||
POPUP "&Background"
|
||||
BEGIN
|
||||
MENUITEM "&Blue", CM_BLUE
|
||||
MENUITEM "&Red", CM_RED
|
||||
MENUITEM "&Green", CM_GREEN
|
||||
MENUITEM "&Special_1", CM_SPECIAL1
|
||||
MENUITEM "&Special_2", CM_SPECIAL2
|
||||
MENUITEM "&Special_3", CM_SPECIAL3
|
||||
END
|
||||
MENUITEM "&Help", CM_HELP
|
||||
END
|
||||
|
||||
PATTERN1 BITMAP "Pattern1.bmp"
|
||||
PATTERN2 BITMAP "Pattern2.bmp"
|
||||
PATTERN3 BITMAP "Pattern3.bmp"
|
||||
@@ -0,0 +1,334 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "c_WinApp.h"
|
||||
#include "WinStyle.h"
|
||||
|
||||
#ifndef GCL_HBRBACKGROUND
|
||||
#define GCL_HBRBACKGROUND (-10)
|
||||
#endif
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
#define WINDOW_CLASS_NAME "WinStyle.Main"
|
||||
#define CHILD_CLASS_NAME "WinStyle.Child"
|
||||
|
||||
static HWND ChildWindows[10];
|
||||
static HBRUSH hPurpleHaze;
|
||||
static HBITMAP Pattern1;
|
||||
static HBITMAP Pattern2;
|
||||
static HBITMAP Pattern3;
|
||||
|
||||
static DWORD Styles[]={
|
||||
WS_POPUP|WS_VISIBLE,
|
||||
WS_POPUP|WS_VISIBLE|WS_CAPTION,
|
||||
WS_POPUP|WS_VISIBLE|WS_CAPTION|WS_MINIMIZEBOX|WS_MAXIMIZEBOX,
|
||||
WS_POPUP|WS_VISIBLE|WS_CAPTION|WS_HSCROLL|WS_VSCROLL,
|
||||
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
|
||||
WS_CHILDWINDOW|WS_VISIBLE,
|
||||
WS_CHILDWINDOW|WS_VISIBLE|WS_THICKFRAME,
|
||||
WS_CHILDWINDOW|WS_VISIBLE|WS_BORDER|WS_CAPTION,
|
||||
WS_CHILDWINDOW|WS_VISIBLE|WS_CAPTION|WS_DISABLED,
|
||||
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
|
||||
};
|
||||
|
||||
static char* szStyles[]={
|
||||
"WS_POPUP|WS_VISIBLE",
|
||||
"WS_POPUP|WS_VISIBLE|WS_CAPTION",
|
||||
"WS_POPUP|WS_VISIBLE|WS_CAPTION|WS_MINIMIZEBOX|WS_MAXIMIZEBOX",
|
||||
"WS_POPUP|WS_VISIBLE|WS_CAPTION|WS_HSCROLL|WS_VSCROLL",
|
||||
"WS_OVERLAPPEDWINDOW|WS_VISIBLE",
|
||||
"WS_CHILDWINDOW|WS_VISIBLE",
|
||||
"WS_CHILDWINDOW|WS_VISIBLE|WS_THICKFRAME",
|
||||
"WS_CHILDWINDOW|WS_VISIBLE|WS_BORDER|WS_CAPTION",
|
||||
"WS_CHILDWINDOW|WS_VISIBLE|WS_CAPTION|WS_DISABLED",
|
||||
"WS_OVERLAPPEDWINDOW|WS_VISIBLE",
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
static void ArrangeWinds(HWND hwnd) {
|
||||
RECT R;
|
||||
int i;
|
||||
int j = 0;
|
||||
for (i=0; i<9; i++) {
|
||||
MoveWindow(ChildWindows[i], 10 + (j * 100), 10, 100, 100, TRUE);
|
||||
if (i==4) {
|
||||
j=0;
|
||||
}else {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
GetWindowRect(hwnd, &R);
|
||||
MoveWindow(ChildWindows[i],
|
||||
R.left + 10 + GetSystemMetrics(SM_CXFRAME) + (j*100),
|
||||
R.top + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYMENU) + 10,
|
||||
100, 100, TRUE);
|
||||
}
|
||||
|
||||
static void HandleBrush(HWND hwnd, int id) {
|
||||
HBRUSH OldBrush;
|
||||
#ifdef WIN32
|
||||
OldBrush = (HBRUSH)GetClassLongPtr(hwnd, GCLP_HBRBACKGROUND);
|
||||
#else
|
||||
OldBrush = (HBRUSH)GetClassWord(hwnd, GCL_HBRBACKGROUND);
|
||||
#endif
|
||||
switch (id) {
|
||||
case CM_RED: {
|
||||
hPurpleHaze = CreateSolidBrush(RGB(255, 127, 127));
|
||||
break;
|
||||
}
|
||||
case CM_GREEN: {
|
||||
hPurpleHaze = CreateSolidBrush(RGB(127, 255, 127));
|
||||
break;
|
||||
}
|
||||
case CM_BLUE: {
|
||||
hPurpleHaze = CreateSolidBrush(RGB(127, 127, 255));
|
||||
break;
|
||||
}
|
||||
case CM_SPECIAL1: {
|
||||
hPurpleHaze = CreatePatternBrush(Pattern1);
|
||||
break;
|
||||
}
|
||||
case CM_SPECIAL2: {
|
||||
hPurpleHaze = CreatePatternBrush(Pattern2);
|
||||
break;
|
||||
}
|
||||
case CM_SPECIAL3: {
|
||||
hPurpleHaze = CreatePatternBrush(Pattern3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#ifdef WIN32
|
||||
SetClassLongPtr(hwnd, GCLP_HBRBACKGROUND, (LONG_PTR)hPurpleHaze);
|
||||
#else
|
||||
SetClassWord(hwnd, GCLP_HBRBACKGROUND, (WORD)hPurpleHaze);
|
||||
#endif
|
||||
DeleteBrush(OldBrush);
|
||||
InvalidateRect(hwnd, NULL, TRUE);
|
||||
UpdateWindow(hwnd);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_DESTROY, Main_Destroy) {
|
||||
HBRUSH OldBrush;
|
||||
DeleteObject(Pattern1);
|
||||
DeleteObject(Pattern2);
|
||||
DeleteObject(Pattern3);
|
||||
|
||||
#ifdef WIN32
|
||||
OldBrush = (HBRUSH)GetClassLong(hwnd, GCL_HBRBACKGROUND);
|
||||
SetClassLongPtr(hwnd, GCLP_HBRBACKGROUND, (LONG)GetStockObject(WHITE_BRUSH));
|
||||
#else
|
||||
OldBrush = (HBRUSH)GetClassWord(hwnd, GCL_HBRBACKGROUND);
|
||||
SetClassWord(hwnd, GCL_HBRBACKGROUND, (WORD)GetStockObject(WHITE_BRUSH));
|
||||
#endif
|
||||
|
||||
DeleteBrush(OldBrush);
|
||||
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_CREATE, Main_Create) {
|
||||
WORD i;
|
||||
Pattern1 = LoadBitmap(WinApp.hInstance, "PATTERN1");
|
||||
if (!Pattern1) {
|
||||
MessageBox(hwnd, "No Pattern", "Error", MB_OK);
|
||||
}
|
||||
Pattern2 = LoadBitmap(WinApp.hInstance, "PATTERN2");
|
||||
if (!Pattern2) {
|
||||
MessageBox(hwnd, "No Pattern", "Error", MB_OK);
|
||||
}
|
||||
Pattern3 = LoadBitmap(WinApp.hInstance, "PATTERN3");
|
||||
if (!Pattern3) {
|
||||
MessageBox(hwnd, "No Pattern", "Error",
|
||||
MB_OK);
|
||||
}
|
||||
hPurpleHaze = CreateSolidBrush(RGB(127, 255, 255));
|
||||
#ifdef WIN32
|
||||
SetClassLongPtr(hwnd, GCLP_HBRBACKGROUND, (LONG)hPurpleHaze);
|
||||
#else
|
||||
SetClassWord(hwnd, GCW_HBRBACKGROUND, (WORD)hPurpleHaze);
|
||||
#endif
|
||||
|
||||
for (i=0; i<9; i++) {
|
||||
ChildWindows[i] = CreateWindow(CHILD_CLASS_NAME, NULL, Styles[i], 0, 0, 0, 0, hwnd, NULL, WinApp.hInstance, NULL);
|
||||
}
|
||||
ChildWindows[i] = CreateWindow(CHILD_CLASS_NAME, NULL, Styles[i], 0, 0, 0, 0, hwnd, NULL, WinApp.hInstance, NULL);
|
||||
|
||||
#ifdef WIN32
|
||||
SetClassLongPtr(ChildWindows[0], GCLP_HBRBACKGROUND, (LONG)hPurpleHaze);
|
||||
#else
|
||||
SetClassWord(ChildWindows[0], GCW_HBRBACKGROUND, (WORD)hPurpleHaze);
|
||||
#endif
|
||||
|
||||
for (i=0; i<10; i++) {
|
||||
SetWindowLong(ChildWindows[i], 0, i);
|
||||
}
|
||||
ArrangeWinds(hwnd);
|
||||
SetWindowText(ChildWindows[8], "Inactive");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_COMMAND, Main_Command) {
|
||||
HBRUSH OldBrush;
|
||||
switch (id) {
|
||||
case CM_ARRANGE: {
|
||||
ArrangeWinds(hwnd);
|
||||
InvalidateRect(hwnd, NULL, TRUE);
|
||||
break;
|
||||
}
|
||||
case CM_WHISTLE: {
|
||||
SetFocus(ChildWindows[9]);
|
||||
break;
|
||||
}
|
||||
case CM_RED:
|
||||
case CM_GREEN:
|
||||
case CM_BLUE:
|
||||
case CM_SPECIAL1:
|
||||
case CM_SPECIAL2:
|
||||
case CM_SPECIAL3: {
|
||||
HandleBrush(hwnd, id);
|
||||
break;
|
||||
}
|
||||
case CM_EXIT: {
|
||||
SendMessage(ChildWindows[9], WM_CLOSE, 0, 0);
|
||||
#ifdef WIN32
|
||||
OldBrush = (HBRUSH)GetClassLong(ChildWindows[0], GCL_HBRBACKGROUND);
|
||||
SetClassLong(ChildWindows[0], GCL_HBRBACKGROUND, (WORD)GetStockObject(WHITE_BRUSH));
|
||||
#else
|
||||
OldBrush = (HBRUSH)GetClassWord(ChildWindows[0], GCL_HBRBACKGROUND);
|
||||
SetClassWord(ChildWindows[0], GCL_HBRBACKGROUND, (WORD)GetStockObject(WHITE_BRUSH));
|
||||
#endif
|
||||
DeleteBrush(OldBrush);
|
||||
DestroyWindow(hwnd);
|
||||
break;
|
||||
}
|
||||
case CM_HELP: {
|
||||
MessageBox(hwnd, "Click on child windows to see their style", "Help", MB_OK|MB_ICONASTERISK);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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_EventMapEnd()
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_LBUTTONDOWN, Child_LButtonDown) {
|
||||
char szNum[100];
|
||||
LONG i= GetWindowLong(hwnd, 0);
|
||||
sprintf(szNum, "Number: %ld", i);
|
||||
MessageBox(hwnd, szStyles[i], szNum, MB_OK|MB_ICONINFORMATION);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_PAINT, Child_Paint) {
|
||||
PAINTSTRUCT ps;
|
||||
char lpszBuffer[100];
|
||||
RECT R;
|
||||
LONG i = GetWindowLong(hwnd, 0);
|
||||
sprintf(lpszBuffer, "%ld", i);
|
||||
|
||||
HDC PaintDC = BeginPaint(hwnd, &ps);
|
||||
SetTextColor(PaintDC, RGB(0, 0, 255));
|
||||
SetBkMode(PaintDC, TRANSPARENT);
|
||||
GetClientRect(hwnd, &R);
|
||||
DrawText(PaintDC, lpszBuffer, -1, &R, DT_SINGLELINE|DT_CENTER|DT_VCENTER);
|
||||
EndPaint(hwnd, &ps);
|
||||
}
|
||||
|
||||
c_WinGUI_EventMapBegin(ChildWndProc)
|
||||
c_WinGUI_EventMap(WM_PAINT, Child_Paint);
|
||||
c_WinGUI_EventMap(WM_LBUTTONDOWN, Child_LButtonDown);
|
||||
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 = NULL;
|
||||
WndClass.lpszMenuName = "Menu";
|
||||
WndClass.lpszClassName = WINDOW_CLASS_NAME;
|
||||
BOOL Result = RegisterClass(&WndClass);
|
||||
if (!Result) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
WndClass.lpfnWndProc = ChildWndProc;
|
||||
WndClass.cbWndExtra = sizeof(LONG);
|
||||
WndClass.hIcon = NULL;
|
||||
WndClass.hCursor = LoadCursor(NULL, IDC_IBEAM);
|
||||
WndClass.lpszMenuName = NULL;
|
||||
WndClass.lpszClassName = CHILD_CLASS_NAME;
|
||||
return RegisterClass(&WndClass);
|
||||
}
|
||||
|
||||
static
|
||||
HWND Create(HINSTANCE hInstance, int nCmdShow) {
|
||||
HWND hwnd = CreateWindow(WINDOW_CLASS_NAME, WINDOW_CLASS_NAME,
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
100, 150,
|
||||
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;
|
||||
}
|
||||
|
||||
|
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;
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
@@ -0,0 +1,3 @@
|
||||
#include <c_WinApp.h>
|
||||
|
||||
c_WinApp_t WinApp={0};
|
||||
@@ -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>
|
||||
@@ -0,0 +1,459 @@
|
||||
#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_EventFn_WM_USERDEFINED(fn) \
|
||||
LRESULT fn(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
#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_UDEventMap(message, fn) \
|
||||
case message: return fn(hwnd, wParam, lParam)
|
||||
|
||||
#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};
|
||||
|
||||
|
||||
@@ -1,106 +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_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)
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#include <c_WinGuiUtil.h>
|
||||
|
||||
void c_WinGuiUtil_MoveWindowToScreenCenter(HWND hwnd){
|
||||
int width = GetSystemMetrics(SM_CXSCREEN);
|
||||
int height = GetSystemMetrics(SM_CYSCREEN);
|
||||
RECT Rect;
|
||||
GetWindowRect(hwnd, &Rect);
|
||||
int x = (width - (Rect.right - Rect.left))/2;
|
||||
int y = (height - (Rect.bottom - Rect.top))/2;
|
||||
SetWindowPos(hwnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef INCLUDED_C_WINGUIUTIL_H
|
||||
#define INCLUDED_C_WINGUIUTIL_H
|
||||
|
||||
#ifndef INCLUDED_WINDOWS_H
|
||||
#define INCLUDED_WINDOWS_H
|
||||
#include <windows.h>
|
||||
#endif /*INCLUDED_WINDOWS_H*/
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
}c_WinGui_Point_t;
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
void c_WinGuiUtil_MoveWindowToScreenCenter(HWND hwnd);
|
||||
|
||||
|
||||
#endif /*INCLUDED_C_WINGUIUTIL_H*/
|
||||
@@ -0,0 +1,52 @@
|
||||
#include <c_WinUI_Console.h>
|
||||
|
||||
static void BlankLine(HANDLE hOut, int y) {
|
||||
DWORD NumWritten;
|
||||
COORD c;
|
||||
c.X = 0;
|
||||
c.Y = y;
|
||||
FillConsoleOutputCharacter(hOut, ' ', 80, c, &NumWritten);
|
||||
}
|
||||
|
||||
void c_WinUI_Console_ClearScreen() {
|
||||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
for (int i=0; i<25; i++) {
|
||||
BlankLine(hOut, i);
|
||||
}
|
||||
c_WinUI_Console_GotoXY(0, 0);
|
||||
}
|
||||
|
||||
void c_WinUI_Console_WriteStr(const char* str) {
|
||||
if (!str) return;
|
||||
DWORD NumWritten;
|
||||
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), str, strlen(str), &NumWritten, NULL);
|
||||
}
|
||||
|
||||
void c_WinUI_Console_WriteXY(int x, int y, const char* s, WORD attr) {
|
||||
if (!s) return;
|
||||
|
||||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
COORD c;
|
||||
DWORD result;
|
||||
|
||||
c.X = x;
|
||||
c.Y = y;
|
||||
|
||||
SetConsoleTextAttribute(hOut, attr);
|
||||
SetConsoleCursorPosition(hOut, c);
|
||||
WriteConsole(hOut, s, strlen(s), &result, NULL);
|
||||
}
|
||||
|
||||
void c_WinUI_Console_GotoXY(int x, int y) {
|
||||
COORD c;
|
||||
c.X = x;
|
||||
c.Y = y;
|
||||
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
|
||||
}
|
||||
|
||||
void c_WinUI_Console_BlankLine(int y) {
|
||||
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
BlankLine(hOut, y);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef INCLUDED_C_WINUI_CONSOLE_H
|
||||
#define INCLUDED_C_WINUI_CONSOLE_H
|
||||
|
||||
#ifndef INCLUDED_WINDOWS_H
|
||||
#define INCLUDED_WINDOWS_H
|
||||
#include <windows.h>
|
||||
#endif /*INCLUDED_WINDOWS_H*/
|
||||
|
||||
#ifndef INCLUDED_STDIO_H
|
||||
#define INCLUDED_STDIO_H
|
||||
#include <stdio.h>
|
||||
#endif /*INCLUDED_STDIO_H*/
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
void c_WinUI_Console_ClearScreen();
|
||||
|
||||
void c_WinUI_Console_WriteXY(int x, int y, const char* s, WORD attr);
|
||||
|
||||
void c_WinUI_Console_GotoXY(int x, int y);
|
||||
|
||||
void c_WinUI_Console_BlankLine(int y);
|
||||
|
||||
void c_WinUI_Console_WriteStr(const char* str);
|
||||
|
||||
#endif /*INCLUDED_C_WINUI_CONSOLE_H*/
|
||||
@@ -0,0 +1,112 @@
|
||||
#include <c_WinUI_Toast.h>
|
||||
#include <string.h>
|
||||
|
||||
// 定义定时器 ID
|
||||
#define TIMER_CLOSE_ID 1
|
||||
|
||||
// Toast 窗口的全局配置
|
||||
#define TOAST_WIDTH 320
|
||||
#define TOAST_HEIGHT 80
|
||||
#define MARGIN_RIGHT 20
|
||||
#define MARGIN_BOTTOM 60
|
||||
|
||||
#define WINDOW_CLASS_NAME "c_WinUI_Toast"
|
||||
|
||||
#define PROP_KEY_TITLE "c_WinUI_Toast.Title"
|
||||
#define PROP_KEY_MESSAGE "c_WinUI_Toast.Message"
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_PAINT, Toast_Paint) {
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc = BeginPaint(hwnd, &ps);
|
||||
|
||||
char* title = GetProp(hwnd, PROP_KEY_TITLE);
|
||||
char* message = GetProp(hwnd, PROP_KEY_MESSAGE);
|
||||
|
||||
if (title && message) {
|
||||
SetBkMode(hdc, TRANSPARENT);
|
||||
SetTextColor(hdc, RGB(255, 255, 255));
|
||||
RECT rcTitle = {15, 12, TOAST_WIDTH-15, 35};
|
||||
DrawText(hdc, title, -1, &rcTitle, DT_LEFT|DT_TOP|DT_END_ELLIPSIS);
|
||||
|
||||
SetTextColor(hdc, RGB(200, 200, 200));
|
||||
RECT rcMsg = {15, 38, TOAST_WIDTH-15, TOAST_HEIGHT-10};
|
||||
DrawText(hdc, message, -1, &rcMsg, DT_LEFT|DT_TOP|DT_WORDBREAK|DT_END_ELLIPSIS);
|
||||
}
|
||||
|
||||
EndPaint(hwnd, &ps);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_TIMER, Toast_Timer) {
|
||||
if (id==TIMER_CLOSE_ID) {
|
||||
KillTimer(hwnd, TIMER_CLOSE_ID);
|
||||
AnimateWindow(hwnd, 300, AW_HIDE|AW_BLEND);
|
||||
DestroyWindow(hwnd);
|
||||
}
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_LBUTTONDOWN, Toast_LButtonDown) {
|
||||
PostMessage(hwnd, WM_TIMER, TIMER_CLOSE_ID, 0);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_DESTROY, Toast_Destroy) {
|
||||
char* title = GetProp(hwnd, PROP_KEY_TITLE);
|
||||
char* message = GetProp(hwnd, PROP_KEY_MESSAGE);
|
||||
if (title){ free(title); }
|
||||
if (message){ free(message); }
|
||||
RemoveProp(hwnd, PROP_KEY_TITLE);
|
||||
RemoveProp(hwnd, PROP_KEY_MESSAGE);
|
||||
}
|
||||
|
||||
c_WinGUI_EventMapBegin(WndProc)
|
||||
c_WinGUI_EventMap(WM_DESTROY, Toast_Destroy);
|
||||
c_WinGUI_EventMap(WM_TIMER, Toast_Timer);
|
||||
c_WinGUI_EventMap(WM_LBUTTONDOWN, Toast_LButtonDown);
|
||||
c_WinGUI_EventMap(WM_PAINT, Toast_Paint);
|
||||
|
||||
c_WinGUI_EventMapEnd()
|
||||
|
||||
void c_WinUI_Toast_Show(HINSTANCE hInst, const char* title, const char* message, UINT timeoutMs) {
|
||||
if (!title || !message) {
|
||||
return;
|
||||
}
|
||||
|
||||
WNDCLASS wc = {0};
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.hInstance = hInst;
|
||||
wc.lpszClassName = WINDOW_CLASS_NAME;
|
||||
wc.hbrBackground = CreateSolidBrush(RGB(32, 32, 32));
|
||||
// wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
RegisterClass(&wc);
|
||||
|
||||
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
||||
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||
|
||||
int posX = screenWidth - TOAST_WIDTH - MARGIN_RIGHT;
|
||||
int posY = screenHeight - TOAST_HEIGHT - MARGIN_BOTTOM;
|
||||
|
||||
HWND hwnd = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TOOLWINDOW,
|
||||
WINDOW_CLASS_NAME, title,
|
||||
WS_POPUP,
|
||||
posX, posY, TOAST_WIDTH, TOAST_HEIGHT,
|
||||
NULL, NULL, hInst, NULL);
|
||||
|
||||
if (!hwnd) {
|
||||
return;
|
||||
}
|
||||
char* p_title = strdup(title);
|
||||
char* p_message = strdup(message);
|
||||
|
||||
SetProp(hwnd, PROP_KEY_TITLE, p_title);
|
||||
SetProp(hwnd, PROP_KEY_MESSAGE, p_message);
|
||||
|
||||
SetTimer(hwnd, TIMER_CLOSE_ID, timeoutMs, NULL);
|
||||
|
||||
AnimateWindow(hwnd, 200, AW_SLIDE | AW_VER_NEGATIVE | AW_ACTIVATE);
|
||||
|
||||
InvalidateRect(hwnd, NULL, TRUE); // 标记整个窗口需要重绘
|
||||
UpdateWindow(hwnd); // 立即发送 WM_PAINT 消息
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef INCLUDED_C_WINUI_TOAST_H
|
||||
#define INCLUDED_C_WINUI_TOAST_H
|
||||
|
||||
#ifndef INCLUDED_C_WINAPP_H
|
||||
#include <c_WinApp.h>
|
||||
#endif /*INCLUDED_C_WINAPP_H*/
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
void c_WinUI_Toast_Show(HINSTANCE hInst, const char* title, const char* message, UINT timeoutMs);
|
||||
|
||||
#endif /*INCLUDED_C_WINUI_TOAST_H*/
|
||||