2013年6月16日日曜日

メニューの操作

メニューアイテムを無効化し選択出来なくする。

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 int wmId, wmEvent;

 static HMENU hmenu;
 static MENUITEMINFO menuInfo;

 switch (message)
 {
 case WM_CREATE:
  hmenu = GetMenu(hWnd);
  menuInfo.cbSize = sizeof (MENUITEMINFO);
  menuInfo.fMask = MIIM_STATE;
  menuInfo.fState = MFS_GRAYED;
  SetMenuItemInfo(hmenu , IDM_PLAY_PAUSE , FALSE , &menuInfo);
  break;
........

メニューにチェックを付ける


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 int wmId, wmEvent;

 static HMENU hmenu;
 static MENUITEMINFO menuInfo;

 switch (message)
 {
 case WM_CREATE:
  hmenu = GetMenu(hWnd);
  menuInfo.cbSize = sizeof (MENUITEMINFO);
  menuInfo.fState = MFS_UNCHECKED;
  break;
 case WM_COMMAND:
  wmId    = LOWORD(wParam);
  wmEvent = HIWORD(wParam);
  
  // 選択されたメニューの解析:
  switch (wmId)
  {
  case IDM_ABOUT:
   DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
   break;
  case IDM_EXIT:
   DestroyWindow(hWnd);
   break;
  case IDM_PLAY_PAUSE:
   menuInfo.fMask = MIIM_STATE;
   if (menuInfo.fState == MFS_CHECKED)
    menuInfo.fState = MFS_UNCHECKED;
   else menuInfo.fState = MFS_CHECKED;
   SetMenuItemInfo(hmenu , IDM_PLAY_PAUSE , FALSE , &menuInfo);
   break;
  default:
   return DefWindowProc(hWnd, message, wParam, lParam);
  }
  break;
 case WM_DESTROY:
  PostQuitMessage(0);
  break;
 default:
  return DefWindowProc(hWnd, message, wParam, lParam);
 }
 return 0;
}


0 件のコメント:

コメントを投稿