我的程序如下,为什么运行后显示不了窗口呢?请指点
#include <windows.h>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
static TCHAR szAppName[] = TEXT ("autooff") ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,                    PSTR szCmdLine, int iCmdShow)
{
     WNDCLASS     wndclass ;
     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;     wndclass.lpfnWndProc   = WndProc ;     wndclass.cbClsExtra    = 0 ;     wndclass.cbWndExtra    = 0 ;     wndclass.hInstance     = hInstance ;     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;     wndclass.hbrBackground = (HBRUSH) (COLOR_BTNFACE+1) ;     wndclass.lpszMenuName  = NULL;     wndclass.lpszClassName = szAppName ;     if (!RegisterClass (&wndclass))     {
          MessageBox (NULL, TEXT ("This program requires Windows NT!"),                       szAppName, MB_ICONERROR) ;
          return 0 ;
     }  HWND hwnd;
 hwnd=CreateDialog(hInstance,szAppName,NULL,NULL) ;     ShowWindow (hwnd, iCmdShow) ;     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 lParam){
     switch (message)     {
  case WM_CREATE:
  return 0;      case WM_DESTROY:          PostQuitMessage (0);          return 0;     }     return DefWindowProc (hwnd, message, wParam, lParam);}

解决方案 »

  1.   

    hwnd=CreateDialog(hInstance,szAppName,NULL,NULL) 改成
    hwnd=CreateDialog(hInstance,szAppName,NULL,WndProc ) 呢?
      

  2.   

    参考以下代码:// *.rc 资源文件: 注意 CLASS "DIALOG_CLASS"
    #include "resource.h"  // 仅含 #define IDD_DIALOG     101#pragma code_page(936)IDD_DIALOG DIALOG DISCARDABLE  0, 0, 187, 100
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "Dialog"
    CLASS "DIALOG_CLASS"
    FONT 10, "@System"
    {
        DEFPUSHBUTTON   "OK",IDOK,130,7,50,14
        PUSHBUTTON      "Cancel",IDCANCEL,130,24,50,14
    }// *.cpp 源代码
    #include <windows.h>
    #include "resource.h"  // 仅含 #define IDD_DIALOG     101LRESULT CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    switch (uMsg)
    {
    case WM_CLOSE:
    PostQuitMessage(0);
    return TRUE; case WM_COMMAND:
    switch (LOWORD(wParam))
    {
    case IDOK:
    case IDCANCEL:
    PostQuitMessage(0);
    return TRUE;
    }
    break;
    } return DefDlgProc(hWnd, uMsg, wParam, lParam);
    }extern "C" int WINAPI WinMain(HINSTANCE hInstance,
        HINSTANCE /*hPrevInstance*/, LPSTR lpCmdLine, int /*nShowCmd*/)
    {
    WNDCLASS wndclass = { 0 }; wndclass.style = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc = DialogProc;
    wndclass.cbWndExtra = DLGWINDOWEXTRA;  // 重要
    wndclass.hInstance = hInstance;
    wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
    wndclass.lpszClassName = TEXT("DIALOG_CLASS"); // 同资源 RegisterClass(&wndclass); HWND hDialog = 
    CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, NULL); ShowWindow(hDialog, SW_SHOW);
    UpdateWindow(hDialog); MSG msg = { 0 }; while (GetMessage(&msg, NULL, 0, 0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    } return 0;
    }