Skip to content

Commit

Permalink
・メニューアイテムが選択された時の処理
Browse files Browse the repository at this point in the history
  • Loading branch information
bg1bgst333 committed Jan 22, 2017
1 parent 5e2b956 commit 26143c9
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 4 deletions.
Binary file modified Debug/ObjeqtNote.exe
Binary file not shown.
124 changes: 123 additions & 1 deletion ObjeqtNote/MenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,128 @@ BOOL CMenuBar::SetMenu(HWND hwnd){
// メニュー選択時のハンドラOnCommandMenuItem.
BOOL CMenuBar::OnCommandMenuItem(WPARAM wParam, LPARAM lParam){

return 0;
// メニュー処理
switch (LOWORD(wParam)) { // LOWORD(wParam)でどのメニューアイテムが選択されたか, IDが返ってくる.

// ID_FILE_NEWの時.
case ID_FILE_NEW:

// ID_FILE_NEWブロック
{

// OnFileNewに任せる.
OnFileNew();

}

// 既定の処理
break; // breakで抜ける.

// ID_FILE_OPENの時.
case ID_FILE_OPEN:

// ID_FILE_OPENブロック
{

// OnFileOpenに任せる.
OnFileOpen();

}

// 既定の処理
break; // breakで抜ける.

// ID_FILE_SAVEの時.
case ID_FILE_SAVE:

// ID_FILE_SAVEブロック
{

// OnFileSaveに任せる.
OnFileSave();

}

// 既定の処理
break; // breakで抜ける.

// ID_FILE_SAVEASの時.
case ID_FILE_SAVEAS:

// ID_FILE_SAVEASブロック
{

// OnFileSaveAsに任せる.
OnFileSaveAs();

}

// 既定の処理
break; // breakで抜ける.

// ID_APP_EXITの時.
case ID_APP_EXIT:

// ID_APP_EXITブロック
{

// OnAppExitに任せる.
OnAppExit();

}

// 既定の処理
break; // breakで抜ける.

// それ以外の時.
default:

// FALSEを返す.
return FALSE;

}

// どれかのハンドラが処理された後はTRUEを返す.
return TRUE;

}

// "新規"選択時の独自ハンドラOnFileNew.
void CMenuBar::OnFileNew(){

// "新規"と表示.
MessageBox(NULL, _T("新規"), _T("ObjeqtNote"), MB_OK); // MessageBoxで"新規"と表示.

}

// "開く"選択時の独自ハンドラOnFileOpen.
void CMenuBar::OnFileOpen(){

// "開く"と表示.
MessageBox(NULL, _T("開く"), _T("ObjeqtNote"), MB_OK); // MessageBoxで"開く"と表示.

}

// "上書き保存"選択時の独自ハンドラOnFileSave.
void CMenuBar::OnFileSave(){

// "上書き保存"と表示.
MessageBox(NULL, _T("上書き保存"), _T("ObjeqtNote"), MB_OK); // MessageBoxで"上書き保存"と表示.

}

// "名前を付けて保存"選択時の独自ハンドラOnFileSaveAs.
void CMenuBar::OnFileSaveAs(){

// "名前を付けて保存"と表示.
MessageBox(NULL, _T("名前を付けて保存"), _T("ObjeqtNote"), MB_OK); // MessageBoxで"名前を付けて保存"と表示.

}

// "アプリケーションの終了"選択時の独自ハンドラOnAppExit.
void CMenuBar::OnAppExit(){

// "アプリケーションの終了"と表示.
MessageBox(NULL, _T("アプリケーションの終了"), _T("ObjeqtNote"), MB_OK); // MessageBoxで"アプリケーションの終了"と表示.

}
8 changes: 8 additions & 0 deletions ObjeqtNote/MenuBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
// ヘッダのインクルード
// 既定のヘッダ
#include <windows.h> // 標準WindowsAPI
#include <tchar.h> // TCHAR型
// 独自のヘッダ
#include "resource.h" // リソース

// メニューバークラスCMenuBar
class CMenuBar {
Expand All @@ -24,5 +27,10 @@ class CMenuBar {
virtual BOOL LoadMenu(HINSTANCE hInstance, UINT nID); // メニューロード関数LoadMenu.
virtual BOOL SetMenu(HWND hwnd); // メニューセット関数SetMenu.
virtual BOOL OnCommandMenuItem(WPARAM wParam, LPARAM lParam); // メニュー選択時のハンドラOnCommandMenuItem.
void OnFileNew(); // "新規"選択時の独自ハンドラOnFileNew.
void OnFileOpen(); // "開く"選択時の独自ハンドラOnFileOpen.
void OnFileSave(); // "上書き保存"選択時の独自ハンドラOnFileSave.
void OnFileSaveAs(); // "名前を付けて保存"選択時の独自ハンドラOnFileSaveAs.
void OnAppExit(); // "アプリケーションの終了"選択時の独自ハンドラOnAppExit.

};
17 changes: 15 additions & 2 deletions ObjeqtNote/MenuWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,20 @@ int CMenuWindow::OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct){
// コマンド処理時のハンドラOnCommand.
BOOL CMenuWindow::OnCommand(WPARAM wParam, LPARAM lParam){

// とりあえずTRUEを返す.
return TRUE; // TRUEを返す.
// メニューコマンドだった場合.
if (HIWORD(wParam) == 0) { // HIWORD(wParam)が0ならメニューが選択されたということ.

// メニューオブジェクトがあるかチェック.
if (m_pMenuBar != NULL) { // m_pMenuBarがNULLでない場合.

// OnCommandMenuItemにコマンド処理を任せる.
return m_pMenuBar->OnCommandMenuItem(wParam, lParam); // OnCommandMenuItemにwParam, lParamを渡してあとは任せ, 戻り値をそのまま返す.

}

}

// FALSEを返す.
return TRUE;

}
1 change: 0 additions & 1 deletion ObjeqtNote/MenuWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// 独自のヘッダ
#include "BasicWindow.h" // ベーシックウィンドウクラス
#include "MenuBar.h" // メニューバークラス
#include "resource.h" // リソース

// メニューウィンドウクラスCMenuWindow
class CMenuWindow : public CBasicWindow {
Expand Down
Binary file modified ObjeqtNote/ObjeqtNote.rc
Binary file not shown.
Binary file modified Release/ObjeqtNote.exe
Binary file not shown.

0 comments on commit 26143c9

Please sign in to comment.