#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;
}
LRESULT CALLBACK WndProc( HWND hwnd,UINT message, WPARAM wParam,LPARAM lParam)
{
HDC hdc ;        //设备句柄
PAINTSTRUCT ps ;    //画刷结构
int Xchar,Ychar;
SIZE size;
LPCTSTR pstring= "自定义的字体";
RECT rect ;        //无效矩形区
HFONT holdFont,hnewFont;
switch (message)    //消息处理函数
{
case WM_CREATE:  return 0;  //窗口创建
case WM_PAINT:        //绘制消息
hnewFont=CreateFont            //创建一种新的逻辑字体
( 64,0, 0, 0, 500,0,0,0,
GB2312_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH & FF_DONTCARE,
"黑体");
hdc=BeginPaint (hwnd, &ps);  //得到设备环境句柄
GetClientRect (hwnd, &rect);  //得到需要绘制的客户区
holdFont=(HFONT)SelectObject(hdc,hnewFont);  //选择新的字体
SetTextColor(hdc,RGB(255,0,0));  //设置文本颜
SetBkColor(hdc,RGB(0,0,255));  //设置背景颜
GetTextExtentPoint32(hdc,pstring,12,&size);
Xchar=(rect.right-rect.left)//2;
Ychar=(p)//2;
TextOut(hdc,Xchar,Ychar,pstring,12);
SelectObject(hdc,holdFont);  //保存原来的字体格式
DeleteObject(hnewFont);    //删除新的字体格式
EndPaint (hwnd, &ps) ;    //结束绘制
return 0 ;
case WM_DESTROY:    //退出消息
PostQuitMessage (0) ; return 0 ; 
}
return DefWindowProc(hwnd,message,wParam,lParam) ;
}
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)//初始化窗口
{
HWND hWnd;
hWnd=CreateWindow("WinFill",  //生成窗口
"填充示例程序",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
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小时内删除。