Exemple #1
0
LRESULT CALLBACK HighlightViewCommandHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	extern HWND g_hwndMain;

	HWND hwndHV = GetActiveHexView(g_hwndMain);

	if (msg == WM_COMMAND)
	{
		switch (LOWORD(wParam))
		{
		case IDC_HIGHLIGHT_ADD:
			HighlightDlg(NULL, NULL);
			break;
		case IDC_HIGHLIGHT_EDIT:
		{
			HWND hwndGridView = GetDlgItem(hwnd, IDC_HIGHLIGHT_GRIDVIEW);
			ULONG curSelItem = GridView_GetCurSel(hwndGridView);
			HGRIDITEM hgCurSelItem = GridView_GetItemHandle(hwndGridView, curSelItem);
			GVITEM curItem = { GVIF_PARAM, curSelItem, 0 };

			// Get the current item - param contains the HBOOKMARK for this item
			if (GridView_GetItem(hwndGridView, hgCurSelItem, &curItem) && curItem.param)
			{
				HBOOKMARK hbm = (HBOOKMARK)curItem.param;

				// Get the parent item - param contains the HWND for the hexview
				if (GridView_GetParentItem(hwndGridView, hgCurSelItem, &curItem) && curItem.param)
				{
					HWND hwndHexView = (HWND)curItem.param;

					HighlightDlg(hwndHexView, hbm);
				}
			}

			break;
		}
		case IDC_HIGHLIGHT_DELETE:
		{
			TCHAR itemText[100] = { 0 };
			HWND hwndGridView = GetDlgItem(hwnd, IDC_HIGHLIGHT_GRIDVIEW);
			ULONG curSelItem = GridView_GetCurSel(hwndGridView);
			HGRIDITEM hgCurSelItem = GridView_GetItemHandle(hwndGridView, curSelItem);
			GVITEM curItem = { GVIF_PARAM | GVIF_TEXT, curSelItem, 0 };
			curItem.pszText = itemText;
			curItem.cchTextMax = ARRAYSIZE(itemText);

			// Get the current item - param contains the HBOOKMARK for this item
			if (GridView_GetItem(hwndGridView, hgCurSelItem, &curItem))
			{
				if (curItem.param)
				{
					HBOOKMARK hbm = (HBOOKMARK)curItem.param;

					// Get the parent item - param contains the HWND for the hexview
					if (GridView_GetParentItem(hwndGridView, hgCurSelItem, &curItem) && curItem.param)
					{
						HWND hwndHexView = (HWND)curItem.param;

						GridView_DeleteItem(hwndGridView, hgCurSelItem);
						HexView_DelBookmark(hwndHexView, hbm);
						GridView_Update(hwndGridView);
					}
				}
				else
				{
					// This wasn't a live bookmark - it exists in a config file
					TCHAR parentText[100] = { 0 };
					curItem.pszText = parentText;
					if (GridView_GetParentItem(hwndGridView, hgCurSelItem, &curItem))
					{
						DeleteBookmarkFromConfig(parentText, itemText);
						GridView_DeleteAll(hwndGridView);
						UpdateHighlights(TRUE);
					}
				}
			}

			break;
		}
		}
		return 0;
	}

	if(msg == WM_NOTIFY)
	{
		NMGRIDVIEW *nmgv = (NMGRIDVIEW *)lParam;

		if(nmgv->hdr.code == GVN_DBLCLK)
		{
			GVITEM gvi = { GVIF_PARAM, nmgv->iItem, 0 };//nmgv->nColumn };

			if(GridView_GetParent(nmgv->hdr.hwndFrom, nmgv->hItem))
			{
				if(GridView_GetItem(nmgv->hdr.hwndFrom, nmgv->hItem, &gvi))
				{
					// file is not open yet!
					if(gvi.param == 0)
					{
						TCHAR szFileName[MAX_PATH];
						gvi.mask |= GVIF_TEXT;
						gvi.pszText = szFileName;
						gvi.cchTextMax = MAX_PATH;
						
						if(GridView_GetParentItem(nmgv->hdr.hwndFrom, nmgv->hItem, &gvi))
						{
							HexOpenFile(g_hwndMain, szFileName, DefaultFileMode());
						}
					}
					else
					{
						HighlightDlg(hwndHV, (HBOOKMARK)gvi.param);
					}
				}
			}
		}
		else if(nmgv->hdr.code == GVN_DELETED)
		{
			GVITEM gvi = { GVIF_PARAM, nmgv->iItem, 0 };//nmgv->nColumn };
			//HIGHLIGHT_PARAM hp;

			// get current item in gridview
			GridView_GetItem(nmgv->hdr.hwndFrom, nmgv->hItem, &gvi);

			HexView_DelBookmark(hwndHV, (HBOOKMARK)gvi.param);
			return 0;
		}
		else if(nmgv->hdr.code == GVN_SELCHANGED)
		{
			GVITEM gvi = { GVIF_PARAM, nmgv->iItem, 0 };//nmgv->nColumn };
			BOOKMARK bm;

			// get the gvi.param - contains the HBOOKMARK for this bookmark entry
			if(GridView_GetItem(nmgv->hdr.hwndFrom, nmgv->hItem, &gvi) && gvi.param)
			{
				HBOOKMARK hbm = (HBOOKMARK)gvi.param;

				// get parent item's param - contains HWND to the hexview
				if(GridView_GetParentItem(nmgv->hdr.hwndFrom, nmgv->hItem, &gvi) && gvi.param)
				{
					// make sure the current file is active
					hwndHV = (HWND)gvi.param;
					HexSetCurFileHwnd(g_hwndMain, hwndHV);

					if(HexView_GetBookmark(hwndHV, hbm, &bm))
					{
						HexView_SetCurPos(hwndHV, bm.offset + bm.length);
						HexView_SetSelStart(hwndHV, bm.offset);
						HexView_SetSelEnd(hwndHV, bm.offset + bm.length);
						HexView_ScrollTo(hwndHV,  bm.offset + bm.length);
						InvalidateRect(hwndHV,0,0);
					}
				}
			}
			return 0;
		}
	}

	return 0;
}
Exemple #2
0
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nShowCmd)
{
    MSG		msg;
    HACCEL	hAccel;
    TCHAR	arg[MAX_PATH];
    TCHAR *	pszCmdline;

    EnableCrashingOnCrashes();

    //INITCOMMONCONTROLSEX icx = { sizeof(icx), ICC_
    g_hInstance = hInst;

    // This program requires COM
    OleInitialize(0);

    //
    //	Commandline processing
    //

    pszCmdline = GetArg(GetCommandLineW(), arg, MAX_PATH);

    if(pszCmdline && *pszCmdline == '-')
    {
        pszCmdline = GetArg(pszCmdline, arg, MAX_PATH);

        // 'touch' the specified file!
        if(lstrcmpi(arg, TEXT("-touch")) == 0)
        {
            // check to see if it's a quoted filename
            if(*pszCmdline == '\"')
            {
                GetArg(pszCmdline, arg, MAX_PATH);
                pszCmdline = arg;
            }

            if(!TouchFile(pszCmdline))
            {
                HexWinErrorBox(GetLastError(), 0);
                return 1;
            }
            return 0;
        }
        else
        {
            pszCmdline = GetArg(pszCmdline, arg, MAX_PATH);
        }
    }


    {
        INITCOMMONCONTROLSEX icex = { sizeof(icex), -1 };
        InitCommonControlsEx(&icex);
    }

    /*g_Config = OpenConfig(TEXT("mapsize.exe.129082349834.bookmarks"));
    smeg(g_Config, TEXT("bookmarks.bookmark."), TEXT("mapsize.exe"));
    SaveConfig(TEXT("oof.config"), g_Config);*/
    LoadSettings();

    RegisterTabView();
    InitMainWnd();
    CreateMainWnd();


    // open file specified on commmand line?
    if(pszCmdline && *pszCmdline)
    {
        // check to see if it's a quoted filename
        if(*pszCmdline == '\"')
        {
            GetArg(pszCmdline, arg, MAX_PATH);
            pszCmdline = arg;
        }

        if(!HexeditOpenFile(g_hwndMain, pszCmdline, DefaultFileMode()))//HVOF_DEFAULT))
        {
            SendMessage(g_hwndMain, WM_COMMAND, IDM_FILE_NEW, 0);
        }
    }
    // automatically create new document if none specified
    else
    {
        SendMessage(g_hwndMain, WM_COMMAND, IDM_FILE_NEW, 0);
    }

    InitDockingBars(g_hwndMain);

    if(g_fRestoreWinPos)
        nShowCmd = SW_SHOW;

    ShowWindow(g_hwndMain, nShowCmd);

    // force any floating popups (i.e. the DOCKWNDs) to
    // become visible at the same time
    //ShowOwnedPopups(g_hwndMain, TRUE);
    DockWnd_ShowDeferredPopups(g_hwndMain);

    //
    // load keyboard accelerator table
    //
    hAccel = LoadAccelerators(GetModuleHandle(0)/*g_hResourceModule*/, MAKEINTRESOURCE(IDR_ACCELERATOR1));

    //
    // message-pump
    //
    while(GetMessage(&msg, 0, 0, 0) > 0)
    {
        if(!TranslateAccelerator(g_hwndMain, hAccel, &msg))
        {
            if( !IsDialogMessage(g_hwndSearch, &msg) &&
                    !IsDialogMessage(g_hwndGoto, &msg)   &&
                    !DockWnd_IsDialogMessage(g_hwndMain, DWID_TYPEVIEW, &msg) &&
                    !DockWnd_IsDialogMessage(g_hwndMain, DWID_SEARCHBAR, &msg) &&
                    !DockWnd_IsDialogMessage(g_hwndMain, DWID_HIGHLIGHT, &msg)
              )
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
    }

    SaveSettings();

    // Shutdown COM
    OleUninitialize();

    return 0;
}