win32,创建两个非模态对话框但有一个不能退出、按钮无法响应、无法移动(分数不多了,无法给太多分。但是希望大家帮忙解决,谢谢。)

幸福绿光 2015-05-05 03:20:34

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; // 处理过的消息
}


...全文
160 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
幸福绿光 2015-05-06
  • 打赏
  • 举报
回复
引用 3 楼 VisualEleven 的回复:
我记得对话框的DlgProc窗口过程最后需要return FALSE;
不行
引用 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; 不知道为什么.
Eleven 2015-05-05
  • 打赏
  • 举报
回复
我记得对话框的DlgProc窗口过程最后需要return FALSE;
schlafenhamster 2015-05-05
  • 打赏
  • 举报
回复
CreateDialog The CreateDialog macro creates a modeless dialog box from a dialog box template resource. The CreateDialog macro uses the CreateDialogParam function. HWND CreateDialog( HINSTANCE hInstance, // handle to application instance LPCTSTR lpTemplate, // identifies dialog box template name HWND hWndParent, // handle to owner window DLGPROC lpDialogFunc // pointer to dialog box procedure );
幸福绿光 2015-05-05
  • 打赏
  • 举报
回复

16,370

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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