📄 cdlgopenfile.cpp
字号:
// $Id: CDlgOpenFile.cpp,v 1.22 2005/04/22 23:48:20 genta Exp $
/*! @file
@brief ファイルオープンダイアログボックス
@author Norio Nakatani
@date 1998/08/10 作成
$Revision: 1.22 $
*/
/*
Copyright (C) 1998-2001, Norio Nakatani
This source code is designed for sakura editor.
Please contact the copyright holder to use this code for other purpose.
*/
#include "CDlgOpenFile.h"
#include "debug.h"
#include "sakura_rc.h"
#include "etc_uty.h"
#include "global.h"
#include "funccode.h" //Stonee, 2001/05/18
#include "MY_SP.h" // Jun. 23, 2002 genta
#include "CFileExt.h"
#include "my_icmp.h"
// オープンファイル CDlgOpenFile.cpp //@@@ 2002.01.07 add start MIK
#include "sakura.hh"
static const DWORD p_helpids[] = { //13100
// IDOK, HIDOK_OPENDLG, //Winのヘルプで勝手に出てくる
// IDCANCEL, HIDCANCEL_OPENDLG, //Winのヘルプで勝手に出てくる
// IDC_BUTTON_HELP, HIDC_OPENDLG_BUTTON_HELP, //ヘルプボタン
IDC_COMBO_CODE, HIDC_OPENDLG_COMBO_CODE, //文字コードセット
IDC_COMBO_MRU, HIDC_OPENDLG_COMBO_MRU, //最近のファイル
IDC_COMBO_OPENFOLDER, HIDC_OPENDLG_COMBO_OPENFOLDER, //最近のフォルダ
IDC_COMBO_EOL, HIDC_OPENDLG_COMBO_EOL, //改行コード
// IDC_STATIC, -1,
0, 0
}; //@@@ 2002.01.07 add end MIK
#ifndef OFN_ENABLESIZING
#define OFN_ENABLESIZING 0x00800000
#endif
WNDPROC m_wpOpenDialogProc;
const char** m_ppszMRU;
const char** m_ppszOPENFOLDER;
char m_szHelpFile[_MAX_PATH + 1];
int m_nHelpTopicID;
BOOL m_bReadOnly; /* 読み取り専用か */
BOOL m_bIsSaveDialog; /* 保存のダイアログか */
/*
|| 開くダイアログのサブクラスプロシージャ
@date 2002.2.17 YAZAKI CShareDataのインスタンスは、CProcessにひとつあるのみ。
*/
LRESULT APIENTRY OFNHookProcMain( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
// WPARAM wCtlFocus; /* フォーカスを持つコントロールのID */
// BOOL fHandle; /* wParamが処理するフラグ */
int idCtrl;
OFNOTIFY* pofn;
// int nIdx;
// char* pszWork;
WORD wNotifyCode;
WORD wID;
HWND hwndCtl;
// HWND hwndFrame;
static DLLSHAREDATA* pShareData;
switch( uMsg ){
case WM_MOVE:
/* 「開く」ダイアログのサイズと位置 */
pShareData = CShareData::getInstance()->GetShareData();
::GetWindowRect( hwnd, &pShareData->m_Common.m_rcOpenDialog );
// MYTRACE( "WM_MOVE 1\n" );
break;
case WM_COMMAND:
wNotifyCode = HIWORD(wParam); // notification code
wID = LOWORD(wParam); // item, control, or accelerator identifier
hwndCtl = (HWND) lParam; // handle of control
switch( wNotifyCode ){
// break;
/* ボタン/チェックボックスがクリックされた */
case BN_CLICKED:
switch( wID ){
case pshHelp:
/* ヘルプ */
::WinHelp( hwnd, m_szHelpFile, HELP_CONTEXT, m_nHelpTopicID );
break;
case chx1: // The read-only check box
m_bReadOnly = ::IsDlgButtonChecked( hwnd , chx1 );
break;
}
break;
}
break;
case WM_NOTIFY:
idCtrl = (int) wParam;
pofn = (OFNOTIFY*) lParam;
// MYTRACE( "=========WM_NOTIFY=========\n" );
// MYTRACE( "pofn->hdr.hwndFrom=%xh\n", pofn->hdr.hwndFrom );
// MYTRACE( "pofn->hdr.idFrom=%xh(%d)\n", pofn->hdr.idFrom, pofn->hdr.idFrom );
// MYTRACE( "pofn->hdr.code=%xh(%d)\n", pofn->hdr.code, pofn->hdr.code );
break;
}
// return ::CallWindowProc( (int (__stdcall *)( void ))(WNDPROC)m_wpOpenDialogProc, hwnd, uMsg, wParam, lParam );
return ::CallWindowProc( (WNDPROC)m_wpOpenDialogProc, hwnd, uMsg, wParam, lParam );
}
/*!
開くダイアログのフックプロシージャ
*/
// Modified by KEITA for WIN64 2003.9.6
// APIENTRY -> CALLBACK Moca 2003.09.09
//UINT APIENTRY OFNHookProc(
UINT_PTR CALLBACK OFNHookProc(
HWND hdlg, // handle to child dialog window
UINT uiMsg, // message identifier
WPARAM wParam, // message parameter
LPARAM lParam // message parameter
)
{
HFONT hFont;
POINT po;
// RECT rc0;
RECT rc;
static HWND hwndEdit1;
static HWND hwndExplororList;
static OPENFILENAME* pOf;
static HWND hwndOpenDlg;
static HWND hwndComboMRU;
static HWND hwndComboOPENFOLDER;
static HWND hwndComboCODES;
static HWND hwndComboEOL; // Feb. 9, 2001 genta
static HWND hwndCheckBOM; // Jul. 26, 2003 ryoji BOMチェックボックス
static CDlgOpenFile* pcDlgOpenFile;
int i;
OFNOTIFY* pofn;
int idCtrl;
// HWND hwndCtrl;
char szFolder[_MAX_PATH];
LRESULT lRes;
const int nExtraSize = 100;
const int nControls = 9;
char szWork[_MAX_PATH + 1];
WORD wNotifyCode;
WORD wID;
HWND hwndCtl;
int nIdx;
int nIdxSel;
int fwSizeType;
int nWidth;
int nHeight;
WPARAM fCheck; // Jul. 26, 2003 ryoji BOM状態用
// From Here Feb. 9, 2001 genta
const int nEolValueArr[] = {
EOL_NONE,
EOL_CRLF,
EOL_LF,
EOL_CR,
};
// 文字列はResource内に入れる
const char* const pEolNameArr[] = {
"変換なし",
"CR+LF",
"LF (UNIX)",
"CR (Mac)",
};
int nEolNameArrNum = (int) (sizeof( pEolNameArr ) / sizeof( pEolNameArr[0] ) );
// To Here Feb. 9, 2001 genta
int Controls[nControls] = {
stc3, stc2, // The two label controls
edt1, cmb1, // The edit control and the drop-down box
IDOK, IDCANCEL,
pshHelp, // The Help command button (push button)
lst1, // The Explorer window
chx1 // The read-only check box
};
int nRightMargin = 24;
HWND hwndFrame;
switch( uiMsg ){
case WM_MOVE:
// MYTRACE( "WM_MOVE 2\n" );
break;
case WM_SIZE:
fwSizeType = wParam; // resizing flag
nWidth = LOWORD(lParam); // width of client area
nHeight = HIWORD(lParam); // height of client area
/* 「開く」ダイアログのサイズと位置 */
hwndFrame = ::GetParent( hdlg );
::GetWindowRect( hwndFrame, &pcDlgOpenFile->m_pShareData->m_Common.m_rcOpenDialog );
::GetWindowRect( hwndEdit1, &rc );
po.x = rc.left;
po.y = rc.top;
::ScreenToClient( hwndOpenDlg, &po );
// ::GetWindowRect( hwndExplororList, &rc2 );
// po2.x = rc2.right;
// po2.y = rc2.bottom;
// ::ScreenToClient( hwndOpenDlg, &po2 );
::SetWindowPos( hwndComboMRU, 0, 0, 0, nWidth - po.x - nRightMargin, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER );
::SetWindowPos( hwndComboOPENFOLDER, 0, 0, 0, nWidth - po.x - nRightMargin, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER );
return 0;
case WM_INITDIALOG:
// Save off the long pointer to the OPENFILENAME structure.
// Modified by KEITA for WIN64 2003.9.6
::SetWindowLongPtr(hdlg, DWLP_USER, lParam);
pOf = (OPENFILENAME*)lParam;
pcDlgOpenFile = (CDlgOpenFile*)pOf->lCustData;
/* Explorerスタイルの「開く」ダイアログのハンドル */
hwndOpenDlg = ::GetParent( hdlg );
/* コントロールのハンドル */
hwndComboCODES = ::GetDlgItem( hdlg, IDC_COMBO_CODE );
hwndComboMRU = ::GetDlgItem( hdlg, IDC_COMBO_MRU );
hwndComboOPENFOLDER = ::GetDlgItem( hdlg, IDC_COMBO_OPENFOLDER );
hwndComboEOL = ::GetDlgItem( hdlg, IDC_COMBO_EOL );
hwndCheckBOM = ::GetDlgItem( hdlg, IDC_CHECK_BOM );// Jul. 26, 2003 ryoji BOMチェックボックス
/* コンボボックスのユーザー インターフェイスを拡張インターフェースにする */
::SendMessage( hwndComboCODES, CB_SETEXTENDEDUI, (WPARAM) (BOOL) TRUE, 0 );
::SendMessage( hwndComboMRU, CB_SETEXTENDEDUI, (WPARAM) (BOOL) TRUE, 0 );
::SendMessage( hwndComboOPENFOLDER, CB_SETEXTENDEDUI, (WPARAM) (BOOL) TRUE, 0 );
::SendMessage( hwndComboEOL, CB_SETEXTENDEDUI, (WPARAM) (BOOL) TRUE, 0 );
// From Here Feb. 9, 2001 genta
// 改行コードの選択コンボボックス初期化
// 必要なときのみ利用する
if( pcDlgOpenFile->m_bUseEol ){
// 値の設定
for( i = 0; i < nEolNameArrNum; ++i ){
nIdx = ::SendMessage( hwndComboEOL, CB_ADDSTRING, 0, (LPARAM)pEolNameArr[i] );
::SendMessage( hwndComboEOL, CB_SETITEMDATA, nIdx, nEolValueArr[i] );
}
// 使うときは先頭の要素を選択状態にする
::SendMessage( hwndComboEOL, CB_SETCURSEL, (WPARAM)0, 0 );
}
else {
// 使わないときは隠す
::ShowWindow( ::GetDlgItem( hdlg, IDC_STATIC_EOL ), SW_HIDE );
::ShowWindow( hwndComboEOL, SW_HIDE );
}
// To Here Feb. 9, 2001 genta
// From Here Jul. 26, 2003 ryoji BOMチェックボックスの初期化
if( pcDlgOpenFile->m_bUseBom ){
// 使うときは有効/無効を切り替え、チェック状態を初期値に設定する
switch( pcDlgOpenFile->m_nCharCode ){
case CODE_UNICODE:
case CODE_UTF8:
case CODE_UNICODEBE:
::EnableWindow( hwndCheckBOM, TRUE );
fCheck = pcDlgOpenFile->m_bBom? BST_CHECKED: BST_UNCHECKED;
break;
default:
::EnableWindow( hwndCheckBOM, FALSE );
fCheck = BST_UNCHECKED;
break;
}
::SendMessage( hwndCheckBOM, BM_SETCHECK, fCheck, 0 );
}
else {
// 使わないときは隠す
::ShowWindow( hwndCheckBOM, SW_HIDE );
}
// To Here Jul. 26, 2003 ryoji BOMチェックボックスの初期化
/* Explorerスタイルの「開く」ダイアログをフック */
// Modified by KEITA for WIN64 2003.9.6
m_wpOpenDialogProc = (WNDPROC) ::SetWindowLongPtr( hwndOpenDlg, GWLP_WNDPROC, (LONG_PTR) OFNHookProcMain );
// /* Explorerスタイルの「開く」ダイアログのスタイル */
// lStyle = ::GetWindowLong( hwndOpenDlg, GWL_STYLE );
// if( lStyle & WS_BORDER ) lStyle = WS_BORDER;
// if( lStyle & WS_DLGFRAME ) lStyle = WS_DLGFRAME;
// if( lStyle & WS_SYSMENU ) lStyle = WS_SYSMENU;
// ::SetWindowLong( hwndOpenDlg, GWL_STYLE, lStyle );
// lStyle = ::GetWindowLong( hwndOpenDlg, GWL_EXSTYLE );
// lStyle =~ WS_EX_DLGMODALFRAME;
// ::SetWindowLong( hwndOpenDlg, GWL_EXSTYLE, lStyle );
/* 文字コード選択コンボボックス初期化 */
nIdxSel = 0;
if( m_bIsSaveDialog ){ /* 保存のダイアログか */
i = 1;
}else{
i = 0;
}
for( /*i = 0*/; i < gm_nCodeComboNameArrNum; ++i ){
nIdx = ::SendMessage( hwndComboCODES, CB_ADDSTRING, 0, (LPARAM)gm_pszCodeComboNameArr[i] );
::SendMessage( hwndComboCODES, CB_SETITEMDATA, nIdx, gm_nCodeComboValueArr[i] );
if( gm_nCodeComboValueArr[i] == pcDlgOpenFile->m_nCharCode ){
nIdxSel = nIdx;
}
}
::SendMessage( hwndComboCODES, CB_SETCURSEL, (WPARAM)nIdxSel, 0 );
// ::GetWindowRect( hwndOpenDlg, &rc0 );
// for( i = 0; i < nControls; ++i ){
// hwndCtrl = ::GetDlgItem( hwndOpenDlg, Controls[i] );
// ::GetWindowRect( hwndCtrl, &rc );
// po.x = rc.left;
// po.y = rc.top;
// ::ScreenToClient( hwndOpenDlg, &po );
// rc.left = po.x;
// rc.top = po.y;
// po.x = rc.right;
// po.y = rc.bottom;
// ::ScreenToClient( hwndOpenDlg, &po );
// rc.right = po.x;
// rc.bottom = po.y;
// if( Controls[i] != lst1 ){
// ::SetWindowPos( hwndCtrl, NULL, rc.left, rc.top + nExtraSize, 0, 0, SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOZORDER );
// }else{
// ::SetWindowPos( hwndCtrl, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top + nExtraSize, SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER );
// }
// }
// ::SetWindowPos(
// hwndOpenDlg,
// HWND_TOP,
// 0, 0,
// rc0.right - rc0.left,
// (rc0.bottom - rc0.top)+ nExtraSize,
// SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER
// );
/* 読み取り専用の初期値セット */
hwndEdit1 = ::GetDlgItem( hwndOpenDlg, edt1 );
hwndExplororList = ::GetDlgItem( hwndOpenDlg, lst1 );
::CheckDlgButton( hwndOpenDlg, chx1, m_bReadOnly );
// ::ShowWindow( hwndEdit1, SW_HIDE );
::GetWindowRect( hwndEdit1, &rc );
po.x = rc.left;
po.y = rc.top;
::ScreenToClient( hwndOpenDlg, &po );
rc.left = po.x;
rc.top = po.y;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -