// Entry point. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nShowCmd ) { int rc = 0; // Setup app. if ( ClsGetApp()->Setup( hInstance, lpCmdLine, nShowCmd )) { // Check OS version. if ( ClsGetApp()->GetPlatformID() != VER_PLATFORM_WIN32_WINDOWS && ClsGetApp()->GetPlatformID() != VER_PLATFORM_WIN32_NT ) { MessageBox( NULL, _T( "Windows 95/98/ME/NT/2000 required!" ), _T( "\"ClsFileDirTree\" Sample" ), MB_OK ); return NULL; } // Create and open the dialog. ClsMessageBox mb; mb.Body() = ISEQ_CENTER ISEQ_BOLD _T( "ClsMessageBox\n\n" ) ISEQ_NORMAL ISEQ_LEFT _T( "This class allows you to create dialogs simular to the way the\n" ) _T( "system MessageBox() API does. The major difference between the\n" ) _T( "system solution and the solution of this class is that this class\n" ) _T( "uses the \"" ) ISEQ_BOLD ISEQ_TEXTRGB( _T( "200,0,0" )) _T( "ClsInfoControl" ) ISEQ_NORMAL ISEQ_TEXTSYSCOLOR( IG_COLOR_BTNTEXT ) _T( "\" control to display it's body text.\n\n" ) _T( "By using command sequences in the text this control can show\ntext styles like:\n\n" ) ISEQ_CENTER ISEQ_BOLD _T( "Bold" ) ISEQ_NORMAL _T( "," ) ISEQ_ITALIC _T( "Italic" ) ISEQ_NORMAL _T( "," ) ISEQ_UNDERLINE _T( "Underline" ) ISEQ_NORMAL _T( ", and " ) ISEQ_BOLD ISEQ_ITALIC ISEQ_UNDERLINE _T( "Combinations" ) ISEQ_NORMAL _T( "\n\n" ) _T( "Also text in " ) ISEQ_BACKRGB( _T( "255,255,245" )) ISEQ_TEXTRGB( _T( "255,0,0C" )) ISEQ_TEXTRGB( _T( "0,155,0o" )) ISEQ_TEXTRGB( _T( "0,0,255l" )) ISEQ_TEXTRGB( _T( "0,155,0o" )) ISEQ_TEXTRGB( _T( "255,0,0r" )) ISEQ_TEXTRGB( _T( "0,155,0s" )) ISEQ_TEXTSYSCOLOR( IG_COLOR_BTNTEXT ) ISEQ_BACKSYSCOLOR( IG_COLOR_BTNFACE ) _T( " is possible...\n\n" ) _T( "Besides that text can also be\n\n" ) ISEQ_LEFT _T( "left aligned\n" ) ISEQ_RIGHT _T( "right aligned\n" ) ISEQ_CENTER _T( "or centered" ); mb.Buttons() = _T( "&OK" ); mb.Title() = _T( "A litle test..." ); mb.Flags() = ClsMessageBox::MBF_ICONQUESTION; FONTDATA fd; fd.sPointSize = 9; fd.sWeight = FW_NORMAL; fd.bItalic = FALSE; _tcscpy( fd.szFacename, _T( "Courier New")); mb.MsgBox( NULL ); } return rc; }
// WM_COMMAND message handler. LRESULT KeywordEdit::OnCommand( UINT nNotifyCode, UINT nCtrlID, HWND hWndCtrl ) { // What's the ID? switch ( nCtrlID ) { case EditToolbar::ETID_EDIT: { // Valid entry? LPKEYWORDS pKW = ( LPKEYWORDS )m_List.GetItemData( m_List.GetCurSel()); if ( pKW != ( LPKEYWORDS )LB_ERR ) { // Edit the keywords. KWEdit kwe; kwe.Edit( *this, pKW, this ); } return 0; } case EditToolbar::ETID_INSERT: { // Popup the file dialog. ClsFileDialog fd; fd.Filters() = _T( "Text files (*.txt)\0*.txt\0All files (*.*)\0*.*\0\0" ); fd.Caption().LoadString( IDS_INSERT_KEYWORDS ); if ( fd.DoModal( this, NULL, NULL, TRUE, OFN_FILEMUSTEXIST )) { // Get the selected filename. ClsString name; fd.GetName( 0, name ); // Read the file and add the read keywords // to the selected node. ReadKeywords( name ); // Make sure the keywords are // displayed. SendMessage( WM_COMMAND, MAKEWPARAM( IDC_LIST, LBN_SELCHANGE ), ( LPARAM )m_List.GetSafeHWND()); } return 0; } case EditToolbar::ETID_COLOR: { // Get the current selection. int nSel = m_List.GetCurSel(); // Only show the popup when there is // a valid selection. if ( nSel != LB_ERR ) { // Get the position of the selected entry. ClsRect rc; m_Tools.GetItemRect( 6, rc ); m_Tools.ClientToScreen( rc ); // Obtain the entry data. LPKEYWORDS pKW = ( LPKEYWORDS )m_List.GetItemData( nSel ); if ( pKW != ( LPKEYWORDS )LB_ERR ) { // Create the popup. The popup will automatically destroy // itself. new ClsColorPopup( ClsPoint( rc.Left(), rc.Bottom()), pKW->crColor, this, CS_FORE, NULL, ClsString( MAKEINTRESOURCE( IDS_CUSTOM )), NULL, TRUE, FALSE ); } } return 0; } case EditToolbar::ETID_BGCOLOR: { // Get the current selection. int nSel = m_List.GetCurSel(); // Only show the popup when there is // a valid selection. if ( nSel != LB_ERR ) { // Get the position of the selected entry. ClsRect rc; m_Tools.GetItemRect( 7, rc ); m_Tools.ClientToScreen( rc ); // Obtain the entry data. LPKEYWORDS pKW = ( LPKEYWORDS )m_List.GetItemData( nSel ); if ( pKW != ( LPKEYWORDS )LB_ERR ) { // Create the popup. The popup will automatically destroy // itself. new ClsColorPopup( ClsPoint( rc.Left(), rc.Bottom()), pKW->crBgColor, this, CS_BACK, ClsString( MAKEINTRESOURCE( IDS_TRANSPARENT )), ClsString( MAKEINTRESOURCE( IDS_CUSTOM )), NULL, TRUE, FALSE ); } } return 0; } case IDC_LIST: { // Selection change? if ( nNotifyCode == LBN_SELCHANGE ) { // Valid entry? LPKEYWORDS pKW = ( LPKEYWORDS )m_List.GetItemData( m_List.GetCurSel()); if ( pKW != ( LPKEYWORDS )LB_ERR ) { // Reset words content. m_KeyList.ResetContent(); // Add keywords. m_KeyList.SetRedraw( FALSE ); for ( int i = 0; i < ::ArrayGetSize( pKW->lpaKeywords ); i++ ) m_KeyList.AddString(( LPCTSTR )*(( LPTSTR * )::ArrayGetAt( pKW->lpaKeywords, i ))); m_KeyList.SetRedraw(); // Setup UI. SetupControls(); } } return 0; } case EditToolbar::ETID_DELETE: { // Valid entry? LPKEYWORDS pKW = ( LPKEYWORDS )m_List.GetItemData( m_List.GetCurSel()); if ( pKW != ( LPKEYWORDS )LB_ERR ) { ClsMessageBox mb; mb.Title() = ClsGetApp()->GetAppTitle(); mb.Buttons().LoadString( IDS_YESNO ); mb.Body().LoadString( IDS_KEYWORD_DELETE ); mb.Flags() = ClsMessageBox::MBF_ICONEXCLAMATION; // Sure? if ( mb.MsgBox( GetSafeHWND())) { // Save current selection // position. int nSel = m_List.GetCurSel(); int nPos = nSel; // Select the next one or // the previous one. if ( nSel == m_List.GetCount() - 1 ) nSel--; else nSel++; // Select the other item. m_List.SetCurSel( nSel ); // Setup UI. SetupControls(); // Clear the list contents m_KeyList.ResetContent(); // Reset selection. SendMessage( WM_COMMAND, MAKEWPARAM( IDC_LIST, LBN_SELCHANGE ), ( LPARAM )m_List.GetSafeHWND()); // Remove the selection. m_List.DeleteString( nPos ); // Remove the node. Remove(( LPNODE )pKW ); // Free the keyword array and the node. if ( pKW->lpaKeywords ) ::ArrayDelete( pKW->lpaKeywords ); ::FreePooled( pParserPool, pKW ); } } return 0; } case EditToolbar::ETID_NEW: { // Allocate a new node. LPKEYWORDS pKW = ( LPKEYWORDS )::AllocPooled( pParserPool, sizeof( KEYWORDS )); if ( pKW ) { // Allocate an array. pKW->lpaKeywords = ::ArrayCreate( 0, 500, sizeof( LPTSTR * )); if ( pKW->lpaKeywords ) { // Set color. pKW->crColor = ::GetSysColor( COLOR_WINDOWTEXT ); pKW->crBgColor = CLR_DEFAULT; // Add the node to the list. AddTail(( LPLIST )&m_KeyLst, ( LPNODE )pKW ); // Add it to the listview and select it. int nPos = m_List.AddString(( LPCTSTR )pKW ); m_List.SetCurSel( nPos ); // Clear the keywords list. m_KeyList.ResetContent(); // Setup UI. SetupControls(); return 0; } else ::FreePooled( pParserPool, pKW ); } // Error. MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); return 0; } case IDC_CASE: // Get value. m_bCase = ( BOOL )( m_Case.GetCheck() == BST_CHECKED ); return 0; case IDC_OK: // Return OK EndDialog( TRUE ); return 0; case IDC_CANCEL: // Cancel. EndDialog( FALSE ); return 0; } // Pass onto the base class. return ClsDialog::OnCommand( nNotifyCode, nCtrlID, hWndCtrl ); }