Created
December 11, 2025 06:46
-
-
Save bg1bgst333/a53500f20fd99ab8cce4b353991dc696 to your computer and use it in GitHub Desktop.
CCustomControl::OnSize
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 "CustomControl.h" // CCustomControl | |
| // staticメンバ変数の定義 | |
| std::map<tstring, WNDPROC> CCustomControl::m_mapBaseWindowProcMap; // ベースウィンドウプロシージャマップm_mapBaseWindowProcMap | |
| // コンストラクタCCustomControl | |
| CCustomControl::CCustomControl() : CWindow() { | |
| } | |
| // デストラクタ~CCustomControl | |
| CCustomControl::~CCustomControl() { | |
| } | |
| // スタティックウィンドウプロシージャStaticWindowProc. | |
| LRESULT CALLBACK CCustomControl::StaticWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { | |
| // ポインタの初期化 | |
| CWindow* pWindow = NULL; // CWindowオブジェクトポインタpWindowをNULLに初期化. | |
| // hwndでCWindowオブジェクトポインタが引けたら, pWindowに格納. | |
| if (m_mapWindowMap.find(hwnd) != m_mapWindowMap.end()) { // findでキーをhwndとするCWindowオブジェクトポインタが見つかったら. | |
| pWindow = m_mapWindowMap[hwnd]; // pWindowにhwndで引けるCWindowオブジェクトポインタを格納. | |
| } | |
| // ウィンドウオブジェクトを取得できない場合. | |
| if (pWindow == NULL) { // pWindowがNULLの時. | |
| // 配列の初期化 | |
| TCHAR tszClassName[256] = { 0 }; // tszClassNameを0で初期化. | |
| // ウィンドウハンドルからウィンドウクラス名を取得. | |
| GetClassName(hwnd, tszClassName, 256); // GetClassNameでウィンドウクラス名を取得. | |
| // tszClassNameがm_mapBaseWindowProcMapのキーにあれば. | |
| if (m_mapBaseWindowProcMap.find(tszClassName) != m_mapBaseWindowProcMap.end()) { // みつかったら. | |
| // 既定のプロシージャに任せる. | |
| return CallWindowProc(m_mapBaseWindowProcMap[tszClassName], hwnd, uMsg, wParam, lParam); // CallWindowProcで, このメッセージをm_mapBaseWindowProcMap[tszClassName]に任せる. | |
| } | |
| else { // 無い場合. | |
| // そうでないなら, DefWindowProcに任せる. | |
| return DefWindowProc(hwnd, uMsg, wParam, lParam); // DefWindowProcの値を返す. | |
| } | |
| } | |
| else { // pWindowがあった場合. | |
| // そのウィンドウのDynamicWindowProcに任せる. | |
| return pWindow->DynamicWindowProc(hwnd, uMsg, wParam, lParam); // pWindow->DynamicWindowProcに渡す. | |
| } | |
| } | |
| // ウィンドウ作成関数Create. | |
| BOOL CCustomControl::Create(LPCTSTR lpctszClassName, LPCTSTR lpctszWindowName, DWORD dwStyle, int x, int y, int iWidth, int iHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance) { | |
| // ウィンドウクラス名にはlpctszClassNameを指定. | |
| BOOL bRet = CWindow::Create(lpctszClassName, lpctszWindowName, dwStyle | WS_CHILD | WS_VISIBLE, x, y, iWidth, iHeight, hWndParent, hMenu, hInstance); // CWindow::Createにウィンドウクラス名lpctszClassNameを指定. | |
| if (bRet) { // bRetがTRUE. | |
| // 既定のウィンドウプロシージャを取得し, CCustomControl::StaticWindowProcに差し替える. | |
| WNDPROC lpfnWndProc; // 既定のプロシージャlpfnWndProc | |
| lpfnWndProc = (WNDPROC)GetWindowLong(m_hWnd, GWL_WNDPROC); // GetWindowLongでプロシージャlpfnWndProcを取得. | |
| SetWindowLong(m_hWnd, GWL_WNDPROC, (LONG)StaticWindowProc); // SetWindowLongでプロシージャCCustomControl::StaticWindowProcを設定. | |
| // OnCreateは以降は呼ばれないので, ここで呼んでおく. | |
| CREATESTRUCT cs; // CREATESTRUCTを一応用意. | |
| cs.hInstance = hInstance; // hInstanceは要るかもしれないので, これは渡せるようにしておく. | |
| if (OnCreate(m_hWnd, &cs) != 0) { // OnCreateにm_hWndとcsを渡す. | |
| // 戻り値が0でない場合, 破棄. | |
| Destroy(); // Destroyで破棄. | |
| return FALSE; // FALSEを返す. | |
| } | |
| // マップのキーにウィンドウクラス名がなければ登録. | |
| if (m_mapBaseWindowProcMap.find(lpctszClassName) == m_mapBaseWindowProcMap.end()) { // マップに無い時. | |
| m_mapBaseWindowProcMap.insert(std::pair<LPCTSTR, WNDPROC>(lpctszClassName, lpfnWndProc)); // プロシージャを登録. | |
| } | |
| // WM_CREATEを通らないので, ウィンドウマップの登録も行う. | |
| if (m_mapWindowMap.find(m_hWnd) == m_mapWindowMap.end()) { // ウィンドウマップになければ. | |
| m_mapWindowMap.insert(std::pair<HWND, CWindow*>(m_hWnd, this)); // 登録する. | |
| } | |
| } | |
| return bRet; // bRetを返す. | |
| } | |
| // ウィンドウ作成関数Create(RECTバージョン). | |
| BOOL CCustomControl::Create(LPCTSTR lpctszClassName, LPCTSTR lpctszWindowName, DWORD dwStyle, const RECT& rect, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance) { | |
| // RECTで指定されたサイズをx, y, iWidth, iHeightに変換. | |
| return CCustomControl::Create(lpctszClassName, lpctszWindowName, dwStyle, rect.left, rect.top, rect.right - rect.left + 1, rect.bottom - rect.top + 1, hWndParent, hMenu, hInstance); // CCustomControl::Createでカスタムコントロールのウィンドウ作成. | |
| } | |
| // ウィンドウ破棄関数Destroy | |
| BOOL CCustomControl::Destroy() { | |
| // 親クラスのDestroyを呼ぶ. | |
| return CWindow::Destroy(); // CWindow::Destroyを呼ぶ. | |
| } | |
| // ダイナミックウィンドウプロシージャDynamicWindowProc. | |
| LRESULT CCustomControl::DynamicWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { | |
| // ウィンドウメッセージの処理 | |
| switch (uMsg) { // uMsgの値ごとに処理を振り分ける. | |
| // ウィンドウが破棄された時. | |
| case WM_DESTROY: | |
| // WM_DESTROYブロック | |
| { | |
| // OnDestroyに任せる. | |
| OnDestroy(); // OnDestroyを呼ぶ. | |
| } | |
| // 既定の処理へ向かう. | |
| break; // breakで抜けて, 既定の処理へ向かう. | |
| // ウィンドウのサイズが変更された時. | |
| case WM_SIZE: | |
| // WM_SIZEブロック | |
| { | |
| // OnSizeに任せる. | |
| OnSize((UINT)wParam, LOWORD(lParam), HIWORD(lParam)); // OnSizeに任せる. | |
| } | |
| // 既定の処理へ向かう. | |
| break; // breakで抜けて, 既定の処理(DefWindowProc)へ向かう. | |
| // ウィンドウの描画を要求された時. | |
| case WM_PAINT: | |
| // WM_PAINTブロック | |
| { | |
| // OnPaintに任せる. | |
| OnPaint(); // OnPaintを呼ぶ. | |
| } | |
| // 既定の処理へ向かう. | |
| break; // breakで抜けて, 既定の処理(DefWindowProc)へ向かう. | |
| // 垂直スクロールバーがスクロールされた時. | |
| case WM_VSCROLL: // 垂直スクロールバーがスクロールされた時.(uMsgがWM_VSCROLLの時.) | |
| // WM_VSCROLLブロック | |
| { | |
| // OnVScrollに任せる. | |
| OnVScroll(LOWORD(wParam), HIWORD(wParam)); // OnVScrollに任せる. | |
| } | |
| // 既定の処理へ向かう. | |
| break; // breakで抜けて, 既定の処理(DefWindowProc)へ向かう. | |
| // それ以外の時. | |
| default: | |
| // defaultブロック | |
| { | |
| } | |
| // 既定の処理へ向かう. | |
| break; // breakで抜けて, 既定の処理へ向かう. | |
| } | |
| // 配列の初期化 | |
| TCHAR tszClassName[256] = { 0 }; // tszClassNameを0で初期化. | |
| // ウィンドウハンドルからウィンドウクラス名を取得. | |
| GetClassName(hwnd, tszClassName, 256); // GetClassNameでウィンドウクラス名を取得. | |
| // tszClassNameがm_mapBaseWindowProcMapのキーにあれば. | |
| if (m_mapBaseWindowProcMap.find(tszClassName) != m_mapBaseWindowProcMap.end()) { // みつかったら. | |
| // 既定のプロシージャに任せる. | |
| return CallWindowProc(m_mapBaseWindowProcMap[tszClassName], hwnd, uMsg, wParam, lParam); // CallWindowProcで, このメッセージをm_mapBaseWindowProcMap[tszClassName]に任せる. | |
| } | |
| else { // 無い場合. | |
| // そうでないなら, DefWindowProcに任せる. | |
| return DefWindowProc(hwnd, uMsg, wParam, lParam); // DefWindowProcの値を返す. | |
| } | |
| } | |
| // ウィンドウの作成が開始された時. | |
| int CCustomControl::OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct) { | |
| // 常にウィンドウ作成に成功するものとする. | |
| return 0; // 0を返すと, ウィンドウ作成に成功したということになる. | |
| } | |
| // ウィンドウが破棄された時. | |
| void CCustomControl::OnDestroy() { | |
| // 自分のウィンドウハンドルが残っていたらマップから削除. | |
| if (m_mapWindowMap.find(m_hWnd) != m_mapWindowMap.end()) { // findでみつかったら. | |
| m_mapWindowMap.erase(m_hWnd); // m_mapWindowMap.eraseで削除. | |
| } | |
| } | |
| // ウィンドウのサイズが変更された時. | |
| void CCustomControl::OnSize(UINT nType, int cx, int cy) { | |
| } | |
| // ウィンドウの描画を要求された時. | |
| void CCustomControl::OnPaint() { | |
| // 変数の宣言. | |
| //HDC hDC; // デバイスコンテキストハンドルhDC. | |
| //PAINTSTRUCT ps; // PAINTSTRUCT構造体ps. | |
| // 文字列の描画. | |
| //hDC = BeginPaint(m_hWnd, &ps); // Win32APIのBeginPaintでhDCを取得. | |
| //TextOut(hDC, 0, 0, _T("CCustomControl"), (int)_tcslen(_T("CCustomControl"))); // Win32APIのTextOutで"CCustomControl"と描画. | |
| //EndPaint(m_hWnd, &ps); // Win32APIのEndPaintで描画終了. | |
| } | |
| // 垂直方向スクロールバーイベント時. | |
| void CCustomControl::OnVScroll(UINT nSBCode, UINT nPos) { | |
| } |
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 "EncodingComboBox.h" | |
| // ウィンドウのサイズが変更された時. | |
| void CEncodingComboBox::OnSize(UINT nType, int cx, int cy) { | |
| // 親ウィンドウの既定処理. | |
| CCustomControl::OnSize(nType, cx, cy); // CCustomControl::OnSizeを呼ぶ. | |
| // ウィンドウサイズの取得. | |
| RECT rc = { 0 }; | |
| GetWindowRect(m_hWnd, &rc); | |
| int iWidth = rc.right - rc.left; | |
| int iHeight = rc.bottom - rc.top; | |
| // UM_SIZECHILDを投げる. | |
| WPARAM wParam; | |
| wParam = MAKEWPARAM(iWidth, iHeight); | |
| SendMessage(GetParent(m_hWnd), UM_SIZECHILD, wParam, (LPARAM)m_hWnd); | |
| } |
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 <windows.h> // 標準WindowsAPI | |
| #include <stdio.h> // C標準入出力 | |
| #include <commctrl.h> // コモンコントロール | |
| // 独自のヘッダ | |
| #include "MainWindow.h" // CMainWindow | |
| #include "FileDialog.h" // CFileDialog | |
| #include "CustomEdit.h" // CCustomEdit | |
| #include "EncodingComboBox.h" // CEncodingComboBox | |
| #include "EditCore.h" // CEditCore | |
| #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_hInstance = NULL; | |
| m_pMainMenu = NULL; | |
| m_pMultiView = NULL; | |
| m_pTextFile = NULL; // m_pTextFileを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"を指定. | |
| } | |
| // ウィンドウ作成関数CreateEx. | |
| BOOL CMainWindow::CreateEx(DWORD dwExStyle, LPCTSTR lpctszWindowName, DWORD dwStyle, int x, int y, int iWidth, int iHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance) { | |
| // ウィンドウクラス名は"CMainWindow". | |
| return CWindow::CreateEx(dwExStyle, _T("CMainWindow"), lpctszWindowName, dwStyle, x, y, iWidth, iHeight, hWndParent, hMenu, hInstance); // CWindow::CreateExにウィンドウクラス名"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で初期化. | |
| // テキストファイルオブジェクトの破棄. | |
| if (m_pTextFile != NULL) { // m_pTextFileがNULLでなければ. | |
| delete m_pTextFile; // deleteでm_pTextFileを解放. | |
| m_pTextFile = NULL; // m_pTextFileにNULLをセット. | |
| } | |
| // メンバの終了処理. | |
| if (m_pMultiView != NULL) { | |
| bRet = m_pMultiView->Destroy(); | |
| delete m_pMultiView; | |
| m_pMultiView = NULL; | |
| } | |
| // 破棄したらTRUEを返す. | |
| if (bRet) { // TRUEなら. | |
| return TRUE; // TRUEを返す. | |
| } | |
| // 破棄しなければ, CWindowのDestroyChildrenを返す. | |
| return CWindow::DestroyChildren(); // CWindow::DestroyChildrenを返す. | |
| } | |
| // ウィンドウの作成が開始された時. | |
| int CMainWindow::OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct) { | |
| // 親クラスのOnCreateを呼ぶ. | |
| m_hInstance = lpCreateStruct->hInstance; | |
| int iRet = CWindow::OnCreate(hwnd, lpCreateStruct); // CWindow::OnCreateを呼び, 戻り値をiRetに格納. | |
| m_pMainMenu = GetMenu(); // CWindow::GetMenuでm_pMainMenu取得. | |
| if (m_pMainMenu == NULL) { // メニューハンドルが無い場合は, m_pMainMenuがNULLになる. | |
| m_pMainMenu = new CMenu(); | |
| BOOL bRet = m_pMainMenu->LoadMenu(lpCreateStruct->hInstance, IDM_MAINMENU); | |
| if (bRet) { | |
| SetMenu(m_pMainMenu); | |
| AddCommandHandler(ID_ITEM_FILE_OPEN, 0, (int(CWindow::*)(WPARAM, LPARAM)) & CMainWindow::OnFileOpen); | |
| // CMultiViewの生成. | |
| RECT rc = { 0 }; | |
| GetClientRect(hwnd, &rc); | |
| m_pMultiView = new CMultiView(); | |
| m_pMultiView->Create(_T(""), 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top, hwnd, (HMENU)IDC_MULTIVIEW, m_hInstance); | |
| } | |
| } | |
| return iRet; // iRetを返す. | |
| } | |
| // ウィンドウが破棄された時. | |
| void CMainWindow::OnDestroy() { | |
| // メニューハンドラの削除. | |
| DeleteCommandHandler(ID_ITEM_FILE_OPEN, 0); | |
| // メニューの終了処理. | |
| CMenu::DeleteMenuHandleMap(); | |
| m_pMainMenu = NULL; | |
| // CWindowのOnDestroyを呼ぶ. | |
| CWindow::OnDestroy(); // CWindow::OnDestroyを呼ぶ. | |
| } | |
| // ウィンドウのサイズが変更された時. | |
| void CMainWindow::OnSize(UINT nType, int cx, int cy) { | |
| // マルチビューをメインウィンドウのクライアント領域サイズにリサイズ. | |
| if (m_pMultiView != NULL) { | |
| m_pMultiView->MoveWindow(0, 0, cx, cy); | |
| CMultiViewItem* pItemEncodingComboBox = m_pMultiView->Get(0); | |
| if (pItemEncodingComboBox != NULL) { | |
| CComboBox* pEncodingComboBox = (CComboBox*)pItemEncodingComboBox->m_mapChildMap[_T("MVIEncodingComboBox-EncodingComboBox")]; | |
| pEncodingComboBox->MoveWindow(0, 0, cx, 25); | |
| } | |
| } | |
| } | |
| // ウィンドウが閉じられる時. | |
| int CMainWindow::OnClose() { | |
| // メッセージボックスで"Close CMainWindow OK?"と表示. | |
| int iRet = MessageBox(m_hWnd, _T("Close CMainWindow OK?"), _T("CCustomControl"), 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は常に閉じる処理になっている.) | |
| } | |
| // 開くが選択された時. | |
| int CMainWindow::OnFileOpen(WPARAM wParam, LPARAM lParam) { | |
| // "開く"ダイアログ | |
| CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("Text Files(*.txt)|*.txt|All Files(*.*)|*.*||")); | |
| INT_PTR ret = dlg.DoModal(); | |
| if (ret == IDOK) { | |
| if (dlg.GetFileExt() == _T("txt")) { | |
| // テキストファイルをロードする. | |
| // マルチビューアイテムの追加. | |
| RECT rc = { 0 }; | |
| GetClientRect(m_hWnd, &rc); | |
| m_pMultiView->Add(_T("MVIEncodingComboBox"), 0, 0, rc.right - rc.left, 25, m_hInstance); | |
| m_pMultiView->Add(_T("MVIBomComboBox"), 0, 25, rc.right - rc.left, 25, m_hInstance); | |
| m_pMultiView->Add(_T("MVIContentEditBox"), 0, 50, rc.right - rc.left, rc.bottom - rc.top - 75, m_hInstance); | |
| m_pMultiView->Add(_T("MVINewLineComboBox"), 0, rc.bottom - rc.top - 25, rc.right - rc.left, 25, m_hInstance); | |
| // マルチビューアイテム内にコントロールを配置. | |
| // 文字コードコンボボックス | |
| CMultiViewItem* pItemEncodingComboBox = m_pMultiView->Get(0); | |
| CComboBox* pEncodingComboBox = new CEncodingComboBox(); | |
| pEncodingComboBox->Create(_T("MVIEncodingComboBox-EncodingComboBox"), WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, 0, 0, rc.right - rc.left, 200, pItemEncodingComboBox->m_hWnd, (HMENU)WM_APP + 200, m_hInstance); | |
| pItemEncodingComboBox->m_mapChildMap.insert(std::make_pair(_T("MVIEncodingComboBox-EncodingComboBox"), pEncodingComboBox)); | |
| // BOMコンボボックス | |
| CMultiViewItem* pItemBomComboBox = m_pMultiView->Get(1); | |
| CComboBox* pBomComboBox = new CComboBox(); | |
| pBomComboBox->Create(_T("MVIBomComboBox-BomComboBox"), WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, 0, 0, rc.right - rc.left, 200, pItemBomComboBox->m_hWnd, (HMENU)WM_APP + 201, m_hInstance); | |
| pItemBomComboBox->m_mapChildMap.insert(std::make_pair(_T("MVIBomComboBox-BomComboBox"), pBomComboBox)); | |
| // コンテントエディットボックス | |
| CMultiViewItem* pItemContentEditBox = m_pMultiView->Get(2); | |
| CEditCore* pContentEditBox = new CEditCore(); | |
| pContentEditBox->Create(_T(""), WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL | WS_BORDER, 0, 0, rc.right - rc.left, rc.bottom - rc.top - 75, pItemContentEditBox->m_hWnd, (HMENU)WM_APP + 202, m_hInstance); | |
| // 改行コンボボックス | |
| CMultiViewItem* pItemNewLineComboBox = m_pMultiView->Get(3); | |
| CComboBox* pNewLineComboBox = new CComboBox(); | |
| pNewLineComboBox->Create(_T("MVINewLineComboBox-NewLineComboBox"), WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, 0, 0, rc.right - rc.left, 200, pItemNewLineComboBox->m_hWnd, (HMENU)WM_APP + 202, m_hInstance); | |
| pItemNewLineComboBox->m_mapChildMap.insert(std::make_pair(_T("MVINewLineComboBox-NewLineComboBox"), pNewLineComboBox)); | |
| // 文字コードコンボボックスに文字列アイテムを追加 | |
| pEncodingComboBox->AddString(_T("Shift_JIS")); | |
| pEncodingComboBox->AddString(_T("UTF-16LE")); | |
| pEncodingComboBox->AddString(_T("UTF-16BE")); | |
| pEncodingComboBox->AddString(_T("UTF-8")); | |
| pEncodingComboBox->AddString(_T("EUC-JP")); | |
| pEncodingComboBox->AddString(_T("JIS")); | |
| // BOMコンボボックスに文字列アイテムを追加 | |
| pBomComboBox->AddString(_T("UTF-16LE BOM")); | |
| pBomComboBox->AddString(_T("UTF-16BE BOM")); | |
| pBomComboBox->AddString(_T("UTF-8 BOM")); | |
| pBomComboBox->AddString(_T("なし")); | |
| // 改行コンボボックスに文字列アイテムを追加 | |
| pNewLineComboBox->AddString(_T("CRLF")); | |
| pNewLineComboBox->AddString(_T("LF")); | |
| pNewLineComboBox->AddString(_T("CR")); | |
| // テキストファイルの読み込み. | |
| if (m_pTextFile == NULL) { | |
| m_pTextFile = new CTextFile(); | |
| } | |
| BOOL bRet = m_pTextFile->Read(dlg.GetOFN().lpstrFile); // 指定されたファイルを読み込み, 読み込んだバイト列を文字コード変換し, テキストとして持つ. | |
| if (bRet) { // 成功. | |
| // 文字コード. | |
| if (m_pTextFile->m_Encoding == CTextFile::ENCODING_UTF_16LE) { | |
| pEncodingComboBox->SetCurSel(1); | |
| } | |
| else if (m_pTextFile->m_Encoding == CTextFile::ENCODING_UTF_16BE) { | |
| pEncodingComboBox->SetCurSel(2); | |
| } | |
| else if (m_pTextFile->m_Encoding == CTextFile::ENCODING_UTF_8) { | |
| pEncodingComboBox->SetCurSel(3); | |
| } | |
| else if (m_pTextFile->m_Encoding == CTextFile::ENCODING_SHIFT_JIS) { | |
| pEncodingComboBox->SetCurSel(0); | |
| } | |
| else if (m_pTextFile->m_Encoding == CTextFile::ENCODING_EUC_JP) { | |
| pEncodingComboBox->SetCurSel(4); | |
| } | |
| else { | |
| pEncodingComboBox->SetCurSel(5); | |
| } | |
| // BOM | |
| if (m_pTextFile->m_Bom == CTextFile::BOM_UTF16LE) { | |
| pBomComboBox->SetCurSel(0); | |
| } | |
| else if (m_pTextFile->m_Bom == CTextFile::BOM_UTF16BE) { | |
| pBomComboBox->SetCurSel(1); | |
| } | |
| else if (m_pTextFile->m_Bom == CTextFile::BOM_UTF8) { | |
| pBomComboBox->SetCurSel(2); | |
| } | |
| else { | |
| pBomComboBox->SetCurSel(3); | |
| } | |
| // ファイル内容 | |
| pContentEditBox->SetWindowText(m_pTextFile->m_tstrText.c_str()); | |
| // 改行 | |
| if (m_pTextFile->m_NewLine == CTextFile::NEW_LINE_CR) { | |
| pNewLineComboBox->SetCurSel(2); | |
| } | |
| else if (m_pTextFile->m_NewLine == CTextFile::NEW_LINE_LF) { | |
| pNewLineComboBox->SetCurSel(1); | |
| } | |
| else { | |
| pNewLineComboBox->SetCurSel(0); | |
| } | |
| } | |
| } | |
| } | |
| // 0を返す. | |
| return 0; // 処理したので0. | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment