BOOL GetBookmarkFileName(HWND hwndHexView, LPCTSTR szFileName, TCHAR *szBookPath) { TCHAR szBase[MAX_PATH] = {0}; TCHAR szAppData[MAX_PATH]; TCHAR *pszName; UINT64 bookid; if(szFileName == 0) { szFileName = szBase; if(!HexView_GetFileName(hwndHexView, szBase, MAX_PATH)) return FALSE; } // has this file got a bookmark id already?? if(LoadFileData(szFileName, TEXT("HexEdit.bookmark"), &bookid, sizeof(UINT64)) != sizeof(UINT64)) { //BY_HANDLE_FILE_INFORMATION bhfi; //HANDLE hFile = CreateFile(szBase, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); //if(hFile == INVALID_HANDLE_VALUE) // return FALSE; // generate one from the base NTFS fileid //GetFileInformationByHandle(hFile, &bhfi); //CloseHandle(hFile); bookid = GetTickCount();//(UINT64)bhfi.nFileIndexLow | ((UINT64)bhfi.nFileIndexHigh << 32); // only save if the file exists if(GetFileAttributes(szFileName) != INVALID_FILE_ATTRIBUTES) { SaveFileData(szFileName, TEXT("HexEdit.bookmark"), &bookid, sizeof(UINT64)); } } if((pszName = _tcsrchr(szFileName, '\\')) == 0) return FALSE; // get location of application data // // get/create the following directory: // // {ApplicationData}\Local\Catch22\Bookmarks // GetProgramDataPath(szAppData, MAX_PATH); lstrcat(szAppData, TEXT("\\Bookmarks")); SHCreateDirectory(NULL, szAppData); // // Formulate the bookmark filename // wsprintf(szBookPath, TEXT("%s\\%s-%08x-bookmark.xml"), szAppData, pszName+1, bookid); //lstrcat(szBookPath, pszName+1); //lstrcat(szBookPath, TEXT(".bookmark")); return TRUE; }
void NeatpadOpenFile(HWND hwnd, TCHAR *szFile) { TCHAR *name; // save current file's position! SaveFileData(g_szFileName, hwnd); _tcscpy(g_szFileName, szFile); name = _tcsrchr(g_szFileName, '\\'); _tcscpy(g_szFileTitle, name ? name+1 : szFile); DoOpenFile(hwnd, g_szFileName, g_szFileTitle); }
// // Main window procedure // LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { int width, height, heightsb; HIMAGELIST hImgList; RECT rect; HDWP hdwp; NMHDR *nmhdr; TCHAR msgstr[MAX_PATH+200]; switch(msg) { case WM_CREATE: g_hwndTextView = CreateTextView(hwnd); g_hwndStatusbar = CreateStatusBar(hwnd); TextView_SetContextMenu(g_hwndTextView, GetSubMenu(LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(IDR_MENU2)), 0)); // load the image list hImgList = ImageList_LoadImage( GetModuleHandle(0), MAKEINTRESOURCE(IDB_BITMAP1), 16, 0, RGB(255,0,255), IMAGE_BITMAP, LR_LOADTRANSPARENT|LR_CREATEDIBSECTION ); TextView_SetImageList(g_hwndTextView, hImgList); // highlight specific lines with image-index "1" //TextView_SetLineImage(g_hwndTextView, 16, 1); //TextView_SetLineImage(g_hwndTextView, 5, 1); //TextView_SetLineImage(g_hwndTextView, 36, 1); //TextView_SetLineImage(g_hwndTextView, 11, 1); // tell windows that we can handle drag+drop'd files DragAcceptFiles(hwnd, TRUE); return 0; case WM_DROPFILES: HandleDropFiles(hwnd, (HDROP)wParam); return 0; case WM_DESTROY: SaveFileData(g_szFileName, hwnd); PostQuitMessage(0); DeleteObject(g_hFont); return 0; //case WM_NCCALCSIZE: // return NcCalcSize(hwnd, wParam, lParam); case WM_INITMENU: CheckMenuCommand((HMENU)wParam, IDM_VIEW_LINENUMBERS, g_fLineNumbers); CheckMenuCommand((HMENU)wParam, IDM_VIEW_LONGLINES, g_fLongLines); CheckMenuCommand((HMENU)wParam, IDM_VIEW_SAVEEXIT, g_fSaveOnExit); CheckMenuCommand((HMENU)wParam, IDM_VIEW_STATUSBAR, g_fShowStatusbar); //CheckMenuCommand((HMENU)wParam, IDM_VIEW_SEARCHBAR, g_hwndSearchBar ? TRUE : FALSE); EnableMenuCommand((HMENU)wParam, IDM_EDIT_UNDO, TextView_CanUndo(g_hwndTextView)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_REDO, TextView_CanRedo(g_hwndTextView)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_PASTE, IsClipboardFormatAvailable(CF_TEXT)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_COPY, TextView_GetSelSize(g_hwndTextView)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_CUT, TextView_GetSelSize(g_hwndTextView)); EnableMenuCommand((HMENU)wParam, IDM_EDIT_DELETE, TextView_GetSelSize(g_hwndTextView)); return 0; //case WM_USER: // wsprintf(msgstr, _T("%s\n\nThis file has been modified outside of Neatpad.") // _T("Do you wish to reload it?"), g_szFileName); // MessageBox(hwnd, msgstr, _T("Neatpad"), MB_ICONQUESTION|MB_YESNO); // // return 0; case WM_ENABLE: // keep the modeless find/replace dialog in the same enabled state as the main window EnableWindow(g_hwndSearchDlg, (BOOL)wParam); return 0; case WM_MENUSELECT: StatusBarMenuSelect(hwnd, g_hwndStatusbar, wParam, lParam); return 0; case WM_NOTIFY: nmhdr = (NMHDR *)lParam; if(nmhdr->hwndFrom == g_hwndTextView) return TextViewNotifyHandler(hwnd, nmhdr); else return NotifyHandler(hwnd, nmhdr); case WM_COMMAND: return CommandHandler(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); case WM_SETFOCUS: SetFocus(g_hwndTextView); return 0; case WM_CLOSE: // does the file need saving? if(TextView_CanUndo(g_hwndTextView)) { UINT r; wsprintf(msgstr, _T("Do you want to save changes to\r\n%s?"), g_szFileName); r = MessageBox(hwnd, msgstr, APP_TITLE, MB_YESNOCANCEL | MB_ICONQUESTION); if(r == IDCANCEL) return 0; } DestroyWindow(hwnd); return 0; case WM_SIZE: // resize the TextView and StatusBar to fit within the main window's client area width = (short)LOWORD(lParam); height = (short)HIWORD(lParam); GetWindowRect(g_hwndStatusbar, &rect); heightsb = rect.bottom-rect.top; hdwp = BeginDeferWindowPos(3); if(g_fShowStatusbar) { DeferWindowPos(hdwp, g_hwndStatusbar, 0, 0, height - heightsb, width, heightsb, SWP_SHOWWINDOW); // MoveWindow(g_hwndStatusbar, 0, height - heightsb, width, heightsb, TRUE); height -= heightsb; } DeferWindowPos(hdwp, g_hwndTextView, 0, 0, 0, width, height, SWP_SHOWWINDOW); //MoveWindow(g_hwndTextView, 0, 0, width, height, TRUE); EndDeferWindowPos(hdwp); SetStatusBarParts(g_hwndStatusbar); return 0; } return DefWindowProc(hwnd, msg, wParam, lParam); }