1,221
社区成员
发帖
与我相关
我的任务
分享
// win32 8.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
// win32 6.cpp : Defines the entry point for the application.
//
LRESULT CALLBACK MainWndProc(HWND,UINT,WPARAM,LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
//USES_CONVERSION;
char szClassName[]="MainWndClass";
WNDCLASSEX wndclass;
wndclass.cbSize=sizeof(wndclass);
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=MainWndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szClassName;
wndclass.hIconSm=NULL;
RegisterClassEx(&wndclass);
HWND hWnd=CreateWindowEx(
0,
szClassName,
"My First Window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if(hWnd==NULL)
{
MessageBox(NULL,"创建窗口出错!","ERROR",MB_OK|MB_ICONHAND);
return -1;
}
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
return msg.wParam;
}
}
LRESULT CALLBACK MainWndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
//USES_CONVERSION;
char szText[]="窗口程序摸板";
switch(message)
{
case WM_PAINT:
{
HDC hDC;//设备句柄
PAINTSTRUCT psE;
hDC=BeginPaint(hWnd,&psE);
TextOut(hDC,10,10,szText,strlen(szText));
EndPaint(hWnd,&psE);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return (NULL);
}