马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 spongebobyey 于 2019-10-9 08:05 编辑
设置结构体#define NUMBERLINES (int)(sizeof(Sysmetrics)/sizeof(Sysmetrics[0]))
struct
{
int iIndex;
TCHAR *szLabel;
TCHAR *szDesc;
} Sysmetrics[]=
{
SM_CMOUSEBUTTONS,TEXT("SM_CMOUSEBUTTONS"),
TEXT("arranged minimized windows"),
SM_CMONITORS, TEXT("SM_CMONITORS"),
TEXT("The number of display monitors on a desktop")
};
结构体中的值在GetSystemMetrics()函数中可以找到
在WINDPROC 中定义的局部变量 int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
size_t iTarget;
int i;
TEXTMETRIC tm;
static int cxChar,cyChar,cxCaps;
设置字符的宽度,高度,大写宽度
case WM_CREATE:
hdc=GetDC(hWnd);
GetTextMetrics(hdc,&tm);
cxChar=tm.tmAveCharWidth;
cyChar=tm.tmHeight+tm.tmExternalLeading;
cxCaps=(tm.tmPitchAndFamily &1 ?3:2)*cxChar/2;
ReleaseDC(hWnd,hdc);
return 0;
break;
打印代码
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
for(i=0;i<NUMBERLINES;i++)
{
StringCchLength(Sysmetrics[i].szLabel,1024,&iTarget);
TextOut(hdc,0,cyChar*i,Sysmetrics[i].szLabel,iTarget);
StringCchLength(Sysmetrics[i].szDesc,1024,&iTarget);
TextOut(hdc,22*cxCaps,cyChar*i,Sysmetrics[i].szDesc,iTarget);
SetTextAlign(hdc,TA_RIGHT |TA_TOP);
StringCchPrintf(szBuffer,10,TEXT("%5d"),GetSystemMetrics(Sysmetrics[i].iIndex));
StringCchLength(szBuffer,10,&iTarget);
TextOut(hdc,22*cxCaps+50*cxChar,cyChar*i,szBuffer,iTarget);
SetTextAlign(hdc,TA_LEFT|TA_TOP);
}
EndPaint(hWnd, &ps);
break;
|