This commit is contained in:
2026-07-28 14:17:49 +08:00
parent a68366efb2
commit a222cf81bb
28 changed files with 2421 additions and 231 deletions
+305
View File
@@ -0,0 +1,305 @@
#include "c_WinApp.h"
#include "Resource.h"
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
#define MAIN_WINDOW_CLASSNAME "Resource.Main"
static HANDLE hResource;
static HBITMAP hTheBitmap;
static int ScrollWidth;
static int MaxLines = 21;
static int Start = 0;
static int TextHeight=0;
static int PageSize = 3;
static int nPosition = 0;
static BOOL bDrawBitmaps = TRUE;
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
static void NotYetAvailable(HWND hwnd) {
MessageBox(hwnd, "Not Yet Available!", "Under Construction", MB_OK);
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
BOOL CALLBACK AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_INITDIALOG: {
return TRUE;
}
case WM_COMMAND: {
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
}
return FALSE;
}
c_WinGUI_EventHandlerDef(WM_CREATE, Main_Create) {
TEXTMETRIC TextMetric;
hTheBitmap = LoadBitmap(WinApp.hInstance, "Bitmap");
if (!hTheBitmap) {
MessageBox(hwnd, "No Bitmap", "Fatal Error", MB_OK);
return FALSE;
}
hResource = LoadResource(WinApp.hInstance, FindResource(WinApp.hInstance, "Brahma", "CUSTOM"));
HDC PaintDC = GetDC(hwnd);
GetTextMetrics(PaintDC, &TextMetric);
ReleaseDC(hwnd, PaintDC);
TextHeight = TextMetric.tmHeight + TextMetric.tmExternalLeading;
SetScrollRange(hwnd, SB_VERT, 0, -1, FALSE);
return TRUE;
}
c_WinGUI_EventHandlerDef(WM_DESTROY, Main_Destroy) {
FreeResource(hResource);
DeleteBitmap(hTheBitmap);
PostQuitMessage(0);
}
c_WinGUI_EventHandlerDef(WM_COMMAND, Main_Command) {
switch (id) {
case CM_ABOUT: {
FARPROC AboutBox = MakeProcInstance((FARPROC)AboutDlgProc, WinApp.hInstance);
DialogBox(WinApp.hInstance, "About", hwnd, (DLGPROC)AboutBox);
FreeProcInstance(AboutBox);
break;
}
case CM_BITMAP: {
bDrawBitmaps = TRUE;
SetScrollRange(hwnd, SB_VERT, 0, -1, FALSE);
InvalidateRect(hwnd, NULL, TRUE);
break;
}
case CM_BRAHMIN: {
Start = 32;
MaxLines = 22;
SetScrollRange(hwnd, SB_VERT, 0, MaxLines-1, FALSE);
InvalidateRect(hwnd, NULL, TRUE);
bDrawBitmaps = FALSE;
break;
}
case CM_WOODNOTES: {
Start = 0;
MaxLines = 32;
SetScrollRange(hwnd, SB_VERT, 0, MaxLines-1, FALSE);
InvalidateRect(hwnd, NULL, TRUE);
bDrawBitmaps = FALSE;
break;
}
case CM_SEASHORE: {
Start = 64;
MaxLines = 37;
SetScrollRange(hwnd, SB_VERT, 0, MaxLines-1, FALSE);
InvalidateRect(hwnd, NULL, TRUE);
bDrawBitmaps = FALSE;
break;
}
}
}
c_WinGUI_EventHandlerDef(WM_PAINT, Main_Paint) {
PAINTSTRUCT PaintStruct;
int NumImages = 15;
char s[101];
int Y = 0;
HDC PaintDC = BeginPaint(hwnd, &PaintStruct);
SetBkMode(PaintDC, TRANSPARENT);
if (bDrawBitmaps) {
HDC BitmapDC = CreateCompatibleDC(PaintDC);
HBITMAP oldBitmap = SelectBitmap(BitmapDC, hTheBitmap);
for (int i=0; i<NumImages; i++) {
for (int j=0; j<NumImages; j++) {
BitBlt(PaintDC, i*66, j*66, 64, 64, BitmapDC, 0, 0, SRCCOPY);
}
}
SelectBitmap(BitmapDC, oldBitmap);
DeleteDC(BitmapDC);
}else {
for (int i=nPosition; i<MaxLines; i++) {
LoadString(WinApp.hInstance, i+Start, s, 100);
TextOut(PaintDC, 1, Y, s, strlen(s));
Y+=TextHeight;
}
}
EndPaint(hwnd, &PaintStruct);
#if 0
PAINTSTRUCT PaintStruct;
RECT Rect;
HDC PaintDC = BeginPaint(hwnd, &PaintStruct);
SetBkMode(PaintDC, TRANSPARENT);
char *Poem = (char *) LockResource(hResource);
GetClientRect(hwnd, &Rect);
Rect.left += 10;
Rect.top += 10;
DrawText(PaintDC, Poem, -1, &Rect, DT_EXTERNALLEADING);
GlobalUnlock(hResource);
EndPaint(hwnd, &PaintStruct);
#endif
}
c_WinGUI_EventHandlerDef(WM_KEYDOWN, Main_Key) {
switch (vk) {
case VK_HOME: {
SendMessage(hwnd, WM_VSCROLL, SB_TOP, 0L);
break;
}
case VK_DOWN: {
SendMessage(hwnd, WM_VSCROLL, SB_LINEDOWN, 0L);
break;
}
case VK_UP: {
SendMessage(hwnd, WM_VSCROLL, SB_LINEUP, 0L);
break;
}
case VK_PRIOR: {
SendMessage(hwnd, WM_VSCROLL, SB_PAGEUP, 0L);
break;
}
case VK_NEXT: {
SendMessage(hwnd, WM_VSCROLL, SB_PAGEDOWN, 0L);
break;
}
}
}
c_WinGUI_EventHandlerDef(WM_VSCROLL, Main_VScroll) {
int SrcMove = 0;
int Temp;
int i;
switch (code) {
case SB_TOP: {
nPosition = 0;
break;
}
case SB_BOTTOM: {
nPosition = MaxLines;
break;
}
case SB_LINEUP: {
if (nPosition>0) {
nPosition -= 1;
SrcMove = TextHeight;
}
break;
}
case SB_LINEDOWN: {
if (nPosition < MaxLines) {
nPosition +=1;
SrcMove = -TextHeight;
}
break;
}
case SB_PAGEUP: {
if ((nPosition - PageSize) > 0) {
for (i=0; i<PageSize; i++) {
SendMessage(hwnd, WM_VSCROLL, SB_LINEUP, 0L);
}
}
break;
}
case SB_PAGEDOWN: {
if ((nPosition + PageSize) < MaxLines) {
for (i=0; i<PageSize; i++) {
SendMessage(hwnd, WM_VSCROLL, SB_LINEDOWN, 0L);
}
}
break;
}
case SB_THUMBTRACK: {
Temp = nPosition;
nPosition = pos;
SrcMove = (Temp - nPosition) * TextHeight;
break;
}
case SB_THUMBPOSITION: {
nPosition = pos;
break;
}
}
nPosition = max(0, min(nPosition, MaxLines-1));
SetScrollPos(hwnd, SB_VERT, nPosition, TRUE);
ScrollWindow(hwnd, 0, SrcMove, NULL, NULL);
}
c_WinGUI_EventMapBegin(WndProc)
c_WinGUI_EventMap(WM_DESTROY, Main_Destroy);
c_WinGUI_EventMap(WM_CREATE, Main_Create);
c_WinGUI_EventMap(WM_COMMAND, Main_Command);
c_WinGUI_EventMap(WM_PAINT, Main_Paint);
c_WinGUI_EventMap(WM_KEYDOWN, Main_Key);
c_WinGUI_EventMap(WM_VSCROLL, Main_VScroll);
c_WinGUI_EventMapEnd()
static bool Register(HINSTANCE hInstance){
WNDCLASS WndClass;
WndClass.lpszClassName = MAIN_WINDOW_CLASSNAME;
WndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
WndClass.cbWndExtra = 0;
WndClass.cbClsExtra = 0;
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = WndProc;
WndClass.hIcon = LoadIcon(hInstance, "Icon"); /* Icon Resource */
WndClass.hCursor = LoadCursor(hInstance, "Cursor"); /* Cursor Resource */
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
WndClass.lpszMenuName = "Menu"; /* Menu Resource */
return (RegisterClass(&WndClass)!=0);
}
static HWND Create(HINSTANCE hInstance, int nCmdShow){
HWND hWindow = CreateWindowEx(0, MAIN_WINDOW_CLASSNAME, MAIN_WINDOW_CLASSNAME,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
if(!hWindow) return NULL;
ShowWindow(hWindow, nCmdShow);
UpdateWindow(hWindow);
return hWindow;
}
/* ------------------------------------------------------------------------------------------------------------------ */
/* */
c_WinGUI_Main() {
MSG msg;
if (!hPrevInstance) {
if (!Register(hInstance)) {
return FALSE;
}
}
WinApp.hInstance = hInstance;
HWND MainHwnd = Create(hInstance, nShowCmd);
if (!MainHwnd) {
return FALSE;
}
WinApp.hwnd = MainHwnd;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}