File: message_box.c

package info (click to toggle)
putty 0.78-2%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,964 kB
  • sloc: ansic: 137,777; python: 7,775; perl: 1,798; makefile: 133; sh: 111
file content (49 lines) | stat: -rw-r--r-- 1,442 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * Message box with optional context help.
 */

#include "putty.h"

static HWND message_box_owner;

/* Callback function to launch context help. */
static VOID CALLBACK message_box_help_callback(LPHELPINFO lpHelpInfo)
{
    const char *context = NULL;
#define CHECK_CTX(name) \
    do { \
        if (lpHelpInfo->dwContextId == WINHELP_CTXID_ ## name) \
            context = WINHELP_CTX_ ## name; \
    } while (0)
    CHECK_CTX(errors_hostkey_absent);
    CHECK_CTX(errors_hostkey_changed);
    CHECK_CTX(errors_cantloadkey);
    CHECK_CTX(option_cleanup);
    CHECK_CTX(pgp_fingerprints);
#undef CHECK_CTX
    if (context)
        launch_help(message_box_owner, context);
}

int message_box(HWND owner, LPCTSTR text, LPCTSTR caption,
                DWORD style, DWORD helpctxid)
{
    MSGBOXPARAMS mbox;

    /*
     * We use MessageBoxIndirect() because it allows us to specify a
     * callback function for the Help button.
     */
    mbox.cbSize = sizeof(mbox);
    /* Assumes the globals `hinst' and `hwnd' have sensible values. */
    mbox.hInstance = hinst;
    mbox.hwndOwner = message_box_owner = owner;
    mbox.lpfnMsgBoxCallback = &message_box_help_callback;
    mbox.dwLanguageId = LANG_NEUTRAL;
    mbox.lpszText = text;
    mbox.lpszCaption = caption;
    mbox.dwContextHelpId = helpctxid;
    mbox.dwStyle = style;
    if (helpctxid != 0 && has_help()) mbox.dwStyle |= MB_HELP;
    return MessageBoxIndirect(&mbox);
}