1

我的程序试图灰显(和禁用)子菜单项时遇到问题。

我正在寻找的是禁用“运行”项,除非所需的 .ini 条目不为空。

我的代码

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HMENU hmenu = GetMenu(hWnd);
// Reading in ini
    if (0 == strcmp(webLocation, "")){
    EnableMenuItem(hmenu,ID_WEBSERVICES_RUN,MF_DISABLED | MF_GRAYED);
    WritePrivateProfileString(_T("WEBSERVICES"), _T("Location"), _T("Tool Not Found"), WpathStr);
}

我不确定我是否正确获取了 HMENU,以及为什么此代码无法达到预期的效果。

对此的任何帮助将不胜感激。

4

1 回答 1

1

你不能只把它放在顶层的 WndProc 中。WndProc 处理事件,窗口是否已经构建。由于许多不同的原因,它会被多次调用。

您的 WndProc 几乎肯定会看起来像一个大开关message。你想要的一个是WM_INITDIALOG

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
         case WM_INITDIALOG:
             // jump to a new function that reads the .ini
             // and disables the control etc.
             return OnInitDialog(hWnd, wParam, lParam);

         default:
             return DefWindowProc(hWnd, message, wParam, lParam);
    }
}
于 2012-04-19T12:23:04.173 回答