TNB Library
TnbCeMenuBar.h
[詳解]
1#pragma once
11#ifndef _WIN32_WCE
12 #error TnbCeMenuBar.h is only supported on Windows CE platforms.
13#endif // _WIN32_WCE
14
15
16
17#include "TnbDef.h"
18
19
20
21#ifndef _TnbDOXYGEN //Document作成用シンボル
22#ifndef TBIF_BYINDEX
23 #define TBIF_BYINDEX 0x80000000
24#endif
25#endif
26
27
28
29//TNB Library
30namespace TNB{
31
32
33
80{
81public:
82
84 CCeMenuBar(void) : m_menu(NULL), m_isShow(true)
85 {
86 Zero(m_mbi);
87 }
88
94 HWND GetMenuWndHandle(void) const
95 {
96 return m_mbi.hwndMB;
97 }
98
102 void Destory(void)
103 {
104 ::SendMessage(m_mbi.hwndMB, WM_CLOSE, 0, 0);
105 if ( m_menu != NULL )
106 {
107 ::DestroyMenu(m_menu);
108 m_menu = NULL;
109 }
110 Zero(m_mbi);
111 }
112
121 bool Create(HWND hWnd, UINT barId, UINT menuId)
122 {
123 m_isShow = true;
124 return m_Create(hWnd, barId, MAKEINTRESOURCE(menuId));
125 }
126
133 bool IsBarVisible(void) const
134 {
135 return !! ::IsWindowVisible(m_mbi.hwndMB);
136 }
137
149 bool ShowBar(bool isShow, bool withParent = true)
150 {
151 if ( m_mbi.hwndMB == NULL )
152 {
153 return false;
154 }
155 if ( ! withParent )
156 {
157 m_isShow = isShow;
158 return !! ::ShowWindow(m_mbi.hwndMB, isShow ? SW_SHOW : SW_HIDE);
159 }
160 bool r = true;
161 HDC dc = ::GetWindowDC(NULL);
162 int cx = ::GetDeviceCaps(dc, HORZRES);
163 int cy = ::GetDeviceCaps(dc, VERTRES);
164 ::ReleaseDC(NULL, dc);
165 RECT rc = { 0, 0, cx, cy };
166 HWND hWnd = m_mbi.hwndParent;
167 if ( isShow )
168 {
169 int height = ::CalcScaleY(26);
170 r &= !! ::SHFullScreen(hWnd, SHFS_SHOWTASKBAR);
171 r &= !! ::ShowWindow(m_mbi.hwndMB, SW_SHOW);
172 rc.top = height;
173 rc.bottom -= (2 * height);
174 ::SetForegroundWindow(hWnd);
175 }
176 else
177 {
178 if ( m_isShow )
179 {
180 SHINITDLGINFO shidi;
181 shidi.hDlg = hWnd;
182 shidi.dwMask = SHIDIM_FLAGS;
183 shidi.dwFlags = SHIDIF_FULLSCREENNOMENUBAR | SHIDIF_SIPDOWN;
184 ::SHInitDialog(&shidi);
185 }
186 r &= !! ::SHFullScreen(hWnd, SHFS_HIDETASKBAR);
187 r &= !! ::SHFullScreen(hWnd, SHFS_HIDESIPBUTTON);
188 r &= !! ::ShowWindow(m_mbi.hwndMB, SW_HIDE);
189 }
190 r &= !! ::MoveWindow(m_mbi.hwndParent, rc.left, rc.top, rc.right, rc.bottom, TRUE);
191 m_isShow = isShow;
192 return r;
193 }
194
199 size_t GetTopItemCount(void) const
200 {
201 return min(MAXMENU, ::GetMenuItemCount(m_menu));
202 }
203
209 HMENU GetTopMenu(void) const
210 {
211 return m_menu;
212 }
213
221 bool EnableTopItem(INDEX index, bool isEnable)
222 {
223 return SetTopItemState(index, isEnable ? TBSTATE_ENABLED : TBSTATE_INDETERMINATE);
224 }
225
233 bool SetTopItemString(INDEX index, LPCTSTR lpszText)
234 {
235 CSimpleStr s = lpszText;
236 TBBUTTONINFO info = { 0 };
237 info.cbSize = sizeof(TBBUTTONINFO);
238 info.dwMask = TBIF_TEXT | TBIF_BYINDEX;
239 info.pszText = s;
240 info.cchText = _tcslen(lpszText);
241 LPARAM lParam = reinterpret_cast<LPARAM>(&info);
242 return ::SendMessage(m_mbi.hwndMB, TB_SETBUTTONINFO, index, lParam) != 0;
243 }
244
252 bool SetTopItemState(INDEX index, DWORD state)
253 {
254 TBBUTTONINFO info = { 0 };
255 info.cbSize = sizeof(TBBUTTONINFO);
256 info.dwMask = TBIF_STATE | TBIF_BYINDEX;
257 info.fsState = down_cast<BYTE>(state);
258 LPARAM lParam = reinterpret_cast<LPARAM>(&info);
259 return ::SendMessage(m_mbi.hwndMB, TB_SETBUTTONINFO, index, lParam) != 0;
260 }
261
268 DWORD GetTopItemState(INDEX index) const
269 {
270 TBBUTTONINFO info = { 0 };
271 info.cbSize = sizeof(TBBUTTONINFO);
272 info.dwMask = TBIF_STATE | TBIF_BYINDEX;
273 LPARAM lParam = reinterpret_cast<LPARAM>(&info);
274 if ( ::SendMessage(m_mbi.hwndMB, TB_GETBUTTONINFO, index, lParam) )
275 {
276 return info.fsState;
277 }
278 return DWORD_MAX;
279 }
280
287 void OnActivate(UINT nState)
288 {
289 if ( nState != WA_INACTIVE && ! IsBarVisible() )
290 {
291 ShowBar(false);
292 }
293 }
294
295private:
304 bool m_Create(HWND hWnd, UINT barId, LPCTSTR menuName)
305 {
306 HINSTANCE hInst = GetInstanceHandleByTnb();
307 Destory();
308 m_mbi.cbSize = sizeof(SHMENUBARINFO);
309 m_mbi.hwndParent = hWnd;
310 m_mbi.nToolBarId = barId;
311 m_mbi.hInstRes = hInst;
312 if ( ! ::SHCreateMenuBar(&m_mbi) )
313 {
314 _GetLastError("SHCreateMenuBar");
315 return false;
316 }
317 if ( menuName == NULL )
318 {
319 return true;
320 }
321 m_menu = ::LoadMenu(hInst, menuName);
322 bool r = true;
323 loop( i, min(MAXMENU, ::GetMenuItemCount(m_menu)) )
324 {
325 int len = ::GetMenuString(m_menu, i, NULL, 0, MF_BYPOSITION);
326 if ( len == 0 )
327 {
328 r = false;
329 break;
330 }
331 CWorkMemT<WCHAR> tempName(len + 1);
332 if ( ::GetMenuString(m_menu, i, tempName.Ref(), len + 1, MF_BYPOSITION) == 0 )
333 {
334 r = false;
335 break;
336 }
337 TBBUTTON tbb;
338 Zero(tbb);
339 tbb.iBitmap = I_IMAGENONE;
340 tbb.fsState = TBSTATE_ENABLED;
341 UINT state = ::GetMenuState(m_menu, i, MF_BYPOSITION);
342 if ( state != 0xFFFFFFFF && (state & MF_GRAYED) != 0 )
343 {
344 tbb.fsState = TBSTATE_INDETERMINATE;
345 }
346 LPCTSTR lpsz = tempName;
347 tbb.iString = reinterpret_cast<int>(lpsz);
348 HMENU sub = ::GetSubMenu(m_menu, i);
349 if ( sub != NULL )
350 {
351 tbb.fsStyle = TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE;
352 tbb.dwData = reinterpret_cast<DWORD>(sub);
353 }
354 else
355 {
356 tbb.fsStyle = TBSTYLE_AUTOSIZE;
357 tbb.idCommand = ::GetMenuItemID(m_menu, i);
358 }
359 ::SendMessage(m_mbi.hwndMB, TB_INSERTBUTTON, i, reinterpret_cast<LPARAM>(&tbb));
360 }
361 if ( ! r )
362 {
363 Destory();
364 }
365 return r;
366 }
367
368 enum { MAXMENU = 2 };
369 SHMENUBARINFO m_mbi;
370 HMENU m_menu;
371 bool m_isShow;
372};
373
374
375
376};//TNB
377
378
TNBライブラリの定義ヘッダ
#define loop(VAR, CNT)
loop構文.
Definition: TnbDef.h:343
メニューバークラス(CE専用)
Definition: TnbCeMenuBar.h:80
bool EnableTopItem(INDEX index, bool isEnable)
[設定] トップメニュー有効無効.
Definition: TnbCeMenuBar.h:221
bool SetTopItemState(INDEX index, DWORD state)
[設定] トップメニュー状態設定.
Definition: TnbCeMenuBar.h:252
HMENU GetTopMenu(void) const
[取得] メニューハンドル取得
Definition: TnbCeMenuBar.h:209
size_t GetTopItemCount(void) const
[取得] トップメニューアイテム数
Definition: TnbCeMenuBar.h:199
bool Create(HWND hWnd, UINT barId, UINT menuId)
[作成] メニューバー作成.
Definition: TnbCeMenuBar.h:121
CCeMenuBar(void)
コンストラクタ
Definition: TnbCeMenuBar.h:84
bool ShowBar(bool isShow, bool withParent=true)
[操作] 表示非表示.
Definition: TnbCeMenuBar.h:149
bool SetTopItemString(INDEX index, LPCTSTR lpszText)
[設定] トップメニュー文字列設定.
Definition: TnbCeMenuBar.h:233
HWND GetMenuWndHandle(void) const
[取得] メニューバーハンドル
Definition: TnbCeMenuBar.h:94
void Destory(void)
[破棄] メニュー破棄.
Definition: TnbCeMenuBar.h:102
DWORD GetTopItemState(INDEX index) const
[取得] トップメニュー状態取得.
Definition: TnbCeMenuBar.h:268
bool IsBarVisible(void) const
[確認] 表示確認
Definition: TnbCeMenuBar.h:133
void OnActivate(UINT nState)
[処理] アクティブ化処理.
Definition: TnbCeMenuBar.h:287
[ETC] コピー不可能スーパークラス.
Definition: TnbDef.h:599
簡易文字列管理クラス.
Definition: TnbDef.h:772
ワークメモリテンプレート.
Definition: TnbDef.h:633
void Zero(V &value)
[設定] ゼロクリア.
Definition: TnbDef.h:399
HINSTANCE GetInstanceHandleByTnb(EInstanceType type=EI_Process)
[取得] インスタンスハンドル取得.
Definition: TnbDef.h:1341
TNB Library
Definition: TnbDoxyTitle.txt:2