注册 登录
编程论坛 版务及公告

程序没错,为什么没有窗口

quyu12 发布于 2008-09-18 11:54, 2336 次点击
#include<windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(
  HINSTANCE hInstance,      // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,          // command line
  int nCmdShow              // show state
)
{
      //窗口类
      WNDCLASS wndclass;
      wndclass.cbClsExtra=0;
      wndclass.cbWndExtra=0;
      wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
      wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
      wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
      wndclass.hInstance=hInstance;
      wndclass.lpfnWndProc=WndProc;
      wndclass.lpszClassName="liudddehua";
      wndclass.style=CS_HREDRAW|CS_VREDRAW;
      wndclass.lpszMenuName=NULL;
      //注册窗口
      if(!RegisterClass(&wndclass))
      {
         MessageBox(NULL,"窗口注册失败!","liudddehua",0);
         return 0;
      }
      //创建窗口
      HWND hwnd;
      hwnd=CreateWindow(
          "LIUDEHUA",  // registered class name
          "我的梦", // window name
          WS_OVERLAPPEDWINDOW,        // window style
          CW_USEDEFAULT,                // horizontal position of window
          CW_USEDEFAULT,                // vertical position of window
          CW_USEDEFAULT,           // window width
          CW_USEDEFAULT,          // window height
          NULL,      // handle to parent or owner window
          NULL,          // menu handle or child identifier
          hInstance,  // handle to application instance
          NULL        // window-creation data
        );
      //显示窗口
      ShowWindow(hwnd,nCmdShow);
      //更新窗口
      UpdateWindow(hwnd);
      //消息循环
      MSG msg;
      while(GetMessage(&msg,NULL,0,0))
      {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
      }
      return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lPram)
{
    switch(message){
    case WM_CREATE:
        return 0;
    case WM_LBUTTONDOWN:
        MessageBox(NULL,"你好啊,我的爱","哈哈",0);
        return 0;
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
   return DefWindowProc(hwnd,message,wParam,lPram);
}
6 回复
#2
taiyang03312008-09-24 15:50
wndclass.lpszClassName="liudddehua";

   hwnd=CreateWindow(
          "LIUDEHUA",  // registered class name

两个好像应该一致的吧
#3
wen111hui2008-12-03 19:16
顶2楼
#4
zwg198911292009-07-29 14:57
支持二楼...
#5
vfdff2009-09-22 14:20
没有主函数
1