void Replace(HWND hwndDlg, HWND hwndHV) { //BYTE replaceData[100]; //int replaceLen = sizeof(replaceData); int idx; int searchType; size_w selsize; // get the searchType from the datatype dropdown idx = (int)SendDlgItemMessage(hwndDlg, IDC_COMBO_DATATYPE, CB_GETCURSEL, 0, 0); searchType = (int)SendDlgItemMessage(hwndDlg, IDC_COMBO_DATATYPE, CB_GETITEMDATA, idx, 0); replaceLen = sizeof(replaceData); UpdateSearchData(GetDlgItem(hwndDlg, IDC_COMBO2), searchType, g_fBigEndian, replaceData, &replaceLen); HexView_GetSelSize(hwndHV, &selsize); if(selsize != replaceLen && HexView_GetEditMode(hwndHV) != HVMODE_INSERT) { MessageBox(hwndDlg, TEXT("Replace data must be same length in Overwrite mode"), TEXT("error"), MB_OK|MB_ICONWARNING); } else { HexView_SetDataCur(hwndHV, replaceData, replaceLen); } }
INT_PTR CALLBACK HighlightDlgProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { static BOOL fMask = FALSE; static HWND hwndHV; size_w offset, length; BOOKMARK bm = {0}; static TCHAR title[100]; static TCHAR text[200]; static int count; static HBOOKMARK hbm; switch (iMsg) { case WM_INITDIALOG: hwndHV = GetActiveHexView(GetParent(hwnd)); // GetOwner(hwnd);// SendDlgItemMessage(hwnd, IDC_NAME, EM_SETCUEBANNER, TRUE, (LPARAM)TEXT("Enter some descriptive text here")); SendDlgItemMessage(hwnd, IDC_ANNOTATION, EM_SETCUEBANNER, 0, (LPARAM)TEXT("Enter some descriptive text here")); //MakeColourCombo(GetDlgItem(hwnd, IDC_COMBO1), fgcollist, fgtextlist, 16); MakeColourCombo(GetDlgItem(hwnd, IDC_COMBO4), bgcollist, bgtextlist, 16); hbm = (HBOOKMARK)lParam; if(hbm == 0) { HexView_GetSelStart(hwndHV, &offset); HexView_GetSelSize(hwndHV, &length); wsprintf(title, TEXT("bookmark-%03d"), ++count); //lstrcpy(title, TEXT(""));//TEXT("Enter some descriptive text here")); lstrcpy(text, TEXT(""));//TEXT("Enter some descriptive text here")); } else { HBOOKMARK hbm = (HBOOKMARK)lParam; BOOKMARK bm; HexView_GetBookmark(hwndHV, hbm, &bm); offset = bm.offset; length = bm.length; lstrcpy(title, bm.pszTitle); lstrcpy(text, bm.pszText); // Set the selected color for (int i = 0; i < 16; i++) { if (bm.backcol == bgcollist[i]) { SendMessage(GetDlgItem(hwnd, IDC_COMBO4), CB_SETCURSEL, i, 0); break; } } } SetDlgItemBaseInt(hwnd, IDC_OFFSET, offset, 16, 1); SetDlgItemBaseInt(hwnd, IDC_LENGTH, length, 16, 1); SetDlgItemText(hwnd, IDC_NAME, title); SetDlgItemText(hwnd, IDC_ANNOTATION, text); //ClientToScreen(hwndParent, &pt); //GetCursorPos(&pt); //SetWindowPos(hwnd, 0, pt.x, pt.y, 0, 0, SWP_NOSIZE); CenterWindow(hwnd); return TRUE; case WM_CLOSE: EndDialog(hwnd, FALSE); return TRUE; case WM_COMMAND: switch(LOWORD(wParam)) { case IDOK: GetDlgItemText(hwnd, IDC_ANNOTATION, text, 200); GetDlgItemText(hwnd, IDC_NAME, title, 100); bm.col = 0; bm.backcol = GetColourComboRGB(GetDlgItem(hwnd, IDC_COMBO4));//RGB(rand()+128, rand()+128, rand()+128);//0xffffff; bm.pszText = text; bm.pszTitle = title; bm.offset = GetDlgItemBaseInt(hwnd, IDC_OFFSET, 16); bm.length = GetDlgItemBaseInt(hwnd, IDC_LENGTH, 16); if(hbm == 0) { HexView_AddBookmark(hwndHV, &bm); } else { HexView_SetBookmark(hwndHV, hbm, &bm); } // DockWnd_UpdateContent(g_hwndMain, DWID_HIGHLIGHT); ///UpdateHighlights(hwndHV, hwndGridView); EndDialog(hwnd, TRUE); return 0; case IDCANCEL: EndDialog(hwnd, FALSE); return 0; default: return FALSE; } default: break; } return FALSE; }
// // Main Window message handler // LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { NMHDR *hdr; POINT pt; RECT rect; HMENU hMenu; HWND hwndHV = GetActiveHexView(hwnd);//g_hwndHexView; int i; TCITEM tci; MAINWND *mainWnd = (MAINWND *)GetWindowLongPtr(hwnd, 0); switch(msg) { case WM_NCCREATE: if((mainWnd = malloc(sizeof(MAINWND))) == 0) return FALSE; SetWindowLongPtr(hwnd, 0, (LONG_PTR)mainWnd); ZeroMemory(mainWnd, sizeof(MAINWND)); return TRUE; case WM_NCDESTROY: free(mainWnd); return 0; case WM_CREATE: g_hwndMain = hwnd; SetWindowIcon(hwnd, IDI_APP); // create a child-window EDIT control //g_hwndHexView = CreateHexViewCtrl(hwnd); g_hwndTabView = CreateWindow(WC_TABVIEW, TEXT(""), WS_CHILD|WS_VISIBLE,0,0,0,0,hwnd, 0, g_hInstance, 0); g_hwndStatusBar = CreateStatusBar(hwnd); SendMessage(g_hwndTabView, TCM_SETITEMSIZE, 0, MAKELPARAM(150, 0)); SetStatusBarParts(g_hwndStatusBar); hwndHV = g_hwndHexView; mainWnd->hwndMain = hwnd; mainWnd->hwndStatusBar = g_hwndStatusBar; mainWnd->hwndTabView = g_hwndTabView; CreateToolTip(g_hwndHexView); // g_hwndDock[0] = CreateDockWnd(&dock, hwnd, TEXT("Toolbar")); //g_hwndToolbar = InitToolbar(hwnd); //g_hwndSearchBar = CreateSearchBar(hwnd); //g_hwndTypeView = CreateTypeView(hwnd); SetFocus(hwndHV); // tell windows that we can handle drag+drop'd files DragAcceptFiles(hwnd, TRUE); UpdateRecentMenu(GetSubMenu(GetMenu(hwnd), 0)); SetTimer(hwnd, 0xdeadbeef, 1000, 0); return TRUE; case WM_TIMER: if(wParam == 0xdeadbeef) { KillTimer(hwnd, wParam); //FirstTimeOptions(hwnd); } return 0; case WM_DROPFILES: // get the screen coordinates of the drop-location if(DragQueryPoint((HDROP)wParam, &pt)) ClientToScreen(hwnd, &pt); GetWindowRect(hwndHV, &rect); // drop anywhere *except* the hexview, as that does D&D itself if(!PtInRect(&rect, pt)) { HandleDropFiles(hwnd, (HDROP)wParam); } //CreateToolTip(mainWnd->hwndTabView); return 0; case WM_ENABLE: EnableWindow(g_hwndSearch, (BOOL)wParam); EnableWindow(g_hwndGoto, (BOOL)wParam); return 0; case WM_CONTEXTMENU: if((HWND)wParam == DockWnd_GetWindow(hwnd, DWID_TYPEVIEW)) { HMENU hMenu = GetSubMenu(LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_TYPECONTEXT)), 0); UINT u; MenuCheckMark(hMenu, IDM_TYPEVIEW_HEX, g_fDisplayHex); MenuCheckMark(hMenu, IDM_TYPEVIEW_BIGENDIAN, g_fDisplayBigEndian); u = TrackPopupMenu(hMenu, TPM_RETURNCMD, (short)LOWORD(lParam), (short)HIWORD(lParam), 0, hwnd, 0); SendMessage(DockWnd_GetContents(hwnd, DWID_TYPEVIEW), WM_COMMAND, u, 0); } break; case WM_COMMAND: return HexEdit_OnCommand(hwnd, LOWORD(wParam), HIWORD(wParam), (HWND)lParam); case WM_NOTIFY: hdr = (NMHDR *)lParam; if(hdr->hwndFrom == hwndHV) return HexViewNotifyHandler(mainWnd, hwnd, hdr); else return HexEdit_OnNotify(mainWnd, hwnd, (UINT)wParam, (NMHDR *)lParam); case WM_CLOSE: tci.mask = TCIF_PARAM; for(i = 0; (hwndHV = EnumHexView(hwnd, i)) != NULL; ) { UINT uAnswer = HexFileCloseNotify(hwnd, hwndHV); if(uAnswer == IDCANCEL) { return 0; } else if(uAnswer == IDNO) { SaveHighlights(hwndHV); TabCtrl_DeleteItem(mainWnd->hwndTabView, i); } else { i++; } } // save settings *before* we destroy anything! DockWnd_SaveSettings(hwnd); // shut program down DestroyWindow(hwnd); return 0; case WM_DESTROY: DestroyWindow(hwndHV); // PostQuitMessage(0); return 0; case WM_SETFOCUS: SetFocus(hwndHV); return 0; case WM_SIZE: MainWndSize(mainWnd, LOWORD(lParam), HIWORD(lParam)); UpdateStatusbar(mainWnd->hwndStatusBar); return 0; case WM_INITMENUPOPUP: hMenu = (HMENU)wParam;//GetMenu(hwnd); MenuCheckMark(hMenu, IDM_VIEW_TOOLBAR, DockWnd_IsOpen(hwnd, DWID_TOOLBAR)); MenuCheckMark(hMenu, IDM_TOOLS_TYPEVIEW, DockWnd_IsOpen(hwnd, DWID_TYPEVIEW)); MenuCheckMark(hMenu, IDM_TOOLS_SEARCHBAR, DockWnd_IsOpen(hwnd, DWID_SEARCHBAR)); CheckMenuRadioItem(hMenu, IDM_VIEW_HEX, IDM_VIEW_BIN, IDM_VIEW_HEX + (HexView_GetStyle(hwndHV) & HVS_FORMAT_MASK), MF_BYCOMMAND); { int look[32] = { 0, 0, 1, 0, 2 }; CheckMenuRadioItem(hMenu, IDM_GROUP_BYTE, IDM_GROUP_DWORD, IDM_GROUP_BYTE + look[HexView_GetGrouping(hwndHV)], MF_BYCOMMAND); } { size_w selsize; UINT edmode = HexView_GetEditMode(hwndHV); BOOL cftext = IsClipboardFormatAvailable(CF_TEXT); BOOL canundo = HexView_CanUndo(hwndHV); BOOL canredo = HexView_CanRedo(hwndHV); HexView_GetSelSize(hwndHV, &selsize); //hMenu = GetSubMenu(GetMenu(hwnd), 1); EnableMenuCmdItem(hMenu, IDM_EDIT_UNDO, canundo); EnableMenuCmdItem(hMenu, IDM_EDIT_REDO, canredo); EnableMenuCmdItem(hMenu, IDM_EDIT_CUT, selsize > 0 && edmode == HVMODE_INSERT); EnableMenuCmdItem(hMenu, IDM_EDIT_COPY, selsize > 0); EnableMenuCmdItem(hMenu, IDM_EDIT_COPYAS, selsize > 0); EnableMenuCmdItem(hMenu, IDM_EDIT_PASTE, cftext && edmode != HVMODE_READONLY ); EnableMenuCmdItem(hMenu, IDM_EDIT_PASTESPECIAL, edmode != HVMODE_READONLY ); EnableMenuCmdItem(hMenu, IDM_EDIT_DELETE, selsize > 0 && edmode != HVMODE_READONLY ); EnableMenuCmdItem(hMenu, IDM_EDIT_REVERSE, selsize > 0 && edmode != HVMODE_READONLY ); EnableMenuCmdItem(hMenu, IDM_TOOLS_TRANSFORM, selsize > 0 && edmode != HVMODE_READONLY ); EnableMenuCmdItem(hMenu, IDM_FILE_REVERT, canundo || canredo); } return 0; } return DefWindowProc(hwnd, msg, wParam, lParam); }
INT_PTR CALLBACK ModifyDlgProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { static size_w len; HWND hwndHV = GetActiveHexView(g_hwndMain); static BOOL fHexLength = FALSE; static int nLastOperand = 0; static int nLastOperation = 0; static BOOL fBigEndian = FALSE; int basetype; static const int SearchTypeFromBaseType[] = { SEARCHTYPE_BYTE, SEARCHTYPE_WORD, SEARCHTYPE_DWORD, SEARCHTYPE_QWORD, SEARCHTYPE_BYTE, SEARCHTYPE_WORD, SEARCHTYPE_DWORD, SEARCHTYPE_QWORD, SEARCHTYPE_FLOAT, SEARCHTYPE_DOUBLE, }; switch (iMsg) { case WM_INITDIALOG: AddComboStringList(GetDlgItem(hwnd, IDC_MODIFY_DATATYPE), szTypeList, 0); AddComboStringList(GetDlgItem(hwnd, IDC_MODIFY_OPERATION), szOpList, nLastOperation); SetDlgItemBaseInt(hwnd, IDC_MODIFY_OPERAND, nLastOperand, fHexLength ? 16 : 10, FALSE); CheckDlgButton(hwnd, IDC_HEX, fHexLength ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwnd, IDC_ENDIAN, fBigEndian ? BST_CHECKED : BST_UNCHECKED); //len = HexView_GetSelSize(hwndHV); //SetDlgItemBaseInt(hwnd, IDC_MODIFY_NUMBYTES, len, fHexLength ? 16 : 10, FALSE); CenterWindow(hwnd); return TRUE; case WM_CLOSE: EndDialog(hwnd, FALSE); return TRUE; case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_MODIFY_OPERATION: case IDC_MODIFY_OPERAND: case IDC_MODIFY_NUMBYTES: nLastOperation = (int)SendDlgItemMessage(hwnd, IDC_MODIFY_OPERATION, CB_GETCURSEL, 0, 0); nLastOperand = (int)GetDlgItemBaseInt(hwnd, IDC_MODIFY_OPERAND, fHexLength ? 16 : 10); len = GetDlgItemBaseInt(hwnd, IDC_MODIFY_NUMBYTES, fHexLength ? 16 : 10); return TRUE; case IDC_ENDIAN: fBigEndian = IsDlgButtonChecked(hwnd, IDC_ENDIAN); return TRUE; case IDC_HEX: fHexLength = IsDlgButtonChecked(hwnd, IDC_HEX); /* len = HexView_GetSelSize(hwndHV); SetDlgItemBaseInt(hwnd, IDC_MODIFY_NUMBYTES, len, fHexLength ? 16 : 10, FALSE); */ SetDlgItemBaseInt(hwnd, IDC_MODIFY_OPERAND, nLastOperand, fHexLength ? 16 : 10, FALSE); SendDlgItemMessage(hwnd, IDC_MODIFY_OPERAND, EM_SETSEL, 0, -1); SetDlgItemFocus(hwnd, IDC_MODIFY_OPERAND); return TRUE; case IDOK: // get the basetype we are using basetype = (int)SendDlgItemMessage(hwnd, IDC_INSERT_DATATYPE, CB_GETCURSEL, 0, 0); basetype = SearchTypeFromBaseType[basetype]; // get the operand in raw-byte format, ensure it is always little-endian // as we must do these calculations using the native byte ordering format operandLen = sizeof(operandData); UpdateSearchData(GetDlgItem(hwnd, IDC_MODIFY_OPERAND), basetype, FALSE, operandData, &operandLen); HexView_GetSelSize(hwndHV, &len); ModifyHexViewData(hwndHV, nLastOperation, operandData, len, basetype, fBigEndian); EndDialog(hwnd, TRUE); return TRUE; case IDCANCEL: EndDialog(hwnd, FALSE); return TRUE; default: return FALSE; } case WM_HELP: return HandleContextHelp(hwnd, lParam, IDD_TRANSFORM); default: break; } return FALSE; }