Created
July 3, 2024 02:27
-
-
Save bg1bgst333/0908dc207689f99274a0fdf59cd10181 to your computer and use it in GitHub Desktop.
CFileDialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "resource.h" | |
IDM_MAINMENU MENU | |
BEGIN | |
POPUP "Item1" | |
BEGIN | |
MENUITEM "Item1-1(&A)", ID_ITEM_1_1 | |
MENUITEM "Item1-2(&B)", ID_ITEM_1_2 | |
END | |
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ヘッダファイルのインクルード | |
// 既定のヘッダ | |
#include <afxdlgs.h> // ダイアログなど. | |
// 独自のヘッダ | |
#include "CFrameWnd_.h" // CFrameWnd_クラス | |
#include "resource.h" // リソースID | |
// CFrameWnd_のメッセージマップ | |
BEGIN_MESSAGE_MAP(CFrameWnd_, CFrameWnd) | |
ON_UPDATE_COMMAND_UI(ID_ITEM_1_1, OnUpdateItem1_1) // メニュー項目などのUI更新マクロ.(Item1_1) | |
ON_COMMAND(ID_ITEM_1_1, OnItem1_1) // メニュー項目などのコマンドマクロ.(Item1_1) | |
ON_UPDATE_COMMAND_UI(ID_ITEM_1_2, OnUpdateItem1_2) // メニュー項目などのUI更新マクロ.(Item1_2) | |
ON_COMMAND(ID_ITEM_1_2, OnItem1_2) // メニュー項目などのコマンドマクロ.(Item1_2) | |
END_MESSAGE_MAP() | |
// CFrameWnd_のメンバの定義 | |
// コンストラクタCFrameWnd_() | |
CFrameWnd_::CFrameWnd_(){ // 初期化処理 | |
} | |
// ハンドラOnUpdateItem1_1() | |
void CFrameWnd_::OnUpdateItem1_1(CCmdUI* pCmdUI){ // メニュー項目Item1_1のUI更新ハンドラ | |
// メニュー項目Item1_1のUI更新 | |
if (pCmdUI){ // pCmdUIがNULLでないなら. | |
// メニュー項目Item1_1の有効化 | |
pCmdUI->Enable(); // EnableでItem1_1を有効にする.(デフォルト引数はTRUE.) | |
} | |
} | |
// ハンドラOnItem1_1() | |
void CFrameWnd_::OnItem1_1(){ // メニュー項目Item1_1のコマンドハンドラ | |
// "ファイルを開く"ダイアログの表示. | |
CFileDialog dlg(TRUE); // CFileDialogオブジェクトdlgのコンストラクタでTRUEだけ渡す. | |
INT_PTR ret = dlg.DoModal(); // dlg.DoModalで表示. | |
if (ret == IDOK){ // 選択された. | |
AfxMessageBox(_T("IDOK")); | |
} | |
else if (ret == IDCANCEL){ // キャンセル. | |
AfxMessageBox(_T("IDCANCEL")); | |
} | |
} | |
// ハンドラOnUpdateItem1_2() | |
void CFrameWnd_::OnUpdateItem1_2(CCmdUI* pCmdUI){ // メニュー項目Item1_2のUI更新ハンドラ | |
// メニュー項目Item1_2のUI更新 | |
if (pCmdUI){ // pCmdUIがNULLでないなら. | |
// メニュー項目Item1_2の有効化 | |
pCmdUI->Enable(); // EnableでItem1_2を有効にする.(デフォルト引数はTRUE.) | |
} | |
} | |
// ハンドラOnItem1_2() | |
void CFrameWnd_::OnItem1_2(){ // メニュー項目Item1_2のコマンドハンドラ | |
// "名前を付けて保存"ダイアログの表示. | |
CFileDialog dlg(FALSE); // CFileDialogオブジェクトdlgのコンストラクタでFALSEだけ渡す. | |
INT_PTR ret = dlg.DoModal(); // dlg.DoModalで表示. | |
if (ret == IDOK){ // 選択された. | |
AfxMessageBox(_T("IDOK")); | |
} | |
else if (ret == IDCANCEL){ // キャンセル. | |
AfxMessageBox(_T("IDCANCEL")); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 二重インクルード防止 | |
#pragma once // VisualC++独自のプリプロセッサ#pragma onceで二重インクルード防止. | |
// ヘッダファイルのインクルード | |
// 既定のヘッダファイル | |
#include <afxwin.h> // MFC標準 | |
#include <tchar.h> // TCHAR型 | |
// CFrameWndの派生クラスCFrameWnd_の定義 | |
class CFrameWnd_ : public CFrameWnd{ // フレームウィンドウクラス | |
// publicメンバ | |
public: | |
// publicメンバ関数 | |
// コンストラクタ | |
CFrameWnd_(); // コンストラクタ(引数なし) | |
// ハンドラ | |
void OnUpdateItem1_1(CCmdUI* pCmdUI); // メニュー項目Item1_1のUI更新ハンドラ | |
void OnItem1_1(); // メニュー項目Item1_1のコマンドハンドラ | |
void OnUpdateItem1_2(CCmdUI* pCmdUI); // メニュー項目Item1_2のUI更新ハンドラ | |
void OnItem1_2(); // メニュー項目Item1_2のコマンドハンドラ | |
// メッセージマップ | |
DECLARE_MESSAGE_MAP() // メッセージマップの利用を宣言. | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#define IDM_MAINMENU 101 | |
#define ID_ITEM_1_1 10101 | |
#define ID_ITEM_1_2 10102 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment