/*
* Menu.h
* Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
// 2000.06.15 Added some new methods.
// 2000/11/18 to-arai:Added return to some methods.
#pragma once
#include <sol\View.h>
namespace SOL {
class Menu :public Object {
View* owner;
HMENU hmenu;
void redraw() {
::DrawMenuBar(owner -> getWindow());
}
public:
Menu(View* view) {
owner = view;
hmenu = NULL;
}
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; }
View* 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);
}
//<added date="2000.06.15">
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);
// 2000/11/18
return ::GetMenuItemInfo(hmenu, id, FALSE, &menuItemInfo);
}
BOOL getMenuItemInfoByPosition(MENUITEMINFO& menuItemInfo, int pos) {
memset(&menuItemInfo, 0, sizeof(MENUITEMINFO));
menuItemInfo.cbSize = sizeof(MENUITEMINFO);
// 2000/11/18
return ::GetMenuItemInfo(hmenu, pos, TRUE, &menuItemInfo);
}
// if Windows2000
/*
int getMenuInfo(MENUINFO& menuInfo) {
memset(&menuInfo, 0, sizeof(menuInfo));
menuInfo.cbSize = sizeof(MENUINFO);
::GetMenuInfo(hmenu, &menuInfo);
}
*/
//</added>
};
}
|