📄 demo.c
字号:
/* * Copyright (c) 1999 Greg Haerr <greg@censoft.com> * * Demo program for Micro-Windows */#include "windows.h"#include "wintern.h" /* for WndSetDesktopWallpaper*/#ifndef ELKS#define GRAPH3D 1 /* 3d graphics demo*/#define IMAGE 0 /* 256 color image demo*/#endif#define CHILD 1 /* child window demo*/#define CLIENT3D 0 /* old client draw test*/#if GRAPH3D#include "graph3d.h"#endifextern IMAGEHDR image_car8;extern IMAGEHDR image_zion208;extern IMAGEHDR image_under4;extern IMAGEHDR image_microwin;extern IMAGEHDR image_cs1;extern IMAGEHDR image_rle8;#if CHILD#if ELKS | MSDOSPIMAGEHDR image = &image_cs1; /* 2 color bitmap for 16 color systems*/#elsePIMAGEHDR image = &image_zion208;#endif#endif#if IMAGEPIMAGEHDR image2 = &image_zion208;#endif#define APPCLASS "test"#define APPCHILD "test2"/* forward decls*/LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wp,LPARAM lp);LRESULT CALLBACK ChildWndProc(HWND hwnd,UINT uMsg,WPARAM wp,LPARAM lp);intGsUserInit(int ac, char **av){ /* test user init procedure - do nothing*/ return 0;}intRegisterAppClass(void){ WNDCLASS wc;#if !ELKS WndButtonRegister(NULL);#endif wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW; wc.lpfnWndProc = (WNDPROC)WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = 0; wc.hIcon = 0; /*LoadIcon(GetHInstance(), MAKEINTRESOURCE( 1));*/ wc.hCursor = 0; /*LoadCursor(NULL, IDC_ARROW);*/ wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = APPCLASS; RegisterClass( &wc);#if CHILD wc.lpfnWndProc = (WNDPROC)ChildWndProc; wc.lpszClassName = APPCHILD; return RegisterClass( &wc);#endif return 1;}HWNDCreateAppWindow(void){ HWND hwnd; static int nextid = 1; int width, height; RECT r; GetWindowRect(GetDesktopWindow(), &r); width = height = r.right / 2; hwnd = CreateWindowEx(0L, APPCLASS, "Micro Application", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, width, height, NULL, (HMENU)nextid++, NULL, NULL);#if CHILD if(hwnd#if GRAPH3D && (nextid & 03)!=2#endif ) { CreateWindowEx(0L, APPCHILD, "", WS_BORDER | WS_CHILD | WS_VISIBLE, 4, 4, width / 3, height / 3, hwnd, (HMENU)2, NULL, NULL); CreateWindowEx(0L, APPCHILD, "", WS_BORDER | WS_CHILD | WS_VISIBLE, width / 3, height / 3, width / 3, height / 3, hwnd, (HMENU)3, NULL, NULL); CreateWindowEx(0L, APPCHILD, "", WS_BORDER | WS_CHILD | WS_VISIBLE, width * 3 / 5, height * 3 / 5, width * 2 / 3, height * 2 / 3, hwnd, (HMENU)4, NULL, NULL); CreateWindowEx(0L, "BUTTON", "OK", WS_CHILD | WS_VISIBLE, /*WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,*/ width * 5 / 8, 10, 50, 14, hwnd, (HMENU)5, NULL, NULL); }#endif return hwnd;}#if CHILDLRESULT CALLBACKChildWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp){ HDC hdc; RECT rc; PAINTSTRUCT ps; switch(msg) { case WM_PAINT: hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rc); DrawDIB(hdc, rc.left, rc.top, image); EndPaint(hwnd, &ps); break; default: return DefWindowProc( hwnd, msg, wp, lp); } return( 0);}#endifLRESULT CALLBACKWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp){ PAINTSTRUCT ps; HDC hdc;#if CLIENT3D | IMAGE | GRAPH3D RECT rc;#endif#if GRAPH3D int id; static vec1 gx, gy;#endif switch( msg) { case WM_CREATE: break; case WM_DESTROY: break; case WM_SIZE: break; case WM_MOVE: break;#if CLIENT3D case WM_SETFOCUS: PostMessage((HWND)wp, WM_PAINT, 0, 0L); break; case WM_KILLFOCUS: PostMessage((HWND)wp, WM_PAINT, 0, 0L); break; case WM_ERASEBKGND: if(GetFocus() != hwnd) return DefWindowProc(hwnd, msg, wp, lp); return 1;#endif#if GRAPH3D case WM_ERASEBKGND: if((GetWindowLong(hwnd, GWL_ID) & 03) == 1) return 1; return DefWindowProc(hwnd, msg, wp, lp);#endif case WM_PAINT: hdc = BeginPaint(hwnd, &ps);#if CLIENT3D if(GetFocus() == hwnd) { GetClientRect(hwnd, &rc); Draw3dShadow(hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, GetSysColor(COLOR_3DDKSHADOW), GetSysColor(COLOR_3DLIGHT)); InflateRect(&rc, -1, -1); FillRect(hdc, &rc, GetStockObject(GRAY_BRUSH)); }#endif#if IMAGE GetClientRect(hwnd, &rc); DrawDIB(hdc, rc.left+2, rc.top+2, image2);#endif#if GRAPH3D id = (int)GetWindowLong(hwnd, GWL_ID) & 03; init3(hdc, id == 1? hwnd: NULL); switch(id) { case 0: rose(1.0, 7, 13); break; case 1: //look3(0.5, 0.7, 1.5); //look3(0.2, -2 * gy, 1.0+gx); look3(-2 * gx, -2 * gy, 1.2); drawgrid(-8.0, 8.0, 10, -8.0, 8.0, 10); break; case 2: setcolor(BLACK); circle(1.0); break; case 3: setcolor(BLUE); daisy(1.0, 20); break; } paint3(hdc);#endif EndPaint(hwnd, &ps); break; case WM_LBUTTONDOWN: break; case WM_MOUSEMOVE:#if GRAPH3D if((GetWindowLong(hwnd, GWL_ID) & 03) == 1) { POINT pt; POINTSTOPOINT(pt, lp); GetClientRect(hwnd, &rc); gx = (vec1)pt.x / rc.right; gy = (vec1)pt.y / rc.bottom; InvalidateRect(hwnd, NULL, FALSE); }#endif break; case WM_LBUTTONUP: break; case WM_RBUTTONDOWN: break; default: return DefWindowProc( hwnd, msg, wp, lp); } return( 0);}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){ MSG msg; RegisterAppClass(); CreateAppWindow(); CreateAppWindow(); CreateAppWindow();#if !(ELKS | MSDOS) CreateAppWindow(); CreateAppWindow(); CreateAppWindow(); CreateAppWindow(); CreateAppWindow(); CreateAppWindow();#endif#if !(ELKS | MSDOS) /* set background wallpaper*/ WndSetDesktopWallpaper(&image_microwin); /*WndSetDesktopWallpaper(&image_under4);*/ /*WndSetDesktopWallpaper(&image_car8);*/#endif /* type ESC to quit...*/ while( GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -