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:
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);
}
Any help is appreciated.
Get the DLL instance in DllMain(), not through Plugin::m_PluginInstance.
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 from: Skywing on May 23, 2004, 10:39 PM
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.
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 from: UserLoser. on May 24, 2004, 04:05 PM
Quote from: Skywing on May 23, 2004, 10:39 PM
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.
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
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 from: Eibro[yL] on May 24, 2004, 04:14 PM
Quote from: UserLoser. on May 24, 2004, 04:05 PM
Quote from: Skywing on May 23, 2004, 10:39 PM
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.
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
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.
Ah, I didn't even realize that I didn't have a break there