当前位置:编程学习 > VC++ >>

vc++写的windows窗口问题

为什么我写的窗口我运行后无法控制,源码在儿,求高手帮忙看看,是代码的问题么?如果是改怎么改?

#include<windows.h>
#include<stdio.h>
LRESULT CALLBACK wndproc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
       HINSTANCE hPrevInstance,
       LPSTR lpCmdLine,
       int nShowCmd)
{
 WNDCLASS wndclass;
 wndclass.cbClsExtra=0;
 wndclass.cbWndExtra=0;
 wndclass.hbrBackground=(HBRUSH)::GetStockObject(BLACK_BRUSH);
 wndclass.hCursor=::LoadCursor(NULL,IDC_APPSTARTING);
 wndclass.hIcon=::LoadIcon(NULL,IDI_APPLICATION);
 wndclass.hInstance=hInstance;
 wndclass.lpfnWndProc=wndproc;
 wndclass.lpszClassName="sujunda";
 wndclass.lpszMenuName=NULL;
 wndclass.style=CS_HREDRAW|CS_VREDRAW;
 ::RegisterClass(&wndclass);
 HWND hwnd=::CreateWindow("sujunda",
  "first window",
  WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  CW_USEDEFAULT,
  NULL,
  NULL,
  hInstance,
  NULL);
 ::ShowWindow(hwnd,SW_SHOW);
 ::UpdateWindow(hwnd);
 MSG msg;
 while(::GetMessage(&msg,NULL,0,0));
 {
  ::TranslateMessage(&msg);
  ::DispatchMessage(&msg);
 }
 return 0;
}
LRESULT CALLBACK wndproc(HWND hwnd,
       UINT uMsg,
       WPARAM wparam,
       LPARAM lparam)
{
 PAINTSTRUCT ps;
 HDC hdc;
 switch(uMsg)
 {
 case WM_PAINT:
  hdc=::BeginPaint(hwnd,&ps);
  TextOut(hdc,10,10,"最简答的窗口",strlen("最简答的窗口"));
  ::EndPaint(hwnd,&ps);
  break;
 case WM_CHAR:
  char szChar[20];
  sprintf(szChar,"编码是:",wparam);
  ::MessageBox(hwnd,szChar,"first window",MB_OK);
  break;
 case WM_QUIT:
  {
   ::PostQuitMessage(0);
   break;
  }
 default:
  return ::DefWindowProc(hwnd,uMsg,wparam,lparam); 
 }
 return 0;
}

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,