简单的Win 32 Application

 

 

//WinMain

 

 

#include <windows.h>

 

 

#include <stdio.h>

 

 

 

 

LRESULT CALLBACK WinProcOne(

 

 

         HWND hwnd,

 

 

         UINT uMessage,

 

 

         WPARAM wParam,

 

 

         LPARAM lParam

 

 

);

 

 

 

 

int WINAPI WinMain(

 

 

         HINSTANCE hInstance,

 

 

         HINSTANCE hPrevInstance,

 

 

         LPSTR lpCmdLine,

 

 

         int nShowCmd

 

 

)

 

 

{

 

 

         WNDCLASS wndcls;

 

 

         wndcls.cbClsExtra=0;

 

 

         wndcls.cbWndExtra=0;

 

 

         wndcls.hbrBackground=(HBRUSH)GetStockObject(LTGRAY_BRUSH);

 

 

         wndcls.hCursor=LoadCursor(NULL,IDC_ARROW);

 

 

         wndcls.hIcon=LoadIcon(NULL,IDI_QUESTION);

 

 

         wndcls.hInstance=hInstance;

 

 

         wndcls.lpfnWndProc=WinProcOne;

 

 

         wndcls.lpszClassName="WndClassName2011";

 

 

         wndcls.lpszMenuName=NULL;

 

 

         wndcls.style=CS_HREDRAW|CS_VREDRAW;

 

 

         RegisterClass(&wndcls);

 

 

 

 

         HWND hwnd;

 

 

         hwnd=CreateWindow("WndClassName2011","创建一个窗口应用程序",WS_OVERLAPPEDWINDOW,

 

 

                   0,0,600,400,NULL,NULL,hInstance,NULL);

 

 

         ShowWindow(hwnd,SW_SHOWNORMAL);

 

 

         UpdateWindow(hwnd);

 

 

 

 

         MSG msg;

 

 

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

 

 

         {

 

 

                   TranslateMessage(&msg);

 

 

                   DispatchMessage(&msg);

 

 

         }

 

 

         return 0;

 

 

}

 

 

 

 

LRESULT CALLBACK WinProcOne(

 

 

         HWND hwnd,

 

 

         UINT uMessage,

 

 

         WPARAM wParam,

 

 

         LPARAM lParam

 

 

)

 

 

{

 

 

         switch(uMessage)

 

 

         {

 

 

         case WM_CHAR:

 

 

                   char szChar[20];

 

 

                   sprintf(szChar,"char is %d",wParam);

 

 

                   MessageBox(hwnd,szChar,"Create Window Program",MB_OK);

 

 

                   break;

 

 

         case WM_LBUTTONDOWN:

 

 

                   MessageBox(hwnd,"left mouse clicked","Window Program",MB_OK);

 

 

                   HDC hdc;

 

 

                   hdc=GetDC(hwnd);

 

 

                   TextOut(hdc,0,50,"创建一个窗口应用程序",strlen("创建一个窗口应用程序"));

 

 

                   ReleaseDC(hwnd,hdc);

 

 

                   break;

 

 

         case WM_PAINT:

 

 

                   HDC hDC;

 

 

                   PAINTSTRUCT ps;

 

 

                   hDC=BeginPaint(hwnd,&ps);

 

 

                   TextOut(hDC,0,0,"响应WM_PAINT消息",strlen("响应WM_PAINT消息"));

 

 

                   EndPaint(hwnd,&ps);

 

 

                   break;

 

 

         case WM_CLOSE:

 

 

                   if(IDYES==MessageBox(hwnd,TEXT("是否真的结束?"),"window program",MB_YESNO))

 

 

                   {

 

 

                            DestroyWindow(hwnd);

 

 

                   }

 

 

                   break;

 

 

         case WM_DESTROY:

 

 

                   PostQuitMessage(0);

 

 

                   break;

 

 

         default:

 

 

                   return(DefWindowProc(hwnd,uMessage,wParam,lParam));

 

 

         }

 

 

         return 0;

 

 

}

 

 

 

 

截图:

 

 

简单的Win 32 Application_第1张图片

 

 

 

 

源程序下载地址:http://down.qiannao.com/space/file/luowei505050/WinMain.rar/.page

 

 

你可能感兴趣的:(职场,application,Win,Win,休闲,32)