void CFilter::parseExt (const TCHAR *ext_string) { CString ext_str = ext_string; int pos = ext_str.Find (_T(";")); while (pos != -1) { CString tmp = ext_str.Left (pos); addExt (tmp); ext_str.Delete (0, pos+1); pos = ext_str.Find (_T(";")); } addExt (ext_str); }
BOOL APIENTRY FileDialog::run(HWND hWnd, UINT uMsg, WPARAM, LPARAM lParam) { switch (uMsg) { case WM_NOTIFY : { LPNMHDR pNmhdr = (LPNMHDR)lParam; switch(pNmhdr->code) { case CDN_INITDONE : { if (_extTypeIndex == -1) return TRUE; HWND fnControl = ::GetDlgItem(::GetParent(hWnd), _dialogFileBoxId); HWND typeControl = ::GetDlgItem(::GetParent(hWnd), cmb1); ::SendMessage(typeControl, CB_SETCURSEL, _extTypeIndex, 0); currentExt = addExt(fnControl, typeControl); return TRUE; } case CDN_TYPECHANGE : { HWND fnControl = ::GetDlgItem(::GetParent(hWnd), _dialogFileBoxId); HWND typeControl = ::GetDlgItem(::GetParent(hWnd), cmb1); currentExt = addExt(fnControl, typeControl); return TRUE; } case CDN_FILEOK : { HWND typeControl = ::GetDlgItem(::GetParent(hWnd), cmb1); int index = ::SendMessage(typeControl, CB_GETCURSEL, 0, 0); NppParameters *pNppParam = NppParameters::getInstance(); pNppParam->setFileSaveDlgFilterIndex(index); return TRUE; } default : return FALSE; } } default : return FALSE; } }
BOOL CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) { switch (Message) { case WM_INITDIALOG : { getRegisteredExts(); getDefSupportedExts(); //goToCenter(); ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), false); ::EnableWindow(::GetDlgItem(_hSelf, IDC_REMOVEEXT_BUTTON), false); ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, EM_SETLIMITTEXT, extNameMax-1, 0); return TRUE; } case WM_DRAWITEM : { HICON hIcon = ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_DELETE_ICON)); DRAWITEMSTRUCT *pdis = (DRAWITEMSTRUCT *)lParam; ::DrawIcon(pdis->hDC, 0, 0, hIcon); return TRUE; } case WM_COMMAND : { switch (wParam) { case IDC_ADDFROMLANGEXT_BUTTON : { writeNppPath(); TCHAR ext2Add[extNameMax] = TEXT(""); if (!_isCustomize) { int index2Add = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_GETCURSEL, 0, 0); ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_GETTEXT, index2Add, (LPARAM)ext2Add); addExt(ext2Add); ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_DELETESTRING, index2Add, 0); } else { ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, WM_GETTEXT, extNameMax, (LPARAM)ext2Add); int i = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_FINDSTRINGEXACT, 0, (LPARAM)ext2Add); if (i != LB_ERR) return TRUE; addExt(ext2Add); ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, WM_SETTEXT, 0, (LPARAM)TEXT("")); } ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_ADDSTRING, 0, (LPARAM)ext2Add); ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), false); return TRUE; } case IDC_REMOVEEXT_BUTTON : { TCHAR ext2Sup[extNameMax] = TEXT(""); int index2Sup = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_GETCURSEL, 0, 0); ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_GETTEXT, index2Sup, (LPARAM)ext2Sup); if (deleteExts(ext2Sup)) ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_DELETESTRING, index2Sup, 0); int langIndex = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANG_LIST, LB_GETCURSEL, 0, 0); ::EnableWindow(::GetDlgItem(_hSelf, IDC_REMOVEEXT_BUTTON), false); if (langIndex != LB_ERR) { for (int i = 1 ; i < nbExtMax ; i++) { if (!generic_stricmp(ext2Sup, defExtArray[langIndex][i])) { ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_ADDSTRING, 0, (LPARAM)ext2Sup); return TRUE; } } } return TRUE; } case IDCANCEL : ::EndDialog(_hSelf, 0); return TRUE; } if (HIWORD(wParam) == EN_CHANGE) { TCHAR text[extNameMax] = TEXT(""); ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, WM_GETTEXT, extNameMax, (LPARAM)text); if ((lstrlen(text) == 1) && (text[0] != '.')) { text[1] = text[0]; text[0] = '.'; text[2] = '\0'; ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, WM_SETTEXT, 0, (LPARAM)text); ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, EM_SETSEL, 2, 2); } ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), (lstrlen(text) > 1)); return TRUE; } if (HIWORD(wParam) == LBN_SELCHANGE) { int i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETCURSEL, 0, 0); if (LOWORD(wParam) == IDC_REGEXT_LANG_LIST) { if (i != LB_ERR) { TCHAR itemName[32]; ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETTEXT, i, (LPARAM)itemName); if (!generic_stricmp(defExtArray[nbSupportedLang-1][0], itemName)) { ::ShowWindow(::GetDlgItem(_hSelf, IDC_REGEXT_LANGEXT_LIST), SW_HIDE); ::ShowWindow(::GetDlgItem(_hSelf, IDC_CUSTOMEXT_EDIT), SW_SHOW); _isCustomize = true; } else { if (_isCustomize) { ::ShowWindow(::GetDlgItem(_hSelf, IDC_REGEXT_LANGEXT_LIST), SW_SHOW); ::ShowWindow(::GetDlgItem(_hSelf, IDC_CUSTOMEXT_EDIT), SW_HIDE); _isCustomize = false; } int count = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_GETCOUNT, 0, 0); for (count -= 1 ; count >= 0 ; count--) ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_DELETESTRING, count, 0); for (int j = 1 ; j < nbExtMax ; j++) if (lstrcmp(TEXT(""), defExtArray[i][j])) { int index = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_FINDSTRINGEXACT, 0, (LPARAM)defExtArray[i][j]); if (index == -1) ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_ADDSTRING, 0, (LPARAM)defExtArray[i][j]); } } ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), false); } } else if (LOWORD(wParam) == IDC_REGEXT_LANGEXT_LIST) { if (i != LB_ERR) ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), true); } else if (LOWORD(wParam) == IDC_REGEXT_REGISTEREDEXTS_LIST) { if (i != LB_ERR) ::EnableWindow(::GetDlgItem(_hSelf, IDC_REMOVEEXT_BUTTON), true); } } } default : return FALSE; } //return FALSE; }
INT_PTR CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) { switch (Message) { case WM_INITDIALOG : { getRegisteredExts(); getDefSupportedExts(); //goToCenter(); ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), false); ::EnableWindow(::GetDlgItem(_hSelf, IDC_REMOVEEXT_BUTTON), false); ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, EM_SETLIMITTEXT, extNameMax-1, 0); return TRUE; } case WM_DRAWITEM : { HICON hIcon = ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_DELETE_ICON)); DRAWITEMSTRUCT *pdis = (DRAWITEMSTRUCT *)lParam; ::DrawIcon(pdis->hDC, 0, 0, hIcon); return TRUE; } case WM_COMMAND : { // Handle File association list extension if (LOWORD(wParam) == IDC_REGEXT_LANGEXT_LIST || LOWORD(wParam) == IDC_REGEXT_REGISTEREDEXTS_LIST) { // On double click an item in the list then toggle the item between both lists // by simulating "<-" or "->" button clicked if (HIWORD(wParam) == LBN_DBLCLK) { // Check whether click happened on a item not in empty area if (-1 != ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETCURSEL, 0, 0)) { HWND(lParam) == ::GetDlgItem(_hSelf, IDC_REGEXT_LANGEXT_LIST) ? ::SendMessage(_hSelf, WM_COMMAND, IDC_ADDFROMLANGEXT_BUTTON, 0) : ::SendMessage(_hSelf, WM_COMMAND, IDC_REMOVEEXT_BUTTON, 0); } return TRUE; } } switch (wParam) { case IDC_ADDFROMLANGEXT_BUTTON : { writeNppPath(); TCHAR ext2Add[extNameMax] = TEXT(""); if (!_isCustomize) { auto index2Add = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_GETCURSEL, 0, 0); auto lbTextLen = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_GETTEXTLEN, index2Add, 0); if (lbTextLen > extNameMax - 1) return TRUE; ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_GETTEXT, index2Add, reinterpret_cast<LPARAM>(ext2Add)); addExt(ext2Add); ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_DELETESTRING, index2Add, 0); } else { ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, WM_GETTEXT, extNameMax, reinterpret_cast<LPARAM>(ext2Add)); auto i = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_FINDSTRINGEXACT, 0, reinterpret_cast<LPARAM>(ext2Add)); if (i != LB_ERR) return TRUE; addExt(ext2Add); ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(TEXT(""))); } ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(ext2Add)); ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), false); return TRUE; } case IDC_REMOVEEXT_BUTTON : { TCHAR ext2Sup[extNameMax] = TEXT(""); auto index2Sup = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_GETCURSEL, 0, 0); auto lbTextLen = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_GETTEXTLEN, index2Sup, 0); if (lbTextLen > extNameMax - 1) return TRUE; ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_GETTEXT, index2Sup, reinterpret_cast<LPARAM>(ext2Sup)); if (deleteExts(ext2Sup)) ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_DELETESTRING, index2Sup, 0); auto langIndex = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANG_LIST, LB_GETCURSEL, 0, 0); ::EnableWindow(::GetDlgItem(_hSelf, IDC_REMOVEEXT_BUTTON), false); if (langIndex != LB_ERR) { for (int i = 1 ; i < nbExtMax ; ++i) { if (!generic_stricmp(ext2Sup, defExtArray[langIndex][i])) { ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(ext2Sup)); return TRUE; } } } return TRUE; } case IDCANCEL: { ::EndDialog(_hSelf, 0); return TRUE; } } if (HIWORD(wParam) == EN_CHANGE) { TCHAR text[extNameMax] = TEXT(""); ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, WM_GETTEXT, extNameMax, reinterpret_cast<LPARAM>(text)); if ((lstrlen(text) == 1) && (text[0] != '.')) { text[1] = text[0]; text[0] = '.'; text[2] = '\0'; ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(text)); ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, EM_SETSEL, 2, 2); } ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), (lstrlen(text) > 1)); return TRUE; } if (HIWORD(wParam) == LBN_SELCHANGE) { auto i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETCURSEL, 0, 0); if (LOWORD(wParam) == IDC_REGEXT_LANG_LIST) { if (i != LB_ERR) { const size_t itemNameLen = 32; TCHAR itemName[itemNameLen + 1]; auto lbTextLen = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETTEXTLEN, i, 0); if (lbTextLen > itemNameLen) return TRUE; ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETTEXT, i, reinterpret_cast<LPARAM>(itemName)); if (!generic_stricmp(defExtArray[nbSupportedLang-1][0], itemName)) { ::ShowWindow(::GetDlgItem(_hSelf, IDC_REGEXT_LANGEXT_LIST), SW_HIDE); ::ShowWindow(::GetDlgItem(_hSelf, IDC_CUSTOMEXT_EDIT), SW_SHOW); _isCustomize = true; } else { if (_isCustomize) { ::ShowWindow(::GetDlgItem(_hSelf, IDC_REGEXT_LANGEXT_LIST), SW_SHOW); ::ShowWindow(::GetDlgItem(_hSelf, IDC_CUSTOMEXT_EDIT), SW_HIDE); _isCustomize = false; } LRESULT count = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_GETCOUNT, 0, 0); for (count -= 1 ; count >= 0 ; count--) ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_DELETESTRING, count, 0); for (int j = 1 ; j < nbExtMax ; ++j) { if (lstrcmp(TEXT(""), defExtArray[i][j])) { auto index = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_FINDSTRINGEXACT, 0, reinterpret_cast<LPARAM>(defExtArray[i][j])); if (index == -1) ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(defExtArray[i][j])); } } } ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), false); } } else if (LOWORD(wParam) == IDC_REGEXT_LANGEXT_LIST) { if (i != LB_ERR) ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), true); } else if (LOWORD(wParam) == IDC_REGEXT_REGISTEREDEXTS_LIST) { if (i != LB_ERR) ::EnableWindow(::GetDlgItem(_hSelf, IDC_REMOVEEXT_BUTTON), true); } } // break; // no break here } default : return FALSE; } //return FALSE; }
BOOL APIENTRY FileDialog::run(HWND hWnd, UINT uMsg, WPARAM, LPARAM lParam) { switch (uMsg) { case WM_NOTIFY : { LPNMHDR pNmhdr = (LPNMHDR)lParam; switch(pNmhdr->code) { case CDN_INITDONE : { if (_extTypeIndex == -1) return TRUE; HWND fnControl = ::GetDlgItem(::GetParent(hWnd), _dialogFileBoxId); HWND typeControl = ::GetDlgItem(::GetParent(hWnd), cmb1); ::SendMessage(typeControl, CB_SETCURSEL, _extTypeIndex, 0); currentExt = addExt(fnControl, typeControl); return TRUE; } case CDN_TYPECHANGE : { HWND fnControl = ::GetDlgItem(::GetParent(hWnd), _dialogFileBoxId); HWND typeControl = ::GetDlgItem(::GetParent(hWnd), cmb1); currentExt = addExt(fnControl, typeControl); return TRUE; } case CDN_FILEOK : { HWND typeControl = ::GetDlgItem(::GetParent(hWnd), cmb1); int index = static_cast<int32_t>(::SendMessage(typeControl, CB_GETCURSEL, 0, 0)); NppParameters *pNppParam = NppParameters::getInstance(); pNppParam->setFileSaveDlgFilterIndex(index); // change forward-slash to back-slash directory paths so dialog can interpret OPENFILENAME* ofn = reinterpret_cast<LPOFNOTIFY>(lParam)->lpOFN; TCHAR* fileName = ofn->lpstrFile; // note: this check is essential, because otherwise we could return True // with a OFN_NOVALIDATE dialog, which leads to opening every file // in the specified directory. Multi-select terminator is \0\0. if ((ofn->Flags & OFN_ALLOWMULTISELECT) && (*(fileName + lstrlen(fileName) + 1) != '\0')) return FALSE; if (::PathIsDirectory(fileName)) { // change to backslash, and insert trailing '\' to indicate directory hFileDlg = ::GetParent(hWnd); std::wstring _fnStr(fileName); std::replace(_fnStr.begin(), _fnStr.end(), '/', '\\'); if (_fnStr.back() != '\\') _fnStr.insert(_fnStr.end(), '\\'); // change the dialog directory selection ::SendMessage(hFileDlg, CDM_SETCONTROLTEXT, edt1, reinterpret_cast<LPARAM>(_fnStr.c_str())); ::PostMessage(hFileDlg, WM_COMMAND, IDOK, 0); ::SetWindowLongPtr(hWnd, 0 /*DWL_MSGRESULT*/, 1); } return TRUE; } default : return FALSE; } } default : return FALSE; } }
void main(){ int input; int output; long int offset; char buffer[512]; long int tileCount; int row; int bytesRead; char fileName[35]; char outputName[35]; srcin: printf("File to extract from:"); getString(30, fileName); addExt(fileName, "nes"); input = openFile(fileName, 'r'); if(input == -1){ printf("Couldn't open %s!\n\n", fileName); goto srcin; } destin: printf("Bitmap to output to:"); getString(30, outputName); changeExt(outputName, "bmp"); output = openFile(outputName, 't'); if(output == -1){ printf("Couldn't open %s!\n\n", outputName); goto destin; } printf("\nEnter starting address:"); offset=hexInput(); printf("\nExtract how many tiles?"); tileCount=hexInput(); prepBMP(output,tileCount); row = (tileCount - 1) / 32 + 1; lseek(input,offset + (long) (row-1) * 512, 0); bytesRead= _read(input,buffer,512); if (bytesRead / 16 < ((tileCount%32==0)? 32 : tileCount%32)){ printf("File not long enough!"); exit(1); } convert(buffer,output,(tileCount%32==0) ? 32 : tileCount%32,row); row--; while(row > 0){ if(row%32==0) printf("\n%li tiles left to extract....",(long) row*32); lseek(input,offset + (long) (row-1) * 512, 0); bytesRead= _read(input,buffer,512); convert(buffer,output,32,row); row--; } close(input); close(output); printf("\nDone!"); }