📄 chprefs.cpp
字号:
{
string strTag;
LOADSTRING( IDS_TINTIN_NO_FILE, strTag );
pStatic->SetWindowText( strTag );
}
}
/*----------------------------------------------------------------------------
ChTextInPrefsPage message handlers
----------------------------------------------------------------------------*/
void ChTextInPrefsPage::OnUpdateEditLineCount()
{
string strNewText;
const char* pstrOld;
m_editLineCount.GetWindowText( m_strLineCount );
pstrOld = m_strLineCount;
while (*pstrOld)
{
if (isdigit( *pstrOld ))
{
strNewText += *pstrOld;
}
pstrOld++;
}
if (strNewText != m_strLineCount)
{
int iStart;
int iEnd;
m_editLineCount.GetSel( iStart, iEnd );
m_editLineCount.SetWindowText( strNewText );
/* Subtract one since we're
removing a character from
the edit field */
if (iStart > 0) iStart--;
if (iEnd > 0) iEnd--;
m_editLineCount.SetSel( iStart, iEnd );
MessageBeep( MB_OK );
}
}
void ChTextInPrefsPage::OnTintinFile()
{
string strFilter;
string strTitle;
int iResult;
LOADSTRING( IDS_OPEN_TINTIN_FILTER, strFilter );
LOADSTRING( IDS_OPEN_TINTIN_TITLE, strTitle );
ChTinTinSelectFileDlg browseDlg( strTitle, m_strTinTinFile, strFilter,
AfxGetMainWnd() );
iResult = browseDlg.DoModal();
if (IDOK == iResult)
{ // Read the registry again
m_reg.Read( TEXT_IN_TINTIN_FILE, m_strTinTinFile,
TEXT_IN_TINTIN_FILE_DEF );
DisplayTinTinName( m_strTinTinFile );
}
else if (IDC_NO_TINTIN_FILE == iResult)
{
m_strTinTinFile = "";
DisplayTinTinName( m_strTinTinFile );
}
}
/*----------------------------------------------------------------------------
Utility functions
----------------------------------------------------------------------------*/
UINT APIENTRY ChOpenFileHook( HWND hdlg, UINT message, WPARAM wParam,
LPARAM lParam );
CH_INTERN_FUNC( bool )
ChOpenFileHookNotify( HWND hDlg, OFNOTIFY* pOFN );
/*----------------------------------------------------------------------------
ChTinTinSelectFileDlg class
----------------------------------------------------------------------------*/
ChTinTinSelectFileDlg::ChTinTinSelectFileDlg( const string& strTitle,
const string& strBrowser,
const string& strFilter,
CWnd* pParent ) :
CFileDialog( true, "txt", 0, OPEN_DLG_FLAGS, strFilter ),
m_reg( TEXT_IN_PREFS_GROUP )
{
chuint32 flSysProps = ChUtil::GetSystemProperties();
string strBrowserName( strBrowser );
int iIndex = strBrowser.ReverseFind( '\\' );
if (-1 != iIndex)
{
m_strInitialDir = strBrowser.Left( iIndex + 1 );
strBrowserName = strBrowserName.Mid( iIndex + 1 );
}
/* Setup initial file name
(Copied into buffer in
CFileDialog) */
lstrcpyn( m_szFileName, strBrowserName,
(sizeof( m_szFileName ) / sizeof( m_szFileName[0] )) );
m_ofn.lpstrTitle = strTitle;
m_ofn.lpstrInitialDir = m_strInitialDir;
if (flSysProps & CH_PROP_WIN95)
{
m_ofn.Flags |= OFN_EXPLORER;
}
if (flSysProps & CH_PROP_LONG_FILENAMES)
{
m_ofn.Flags |= OFN_LONGNAMES;
}
if (flSysProps & CH_PROP_WIN95)
{
m_ofn.lpTemplateName = MAKEINTRESOURCE( IDD_SELECT_TINTIN_95 );
m_ofn.hInstance = ChTextDLL.hModule;
/* On Windows95, we need a hook
to get button presses */
m_ofn.Flags |= OFN_ENABLEHOOK;
m_ofn.lCustData = (DWORD)this;
m_ofn.lpfnHook = ChOpenFileHook;
}
else
{
m_ofn.lpTemplateName = MAKEINTRESOURCE( IDD_SELECT_TINTIN );
m_ofn.hInstance = ChTextDLL.hModule;
}
//{{AFX_DATA_INIT(ChTinTinSelectFileDlg)
//}}AFX_DATA_INIT
}
int ChTinTinSelectFileDlg::DoModal()
{
int iResult;
m_iModalResult = 0;
if (IDOK == (iResult = CFileDialog::DoModal()))
{
m_reg.Write( TEXT_IN_TINTIN_FILE, GetPathName() );
}
else
{
if (IDC_NO_TINTIN_FILE == m_iModalResult)
{ /* They really pressed
'use internal' */
iResult = IDC_NO_TINTIN_FILE;
}
#if defined( CH_DEBUG )
else if (IDCANCEL == iResult)
{
DWORD dwExtendedError;
dwExtendedError = CommDlgExtendedError();
if (dwExtendedError)
{
switch (dwExtendedError)
{
case CDERR_NOHINSTANCE:
{
TRACE( "The ENABLETEMPLATE flag was specified in the "
"Flags member of a structure for the "
"corresponding common dialog box, but "
"the application failed to provide a "
"corresponding instance handle." );
break;
}
case CDERR_DIALOGFAILURE:
{
TRACE( "The common dialog box procedure's call to "
"the DialogBox function failed. For "
"example, this error occurs if the common "
"dialog box call specifies an invalid window "
"handle.\n" );
break;
}
case CDERR_FINDRESFAILURE:
{
TRACE( "The common dialog box procedure failed to "
"find a specified resource.\n" );
break;
}
case CDERR_INITIALIZATION:
{
TRACE( "The common dialog box procedure failed "
"during initialization. This error often "
"occurs when insufficient memory is "
"available.\n" );
break;
}
case CDERR_LOADRESFAILURE:
{
TRACE( "The common dialog box procedure failed "
"to load a specified resource.\n" );
break;
}
case CDERR_LOCKRESFAILURE:
{
TRACE( "The common dialog box procedure failed "
"to lock a specified resource.\n" );
break;
}
default:
{
TRACE1( "Error %lu in ChSoundOpenFileDlg::DoModal()\n",
dwExtendedError );
break;
}
}
}
}
#endif // defined( CH_DEBUG )
}
return iResult;
}
void ChTinTinSelectFileDlg::DoDataExchange( CDataExchange* pDX )
{
CFileDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(ChTinTinSelectFileDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP( ChTinTinSelectFileDlg, CFileDialog )
//{{AFX_MSG_MAP(ChTinTinSelectFileDlg)
ON_BN_CLICKED(IDC_NO_TINTIN_FILE, OnNoTinTinFile)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/*----------------------------------------------------------------------------
ChTinTinSelectFileDlg message handlers
----------------------------------------------------------------------------*/
void ChTinTinSelectFileDlg::OnNoTinTinFile()
{
m_iModalResult = IDC_NO_TINTIN_FILE;
EndDialog( IDC_NO_TINTIN_FILE );
}
/*----------------------------------------------------------------------------
ChTinTinSelectFileDlg class hook function
----------------------------------------------------------------------------*/
UINT APIENTRY ChOpenFileHook( HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam )
{
bool boolProcessed;
switch( message )
{
case WM_NOTIFY:
{
boolProcessed = ChOpenFileHookNotify( hDlg, (OFNOTIFY*)lParam );
break;
}
case WM_COMMAND:
{
if (HIWORD( lParam ) == BN_CLICKED)
{
switch( LOWORD( wParam ) )
{
case IDC_NO_TINTIN_FILE:
{
HWND hwndButton = (HWND)lParam;
ChTinTinSelectFileDlg* pDlg;
pDlg = (ChTinTinSelectFileDlg*)
GetWindowLong( hwndButton, GWL_USERDATA );
ASSERT( pDlg );
pDlg->UseNoFile();
boolProcessed = true;
break;
}
default:
{
boolProcessed = false;
break;
}
}
}
break;
}
default:
{
boolProcessed = false;
break;
}
}
return boolProcessed;
}
CH_INTERN_FUNC( bool )
ChOpenFileHookNotify( HWND hDlg, OFNOTIFY* pOFN )
{
bool boolProcessed;
switch( pOFN->hdr.code )
{
case CDN_INITDONE:
{
HWND hBtn = GetDlgItem( hDlg, IDC_NO_TINTIN_FILE );
if (hBtn)
{
SetWindowLong( hBtn, GWL_USERDATA,
(DWORD)pOFN->lpOFN->lCustData );
}
boolProcessed = true;
break;
}
default:
{
boolProcessed = false;
break;
}
}
return boolProcessed;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -