Valhalla Legends Forums Archive | C/C++ Programming | DialogBox not showing

AuthorMessageTime
UserLoser.
I'm creating a binarychat plugin that requests and processes the news/motd from Battle.net, but my dialog doesn't want to show and i'm not sure what's the problem. But my only guess is because CreateDialogParam() is returning 0 and i don't know why. Here's basically everything:

[code]
UINT lpuMenuId;
HMENU hMenu;
HHOOK hHook;
HINSTANCE hInstance;
HWND hDlg;

BOOL CALLBACK NewsDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   switch (uMsg) {
   case WM_INITDIALOG:
      BYTE OutBuffer[4];
      *(DWORD *)(OutBuffer + 0) = 0x0;
      API.QueueMessage(0x46, OutBuffer, 0x4);
      return TRUE;
   case WM_COMMAND:
      switch (LOWORD(wParam)) {
      case CMD_OK:
         SendMessage(hWnd, WM_CLOSE, 0, 0);
         break;
      }
   case WM_CLOSE:
      DestroyWindow(hWnd);
      break;
   }
   return FALSE;
}

LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
   if (nCode < 0)
      return CallNextHookEx(hHook, nCode, wParam, lParam);

   if (nCode == HC_ACTION) {
      MSG *uMsg = (MSG*)lParam;
      if (uMsg->message == WM_COMMAND) {
         if (LOWORD(uMsg->wParam) == lpuMenuId) {
            hDlg = CreateDialogParam(hInstance, MAKEINTRESOURCE(DLG_NEWS), uMsg->hwnd, &NewsDialogProc, 0);
            char buf[512] = "";
            wsprintf(buf, "hWnd: %08x\r\n", hDlg);
            API.WriteOutputTimestamp();
            API.SetOutputColor(PluginAPI::Yellow);
            API.WriteOutputString(buf);
            return FALSE;
         }
      }
   }

   return CallNextHookEx(hHook, nCode, wParam, lParam);
}

BOOL Plugin::Initialize()
{
   InitCommonControls();
   hInstance = Plugin::m_PluginInstance;
   hMenu = API.GetMenu(PluginAPI::MainWindowMenu);
   AddPluginMenuItem(hMenu, "&Battle.net News...", &lpuMenuId);
   hHook = SetWindowsHookEx(WH_GETMESSAGE, &GetMsgProc, 0, GetWindowThreadProcessId(API.GetWindow(PluginAPI::MainWindow), 0));
   return TRUE;
}

void Plugin::Terminate()
{
   UnhookWindowsHookEx(hHook);
   RemovePluginMenuItem(hMenu, lpuMenuId);
}

[/code]

Any help is appreciated.
May 22, 2004, 5:22 PM
Spht
Get the DLL instance in DllMain(), not through Plugin::m_PluginInstance.
May 22, 2004, 9:58 PM
Skywing
Did you mark the dialog as having the visible style in the template? If not, then you will want to ShowWindow(hDlg, SW_SHOW); at the end of WM_INITDIALOG or some similar operation.
May 24, 2004, 3:39 AM
UserLoser.
[quote author=Skywing link=board=30;threadid=6912;start=0#msg61490 date=1085369962]
Did you mark the dialog as having the visible style in the template? If not, then you will want to ShowWindow(hDlg, SW_SHOW); at the end of WM_INITDIALOG or some similar operation.
[/quote]

Actually, I did set the style to include visible in the template. I guess the problem was I wasn't using the right hInstance for CreateDialogParam() and in my NewsDialogProc, I moved WM_CLOSE up before WM_INITDIALOG on the switch case - I didn't know that actually made a difference but I guess it did because CreateDialogParam() then returned non-zero after I made the change
May 24, 2004, 9:05 PM
Eibro
[quote author=UserLoser. link=board=30;threadid=6912;start=0#msg61600 date=1085432718]
[quote author=Skywing link=board=30;threadid=6912;start=0#msg61490 date=1085369962]
Did you mark the dialog as having the visible style in the template? If not, then you will want to ShowWindow(hDlg, SW_SHOW); at the end of WM_INITDIALOG or some similar operation.
[/quote]

Actually, I did set the style to include visible in the template. I guess the problem was I wasn't using the right hInstance for CreateDialogParam() and in my NewsDialogProc, I moved WM_CLOSE up before WM_INITDIALOG on the switch case - I didn't know that actually made a difference but I guess it did because CreateDialogParam() then returned non-zero after I made the change
[/quote]The only reason this made a difference is because your WM_COMMAND handler falls through to WM_CLOSE unless you're handling CMD_OK. Move the break; outside the nested switch statement.
May 24, 2004, 9:14 PM
UserLoser.
[quote author=Eibro[yL] link=board=30;threadid=6912;start=0#msg61602 date=1085433246]
[quote author=UserLoser. link=board=30;threadid=6912;start=0#msg61600 date=1085432718]
[quote author=Skywing link=board=30;threadid=6912;start=0#msg61490 date=1085369962]
Did you mark the dialog as having the visible style in the template? If not, then you will want to ShowWindow(hDlg, SW_SHOW); at the end of WM_INITDIALOG or some similar operation.
[/quote]

Actually, I did set the style to include visible in the template. I guess the problem was I wasn't using the right hInstance for CreateDialogParam() and in my NewsDialogProc, I moved WM_CLOSE up before WM_INITDIALOG on the switch case - I didn't know that actually made a difference but I guess it did because CreateDialogParam() then returned non-zero after I made the change
[/quote]The only reason this made a difference is because your WM_COMMAND handler falls through to WM_CLOSE unless you're handling CMD_OK. Move the break; outside the nested switch statement.
[/quote]

Ah, I didn't even realize that I didn't have a break there
May 24, 2004, 9:16 PM

Search