Created
June 19, 2024 03:06
-
-
Save bg1bgst333/685740140ea3b0db25a20ea3588d0399 to your computer and use it in GitHub Desktop.
CMenu::AppendMenu
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 <stdio.h> // C標準入出力 | |
// 独自のヘッダ | |
#include "MainWindow.h" // CMainWindow | |
#include "resource.h" | |
// ウィンドウクラス登録関数RegisterClass. | |
BOOL CMainWindow::RegisterClass(HINSTANCE hInstance){ | |
// ウィンドウクラス名は"CMainWindow". | |
return CWindow::RegisterClass(hInstance, _T("CMainWindow")); // CWindow::RegisterClassでウィンドウクラス名"CMainWindow"を登録. | |
} | |
// ウィンドウクラス登録関数RegisterClass.(メニュー名指定バージョン) | |
BOOL CMainWindow::RegisterClass(HINSTANCE hInstance, LPCTSTR lpctszMenuName){ | |
// メニュー名はlpctszMenuName. | |
return CWindow::RegisterClass(hInstance, _T("CMainWindow"), lpctszMenuName); // CWindow::RegisterClassで, ウィンドウクラス名"CMainWindow", メニュー名lpctszMenuNameを登録. | |
} | |
// コンストラクタCMainWindow() | |
CMainWindow::CMainWindow(){ | |
// メンバの初期化. | |
m_pMainMenu = NULL; | |
} | |
// デストラクタ~CMainWindow() | |
CMainWindow::~CMainWindow(){ | |
// メンバの終了処理. | |
Destroy(); // Destroyで子ウィンドウの破棄. | |
} | |
// ウィンドウ作成関数Create.(ウィンドウクラス名省略バージョン.) | |
BOOL CMainWindow::Create(LPCTSTR lpctszWindowName, DWORD dwStyle, int x, int y, int iWidth, int iHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance){ | |
// ウィンドウクラス名は"CMainWindow". | |
return CWindow::Create(_T("CMainWindow"), lpctszWindowName, dwStyle, x, y, iWidth, iHeight, hWndParent, hMenu, hInstance); // CWindow::Createにウィンドウクラス名"CMainWindow"を指定. | |
} | |
// ウィンドウ破棄関数Destroy | |
BOOL CMainWindow::Destroy(){ | |
// 変数の初期化. | |
BOOL bRet = FALSE; // bRetをFALSEで初期化. | |
// DestroyChildrenを分けたので, 自身のウィンドウ破棄は問題ない. | |
// まず子ウィンドウの破棄. | |
DestroyChildren(); | |
// 自身のウィンドウ破棄. | |
bRet = CWindow::Destroy(); // 戻り値をbRetに格納. | |
// bRetを返す. | |
return bRet; | |
} | |
// 子ウィンドウ破棄関数DestroyChildren | |
BOOL CMainWindow::DestroyChildren(){ | |
// 変数の初期化. | |
BOOL bRet = FALSE; // bRetをFALSEで初期化. | |
// 破棄したらTRUEを返す. | |
if (bRet) { // TRUEなら. | |
return TRUE; // TRUEを返す. | |
} | |
// 破棄しなければ, CWindowのDestroyChildrenを返す. | |
return CWindow::DestroyChildren(); // CWindow::DestroyChildrenを返す. | |
} | |
// ウィンドウの作成が開始された時. | |
int CMainWindow::OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct){ | |
// 親クラスのOnCreateを呼ぶ. | |
int iRet = CWindow::OnCreate(hwnd, lpCreateStruct); // CWindow::OnCreateを呼び, 戻り値をiRetに格納. | |
m_pMainMenu = GetMenu(); // CWindow::GetMenuでm_pMainMenu取得. | |
if (m_pMainMenu != NULL){ // あった場合. | |
CMenu *pSubMenu0 = m_pMainMenu->GetSubMenu(0); // 0番目のサブメニュー取得. | |
if (pSubMenu0 != NULL){ // あった場合. | |
pSubMenu0->AppendMenu(MF_STRING, ID_ITEM_1_2, _T("Item1-2(&C)")); // Item1-2追加. | |
} | |
} | |
return iRet; // iRetを返す. | |
} | |
// ウィンドウが破棄された時. | |
void CMainWindow::OnDestroy(){ | |
// メニューの終了処理. | |
CMenu::DeleteMenuHandleMap(); | |
m_pMainMenu = NULL; | |
// CWindowのOnDestroyを呼ぶ. | |
CWindow::OnDestroy(); // CWindow::OnDestroyを呼ぶ. | |
} | |
// ウィンドウのサイズが変更された時. | |
void CMainWindow::OnSize(UINT nType, int cx, int cy){ | |
} | |
// ウィンドウが閉じられる時. | |
int CMainWindow::OnClose(){ | |
// メッセージボックスで"Close CMainWindow OK?"と表示. | |
int iRet = MessageBox(m_hWnd, _T("Close CMainWindow OK?"), _T("CMenu"), MB_OKCANCEL); // MessageBoxで"Close CMainWindow OK?"と表示し, 戻り値をiRetに格納. | |
if (iRet != IDOK){ // OK以外.(Cancelなど.) | |
return -1; // -1を返す. | |
} | |
// このウィンドウの破棄.(OnCloseの後, ウィンドウの破棄処理が勝手に行われるので, Destroyは不要なのでコメントアウト.) | |
//Destroy(); // Destroyでこのウィンドウの破棄処理. | |
// OKなので閉じる. | |
return CWindow::OnClose(); // 親クラスのOnCloseを呼ぶ.(親クラスのOnCloseは常に閉じる処理になっている.) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment