读,Windows 下编程 有关对话框程序的问题,待解决!!
程序是这样的:我建了一个对话框资源,然后在里面添加了CLASS "Server2"
下面运行
#include "stdafx.h"
#include "resource.h"
#include <windows.h>
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
char szAppName[]="Server2" ;
UINT Ret;
MSG msg;
HWND hwnd ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = DLGWINDOWEXTRA ;
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=CreateDialog(hInstance,szAppName,0,NULL);
Ret=GetLastError();
ShowWindow (hwnd, nCmdShow) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hText;//
HDC hdc ;
PAINTSTRUCT ps ;
int iTemp;
switch (message)
{
case WM_CREATE:
MessageBox(NULL,"A","A",NULL);
break;
case WM_PAINT://显示本机IP地址
break;
case WM_COMMAND:
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
为什么我CreateDialog()之后得到的句柄是0?但是Ret的值也为0,怎么回事?请高手解答!!!