windows_programming_notes.nbk: Home | Index | Next Page: CreateDialog | Previous Page: CommDlgExtendedError


 Context menu on the fly

//////////////////////////////////////////////////////////////////////////////////////
// Generate popup menu for editing RACL opcodes.
//////////////////////////////////////////////////////////////////////////////////////

void racl_win::opcode_popup_menu(HWND hwnd, int x_pos, int y_pos)
{
    HMENU           racl_menu;    
    MENUITEMINFO    mii;
    TCHAR           buffer[100];
    TCHAR           buffer2[100];
    POINT           p;

    racl_menu = CreatePopupMenu();
    myassert(racl_menu > 0);
    
    mii.cbSize      = sizeof(MENUITEMINFO);
    mii.dwTypeData  = buffer2;
    mii.fMask       = MIIM_ID | MIIM_TYPE  | MIIM_STATE;
    mii.fType       = MFT_STRING;
    if (edit_m->is_standard()) {
        mii.fState  = MFS_GRAYED;
    }
    else {
        mii.fState  = MFS_DEFAULT;
    }

    mii.wID         = IDM_RACL_ADD;
    LoadString(g.hinstance, IDS_RACL_ADD, buffer, sizeof(buffer));
    sprintf(buffer2, buffer, edit_s->opcode_text());
    InsertMenuItem(racl_menu, IDM_RACL_ADD, FALSE, &mii);

    // Disable this if the current statement is END
    mii.wID         = IDM_RACL_DELETE;
    if ((edit_s->opcode() == OP_END) || edit_m->is_standard()) {
        mii.fState  = MFS_GRAYED;
    }
    else {
        mii.fState  = MFS_DEFAULT;
    }
    LoadString(g.hinstance, IDS_RACL_DELETE, buffer, sizeof(buffer));
    sprintf(buffer2, buffer, edit_s->opcode_text());
    InsertMenuItem(racl_menu, IDM_RACL_DELETE, FALSE, &mii);

    mii.wID         = IDM_RACL_INFO;
    mii.fState      = MFS_DEFAULT;
    LoadString(g.hinstance, IDS_RACL_INFO, buffer, sizeof(buffer));
    sprintf(buffer2, buffer, edit_s->opcode_text());
    InsertMenuItem(racl_menu, IDM_RACL_INFO, FALSE, &mii);

    p.x = x_pos;
    p.y = y_pos;
    ClientToScreen(hwnd, &p);
    TrackPopupMenuEx(racl_menu, TPM_LEFTALIGN | TPM_TOPALIGN, p.x, p.y, hwnd, NULL);
    
    DestroyMenu(racl_menu);
}

windows_programming_notes.nbk: Home | Index | Next Page: CreateDialog | Previous Page: CommDlgExtendedError


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time