VIZ++ Class: OpenGLPopupMenu

 VIZ++ Class Library  VIZ++ Samples  VIZ++ ClassTree 

Source code

/*
 * OpenGLPopupMenu.h 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


//2015/08/2 Updated

#include <viz++/opengl/OpenGLMainView.h>
#include <viz++/opengl/OpenGLGC.h>
#include <viz++/opengl/OpenGLTexture2D.h>
#include <viz++/opengl/OpenGLDialog.h>
#include <viz++/opengl/OpenGLFileOpenDialog.h>
#include <viz++/StringT.h>
#include <viz++/opengl/MenuItem.h>
#include <viz++/opengl/CascadeMenuItem.h>

namespace VIZ {

class OpenGLPopupMenu :public OpenGLObject {
private:
  OpenGLMainView* view;
  HMENU hPopupMenu;

public:
  OpenGLPopupMenu(OpenGLMainView* view, const MenuItem* items, int numItems)
  :view(view),
  hPopupMenu(NULL)
  {
    if (view == NULL) {
      throw IException("Invalid argument: OpenGLMainView is NULL.");
    }

    hPopupMenu = CreatePopupMenu();
    if (items && numItems) {
      MENUITEMINFO mii;
      memset(&mii, 0, sizeof(mii));
      mii.cbSize    = sizeof (MENUITEMINFO);
      
      for (int i = 0; i<numItems; i++) {
        mii.fMask  = MIIM_TYPE | MIIM_STATE | MIIM_ID;
        mii.fType  = items[i].flags;
        mii.fState = items[i].state;
        mii.wID    = items[i].id;
        mii.dwTypeData = (char*) items[i].name;
        InsertMenuItem(hPopupMenu, i, TRUE, &mii);;
      
      }
    }
  }

  ~OpenGLPopupMenu()
  {
    DestroyMenu(hPopupMenu);
  }

  void popup()
  {
    POINT pt;
    GetCursorPos(&pt);
    HWND hwnd = view ->getHwnd();
    //ScreenToClient(hwnd, &pt);
    TrackPopupMenu(hPopupMenu, 
                         TPM_LEFTALIGN | TPM_RIGHTBUTTON |TPM_RECURSE , 
                         pt.x, pt.y, 0, hwnd, NULL);
  }

  
};

}

Last modified: 10 Feb 2017

Copyright (c) 2009-2017 Antillia.com ALL RIGHTS RESERVED.