Windows 子窗体不显示解决思路
Windows 子窗体不显示
那个按键和 复选框能出来,为什么其他的子窗口不能显示出来?
------解决方案--------------------
- C/C++ code
#include <windows.h> #define ID_LIST 1 #define ID_TEXT 2 #define NUM (sizeof(listitem)/sizeof(listitem[0]) struct{ int index; TCHAR *text; } listitem[]={ 1,TEXT("北京市"), 2,TEXT("湖南省"), 3,TEXT("湖北省"), 4,TEXT("江西省") }; LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("Environ") ; HWND hwnd ; MSG msg ; 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_WINDOW + 1) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass)) { MessageBox ( NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow (szAppName, TEXT ("Environment List Box"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,NULL, NULL, hInstance, NULL) ; ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam) { static int cyChar,cxChar; static HWND hwndList,hwndText,hwndButton,hwndCheck; TCHAR format[]=TEXT("宽=%d,高=%d"); TCHAR buffer[20]; switch(message){ case WM_CREATE: cyChar=HIWORD(GetDialogBaseUnits()); cxChar=LOWORD(GetDialogBaseUnits()); wsprintf(buffer,format,cyChar,cxChar); hwndList=CreateWindow(TEXT("list"),TEXT("=请选择="),WS_CHILD | WS_VISIBLE|WS_BORDER | LBS_STANDARD, 20,30,40,20,hwnd,(HMENU)ID_LIST,(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),NULL); hwndText=CreateWindow(TEXT("text"),NULL, WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | WS_BORDER | ES_LEFT | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,0,50,100,20,hwnd,(HMENU)10,(LPCREATESTRUCT(lParam))->hInstance,NULL); hwndButton =CreateWindow(TEXT("button"),TEXT("点击"),WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,0, 0, 20 * cxChar, 7 * cyChar / 4,hwnd, (HMENU)6,((LPCREATESTRUCT) lParam)->hInstance, NULL) ; hwndCheck=CreateWindow(TEXT("button"),TEXT("复选"),WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,0, 100, 20 * cxChar, 7 * cyChar / 4,hwnd, (HMENU)7,((LPCREATESTRUCT) lParam)->hInstance, NULL) ; return 0; case WM_SIZE : wsprintf(buffer,format,cyChar,cxChar); //MoveWindow (hwndText, 0, cyChar*4, cxChar*20,cyChar,TRUE) ; return 0 ; case WM_SETFOCUS: SetFocus(hwndText); return 0; case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hwnd, message, wParam, lParam); }
那个按键和 复选框能出来,为什么其他的子窗口不能显示出来?
------解决方案--------------------