您的位置:首页 > 编程语言 > C语言/C++

孙鑫VC++学习记录1_windows运行机制

2011-12-26 17:00 253 查看
 
#include <WINDOWS.H>

#include <stdio.h>

LRESULT CALLBACK mywindowsProc(

  HWND hwnd,

  UINT uMsg,

  WPARAM wParam,

  LPARAM lParam

);

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ){

 WNDCLASS wndcls;

 wndcls.cbClsExtra = 0;

 wndcls.style = CS_HREDRAW | CS_VREDRAW;

 wndcls.lpfnWndProc = mywindowsProc;

 wndcls.cbWndExtra = 0;

 wndcls.hInstance = hInstance;

 wndcls.hIcon = LoadIcon(NULL,IDI_WINLOGO);

 wndcls.hCursor = LoadCursor(NULL,IDC_ARROW);

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

 wndcls.lpszMenuName = NULL;

 wndcls.lpszClassName = "zhangkun";

 RegisterClass(&wndcls);

 HWND hwnd;

 hwnd = CreateWindow("zhangkun","zhangkun1234567890",WS_OVERLAPPEDWINDOW,100,100,500,500,NULL,NULL,hInstance,NULL);

 ShowWindow(hwnd,SW_SHOWNORMAL);

 UpdateWindow(hwnd);

 

 MSG msg;

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

 {

  TranslateMessage(&msg);

  DispatchMessage(&msg);

 }

 return msg.wParam;

};

LRESULT CALLBACK mywindowsProc(

  HWND hwnd,

  UINT uMsg,

  WPARAM wParam,

  LPARAM lParam

)

{

 switch(uMsg)

 {

  case WM_CHAR:

   char szChar[20];

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

   MessageBox(hwnd,szChar,"char",0);

   break;

  case WM_LBUTTONDOWN:

   MessageBox(hwnd,"mouse clicked","message",0);

   

   break;

  case WM_PAINT:

   HDC hDC;

   PAINTSTRUCT ps;

   hDC = BeginPaint(hwnd,&ps);

   TextOut(hDC,0,0,"It is just a test",strlen("It is just a test"));

   EndPaint(hwnd,&ps);

   break;

  case  WM_CLOSE:

   if (IDYES == MessageBox(hwnd,"是不是真的结束?","Message",MB_YESNO))

   {

    DestroyWindow(hwnd);

   }

   break;

  case WM_DESTROY:

   PostQuitMessage(0);

   break;

  default:

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

 }

 return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息