为何我创建的对话框显示不出来
程序代码:
#include <windows.h> #include <tchar.h> #include <string.h> #include <stdio.h> #include "resource.h" /*创建窗口的几个过程: 创建窗口类 注册窗口类 创建窗口句柄 显示窗口 更新窗口 循环消息检索 */ LRESULT CALLBACK WinProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) { TCHAR lpClassName[]=_TEXT("ClassName"); WNDCLASS wndclass; HWND hwnd; MSG msg; int Error_code; TCHAR Error_message[100]; wndclass.style=CS_HREDRAW|CS_VREDRAW; wndclass.lpfnWndProc=WinProc; wndclass.cbClsExtra=0; wndclass.cbWndExtra=DLGWINDOWEXTRA; wndclass.hInstance=hInstance; wndclass.hIcon=LoadIcon(NULL,IDI_WARNING); wndclass.hCursor=LoadIcon(NULL,IDC_ARROW); wndclass.hbrBackground=(HBRUSH)COLOR_WINDOW; wndclass.lpszMenuName=NULL; wndclass.lpszClassName=lpClassName; if(!RegisterClass(&wndclass)) { Error_code=GetLastError(); _stprintf(Error_message,_TEXT("错误代码为:%d"),Error_code); MessageBox(NULL,_TEXT("注册失败"),Error_message,MB_OK); } hwnd=CreateDialog(hInstance,lpClassName,0,NULL); ShowWindow(hwnd,SW_SHOW); // UpdateWindow(hwnd); while(GetMessage(&msg,NULL,NULL,NULL)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WinProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { HDC hdc; PAINTSTRUCT ps; switch(uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd,uMsg,wParam,lParam); }main.cpp
resource.rc
程序代码:
//Microsoft Developer Studio generated resource script. // #include "resource.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 2 resource. // #include "afxres.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // Chinese (P.R.C.) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS) #ifdef _WIN32 LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED #pragma code_page(936) #endif //_WIN32 #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // TEXTINCLUDE // 1 TEXTINCLUDE DISCARDABLE BEGIN "resource.h\0" END 2 TEXTINCLUDE DISCARDABLE BEGIN "#include ""afxres.h""\r\n" "\0" END 3 TEXTINCLUDE DISCARDABLE BEGIN "\r\n" "\0" END #endif // APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Dialog // IDD_DIALOG DIALOG DISCARDABLE 0, 0, 187, 174 STYLE WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU CLASS "ClassName" FONT 10, "@黑体" BEGIN DEFPUSHBUTTON "OK",IDOK,49,148,50,14 PUSHBUTTON "Cancel",IDCANCEL,104,148,50,14 CTEXT "TEST",IDC_STATIC,45,65,96,44 END ///////////////////////////////////////////////////////////////////////////// // // DESIGNINFO // #ifdef APSTUDIO_INVOKED GUIDELINES DESIGNINFO DISCARDABLE BEGIN IDD_DIALOG, DIALOG BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 180 TOPMARGIN, 7 BOTTOMMARGIN, 167 END END #endif // APSTUDIO_INVOKED #endif // Chinese (P.R.C.) resources ///////////////////////////////////////////////////////////////////////////// #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 3 resource. // ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED