windows GDI编程窗口模板

来源:互联网 发布:java从入门到精通mobi 编辑:程序博客网 时间:2024/06/05 00:07
#include <Windows.h>HWND hwnd;static TCHAR szAppName[]=TEXT("hellowin");HRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){HDC hdc;PAINTSTRUCT ps;RECT rect;switch(msg){case WM_PAINT:hdc=BeginPaint(hwnd,&ps);GetClientRect(hwnd,&rect);DrawText(hdc,TEXT("fuck jameslee"),-1,&rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER);EndPaint(hwnd,&ps);return 0;case WM_DESTROY:PostQuitMessage(0);return 0;}return DefWindowProc(hwnd,msg,wparam,lparam);}int init(HINSTANCE hInstance){WNDCLASSEX wndclass;wndclass.cbSize        = sizeof(WNDCLASSEX);wndclass.style         = CS_HREDRAW | CS_VREDRAW;wndclass.lpfnWndProc   = WndProc;wndclass.hInstance     = hInstance;wndclass.hIcon       = NULL ;wndclass.hIconSm   = NULL ;wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);wndclass.hbrBackground = NULL ;wndclass.lpszMenuName  = NULL;wndclass.cbClsExtra    = 0;wndclass.cbWndExtra    = 0;wndclass.lpszClassName=szAppName;if(!RegisterClassEx(&wndclass)){MessageBox(NULL,TEXT("Register Class Error"),szAppName,MB_ICONERROR);return 0;}}int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow){MSG msg;init(hInstance);hwnd=CreateWindow(szAppName,TEXT("The hello program"),WS_OVERLAPPEDWINDOW, //窗口样式,WS_POPUPWINDOW 无边框窗口,此时不能用DEFAULTCW_USEDEFAULT,//左上角坐标CW_USEDEFAULT,CW_USEDEFAULT,//窗口宽度(调用函数获取右下角x坐标)CW_USEDEFAULT,  NULL,  NULL,  hInstance,  NULL);ShowWindow(hwnd,iCmdShow);UpdateWindow(hwnd);while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}return 0;}

0 0
原创粉丝点击