📄 cmenudrawer.cpp
字号:
}
void CMenuDrawer::ResetContents( void )
{
int i;
LOGFONT lf;
for( i = 0; i < m_nMenuItemNum; ++i ){
m_cmemMenuItemStrArr[i].SetData( "", 0 );
m_nMenuItemFuncArr[i] = 0;
}
m_nMenuItemNum = 0;
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof( NONCLIENTMETRICS );
::SystemParametersInfo( SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), (PVOID)&ncm, 0 );
m_nMenuHeight = ncm.iMenuHeight;
if( 21 > m_nMenuHeight ){
m_nMenuHeight = 21;
}
if( NULL != m_hFontMenu ){
::DeleteObject( m_hFontMenu );
m_hFontMenu = NULL;
}
if( NULL != m_hFontMenuUndelLine ){
::DeleteObject( m_hFontMenuUndelLine );
m_hFontMenuUndelLine = NULL;
}
lf = ncm.lfMenuFont;
m_hFontMenu = ::CreateFontIndirect( &lf );
lf.lfUnderline = TRUE;
m_hFontMenuUndelLine = ::CreateFontIndirect( &lf );
//@@@ 2002.01.03 YAZAKI 不使用のため
// m_nMaxTab = 0;
// m_nMaxTabLen = 0;
return;
}
/* メニューアイテムの描画サイズを計算 */
int CMenuDrawer::MeasureItem( int nFuncID, int* pnItemHeight )
{
*pnItemHeight = m_nMenuHeight;
const char* pszLabel;
RECT rc;
HDC hdc;
HFONT hFontOld;
if( NULL == ( pszLabel = GetLabel( nFuncID ) ) ){
return 0;
}
hdc = ::GetDC( m_hWndOwner );
hFontOld = (HFONT)::SelectObject( hdc, m_hFontMenu );
::DrawText( hdc, pszLabel, strlen( pszLabel ), &rc, DT_SINGLELINE | DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT );
::SelectObject( hdc, hFontOld );
::ReleaseDC( m_hWndOwner, hdc );
// *pnItemHeight = 20;
// *pnItemHeight = 2 + 15 + 1;
//@@@ 2002.2.2 YAZAKI Windowsの設定でメニューのフォントを大きくすると表示が崩れる問題に対処
*pnItemHeight = GetSystemMetrics(SM_CYMENU);
return rc.right - rc.left + 20 + 8;
// return m_nMaxTab + 16 + m_nMaxTabLen;
}
/* メニュー項目を追加 */
//void CMenuDrawer::MyAppendMenu( HMENU hMenu, int nFlag, int nFuncId, const char* pszLabel, BOOL bAddKeyStr )
void CMenuDrawer::MyAppendMenu( HMENU hMenu, int nFlag, int nFuncId, const char* pszLabel, BOOL bAddKeyStr, int nForceIconId ) //お気に入り //@@@ 2003.04.08 MIK
{
char szLabel[256];
int nFlagAdd = 0;
int i;
if( nForceIconId == -1 ) nForceIconId = nFuncId; //お気に入り //@@@ 2003.04.08 MIK
szLabel[0] = '\0';
if( NULL != pszLabel ){
strncpy( szLabel, pszLabel, sizeof( szLabel ) / sizeof( szLabel[0] ) - 1 );
szLabel[ sizeof( szLabel ) / sizeof( szLabel[0] ) - 1 ] = '\0';
}
if( nFuncId != 0 ){
/* メニューラベルの作成 */
CKeyBind::GetMenuLabel(
m_hInstance,
m_pShareData->m_nKeyNameArrNum,
m_pShareData->m_pKeyNameArr,
nFuncId,
szLabel,
bAddKeyStr
);
/* アイコン用ビットマップを持つものは、オーナードロウにする */
if( m_nMenuItemNum + 1 > MAX_MENUITEMS ){
::MYMESSAGEBOX( NULL, MB_OK | MB_ICONSTOP | MB_TOPMOST, GSTR_APPNAME,
"CMenuDrawer::MyAppendMenu()エラー\n\nCMenuDrawerが管理できるメニューアイテムの上限はCMenuDrawer::MAX_MENUITEMS==%dです。\n ", MAX_MENUITEMS
);
}else{
m_nMenuItemBitmapIdxArr[m_nMenuItemNum] = -1;
m_nMenuItemFuncArr[m_nMenuItemNum] = nFuncId;
m_cmemMenuItemStrArr[m_nMenuItemNum].SetData( szLabel, strlen( szLabel ) );
//#ifdef _DEBUG
/* メニュー項目をオーナー描画にする */
/* メニューにアイコンを表示する */
if( m_pShareData->m_Common.m_bMenuIcon ){
nFlagAdd = MF_OWNERDRAW;
}
//#endif
/* 機能のビットマップがあるかどうか調べておく */
//@@@ 2002.01.03 YAZAKI m_tbMyButtonなどをCShareDataからCMenuDrawerへ移動したことによる修正。
// for( i = 0; i < m_cShareData.m_nMyButtonNum; ++i ){
// if( nFuncId == m_cShareData.m_tbMyButton[i].idCommand ){
// /* 機能のビットマップの情報を覚えておく */
// m_nMenuItemBitmapIdxArr[m_nMenuItemNum] = m_cShareData.m_tbMyButton[i].iBitmap;
// break;
// }
// }
for( i = 0; i < m_nMyButtonNum; ++i ){
//if( nFuncId == m_tbMyButton[i].idCommand ){
if( nForceIconId == m_tbMyButton[i].idCommand ){ //お気に入り //@@@ 2003.04.08 MIK
/* 機能のビットマップの情報を覚えておく */
m_nMenuItemBitmapIdxArr[m_nMenuItemNum] = m_tbMyButton[i].iBitmap;
break;
}
}
m_nMenuItemNum++;
}
}
MENUITEMINFO mii;
memset( &mii, 0, sizeof( MENUITEMINFO ) );
// Aug. 31, 2001 genta
#ifdef _WIN64
mii.cbSize = sizeof( MENUITEMINFO ); // 64bit版ではサイズ違う
#else
//mii.cbSize = sizeof( MENUITEMINFO ); // 本当はこちらの書き方が正しいが,
mii.cbSize = SIZEOF_MENUITEMINFO; // サイズが大きいとWin95で動かないので,Win95が納得する値を決め打ち
#endif
mii.fMask = MIIM_CHECKMARKS | MIIM_DATA | MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE;
mii.fType = 0;
if( MF_OWNERDRAW & ( nFlag | nFlagAdd ) ) mii.fType |= MFT_OWNERDRAW;
if( MF_SEPARATOR & ( nFlag | nFlagAdd ) ) mii.fType |= MFT_SEPARATOR;
if( MF_STRING & ( nFlag | nFlagAdd ) ) mii.fType |= MFT_STRING;
if( MF_MENUBREAK & ( nFlag | nFlagAdd ) ) mii.fType |= MFT_MENUBREAK;
if( MF_MENUBARBREAK & ( nFlag | nFlagAdd ) ) mii.fType |= MFT_MENUBARBREAK;
mii.fState = 0;
if( MF_GRAYED & ( nFlag | nFlagAdd ) ) mii.fState |= MFS_GRAYED;
if( MF_CHECKED & ( nFlag | nFlagAdd ) ) mii.fState |= MFS_CHECKED;
mii.wID = nFuncId;
mii.hSubMenu = (nFlag&MF_POPUP)?((HMENU)nFuncId):NULL;
mii.hbmpChecked = NULL;
mii.hbmpUnchecked = NULL;
mii.dwItemData = (ULONG_PTR)this;
mii.dwTypeData = szLabel;
mii.cch = 0;
// メニュー内の指定された位置に、新しいメニュー項目を挿入します。
::InsertMenuItem( hMenu, 0xFFFFFFFF, TRUE, &mii );
return;
}
/*! メニューアイテム描画
@date 2001.12.21 YAZAKI デバッグモードでもメニューを選択したらハイライト。
@date 2003.08.27 Moca システムカラーのブラシはCreateSolidBrushをやめGetSysColorBrushに
*/
void CMenuDrawer::DrawItem( DRAWITEMSTRUCT* lpdis )
{
// int i;
int j;
int nItemIndex;
HDC hdc;
const char* pszItemStr;
int nItemStrLen;
// TEXTMETRIC tm;
// SIZE sz;
HFONT hFontOld;
int nIndentLeft;
int nIndentRight;
int nTextTopMargin;
RECT rc1;
HBRUSH hBrush;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -