读,Windows 下编程 有关对话框程序的问题,待解决!!

fengcaho fengcaho 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
程序是这样的:我建了一个对话框资源,然后在里面添加了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,怎么回事?请高手解答!!!
...全文
评论 9
收藏 已收藏
分享
返回顶部
fengcaho
VC/MFC 16,551 成员 421,605 内容