LONG StatusBar_DropDownTB(MAINWND *mainWnd, HWND hwndHV, NMTOOLBAR *nmtb) { RECT rect = nmtb->rcButton; HMENU hMenu, hPopup; UINT mode, cmdId; MapWindowPoints(nmtb->hdr.hwndFrom, 0, (POINT *)&rect, 2); switch(nmtb->hdr.idFrom) { case IDM_STATUSBAR_CURSORPOS: hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MENU3)); hPopup = GetSubMenu(hMenu, 0); MenuCheckMark(hPopup, IDM_STATUS_HEX, g_fStatusHexCursor); MenuCheckMark(hPopup, IDM_STATUS_DEC, !g_fStatusHexCursor); break; case IDM_STATUSBAR_VALUE: hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MENU2)); hPopup = GetSubMenu(hMenu, 0); MenuCheckMark(hPopup, IDM_VALUE_SIGNED, g_fStatusSignedValue); MenuCheckMark(hPopup, IDM_VALUE_ENDIAN, g_fStatusBigEndian); MenuCheckMark(hPopup, IDM_VALUE_HEX, g_fStatusHexValue); CheckMenuRadioItem(hPopup, IDM_VALUE_BYTE, IDM_VALUE_DOUBLE, g_nStatusValueType, MF_BYCOMMAND); break; case IDM_STATUSBAR_SIZE: hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MENU3)); hPopup = GetSubMenu(hMenu, 0); MenuCheckMark(hPopup, IDM_STATUS_HEX, g_fStatusHexSize); MenuCheckMark(hPopup, IDM_STATUS_DEC, !g_fStatusHexSize); break; case IDM_STATUSBAR_MODE: hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MENU4)); hPopup = GetSubMenu(hMenu, 0); mode = HexView_GetEditMode(hwndHV); MenuCheckMark(hPopup, IDM_STATUSBAR_INSERT, mode == HVMODE_INSERT); MenuCheckMark(hPopup, IDM_STATUSBAR_OVERWRITE, mode == HVMODE_OVERWRITE); MenuCheckMark(hPopup, IDM_STATUSBAR_READONLY, mode == HVMODE_READONLY); break; } //CheckMenuItem(hMenu, IDM_ cmdId = TrackPopupMenu(hPopup, TPM_RETURNCMD|TPM_RIGHTALIGN|TPM_BOTTOMALIGN, rect.right, rect.top, 0, g_hwndMain, 0); switch(cmdId) { case IDM_STATUSBAR_INSERT: HexView_SetEditMode(hwndHV, HVMODE_INSERT); break; case IDM_STATUSBAR_OVERWRITE: HexView_SetEditMode(hwndHV, HVMODE_OVERWRITE); break; case IDM_STATUSBAR_READONLY: HexView_SetEditMode(hwndHV, HVMODE_READONLY); break; case IDM_STATUS_HEX: if(nmtb->hdr.idFrom == IDM_STATUSBAR_SIZE) g_fStatusHexSize = TRUE; else g_fStatusHexCursor = TRUE; break; case IDM_STATUS_DEC: if(nmtb->hdr.idFrom == IDM_STATUSBAR_SIZE) g_fStatusHexSize = FALSE; else g_fStatusHexCursor = FALSE; break; case IDM_VALUE_HEX: g_fStatusHexValue = !g_fStatusHexValue; break; case IDM_VALUE_ENDIAN: g_fStatusBigEndian = !g_fStatusBigEndian; break; case IDM_VALUE_SIGNED: g_fStatusSignedValue = !g_fStatusSignedValue; break; case IDM_VALUE_BYTE: case IDM_VALUE_WORD: case IDM_VALUE_DWORD: case IDM_VALUE_QWORD: case IDM_VALUE_FLOAT: case IDM_VALUE_DOUBLE: g_nStatusValueType = cmdId; break; } DestroyMenu(hMenu); UpdateStatusBarText(mainWnd->hwndStatusBar, hwndHV); if(nmtb->hdr.idFrom == IDM_VALUE_SHOW) { } return 0; }
// // 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); }
//------------------------------------------------------------------- LRESULT CALLBACK WndProc (HWND hwnd, UINT mMsg, WPARAM wParam, LPARAM lParam) { switch (mMsg) { case WM_CREATE : { pophwnd(hwnd); // Create toolbar (source resides in toolbar.c). hwndToolBar = InitToolBar (hwnd,hInst) ; // Create status bar (source resides in statbar.c). hwndStatusBar = InitStatusBar (hwnd) ; if (flg_toolbar==0) ShowWindow (hwndToolBar, SW_HIDE) ; if (flg_statbar==0) ShowWindow (hwndStatusBar, SW_HIDE) ; // Create client window (contains notify list). hwndClient = CreateWindowEx (WS_EX_CLIENTEDGE, "ClientWndProc", NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd, (HMENU) 4, hInst, NULL) ; return 0 ; } case WM_INITMENUPOPUP : return poppad_menupop( wParam,lParam ); case WM_SETFOCUS : SetFocus (hwndClient) ; return 0 ; case WM_COMMAND : { // Menu item commands switch (LOWORD (wParam)) { // Toggle display of toolbar case IDM_VIEW_TOOLBAR : { RECT r ; if (hwndToolBar && IsWindowVisible (hwndToolBar)) { ShowWindow (hwndToolBar, SW_HIDE) ; flg_toolbar=0; } else { ShowWindow (hwndToolBar, SW_SHOW) ; flg_toolbar=1; } // Resize other windows. GetClientRect (hwnd, &r) ; PostMessage (hwnd, WM_SIZE, 0, MAKELPARAM (r.right, r.bottom)) ; break; } // Toggle display of status bar case IDM_VIEW_STATUS : { RECT r; if (hwndStatusBar && IsWindowVisible (hwndStatusBar)) { ShowWindow (hwndStatusBar, SW_HIDE) ; flg_statbar=0; } else { ShowWindow (hwndStatusBar, SW_SHOW) ; flg_statbar=1; } // Resize other windows. GetClientRect (hwnd, &r) ; PostMessage (hwnd, WM_SIZE, 0, MAKELPARAM (r.right, r.bottom)) ; break; } case IDM_HSCROLL: poppad_setsb(2); break; default: return (EditProc (hwnd, mMsg, wParam, lParam)) ; } return 0; } case WM_INITMENU : { BOOL bCheck ; HMENU hmenu = (HMENU) wParam ; // View menu items. bCheck = IsWindowVisible (hwndToolBar) ; MenuCheckMark (hmenu, IDM_VIEW_TOOLBAR, bCheck) ; bCheck = IsWindowVisible (hwndStatusBar) ; MenuCheckMark (hmenu, IDM_VIEW_STATUS, bCheck) ; bCheck=poppad_setsb(-1); MenuCheckMark (hmenu, IDM_HSCROLL, bCheck) ; return 0 ; } case WM_CLOSE : case WM_QUERYENDSESSION : return poppad_term( mMsg ); case WM_MENUSELECT : return Statusbar_MenuSelect (hwnd, wParam, lParam) ; case WM_DESTROY : RemoveProp(hwnd, PROP_NAME); PostQuitMessage (0) ; return 0 ; case WM_NOTIFY : { LPNMHDR pnmh = (LPNMHDR) lParam ; // int idCtrl = (int) wParam ; // Display notification details in notify window //DisplayNotificationDetails (wParam, lParam) ; // Toolbar notifications if ((pnmh->code >= TBN_LAST) && (pnmh->code <= TBN_FIRST)) { return ToolBarNotify (hwnd, wParam, lParam) ; } // Fetch tooltip text if (pnmh->code == TTN_NEEDTEXT) { LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT) lParam ; CopyToolTipText (lpttt) ; } return 0 ; } case WM_WINDOWPOSCHANGING : { WINDOWPOS *wp; wp=(WINDOWPOS *)lParam; if ((wp->cy)&&(wp->cy)) { posx=wp->x;posy=wp->y; winx=wp->cx;winy=wp->cy; } } break; case WM_SIZE : { int cx = LOWORD (lParam) ; int cy = HIWORD (lParam) ; int cyStatus ; int cyTB ; int x, y ; DWORD dwStyle ; RECT rWindow ; // Ignore size message to allow auto-move and auto-size // features to be more clearly seen. if (bIgnoreSize) return 0 ; // Adjust toolbar size. if (IsWindowVisible (hwndToolBar)) { dwStyle = GetWindowLong (hwndToolBar, GWL_STYLE) ; if (dwStyle & CCS_NORESIZE) { MoveWindow (hwndToolBar, 0, 0, cx, cyToolBar, FALSE) ; } else { ToolBar_AutoSize (hwndToolBar) ; } InvalidateRect (hwndToolBar, NULL, TRUE) ; GetWindowRect (hwndToolBar, &rWindow) ; ScreenToClient (hwnd, (LPPOINT) &rWindow.left) ; ScreenToClient (hwnd, (LPPOINT) &rWindow.right) ; cyTB = rWindow.bottom - rWindow.top ; } else { cyTB = 0 ; } // Adjust status bar size. if (IsWindowVisible (hwndStatusBar)) { GetWindowRect (hwndStatusBar, &rWindow) ; cyStatus = rWindow.bottom - rWindow.top ; MoveWindow (hwndStatusBar, 0, cy - cyStatus, cx, cyStatus, TRUE) ; } else { cyStatus = 0 ; } // Adjust client window size. x = 0 ; y = cyTB ; cy -= cyStatus + cyTB; MoveWindow (hwndClient, x, y, cx, cy, TRUE) ; return 0; } case WM_COPYDATA: { COPYDATASTRUCT *pcds = (COPYDATASTRUCT*)lParam; LoadFromCommandLine((char *)pcds->lpData); return 0; } default: return (EditDefProc (hwnd, mMsg, wParam, lParam)) ; } return DefWindowProc (hwnd, mMsg, wParam, lParam) ; }