void CMenuCharacterFiles::Build() { CMenuBase::Build(); SetOptionPos(MENU_FILE_FIELD_X + MENU_FILE_TEXT_OFFSET_X, MENU_FILE_FIELD_Y + MENU_FILE_TEXT_OFFSET_Y); SetItemSpacing(0); SetScrollWrap(DFALSE); // Remove all of the menu options RemoveAllOptions(); if(m_nAction == MENU_ACTION_SAVE) { m_hEdit = AddEditOption("Type the filename:", 0, m_pMainMenus->GetSmallFont(), 135, 16, DNULL); m_hEdit->SetText("Default"); } else InitFileList("Players"); m_hTransColor = m_pClientDE->SetupColor1(1.0f, 0.0f, 1.0f, DFALSE); // Delete the surface of the file field if(m_hFileField) { m_pClientDE->DeleteSurface(m_hFileField); m_hFileField = 0; } m_hFileField = m_pClientDE->CreateSurfaceFromBitmap("interface/mainmenus/dialog.pcx"); }
void CDlgSaveFootprint::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_PREVIEW2, m_preview); DDX_Control(pDX, IDC_EDIT_SAVE_NAME, m_edit_name); DDX_Control(pDX, IDC_COMBO_LIBS, m_combo_lib); DDX_Control(pDX, IDC_EDIT_AUTHOR, m_edit_author); DDX_Control(pDX, IDC_EDIT_SOURCE, m_edit_source); DDX_Control(pDX, IDC_EDIT_DESC, m_edit_desc); DDX_Control(pDX, IDC_EDIT_FP_SAVE_FOLDER, m_edit_folder); DDX_Control(pDX, IDC_STATIC_UNITS, m_static_units); if( !pDX->m_bSaveAndValidate ) { // incoming // draw preview of footprint CMetaFileDC m_mfDC; CDC * pDC = this->GetDC(); CRect rw; m_preview.GetClientRect( &rw ); int x_size = rw.right - rw.left; int y_size = rw.bottom - rw.top; HENHMETAFILE hMF = m_footprint->CreateMetafile( &m_mfDC, pDC, x_size, y_size ); m_preview.SetEnhMetaFile( hMF ); ReleaseDC( pDC ); // initialize other fields if( m_units == MM ) m_static_units.SetWindowText( " mm" ); else m_static_units.SetWindowText( " mil" ); m_edit_name.SetWindowText( m_name ); m_edit_author.SetWindowText( m_footprint->m_author ); m_edit_source.SetWindowText( m_footprint->m_source ); m_edit_desc.SetWindowText( m_footprint->m_desc ); // insert all library file names CString * def_lib = m_foldermap->GetLastFolder(); if( *def_lib == "" ) def_lib = m_foldermap->GetDefaultFolder(); m_folder = m_foldermap->GetFolder( def_lib, m_dlg_log ); m_edit_folder.SetWindowText( *def_lib ); InitFileList(); } }
void CDlgSaveFootprint::OnBnClickedButtonBrowse() { CPathDialog dlg( "Open Folder", "Select footprint library folder", *m_folder->GetFullPath() ); int ret = dlg.DoModal(); if( ret == IDOK ) { CString path_str = dlg.GetPathName(); m_edit_folder.SetWindowText( path_str ); m_folder = m_foldermap->GetFolder( &path_str, m_dlg_log ); if( !m_folder ) { CFootLibFolder * new_folder = new CFootLibFolder; CString mess; mess.Format( "Indexing library folder \"%s\"\r\n", path_str ); m_dlg_log->AddLine( mess ); new_folder->IndexAllLibs( &path_str, m_dlg_log ); m_dlg_log->AddLine( "\r\n" ); m_foldermap->AddFolder( &path_str, new_folder ); m_folder = new_folder; } m_foldermap->SetLastFolder( &path_str ); InitFileList(); } }
void CDlgSaveFootprint::OnBnClickedOk() { // update name and other strings // check folder name m_edit_folder.GetWindowText( m_folder_name ); if( *m_folder->GetFullPath() != m_folder_name ) { // folder was changed without browsing, regenerate library int ret = chdir( m_folder_name ); if( ret == -1 ) { // folder doesn't exist CString mess = "Folder \"" + m_folder_name + "\" doesn't exist\n"; mess += "Create it ?"; ret = AfxMessageBox( mess, MB_YESNO ); if( ret == IDNO ) return; // create it ret = mkdir( m_folder_name ); if( ret == -1 ) { // can't create folder CString mess = "Unable to create folder \""; mess += m_folder_name; AfxMessageBox( mess ); return; } } // index folder CFootLibFolder * new_folder = new CFootLibFolder; CString mess; mess.Format( "Indexing library folder \"%s\"\r\n", m_folder_name ); m_dlg_log->AddLine( mess ); new_folder->IndexAllLibs( &m_folder_name, m_dlg_log ); m_dlg_log->AddLine( "\r\n" ); m_foldermap->AddFolder( &m_folder_name, new_folder ); m_folder = m_foldermap->GetFolder( &m_folder_name, m_dlg_log ); m_foldermap->SetLastFolder( &m_folder_name ); InitFileList(); } m_edit_name.GetWindowText( m_name ); m_name.Replace( '\"', '\'' ); // replace any " with ' if( m_name.GetLength() > CShape::MAX_NAME_SIZE ) { CString mess; mess.Format( "Name too long, can't exceed %d characters", CShape::MAX_NAME_SIZE ); AfxMessageBox( mess ); return; } m_footprint->m_units = m_units; m_footprint->m_name = m_name; m_edit_author.GetWindowText( m_author ); m_author.Replace( '\"', '\'' ); m_footprint->m_author = m_author.Trim(); m_edit_source.GetWindowText( m_source ); m_source.Replace( '\"', '\'' ); m_footprint->m_source = m_source.Trim(); m_edit_desc.GetWindowText( m_desc ); m_desc.Replace( '\"', '\'' ); m_footprint->m_desc = m_desc.Trim(); // get footprint name, file name CString file_name; m_combo_lib.GetWindowText( file_name ); CString file_path = *m_folder->GetFullPath() + "\\" + file_name; // save file name and folder gLastFileName = file_name; gLastFolderName = *m_folder->GetFullPath(); // now check for duplication of existing footprint int ilib; int offset; int ifootprint; int next_offset; CString fn; BOOL footprint_exists = m_folder->GetFootprintInfo( &m_name, &file_path, &ilib, &ifootprint, &fn, &offset, &next_offset ); BOOL same_file = ( fn == file_path ); BOOL replace = FALSE; if( footprint_exists && same_file ) { // footprint name already exists in this file CString mess; mess.Format( "Footprint \"%s\" already exists in file \"%s\"\nOverwrite ?", m_name, fn ); int ret = AfxMessageBox( mess, MB_OKCANCEL ); if( ret == IDOK ) { replace = TRUE; } else return; } else if( footprint_exists && !same_file ) { // footprint name already exists in another file CString mess; mess.Format( "Footprint \"%s\" already exists in another library file \"%s\"\nDo you want to change the name?", m_name, fn ); int ret = AfxMessageBox( mess, MB_YESNO ); if( ret == IDYES ) { return; } } // OK, save it BOOL file_exists = ( m_folder->SearchFileName( &file_path ) != -1 ); if( !file_exists ) { // new library file, create it and write footprint CStdioFile f; BOOL ok = f.Open( file_path, CFile::modeCreate | CFile::modeWrite ); if( !ok ) { AfxMessageBox( "Unable to open file " + file_path ); return; } m_footprint->WriteFootprint( &f ); f.Close(); } else if( file_exists && !replace ) { // existing library file, insert new footprint int offset; // no heading, insert ahead of first footprint or heading in file CStdioFile * fin = new CStdioFile( file_path, CFile::modeRead ); CStdioFile * fout = new CStdioFile( "temp.txt", CFile::modeCreate | CFile::modeWrite ); CString in_str; BOOL bInserted = FALSE; // now loop through all lines in file while( fin->ReadString( in_str ) ) { in_str.Trim(); if( !bInserted && (in_str[0] == '[' || in_str.Left(5) == "name:") ) { // insert footprint m_footprint->WriteFootprint( fout ); // now copy last line read from source fout->WriteString( in_str + "\n" ); bInserted = TRUE; } else { // write line fout->WriteString( in_str + "\n" ); } } delete fin; delete fout; int err = remove( file_path ); if( err ) { CString str = "File system error: Unable to modify library file\n"; str += "File could be read-only or you don't have permission to modify it\n"; str += "The modified file has been saved as \"temp.txt\""; AfxMessageBox( str ); return; } else { err = rename( "temp.txt", file_path ); if( err ) { CString str = "File system error: Unable to modify library file\n"; str += "The original file has been deleted but can't be rewritten\n"; str += "The modified file has been saved as \"temp.txt\""; AfxMessageBox( str ); return; } } } else { // replace existing footprint CStdioFile * fin = new CStdioFile( file_path, CFile::modeRead ); CStdioFile * fout = new CStdioFile( "temp.txt", CFile::modeCreate | CFile::modeWrite ); CString in_str; BOOL bDeleted = FALSE; BOOL bInserted = FALSE; // now loop through all lines in file while( fin->ReadString( in_str ) ) { in_str.Trim(); if( !bDeleted && fin->GetPosition() <= offset ) { // haven't reached footprint, write line fout->WriteString( in_str + "\n" ); } else if( !bDeleted && next_offset<0 ) { // reached footprint, this is the last footprint in the file bDeleted = TRUE; } else if( !bDeleted && fin->GetPosition() < next_offset ) { // reached footprint, skip lines to next footprint } else if( !bInserted ) { // we have deleted the original footprint, insert replacement bDeleted = TRUE; m_footprint->WriteFootprint( fout ); // if this was the last footprint in the file, we are done if( next_offset < 0 ) break; // otherwise, copy last line read from source fout->WriteString( in_str + "\n" ); bInserted = TRUE; } else { // finished inserting, this was no the last footprint // copy subsequent lines fout->WriteString( in_str + "\n" ); } } delete fin; delete fout; int err = remove( file_path ); if( err ) { CString str = "File system error: Unable to modify library file\n"; str += "File could be read-only or you don't have permission to modify it\n"; str += "The modified file has been saved as \"temp.txt\""; AfxMessageBox( str ); return; } else { err = rename( "temp.txt", file_path ); if( err ) { CString str = "File system error: Unable to modify library file\n"; str += "The original file has been deleted but can't be rewritten\n"; str += "The modified file has been saved as \"temp.txt\""; AfxMessageBox( str ); return; } } } // now index the file m_folder->IndexLib( &file_name ); OnOK(); }
LRESULT CALLBACK FormTagManager::DlgProc( _In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { //::PrintLog(L"Message: 0x%x, wParam = 0x%x, lParam = 0x%x, hwnd = 0x%x", uMsg, wParam, lParam, hwnd); switch(uMsg) { case WM_INITDIALOG: { ::PrintLog(L"Message: WM_INITDIALOG"); // init this->_hwnd = hwnd; this->_handler = (CHandler *)lParam; this->_handler->AddRef(); // to keep the instance after the Form opend, will be released in WM_NCDESTROY. SHGetImageList(SHIL_SMALL,IID_IImageList,(void **)&_sysImgList); _sysImgList->AddRef(); // will be released in ~ctor. _hErrorInfo = GetDlgItem(_hwnd,IDC_TAGMANAGER_STATIC_ERROR_INFO); _hListTags = GetDlgItem(_hwnd,IDC_TAGMANAGER_LIST_TAGS); _hListFiles = GetDlgItem(_hwnd,IDC_TAGMANAGER_LIST_SelectedFiles); _hEditCtlNewTag = GetDlgItem(_hwnd,IDC_TAGMANAGER_EDIT_TagWord); _hCheckAttachToFiles = GetDlgItem(_hwnd, IDC_TAGMANAGER_CHECK_AttachNewTagToFiles); _hBuAdd = GetDlgItem(_hwnd,IDC_TAGMANAGER_BU_ADD); _hBuEdit = GetDlgItem(_hwnd,IDC_TAGMANAGER_BU_EDIT); _hBuDel = GetDlgItem(_hwnd,IDC_TAGMANAGER_BU_DEL); InitText(); InitTagList(); InitFileList(); Button_SetCheck(_hCheckAttachToFiles,BST_CHECKED); Button_Enable(_hBuAdd,false); Edit_TakeFocus(_hEditCtlNewTag); break; } case MSG_TRANSFER_INSTANCES: ::PrintLog(L"Message: MSG_TRANSFER_INSTANCES: wParam: %d, lParam: %d",wParam, lParam); break; case WM_CTLCOLORSTATIC: { // change the text color of static label ERROR_INFO if( (UINT)lParam == (UINT)_hErrorInfo){ HDC hdcStatic = (HDC) wParam; SetTextColor(hdcStatic, _msgColor); // the background color will be changed to white, that is not what I want, so, restore the background color manual. auto oldBkColor = GetSysColor(CTLCOLOR_DLG); SetBkColor(hdcStatic,oldBkColor); if (_hbrBkgnd == NULL) { _hbrBkgnd = CreateSolidBrush(oldBkColor); } // the return value is a handle to a brush that the system uses to paint the background of the static control. // http://msdn.microsoft.com/en-us/library/windows/desktop/bb787524(v=vs.85).aspx return (INT_PTR)_hbrBkgnd; } } case WM_SYSCOMMAND: { switch (wParam) { case SC_KEYMENU: { ::PrintLog(L"Message: SC_KEYMENU: wParam: %d, lParam: %d",wParam, lParam); break; } case SC_CLOSE: { DestroyWindow(hwnd); break; } default: break; } } break; case WM_COMMAND: { ::PrintLog(L"Message: WM_COMMAND"); switch(LOWORD(wParam)) { case IDC_TAGMANAGER_BU_DEL: { DelTags(); break; } case IDC_TAGMANAGER_BU_EDIT: { EditTag(); break; } case IDC_TAGMANAGER_BU_ADD: { AddTag(); break; } case IDC_TAGMANAGER_CHECK_AttachNewTagToFiles: ::PrintLog(L"Message: IDC_CHECK_AttachNewTagToFiles"); break; case IDC_TAGMANAGER_BU_CANCEL: DestroyWindow(hwnd); break; case IDC_TAGMANAGER_EDIT_TagWord: { OnNewTagChanged(wParam,lParam); break; } default: break; } } break; //case WM_SIZE: // { // auto hTreeView = GetDlgItem(hdlg, IDC_TREE1); // if(hTreeView!=NULL) // { // } // return 0; // } case WM_KEYDOWN: { ::PrintLog(L"Message: WM_KEYDOWN"); } break; case WM_KEYUP: { ::PrintLog(L"Message: WM_KEYUP"); if(wParam==VK_ESCAPE) { DestroyWindow(hwnd); } else if( wParam == VK_RETURN ) { // simulate text changed to validate the new tag. OnNewTagChanged(MAKEWPARAM(IDC_TAGMANAGER_EDIT_TagWord, EN_SETFOCUS),(LPARAM)_hEditCtlNewTag); // simulate the button ADD to be Clicked. SendMessage(_hwnd,WM_COMMAND, MAKEWPARAM(IDC_TAGMANAGER_BU_ADD, BN_CLICKED),(LPARAM)_hBuAdd); } } break; case WM_CHAR: { ::PrintLog(L"Message: WM_CHAR"); } break; case WM_SYSCHAR: { ::PrintLog(L"Message: WM_SYSCHAR"); } break; case WM_DEADCHAR: { ::PrintLog(L"Message: WM_DEADCHAR"); } break; case WM_SYSDEADCHAR: { ::PrintLog(L"Message: WM_SYSDEADCHAR"); } break; case WM_NOTIFY: { LPNMHDR pNmhdr = (LPNMHDR) lParam; switch (pNmhdr->idFrom) { case IDC_TAGMANAGER_LIST_TAGS: { WM_NOTIFY_LIST_Tags(wParam,lParam); break; } case IDC_TAGMANAGER_LIST_SelectedFiles: { WM_NOTIFY_LIST_Files(wParam,lParam); break; } default: break; } } break; case WM_DESTROY: { PostQuitMessage(0); } break; case WM_NCDESTROY: { ::PrintLog(L"Message: WM_NCDESTROY"); if(this->_handler != NULL){ auto x = this->_handler->Release(); if( x == 0 ){ this->_handler = NULL; } } } break; default: break; } return (INT_PTR)FALSE; }