windows简单窗口代码

2022-05-19 23:42:15   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《windows简单窗口代码》,欢迎阅读!
窗口,windows,代码,简单
#include //#include //#include

LRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);

/*int CDECL MessageBoxPrintf(TCHAR * szCaption,TCHAR * szFormat) {

TCHAR szBuffer[1024]; va_listpArgList;

va_start (pArgList,szFormat);

_vsntprintf(szBuffer,sizeof(szBuffer)/sizeof(TCHAR),szFormat,pArgList);

va_end(pArgList);

return MessageBox(NULL,szBuffer,szCaption,0); }*/

intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,PSTRszCmdLine,intiCmdShow) {

/* MessageBox(NULL,TEXT("Hello world"),TEXT("HelloMsg"),0);

intcxScreen,cyScreen;

cxScreen=GetSystemMetrics(SM_CXSCREEN); cyScreen=GetSystemMetrics(SM_CYSCREEN);

MessageBoxPrintf(TEXT("ScreenSize"),TEXT("The screenis %i pixels wide by %i pixels high",cxScreen,cyScreen));*/ staticTCHARszAppName[]=TEXT("HelloIn"); HWNDhwnd; MSGmsg;

WNDCLASSwndclass;

wndclass.style=CS_HREDRAW|CS_VREDRAW; wndclass.lpfnWndProc=WndProc; 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.lpszClassName=szAppName; wndclass.lpszMenuName=NULL;

if(!RegisterClass(&wndclass)) {

MessageBox(NULL,TEXT("This program requires windows NT!"),


szAppName,MB_ICONERROR); return0; }

hwnd=CreateWindow(szAppName, TEXT("The hello program"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,

hInstance, NULL );

ShowWindow(hwnd,iCmdShow); UpdateWindow(hwnd);

while(GetMessage(&msg,NULL,0,0)) {

TranslateMessage(&msg); DispatchMessage(&msg); }

returnmsg.wParam; }

LRESULTCALLBACKWndProc(HWNDhwnd,UINTmessage,WPARAMwParam,LPARAMlParam) {

HDChdc;

PAINTSTRUCTps; RECTrect;

switch(message) {

caseWM_CREATE:

//PlaySound(TEXT("helloin.wav"),NULL,SND_FILENAME | SND_ASYNC); return0; caseWM_PAINT:

hdc=BeginPaint(hwnd,&ps); GetClientRect(hwnd,&rect);

DrawText(hdc,TEXT("Hello,Windows XP"),-1,&rect, DT_SINGLELINE|DT_CENTER|DT_VCENTER);


}



EndPaint(hwnd,&ps); return0;

caseWM_DESTROY:

PostQuitMessage(0); return0; }

returnDefWindowProc(hwnd,message,wParam,lParam);


本文来源:https://www.wddqxz.cn/deb16e3e87c24028915fc33c.html

相关推荐