#include <Windows.h>
#include <stdio.h>
LRESULT CALLBACK WinHeProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE dyg, HINSTANCE deg, LPSTR mlh, int xs)
{
WNDCLASS cklx;
cklx.style = CS_HREDRAW | CS_VREDRAW;
cklx.cbClsExtra = 0;
cklx.cbWndExtra = 0;
cklx.hbrBackground = (HBRUSH)(GetStockObject(DEFAULT_PALETTE));
cklx.hCursor = LoadCursor(NULL, IDC_APPSTARTING);
cklx.hIcon = LoadIcon(NULL, IDI_HAND);
cklx.hInstance = dyg;
cklx.lpfnWndProc = WinHeProc;
cklx.lpszClassName = "dygcx";
cklx.lpszMenuName = NULL;
if (!RegisterClass(&cklx))
{
MessageBeep(0);
return false;
}
HWND ckjbA;
ckjbA= CreateWindow("dygcx", "第一个程序", WS_OVERLAPPEDWINDOW, NULL, NULL, 600, 400, NULL, NULL, dyg, NULL);
if (!ckjbA)
{
MessageBox(NULL, "创建窗口失败!", "错误", NULL);
return false;
}
ShowWindow(ckjbA, SW_SHOWNORMAL);
UpdateWindow(ckjbA);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinHeProc(HWND ckjb, UINT umsg, WPARAM cdcs, LPARAM cscs)
{
TCHAR zf[222];
HDC ht;
PAINTSTRUCT tu;
TEXTMETRIC tm;//存放字体相关信息
LOGFONT lf = { 0 };//自定字体
CHOOSEFONT cf = { 0 };//初始化字体框
CHOOSECOLOR cc = { 0 };//自定颜色
COLORREF crf[16] = { 0 };//初始化自定义颜色
/*BOOL ChooseFont(LPCHOOSEFONT lpcf)
typedef struct{
DWORD lStructSize; //结构体大小
LPLOGFONT lpLogFont;//字体信息
DWORD Flags;//CF_SCREENFONTS在屏幕上显示;CF_EFFECT显示下划线,
字体颜色,删除线功能;CF_INITTOLOGFONTSTRUCT用lpLogFont初始化选择框
。。。。。。
} CHOOSEFONT, *LPCHOOSEFONT */
/*BOOL ChooseColor(LPCHOOSECOLOR lpcc)
typedef struct{
DWORD lStructSize; //结构体大小
COLORREF refResult;//颜色值
COLORREF * lpCustColors;//自定义颜色值储存位置
DWORD Flags;//CC_FULLOPEN显示选择框;CC_RGBINIT用rgbResult值初始化选择框
。。。。。。
} CHOOSECOLOR, *LPCHOOSECOLOR */
switch (umsg)
{
case WM_SIZE:
sprintf(zf, "宽度:%d,高度:%d", LOWORD(cscs), HIWORD(cscs));
MessageBox(NULL, zf, "大小", 0);
break;
case WM_CREATE:
MessageBox(ckjb, "创建完毕", "成功", 0);
break;
case WM_PAINT:
ht = BeginPaint(ckjb, &tu);
GetTextMetrics(ht, &tm);//取得字体大小
for (int i = 0; i < 5; i++)
{
TextOut(ht, 0, tm.tmHeight *i, "我的程序!", strlen("我的程序!"));
}
//SetBkMode(hdc,OPAQUB)文字背景模式不透明
//SetBkMode(hdc,TRANSPARENT)文字背景模式透明
SetTextColor(ht, RGB(255, 222, 22));//设置字体颜色
SetBkColor(ht, RGB(1, 222, 22));//设置字体背景颜色
SelectObject(ht, GetStockObject(ANSI_VAR_FONT));//取得字体形式
TextOut(ht, 0, 300, "我的程序!", strlen("我的程序!"));
SelectObject(ht, GetStockObject(ANSI_FIXED_FONT));//取得字体形式
TextOut(ht, 0, 300 + tm.tmHeight, "我的程序!", strlen("我的程序!"));
lf.lfHeight = 30;//自定字体的高度
lf.lfUnderline = 2;//自定带下划线的字体
SelectObject(ht, CreateFontIndirect(&lf));//选择创建的自定义字体
TextOut(ht, 121, 3 + tm.tmHeight, "我的程序!", strlen("我的程序!"));
EndPaint(ckjb, &tu);
break;
case WM_CHAR:
sprintf(zf, "按下了%c键", cdcs);
MessageBox(ckjb, zf, "键盘消息", 0);
break;
case WM_LBUTTONDOWN:
cc.lStructSize = sizeof(CHOOSECOLOR);
cc.lpCustColors = crf;
cc.Flags = CC_FULLOPEN;
crf[0] = RGB(255, 0, 9);
ht = GetDC(ckjb);
ChooseColor(&cc);
SetBkColor(ht, cc.rgbResult);
TextOut(ht, 131, 111, "我的程序!", strlen("我的程序!"));
ReleaseDC(ckjb, ht);
cf.lStructSize = sizeof(CHOOSEFONT); //字
cf.lpLogFont = &lf;
cf.Flags = CF_SCREENFONTS | CF_EFFECTS; //体
ChooseFont(&cf);
ht = GetDC(ckjb);
SetTextColor(ht, RGB(255, 222, 22)); //设置字体颜色 //选
SetBkColor(ht, RGB(1, 222, 22)); //设置字体背景颜色
SelectObject(ht, CreateFontIndirect(cf.lpLogFont)); //择
TextOut(ht, 131, 88, "我的程序!", strlen("我的程序!"));
ReleaseDC(ckjb, ht); //框
MessageBox(ckjb, "鼠标左键按下了。。。。", "鼠标消息", 0);
break;
case WM_RBUTTONDOWN:
MessageBox(ckjb, "鼠标右键按下了。。。。", "鼠标消息", 0);
break;
case WM_CLOSE:
if (IDYES == MessageBox(ckjb, "是否退出程序?", "退出程序", MB_YESNO))
{
DestroyWindow(ckjb);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(ckjb, umsg, cdcs, cscs);
break;
}
return 0;
}