summaryrefslogtreecommitdiffstats
path: root/private/utils/windisk/src/popup.cxx
blob: e51767bc7499623e804f15d3c2848f78d5e2a1fd (plain) (blame)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//+-------------------------------------------------------------------------
//
//  Microsoft Windows
//  Copyright (C) Microsoft Corporation, 1992 - 1994.
//
//  File:       popup.cxx
//
//  Contents:   Implementation of popup menu functions.
//
//  Functions:  TrackModalPopupMenu
//
//  History:    16-Aug-93   BruceFo Created from JohnEls code
//
//--------------------------------------------------------------------------

#include "headers.hxx"
#pragma hdrstop

#include "popup.hxx"

//////////////////////////////////////////////////////////////////////////////


//+-------------------------------------------------------------------------
//
//  Function:   TrackModalPopupMenu, public
//
//  Synopsis:   Displays a popup menu and returns the user's choice.
//
//  Arguments:  [hMenu]      -- The popup menu to display.
//              [dwFlags]    -- Flags (see flags for [TrackPopupMenu()].
//              [x], [y]     -- Menu position, in screen coordinates.
//              [nReserved]  -- Reserved.  Must be 0.
//              [lpReserved] -- Reserved.  Must be NULL.
//
//  Returns:    The ID corresponding to the menu item chosen by the user.
//              If the user cancels the menu, -1 is returned.  If the
//              attempt to display the menu fails, -2 is returned.
//
//  History:    05-Mar-92 JohnEls   Created.
//
//--------------------------------------------------------------------------

INT
TrackModalPopupMenu(
    HMENU hMenu,
    UINT dwFlags,
    int x,
    int y,
    int nReserved,
    LPRECT prc
    )
{
    INT ret;

    if (TrackPopupMenu(
                hMenu,
                dwFlags,
                x,
                y,
                nReserved,
                g_hwndFrame,
                prc))
    {
        MSG msg;

        //
        //  Look for a WM_COMMAND message in the queue.  If there is none,
        //  then the user cancelled the menu.
        //

        if (PeekMessage(
                    &msg,
                    g_hwndFrame,
                    WM_COMMAND,
                    WM_COMMAND,
                    PM_NOREMOVE | PM_NOYIELD))
        {
            ret = LOWORD(msg.wParam);
        }
        else
        {
            ret = -1;
        }
    }
    else
    {
        //
        //  Failed to display the menu.
        //

        ret = -2;
    }

    return ret;
}