Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Silent message box

May
12,846
164
(Mostly a FYI for plugin writers ...) I wanted my plugin to provide help in the console in response to the HELP command and in a message box in response to F1 or Ctrl-F1. Figuring out which to so was just a matter of checking GetAsyncKeyState(VK_F1).

I wanted the message box to be silent, i.e., to not play the sound associated with the message box's icon (or the default sound). This was easy with MessageBoxIndirect() and the style MB_USERICON. So I did this:

Code:
MSGBOXPARAMS mbp = {sizeof(mbp), NULL, (HINSTANCE) GetModuleHandle(NULL),
    item[i].Help, pluginfo.pszDll, MB_OK | MB_USERICON,
    MAKEINTRESOURCE(53), 0, 0, MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT)};
MessageBoxIndirect(&mbp);
Rex, I see that resource 53 (icon) goes back to v10 at least. Is it likely to stay that way?
 
Again, FYI ...

I had some trouble getting the msgbox to appear on the same monitor as TCMD when TCC was in TCMD. This seems to work nicely.

Code:
INT WINAPI Help ( WCHAR *psz )
{
    INT i = GetItemIndexFromName(psz);
    if ( i >= 0 )
    {
        // if F1 pressed display help in silent msgbox with TCC icon
        if ( GetAsyncKeyState(VK_F1) & 0x8000 )
        {
            HWND hWnd = GetConsoleWindow();
            WCHAR szHwnd[16];
            if ( !TakeCommandIPC(L"HWND", szHwnd) )
            {
                hWnd = (HWND) wcstoul(szHwnd, NULL, 10);
            }
            MSGBOXPARAMS mbp = {sizeof(mbp), hWnd, (HINSTANCE) GetModuleHandle(NULL),
                item[i].Help, pluginfo.pszDll, MB_OK | MB_USERICON,
                MAKEINTRESOURCE(53), 0, 0, MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT)};
            MessageBoxIndirect(&mbp);
        }
        else // display help in the console
        {
            Printf(L"%s\r\n", item[i].Help);
        }
        return 1; // displayed help
    }
    return 0; // didn't display help
}
 
Back
Top