#include "StdAfx.h" #include <windows.h> #include <mmsystem.h>lresult CALLBACK WndProc (Hwnd,uint,wparam, LPARAM); int WINAPI WinMain (hinstance hinstance,hinstance hprevinstance,pstr szcmdline,int icmdshow) {static TCHAR Szappname[]=text ("Hellowin"); HWND hwnd; MSG msg; Wndclass Wndclass;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.lpszmenuname=null;wndclass.lpszclassname= Szappname;if (! RegisterClass (&wndclass)) {MessageBox (Null,text ("This program requiers Windows nt!"), Szappname,mb_iconerror); return 0;} Hwnd=createwindow (Szappname,//window class Nametext ("The Hello Program"),//window captionws_overlappedwindow,// Window stylecw_usedefault,//initial x positioncw_usedefault,//initial Y positioncw_usedefault,//initial x sizeCW_ UsedefAult,//initial y sizenull,//parent window handlenull,//window menu Handlehinstance,//program instance handlenull); ShowWindow (hwnd,icmdshow); UpdateWindow (HWND), while (GetMessage (&msg,null,0,0)) {TranslateMessage (&msg);D ispatchmessage (&msg);} return Msg.wparam;} LRESULT CALLBACK WndProc (HWND hwnd,uint message,wparam wparam,lparam iparam) {HDC hdc; Paintstruct PS; RECT rect;switch (message) {Case Wm_create:playsound (TEXT ("Hellowin.wav"), null,snd_filename| Snd_async); return 0;case wm_paint:hdc=beginpaint (HWND,&PS); GetClientRect (Hwnd,&rect);D Rawtext (Hdc,text ("Hello"), -1,&rect,dt_singleline | Dt_center | Dt_vcenter); EndPaint (HWND,&PS); return 0;case wm_destroy:postquitmessage (0); return 0;} return DefWindowProc (Hwnd,message,wparam,iparam);}
Windows API Programs