VC++完整建议一个空白窗口代码

作者在 2008-09-30 19:36:41 发布以下内容

#include<windows.h>
#include<stdio.h>
LRESULT CALLBACK WinSunProc(
 HWND hwnd,
    UINT uMsg,
 WPARAM wParam,
 LPARAM lParam
);

int WINAPI WinMain(
 HINSTANCE hinstance,
 HINSTANCE hPrevInstance,
 LPSTR lpCmdLine,
 int nCmdShow
)
{
 WNDCLASS wndclas;
 wndclas.cbClsExtra=0;
 wndclas.cbWndExtra=0;
 wndclas.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
 wndclas.hCursor=LoadCursor(NULL,IDC_CROSS);
 wndclas.hIcon=LoadIcon(NULL,IDI_ERROR);
 wndclas.hInstance=hinstance;
 wndclas.lpfnWndProc=WinSunProc;
 wndclas.lpszClassName="weixin2003";
 wndclas.lpszMenuName=NULL;
 wndclas.style=CS_HREDRAW | CS_VREDRAW;

 RegisterClass(&wndclas);
 HWND hwnd;
 hwnd=CreateWindow("weixin2003","培训中心",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 WinSunProc(
 HWND hwnd,
    UINT uMsg,
 WPARAM wParam,
 LPARAM lParam
)
{
 switch(uMsg)
 {
 case WM_CHAR:
  char szChar[20];
  sprintf(szChar,"char is %d",wParam);
  MessageBox(hwnd,szChar,"weixin",0);
  break;
 case WM_LBUTTONDOWN:
  MessageBox(hwnd,"mouse is click","weixin",0);
  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,"维新培训",strlen("维新培训"));
  EndPaint(hwnd,&ps);
  break;
 case WM_CLOSE:
  if(IDYES==MessageBox(hwnd,"是否退出程序","程序退出",MB_YESNO))
      DestroyWindow(hwnd);
  break;
 case WM_DESTROY:
      PostQuitMessage(0);
  break;
    default:
  return DefWindowProc(hwnd,uMsg,wParam,lParam);
  }
 return 0;
}

默认分类 | 阅读 3404 次
文章评论,共0条
游客请输入验证码