VIZ++ Class: OpenGLMenu

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

Source code

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


#pragma once

#include <viz++/opengl/OpenGLIView.h>

namespace VIZ {

class OpenGLMenu :public Object {
private:
  OpenGLIView* owner; //Shallow copy.
  HMENU        hmenu;

  void  redraw() 
  {
    ::DrawMenuBar(owner->getHwnd());
  }

public:
  OpenGLMenu()
  {
    owner = NULL;
    hmenu = NULL;
  }

public:
  void setOwner(OpenGLIView* view)
  {
    owner = view;
  }

public:
  OpenGLMenu(OpenGLIView* view) 
  {
    owner = view;
    hmenu = NULL;
  }

public:  
  void  checkByCommand(int id) 
  {
    ::CheckMenuItem(hmenu, id, MF_BYCOMMAND|MF_CHECKED);
  }
  
  void  checkByPosition(int pos) 
  {
    ::CheckMenuItem(hmenu, pos, MF_BYPOSITION|MF_CHECKED);
  }
  
  int   getItemCount() 
  {
    return ::GetMenuItemCount(hmenu);
  }
  
  void  deleteByCommand(int id) 
  {
    ::DeleteMenu(hmenu, id, MF_BYCOMMAND);
    redraw();
  }
  
  void  deleteByPosition(int pos) 
  {
    ::DeleteMenu(hmenu, pos, MF_BYPOSITION);
    redraw();
  }
  
  void  enableByPosition(int pos) 
  {
    ::EnableMenuItem(hmenu, pos, MF_ENABLED|MF_BYPOSITION);
    redraw();
  }
  
  void  enableByCommand(int id) 
  {
    ::EnableMenuItem(hmenu, id, MF_ENABLED|MF_BYCOMMAND);
    redraw();
  }
  
  void  disableByPosition(int pos) 
  {
    ::EnableMenuItem(hmenu, pos, MF_GRAYED|MF_BYPOSITION);
    redraw();
  }
  
  void  disableByCommand(int id) 
  {
    ::EnableMenuItem(hmenu, id, MF_GRAYED|MF_BYCOMMAND);
    redraw();
  }
  
  void  getStringByCommand(int id, TCHAR* string, int len) 
  {
    ::GetMenuString(hmenu, id,  string, len, MF_BYCOMMAND);
  }
  
  void  getStringByPosition(int pos, TCHAR* string, int len) 
  {
    ::GetMenuString(hmenu, pos, string, len, MF_BYPOSITION);
  }
  HMENU get() 
  { 
    return hmenu; 
  }
  
  OpenGLIView* getOwner() 
  { 
    return owner; 
  }
  
  void  set(HMENU hmenu1) 
  { 
    hmenu = hmenu1; 
  }
  
  void  uncheckByCommand(int id) 
  {
    ::CheckMenuItem(hmenu, id, MF_BYCOMMAND|MF_UNCHECKED);
  }
  
  void  uncheckByPosition(int pos) 
  {
    ::CheckMenuItem(hmenu, pos, MF_BYPOSITION|MF_UNCHECKED);
  }

  BOOL  isCheckedByCommand(int id) 
  {
    BOOL rc = FALSE;
    UINT state =::GetMenuState(hmenu, id, MF_BYCOMMAND);
    if (state & MF_CHECKED) {
      rc = TRUE;
    }
    return rc;
  }

  BOOL  isCheckedByPosition(int pos) 
  {
    BOOL rc = FALSE;
    UINT state =::GetMenuState(hmenu, pos, MF_BYPOSITION);
    if (state & MF_CHECKED) {
      rc = TRUE;
    }
    return rc;
  }


  void  toggleCheckByCommand(int id) 
  {
    if (isCheckedByCommand(id)) {
      uncheckByCommand(id);
    } else {
      checkByCommand(id);
    }
  }

  void  toggleCheckByPosition(int pos) 
  {
    if (isCheckedByPosition(pos)) {
      uncheckByPosition(pos);
    } else {
      checkByPosition(pos);
    }
  }

  UINT  getStateByCommand(int id) 
  {
    return ::GetMenuState(hmenu, id, MF_BYCOMMAND);
  }

  UINT  getStateByPosition(int pos) 
  {
    return ::GetMenuState(hmenu, pos, MF_BYPOSITION);
  }

  BOOL  getMenuItemInfoByCommand(MENUITEMINFO& menuItemInfo, int id) 
  {
    memset(&menuItemInfo, 0, sizeof(MENUITEMINFO));
    menuItemInfo.cbSize = sizeof(MENUITEMINFO);
    return ::GetMenuItemInfo(hmenu, id, FALSE, &menuItemInfo);
  }

  BOOL  getMenuItemInfoByPosition(MENUITEMINFO& menuItemInfo, int pos) 
  {
    memset(&menuItemInfo, 0, sizeof(MENUITEMINFO));
    menuItemInfo.cbSize = sizeof(MENUITEMINFO);
    return ::GetMenuItemInfo(hmenu, pos,  TRUE, &menuItemInfo);
  }

};

}


Last modified: 10 Feb 2017

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