#include<windows.h>
#include<stdlib.h>
#include<string.h>
long WINAPI WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);
HWND hWndMain;
int WINAPI WinMain( HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)//主函数
{ MSG Message;
if(!InitWindowsClass(hInstance)) return FALSE;
if(!InitWindows(hInstance,nCmdShow)) return FALSE;
while(GetMessage(&Message,0,0,0)) //消息循环
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
long WINAPI WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam)
{
static long nXChar,nCaps,nYChar;
HDC hDC; //定义指向设备上下文的句柄
short x;
TEXTMETRIC tm;
short LnCount=6;
PAINTSTRUCT PtStr; //定义指向包含绘图信息的结构体变量
static char *textbuf[]=
{
"This is the First line",
"This is the second line",
"This is the third line",
"This is the fourth line",
"This is the fifth line",
"This is the sixth line"
};
switch(iMessage) //处理消息
{
case WM_CREATE: //处理窗口创建消息
hDC=GetDC(hWnd) ; //获取当前设备表句柄
GetTextMetrics(hDC,&tm); //获取字体信息
AveCharWidth; //获取字符宽度
ExternalLeading;
ReleaseDC(hWnd,hDC); //释放当前设备句柄
return 0;
case WM_PAINT: //处理重画消息
hDC=BeginPaint(hWnd,&PtStr); //开始绘画
for(x=0;x<LnCount;x=x+1) //输出文本
TextOut(hDC,nXChar,nYChar*(1+x),textbuf[x],lstrlen(textbuf[x]));
EndPaint(hWnd,&PtStr);
return 0;
case WM_DESTROY: //结束应用程序
PostQuitMessage(0);
return 0;
default: //其他消息处理程序
return(DefWindowProc(hWnd,iMessage,wParam,lParam)) ;
}
}
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)//初始化窗口
{
HWND hWnd;
hWnd=CreateWindow("WinFill", //生成窗口
"填充示例程序",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
字符串函数title()是使字符串开头首字母大写CW_USEDEFAULT,
0,
NULL,
NULL,
hInstance,
NULL);
if(!hWnd)
return FALSE;
hWndMain=hWnd;
ShowWindow(hWnd,nCmdShow); //显示窗口
UpdateWindow(hWnd);
return TRUE;
}
BOOL InitWindowsClass(HINSTANCE hInstance) //定义窗口类
{
WNDCLASS WndClass;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH));
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,"END");
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName="WinFill";
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW|CS_VREDRAW;
return RegisterClass(&WndClass);
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论