Win32,非模态对话框创建问题

幸福绿光 2015-05-05 03:10:01

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, (LPWSTR)custommessage.commonvariables.szTitle.c_str(), MAX_LOADSTRING);
LoadString(hInstance, IDS_APP_TITLE, (LPWSTR)custommessage.commonvariables.szWindowClass.c_str(), MAX_LOADSTRING);

custommessage.commonvariables.hInst = hInstance; // Store instance handle in our global variable

custommessage.commonvariables.hMainWnd = CreateDialog(custommessage.commonvariables.hInst, MAKEINTRESOURCE(IDD_DIALOG_WNDPROC), 0, (DLGPROC)WndProc);
if (!custommessage.commonvariables.hMainWnd)
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDM_MENU_CWINDOW));
ShowWindow(custommessage.commonvariables.hMainWnd, nCmdShow);

// Main message loop:

while (GetMessage(&msg, NULL, 0, 0))
{
if (msg.hwnd == 0 || !IsDialogMessage (msg.hwnd, &msg))
{
if(!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}

return (int) msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
custommessage.InitializationWndprocControl(hWnd); // 控件初始化
}
break;
case WM_COMMAND:
{
custommessage.commonvariables.wmId = LOWORD(wParam);
custommessage.commonvariables.wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch(custommessage.commonvariables.wmId)
{
case IDB_WNDPROC_SEARCHALLDLGDOWN:
{
custommessage.commonvariables.hSearchWnd = CreateDialog(custommessage.commonvariables.hInst, MAKEINTRESOURCE(IDD_DIALOG_ALLSEARCH), 0, (DLGPROC)AllsearchProc); // hWnd也不成
ShowWindow(custommessage.commonvariables.hSearchWnd, SW_SHOW);
}
break;
case IDM_EXIT:
{
DestroyWindow(hWnd);
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_PAINT:
{
custommessage.commonvariables.hdc = BeginPaint(hWnd, &custommessage.commonvariables.ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &custommessage.commonvariables.ps);
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

LRESULT CALLBACK AllsearchProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
custommessage.InitializationSearchControl(hWnd); // 控件初始化
}
break;
case WM_COMMAND:
{
custommessage.commonvariables.wmId = LOWORD(wParam);
custommessage.commonvariables.wmEvent = HIWORD(wParam);
SetFocus(hWnd);
// Parse the menu selections:
switch(custommessage.commonvariables.wmId)
{
case IDB_SEARCH_ALLSEARCH:
{
DestroyWindow(hWnd);
hWnd = NULL;
}
break;
default:
return FALSE;
}
}
break;
case WM_PAINT:
{
custommessage.commonvariables.hdc = BeginPaint(hWnd, &custommessage.commonvariables.ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &custommessage.commonvariables.ps);
}
break;
case WM_SYSCOMMAND:
{
if(wParam == SC_CLOSE)
{
DestroyWindow(hWnd);
hWnd = NULL;
}
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
}
break;
default:
return FALSE; // 未处理的消息
}
return TRUE; // 处理过的消息
}


...全文
216 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
幸福绿光 2015-05-06
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
http://bbs.csdn.net/topics/390374955
我看过MSDN,但是我遇到的问题,无法用MSDN上的实例解决,您帮我看看,谢谢。 我现在需要直接加载RC资源中的对话框,因此 custommessage.commonvariables.hMainWnd = CreateDialog(custommessage.commonvariables.hInst, MAKEINTRESOURCE(IDD_DIALOG_WNDPROC), 0, (DLGPROC)WndProc); 在回掉函数WndProc中,点击高级搜索后弹出搜索的对话框, case IDB_WNDPROC_SEARCHALLDLGDOWN: { custommessage.commonvariables.hSearchWnd = CreateDialog(custommessage.commonvariables.hInst, MAKEINTRESOURCE(IDD_DIALOG_ALLSEARCH), 0, (DLGPROC)AllsearchProc); // hWnd也不成 ShowWindow(custommessage.commonvariables.hSearchWnd, SW_SHOW); } break; 其中AllsearchProc与WndProc所对应的两个对话框不是父子关系,而是同等关系。但是点击AllsearchProc中的关闭按钮、移动、点击搜索按钮 case IDB_SEARCH_ALLSEARCH: { DestroyWindow(hWnd); hWnd = NULL; } break; 都不响应消息。 而且我也用WM_SYSCOMMAND来实现关闭操作,仍然没反应。 case WM_SYSCOMMAND: { if(wParam == SC_CLOSE) { DestroyWindow(hWnd); hWnd = NULL; } } break; 不知道为什么.
幸福绿光 2015-05-06
  • 打赏
  • 举报
回复
引用 2 楼 Minikinfish 的回复:
Windows程序很简单,就几点内容 1、窗口需要注册, 2、注册需要proc 3、proc需要循环泵的支持 4、大量窗口的api 5、SetWindowLong WGL_DLGPROC 可以对窗体任意修改
这个我知道,我现在需要直接加载RC资源中的对话框,因此 custommessage.commonvariables.hMainWnd = CreateDialog(custommessage.commonvariables.hInst, MAKEINTRESOURCE(IDD_DIALOG_WNDPROC), 0, (DLGPROC)WndProc); 在回掉函数WndProc中,点击高级搜索后弹出搜索的对话框, case IDB_WNDPROC_SEARCHALLDLGDOWN: { custommessage.commonvariables.hSearchWnd = CreateDialog(custommessage.commonvariables.hInst, MAKEINTRESOURCE(IDD_DIALOG_ALLSEARCH), 0, (DLGPROC)AllsearchProc); // hWnd也不成 ShowWindow(custommessage.commonvariables.hSearchWnd, SW_SHOW); } break; 其中AllsearchProc与WndProc所对应的两个对话框不是父子关系,而是同等关系。但是点击AllsearchProc中的关闭按钮、移动、点击搜索按钮 case IDB_SEARCH_ALLSEARCH: { DestroyWindow(hWnd); hWnd = NULL; } break; 都不响应消息。 而且我也用WM_SYSCOMMAND来实现关闭操作,仍然没反应。 case WM_SYSCOMMAND: { if(wParam == SC_CLOSE) { DestroyWindow(hWnd); hWnd = NULL; } } break; 不知道为什么.
Minikinfish 2015-05-05
  • 打赏
  • 举报
回复
Windows程序很简单,就几点内容 1、窗口需要注册, 2、注册需要proc 3、proc需要循环泵的支持 4、大量窗口的api 5、SetWindowLong WGL_DLGPROC 可以对窗体任意修改
赵4老师 2015-05-05
  • 打赏
  • 举报
回复

70,020

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧