首页
社区
课程
招聘
[求助]我的第一个 VC++ 程序,不显示窗口!!
发表于: 2008-6-19 05:46 5316

[求助]我的第一个 VC++ 程序,不显示窗口!!

2008-6-19 05:46
5316
主要原因:CreateWindow  返回总是 0!!!!!!!!

#include <windows.h>
#include <stdio.h>
#include <string>
#include "Winsvc.h"
using namespace std;

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
          WNDCLASS WndClass;
        //HACCEL hAccel;

  WndClass.cbClsExtra = 0;
  WndClass.cbWndExtra = 0;
  WndClass.hbrBackground =(HBRUSH) GetStockObject(BLACK_BRUSH);
  WndClass.hCursor = LoadCursor(hInstance, IDC_ARROW);
  WndClass.hIcon = LoadIcon(hInstance, IDI_WINLOGO);
  WndClass.hInstance = hInstance;
  WndClass.lpfnWndProc = WindowProc;
  WndClass.lpszClassName = "kagayaki";
  WndClass.lpszMenuName = NULL;
  WndClass.style = CS_HREDRAW | CS_VREDRAW;
  RegisterClass(&WndClass);

  HWND hwnd;
  hwnd = CreateWindow("kagayaki", "kagayaki",
                                  WS_OVERLAPPEDWINDOW /* WS_BORDER | WS_CAPTION | WS_VISIBLE */, 320, 240,
                                          320, 240,
                                          NULL, NULL,
                                  hInstance,
                                  NULL);
  ShowWindow(hwnd, nCmdShow);    //   hwnd = 0  ???????
  //UpdateWindow(hwnd);
  

        MSG msg;
        while (GetMessage(&msg, NULL, 0, 0))
        {
       
        TranslateMessage(&msg);
        DispatchMessage(&msg);

        }
        return 0;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
       
               
    case WM_CLOSE:
                DestroyWindow(hwnd);
                break;
    case WM_DESTROY:
                PostQuitMessage(0);
                break;
        //return (TRUE);
        default : DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return (FALSE);
}

[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

收藏
免费 0
支持
分享
最新回复 (4)
雪    币: 306
活跃值: (10)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
2
这样就可以啦~~

#include <windows.h>
#include <stdio.h>
#include <string>
#include "Winsvc.h"
using namespace std;

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASS WndClass;
  //HACCEL hAccel;

  WndClass.cbClsExtra = 0;
  WndClass.cbWndExtra = 0;
  WndClass.hbrBackground =(HBRUSH) GetStockObject(BLACK_BRUSH);
  WndClass.hCursor = LoadCursor(hInstance, IDC_ARROW);
  WndClass.hIcon = LoadIcon(hInstance, IDI_WINLOGO);
  WndClass.hInstance = hInstance;
  WndClass.lpfnWndProc = WindowProc;
  WndClass.lpszClassName = "kagayaki";
  WndClass.lpszMenuName = NULL;
  WndClass.style = CS_HREDRAW | CS_VREDRAW;
  RegisterClass(&WndClass);

  HWND hwnd;
  hwnd = CreateWindow("kagayaki", "kagayaki",
             WS_OVERLAPPEDWINDOW /* WS_BORDER | WS_CAPTION | WS_VISIBLE */, 320, 240,
             320, 240,
             NULL, NULL,
             hInstance,
             NULL);
  ShowWindow(hwnd, nCmdShow);    //   hwnd = 0  ???????
  //UpdateWindow(hwnd);
  

  MSG msg;
  while (GetMessage(&msg, NULL, 0, 0))
  {
  
  TranslateMessage(&msg);
  DispatchMessage(&msg);

  }
  return 0 ;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
  
   
    case WM_CLOSE:
    DestroyWindow(hwnd);
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
       }
return DefWindowProc(hwnd, msg, wParam, lParam);

}
2008-6-19 08:22
0
雪    币: 189
活跃值: (4810)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
3
谢谢!!!!!!!!!!!
2008-6-19 21:24
0
雪    币: 107
活跃值: (12)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
4
哈哈! 我研究好半天了,只加一个字,return. 将上句改为下句
default :  return DefWindowProc(hwnd, msg, wParam, lParam);

对窗口工作机制又加深了!
2008-6-20 15:04
0
雪    币: 189
活跃值: (4810)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
5
我当时也搞了好半天了
2008-6-20 16:29
0
游客
登录 | 注册 方可回帖
返回
//