源代码:
canp-gdi.cpp (大小:11.4KB)
// 2020/12/31
// (illust, original) (C) Copyright solderwire(WVBCommunity), 2020
// (program) (C) Copyright Ghdgtdgu Studio, 2019-2020
// 项目名称: GDI CoolAPK-Niupi
#include <windows.h>
#include <commctrl.h>
#pragma comment (lib, "comctl32.lib")
// 各类句柄
HINSTANCE hInstance;
HWND hWinMain;
HMENU hMenu;
HICON hIcon;
HFONT hTahoma18Bold;
// Color -> hBrush
// 为了迎合Windows GDI函数, 此处的颜色将统一转换为HBRUSH句柄.
// HPEN句柄同理.
HBRUSH cowcolor_brush[16];
HPEN cowcolor_pen[16];
#define USED_HANDLE 15 // 已经使用的句柄(包括默认颜色, 纯黑, 纯白)
// 来自 巨硬中冰(solderwire)的一些宏代码
// >颜色表
const COLORREF cowcolor[13] = {
RGB(213,116,48),RGB(224,130,68),RGB(232,232,232),RGB(244,158,107),
RGB(255,255,255),RGB(230,128,2),RGB(252,248,213),RGB(170,179,160),
RGB(255,87,87),RGB(249,155,94),RGB(163,63,13),RGB(243,149,98),
RGB(17, 182, 103)
};
// >访问宏 (有修改)
#define SKIN1 0
#define SKIN2 1
#define HAND 2
#define HORN 3
#define EYE 4
#define BEER 5
#define FOAM 6
#define CUP 7
#define MOUTH 8
#define NOSE1 9
#define NOSE2 10
#define EAR 11
#define COOLAPK 12
// 以下为重编作者添加
#define BLACK0 13
#define WHITE0 14
// 字符串
const unsigned short ClassName[] = L"DemoProgram";
const unsigned short TitleText[] = L"GDI CoolAPK-Niupi";
const unsigned short MsgTitle[] = L"About GDI CoolAPK-Niupi";
const unsigned short MsgAbout[] = L"(illust, original) (C) Copyright solderwire(WVBCommunity), 2020\n(program) (C) Copyright Ghdgtdgu Studio, 2019-2020\nVisual C++ 6.0, UNICODE";
const unsigned short WindowText[] = L"CoolApk Niupi";
// 各类函数 (共8个)
void RegisterClasses(void);
void MakeCreateWindow(void);
int MessageLoop(void);
BOOL CALLBACK ProcWinMain(HWND hWin, UINT uMessage, WPARAM wParam, LPARAM lParam);
void ResizeWindow(HWND hWin);
void NiupiDrawProc(HDC hDevice);
void LoadhBrush(void);
void DeletehBrush(void);
// 主程序
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpstrCmdLine, int nCmdShow)
{
InitCommonControls();
hInstance = GetModuleHandle(NULL);
hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(1200));
hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(1000));
RegisterClasses();
MakeCreateWindow();
return MessageLoop();
}
// 注册窗口类
void RegisterClasses(void)
{
WNDCLASSEX wndclass1;
HBRUSH hBrush;
hBrush = CreateSolidBrush(RGB(255, 255, 255)); //为了得到白色背景
RtlZeroMemory(&wndclass1, sizeof(WNDCLASSEX));
wndclass1.hIcon = hIcon;
wndclass1.hIconSm = NULL;
wndclass1.hInstance = hInstance;
wndclass1.cbSize = sizeof(WNDCLASSEX);
wndclass1.style = CS_HREDRAW | CS_VREDRAW;
wndclass1.lpfnWndProc = (WNDPROC) ProcWinMain;
wndclass1.hbrBackground = hBrush;
wndclass1.lpszClassName = ClassName;
RegisterClassEx(&wndclass1);
return;
}
// 建立窗口
void MakeCreateWindow(void)
{
// 大小需要修正
hWinMain = CreateWindowEx(NULL,
ClassName, TitleText,
WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU,
100, 100, 100, 100,
NULL, hMenu, hInstance, NULL);
ShowWindow(hWinMain, SW_SHOWNORMAL);
UpdateWindow(hWinMain);
return;
}
// 消息循环
int MessageLoop(void)
{
MSG message;
while(TRUE) {
if(GetMessage(&message, NULL, 0, 0) == 0) {
break;
} else {
TranslateMessage(&message);
DispatchMessage(&message);
}
}
UnregisterClass(ClassName, hInstance);
return (int)message.wParam;
}
// 窗口回调函数
BOOL CALLBACK ProcWinMain(HWND hWin, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
HDC hDevice;
PAINTSTRUCT Paint;
switch (uMessage) {
case WM_CREATE:
hWinMain = hWin;
ResizeWindow(hWinMain);
LoadhBrush();
// 建立用于显示的字体
// Tahoma, 18像素高, 粗体
hTahoma18Bold = CreateFont(18, 0, 0, 0,
FW_BOLD, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Tahoma");
break;
case WM_PAINT:
hDevice = BeginPaint(hWinMain, &Paint);
NiupiDrawProc(hDevice);
EndPaint(hWinMain, &Paint);
break;
case WM_COMMAND:
switch(wParam) {
case 1201:
// 关于菜单项
MessageBox(hWinMain, MsgAbout, MsgTitle, MB_OK);
break;
case 1202:
// 退出菜单项
SendMessage(hWinMain, WM_CLOSE, NULL, NULL);
break;
}
break;
case WM_CLOSE:
// 关闭窗口
DeletehBrush();
DestroyWindow(hWin);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWin, uMessage, wParam, lParam);
}
return FALSE;
}
// 重新设定窗口大小
void ResizeWindow(HWND hWin)
{
// 尺寸: 340x360 (Client)
int dwDestXSize, dwDestYSize;
RECT stRectClient, stRectWindow;
GetClientRect(hWin, &stRectClient);
GetWindowRect(hWin, &stRectWindow);
dwDestXSize = (stRectWindow.right - stRectWindow.left) - (stRectClient.right - stRectClient.left) + 340;
dwDestYSize = (stRectWindow.bottom - stRectWindow.top) - (stRectClient.bottom - stRectClient.top) + 360;
MoveWindow(hWin, 100, 100, dwDestXSize, dwDestYSize, TRUE);
return;
}
// 中央绘图程序
void NiupiDrawProc(HDC hDevice)
{
RECT rectPublic;
int i;
// 来自 巨硬中冰(solderwire)的一些定义代码, 有修改
static POINT tri1[] = { {140,180},{80,180},{110,200} };
static POINT tri2[] = { {95,190},{110,200},{125,190} };
static POINT tri3[] = { {100,20},{100,60},{80,60} };
static POINT tri4[] = { {160,20},{160,60},{180,60} };
static POINT pol1[] = { {80,180},{110,200},{140,180},{160,180},{160,140},
{180,120},{220,200},{210,220},{200,200},{200,300},{120,300} };
static POINT pol2[] = { {180,120},{180,70},{320,140},{320,320},{260,320},{260,300} };
static POINT pol3[] = { {160,140},{180,120},{180,70},{200,70},{200,50},{180,50},{130,40},
{80,50},{60,50},{60,70},{80,70},{80,120},{60,140} };
static POINT pol4[] = { {200,200},{210,220},{220,200},{230,220},{240,200},{250,220},
{260,200},{260,240},{200,240} };
// 顶部Title文字
SelectObject(hDevice, hTahoma18Bold);
SetTextColor(hDevice, RGB(0, 0, 0));
SetBkColor(hDevice, RGB(255, 255, 255));
SetRect(&rectPublic, 5, 5, 0, 0); //定义文字方位
DrawText(hDevice, WindowText, -1, &rectPublic, DT_SINGLELINE | DT_CALCRECT);
DrawText(hDevice, WindowText, -1, &rectPublic, DT_SINGLELINE);
// 底部颜色Bar
// 由于Rectangle函数将边框设定为绘制的一部分, 所以绘制正方形长度+1,
// 即21x21, 以获得源程序的效果. 以下同理.
for(i = 0; i < 13; i++) {
SelectObject(hDevice, cowcolor_brush[i]);
SelectObject(hDevice, cowcolor_pen[BLACK0]);
Rectangle(hDevice, i*20, 340, (i+1)*20+1, 360+1);
}
// 开始绘制图形
// !!!!! 高能警告! 读者注意! !!!!!
// The Cow
// NOTE: HDC中的HPEN元素决定边线颜色, HBRUSH元素决定填充部分颜色
// 即: 使用SelectObject切换HDC的HPEN元素等于操作setlincolor函数,
// 切换HBRUSH元素等于操作setfillcolor函数
// Polygon = Pol, Rectangle = fillrectangle, MoveToEx+LineTo = line Ellipse = fillcircle/circle
SelectObject(hDevice, cowcolor_brush[SKIN2]);
Polygon(hDevice, pol1, 11);
SelectObject(hDevice, cowcolor_pen[BLACK0]);
SelectObject(hDevice, cowcolor_brush[BLACK0]);
Polygon(hDevice, tri1, 3);
SelectObject(hDevice, cowcolor_brush[MOUTH]);
Polygon(hDevice, tri2, 3);
SelectObject(hDevice, cowcolor_pen[SKIN1]);
SelectObject(hDevice, cowcolor_brush[SKIN1]);
Polygon(hDevice, pol2, 6);
SelectObject(hDevice, cowcolor_pen[BLACK0]);
SelectObject(hDevice, cowcolor_brush[HAND]);
Rectangle(hDevice, 50, 240, 70+1, 320+1);
Rectangle(hDevice, 20, 260, 60+1, 320+1);
MoveToEx(hDevice, 40, 280, NULL);
LineTo(hDevice, 60, 280);
MoveToEx(hDevice, 40, 300, NULL);
LineTo(hDevice, 60, 300);
SelectObject(hDevice, cowcolor_brush[SKIN1]);
Rectangle(hDevice, 70, 300, 200+1, 320+1);
SelectObject(hDevice, cowcolor_pen[SKIN1]);
MoveToEx(hDevice, 120, 300, NULL);
LineTo(hDevice, 200, 300);
SelectObject(hDevice, cowcolor_pen[NOSE2]);
SelectObject(hDevice, cowcolor_brush[NOSE1]);
Rectangle(hDevice, 60, 140, 160+1, 180+1);
SelectObject(hDevice, cowcolor_brush[NOSE2]);
Rectangle(hDevice, 80, 150, 100+1, 160+1);
Rectangle(hDevice, 120, 150, 140+1, 160+1);
SelectObject(hDevice, cowcolor_pen[BLACK0]);
SelectObject(hDevice, cowcolor_brush[EAR]);
Polygon(hDevice, tri3, 3);
Polygon(hDevice, tri4, 3);
SelectObject(hDevice, cowcolor_brush[SKIN1]);
Polygon(hDevice, pol3, 13);
SelectObject(hDevice, cowcolor_pen[CUP]);
SelectObject(hDevice, cowcolor_brush[FOAM]);
Polygon(hDevice, pol4, 9);
SelectObject(hDevice, cowcolor_brush[BEER]);
Rectangle(hDevice, 200, 225, 260+1, 310+1);
SelectObject(hDevice, cowcolor_pen[BLACK0]);
SelectObject(hDevice, cowcolor_brush[HAND]);
Rectangle(hDevice, 260, 220, 280+1, 260+1);
Rectangle(hDevice, 260, 240, 300+1, 300+1);
MoveToEx(hDevice, 260, 260, NULL);
LineTo(hDevice, 280, 260);
MoveToEx(hDevice, 260, 280, NULL);
LineTo(hDevice, 280, 280);
SelectObject(hDevice, cowcolor_pen[CUP]);
SelectObject(hDevice, cowcolor_brush[CUP]);
Rectangle(hDevice, 200, 310, 260+1, 320+1);
SelectObject(hDevice, cowcolor_pen[BLACK0]);
SelectObject(hDevice, cowcolor_brush[EYE]);
Rectangle(hDevice, 100, 80, 120+1, 100+1);
Rectangle(hDevice, 140, 80, 160+1, 100+1);
SelectObject(hDevice, cowcolor_brush[BLACK0]);
Rectangle(hDevice, 107, 87, 113+1, 93+1);
Rectangle(hDevice, 147, 87, 153+1, 93+1);
SelectObject(hDevice, cowcolor_pen[SKIN1]);
MoveToEx(hDevice, 180, 70, NULL);
LineTo(hDevice, 180, 120);
MoveToEx(hDevice, 180, 120, NULL);
LineTo(hDevice, 160, 140);
// The CoolAPK Logo
// 原fillcircle函数的参数指定圆的圆心在290, 50, 半径为30.
// 而Ellipse函数的参数指定的是圆所相切的四边形的四角
SelectObject(hDevice, cowcolor_pen[COOLAPK]);
SelectObject(hDevice, cowcolor_brush[COOLAPK]);
Ellipse(hDevice, 290-30, 50-30, 290+30, 50+30);
SelectObject(hDevice, cowcolor_pen[WHITE0]);
Ellipse(hDevice, 280-10, 50-10, 280+10, 50+10);
// 使用Rectangle函数画矩形遮掩一半的圆弧, 即形成半圆
SelectObject(hDevice, cowcolor_pen[COOLAPK]);
Rectangle(hDevice, 289, 40, 300+1, 60+1);
// 最后的部分!
SelectObject(hDevice, cowcolor_pen[WHITE0]);
MoveToEx(hDevice, 288, 54, NULL);
LineTo(hDevice, 300, 40);
MoveToEx(hDevice, 300, 40, NULL);
LineTo(hDevice, 306, 60);
MoveToEx(hDevice, 306, 60, NULL);
LineTo(hDevice, 296, 50);
// 高能警告区结束
return;
}
// 加载hBrush句柄
void LoadhBrush(void)
{
int i;
// 加载十三种绘图默认颜色
for(i = 0; i < 13; i++) {
cowcolor_brush[i] = CreateSolidBrush(cowcolor[i]);
cowcolor_pen[i] = CreatePen(PS_SOLID, 1, cowcolor[i]);
}
// 加载纯黑
cowcolor_brush[13] = CreateSolidBrush(RGB(0, 0, 0));
cowcolor_pen[13] = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
// 加载纯白
cowcolor_brush[14] = CreateSolidBrush(RGB(255, 255, 255));
cowcolor_pen[14] = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
return;
}
// 卸载hBrush句柄
void DeletehBrush(void)
{
int i;
// 卸载全部句柄
for(i = 0; i < USED_HANDLE; i++) {
DeleteObject(cowcolor_brush[i]);
DeleteObject(cowcolor_pen[i]);
}
return;
}
rcsc.rc (大小:209byte)
#include <windows.h>
1 24 "manifest.xml"
1000 ICON "cab.ico"
1200 MENU DISCARDABLE
BEGIN
POPUP "File"
BEGIN
MENUITEM "About", 1201
MENUITEM SEPARATOR
MENUITEM "Exit", 1202
END
END