Created
March 6, 2026 01:19
-
-
Save bg1bgst333/eb3c793074a52994a4a571eb44db8457 to your computer and use it in GitHub Desktop.
CGraphicalApplication::OnIdle
This file contains hidden or 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 "GraphicalApplication.h" // CGraphicalApplication | |
| // コンストラクタCGraphicalApplication | |
| CGraphicalApplication::CGraphicalApplication() : CApplication() { | |
| } | |
| // メッセージループ処理関数Run. | |
| int CGraphicalApplication::Run() { | |
| // 変数の初期化. | |
| MSG msg = { 0 }; // MSG型メッセージ構造体msgを{0}で初期化. | |
| int lCount = 0; // ウィンドウメッセージが来なかった時の回数を保持するint型変数lCountの初期値を0とする. | |
| // PeekMessageによるメインループ. | |
| while (TRUE) { // 常に真(TRUE)なので無限ループ. | |
| // メッセージループが来ていれば処理する. | |
| while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { | |
| // 0にリセット. | |
| lCount = 0; // lCountを0にリセット. | |
| // WM_QUITならExitInstanceを呼んで終了. | |
| if (msg.message == WM_QUIT) { | |
| return ExitInstance(); | |
| } | |
| // ウィンドウメッセージの送出 | |
| TranslateMessage(&msg); // TranslateMessageで仮想キーメッセージを文字メッセージへ変換. | |
| DispatchMessage(&msg); // DispatchMessageで受け取ったメッセージをウィンドウプロシージャ(この場合は独自に定義したWindowProc)に送出. | |
| } | |
| // アイドル処理 | |
| OnIdle(lCount++); | |
| Sleep(1); | |
| } | |
| } | |
| // 終了処理関数ExitInstance. | |
| int CGraphicalApplication::ExitInstance() { | |
| // 親クラスのExitInstanceを呼ぶ. | |
| return CApplication::ExitInstance(); | |
| } | |
| // アイドル処理関数OnIdle. | |
| BOOL CGraphicalApplication::OnIdle(LONG lCount) { | |
| // 画面の更新. | |
| if (m_pMainWnd != NULL) { // m_pMainWndがNULLでない時. | |
| if (m_pMainWnd->m_hWnd != NULL) { // m_pMainWnd->m_hWndがNULLでない時. | |
| HDC hDC = GetDC(m_pMainWnd->m_hWnd); | |
| TextOut(hDC, 50, 50, _T("ABCDE"), lstrlen(_T("ABCDE"))); | |
| ReleaseDC(m_pMainWnd->m_hWnd, hDC); | |
| } | |
| } | |
| // とりあえずTRUE. | |
| return TRUE; | |
| } |
This file contains hidden or 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
| // 二重インクルード防止 | |
| #ifndef __GRAPHICAL_APPLICATION_H__ | |
| #define __GRAPHICAL_APPLICATION_H__ | |
| // ヘッダのインクルード | |
| // 独自のヘッダ | |
| #include "Application.h" // CApplication | |
| // グラフィカルアプリケーションクラスCGraphicalApplication | |
| class CGraphicalApplication : public CApplication { | |
| // publicメンバ | |
| public: | |
| // publicメンバ関数 | |
| // コンストラクタ | |
| CGraphicalApplication(); // コンストラクタCGraphicalApplication | |
| virtual int Run(); // メッセージループ処理関数Run. | |
| virtual int ExitInstance(); // 終了処理関数ExitInstance. | |
| virtual BOOL OnIdle(LONG lCount); // アイドル処理関数OnIdle. | |
| }; | |
| #endif |
This file contains hidden or 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 "MainApplication.h" // CMainApplication | |
| #include "MainWindow.h" // CMainWindow | |
| // インスタンス初期化関数InitInstance. | |
| BOOL CMainApplication::InitInstance(HINSTANCE hInstance, LPTSTR lpCmdLine, int nShowCmd) { | |
| // ウィンドウクラスの登録. | |
| CMainWindow::RegisterClass(hInstance); | |
| // CMainWindowオブジェクトの作成. | |
| CMainWindow* pMainWnd = new CMainWindow(); // CMainWindowオブジェクトを作成し, pMainWndに格納. | |
| m_pMainWnd = pMainWnd; // pMainWndをm_pMainWndにもセット. | |
| // ウィンドウの作成. | |
| if (!pMainWnd->CreateEx(0, _T("CGraphicalApplication"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance)) { // m_pMainWnd->CreateExでウィンドウ作成し, 失敗した場合. | |
| // エラー処理 | |
| return FALSE; // returnでFALSEを返して異常終了. | |
| } | |
| // ウィンドウの表示. | |
| m_pMainWnd->ShowWindow(SW_SHOW); // m_pMainWnd->ShowWindowで表示. | |
| // TRUEを返す. | |
| return TRUE; // returnでTRUEを返す. | |
| } |
This file contains hidden or 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
| // 二重インクルード防止 | |
| #ifndef __MAIN_APPLICATION_H__ | |
| #define __MAIN_APPLICATION_H__ | |
| // ヘッダのインクルード | |
| // 独自のヘッダ | |
| #include "GraphicalApplication.h" // CGraphicalApplication | |
| // メインアプリケーションクラスCMainApplication | |
| class CMainApplication : public CGraphicalApplication { | |
| // publicメンバ | |
| public: | |
| // publicメンバ関数 | |
| virtual BOOL InitInstance(HINSTANCE hInstance, LPTSTR lpCmdLine, int nShowCmd); // インスタンス初期化関数InitInstance. | |
| }; | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment