Ejemplo n.º 1
0
BOOL HexSetCurFileName(HWND hwndMain, LPCTSTR szFileName)
{
	int idx;
	HWND hwndHV;
	
	if((hwndHV = HexIsOpen(hwndMain, szFileName, &idx)) != 0)
	{
		HexSetCurFile(hwndMain, idx, FALSE);
		return TRUE;
	}

	return FALSE;
}
Ejemplo n.º 2
0
BOOL UpdateHighlights2(HWND hwndHexView, HWND hwndGridView)
{

	HGRIDITEM hGridItem;
	hGridItem = GVI_ROOT;//GridView_InsertChild(hwndGridView, GVI_ROOT, &gvitem);

	SendMessage(hwndGridView, WM_SETREDRAW, FALSE, 0);
	GridView_DeleteAll(hwndGridView);

	if(hwndHexView == 0)
	{
		// just add bookmarks for specified hexview
		FillHexViewHighlights(GVI_ROOT, hwndHexView, hwndGridView, 0);
	}
	else if(hwndHexView != (HWND)-1)
	{
		int i;

		// add bookmarks for all open files
		for(i = 0; (hwndHexView = EnumHexView(g_hwndMain, i)) != 0; i++)
		{
			AddHexViewHighlights(GVI_ROOT, hwndHexView, hwndGridView, 0);
		}
	}
	else 
	{
		WIN32_FIND_DATA win32fd;
		HANDLE hFind;
		TCHAR szBookPath[MAX_PATH];
		TCHAR szFilePath[MAX_PATH];
		HCONFIG hConf ;

		GetProgramDataPath(szBookPath, MAX_PATH);
		lstrcat(szBookPath, TEXT("\\Bookmarks\\*"));

		// enumerate all files in the bookmarks directory
		if((hFind = FindFirstFile(szBookPath, &win32fd)) != 0)
		{
			do 
			{
				if((win32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
				{
					HWND hwndHV; 
					int i;
					HCONFIG hBookmarks, bookmark;
					HGRIDITEM hItem;

					GetProgramDataPath(szBookPath, MAX_PATH);
					wsprintf(szFilePath, TEXT("%s\\Bookmarks\\%s"), szBookPath, win32fd.cFileName);				

					hConf = OpenConfig(szFilePath);
					GetConfigStr(hConf, TEXT("hexFileData\\filePath"), szFilePath, MAX_PATH, 0);

					if((hwndHV = HexIsOpen(g_hwndMain, szFilePath, 0)) != 0)
					{
						AddHexViewHighlights(GVI_ROOT, hwndHV, hwndGridView, 0);
					}
					else
					{
						hItem = CreateBookmarkFileRoot(GVI_ROOT, szFilePath, hwndGridView, FALSE);
					//EnumHighlights(szBookPath, addgv, hwndGridView);

						hBookmarks = OpenConfigSection(hConf, TEXT("hexFileData\\bookmarks"));

						for(i = 0; bookmark = EnumConfigSection(hBookmarks, TEXT("bookmark"), i); i++)
						{
							TCHAR name[100], desc[100];
							BOOKMARK bm = { 0, 0, 0, 0, 0, name, 100, desc, 100 };

							GetConfigBookmark(bookmark, &bm);

							FillGridView2(hwndGridView, hItem, NULL, &bm, 0);
						//callback(&bm, param);	
						}
					}

					CloseConfig(hConf);
				}

			} while(FindNextFile(hFind, &win32fd));

			FindClose(hFind);
		}


	}

/*	for(hbm = 0; (hbm = HexView_EnumBookmark(hwndHexView, hbm, &bm)) != 0; )
	{
		TCHAR szOffset[32];
		TCHAR szTitle[32];

		_stprintf(szTitle, TEXT("%s"), bm.pszTitle);
		_stprintf(szOffset, TEXT("%08I64X  (%d bytes)"), bm.offset, bm.length);

		FillGridView2(hwndGridView, hGridItem, hbm, szTitle, szOffset, bm.pszText);
	}*/

	SendMessage(hwndGridView, WM_SETREDRAW, TRUE, 0);
	GridView_Update(hwndGridView);

	//ForceClientResize(hwndGridView);
	//InvalidateRect(hwndGridView, 0, 0);

	return TRUE;
}
Ejemplo n.º 3
0
BOOL UpdateHighlight(LPCTSTR pszFilePath, TCHAR * pszBookPath, BOOL fAlways)
{
	HWND hwndGV;
	HWND hwndHV;

	HGRIDITEM hItem  = 0;  
	GVITEM    gvitem = { GVIF_TEXT };

	// get the bookmark window's gridview
	if ((hwndGV = GetDlgItem(GetBookmarkWnd(), IDC_HIGHLIGHT_GRIDVIEW)) == 0)
		return FALSE;

	// find the gridview item for specified filename
	// (search for the matching filename)
	if(pszFilePath)
	{
		gvitem.pszText = (WCHAR *)pszFilePath;
		hItem = GridView_FindChild(hwndGV, NULL, &gvitem);
	}

	// file already open?
	if((hwndHV = HexIsOpen(g_hwndMain, pszFilePath, 0)) != 0)
	{
		// yes - update bookmarks from the hexview
		if(hItem == 0)
			hItem = CreateBookmarkFileRoot(GVI_ROOT, pszFilePath, hwndGV, TRUE);

		gvitem.mask  = GVIF_PARAM|GVIF_FONT;
		gvitem.iFont = 1; // bold
		gvitem.param = (UINT64)hwndHV;
		GridView_SetItem(hwndGV, hItem, &gvitem);

		GridView_DeleteChildren(hwndGV, hItem);
		FillHexViewHighlights(hItem, hwndHV, hwndGV, RGB(0,0,0));
		//		UpdateHighlights(
	}
	else if(fAlways)
	{
		// no - update bookmarks from the bookmark file
		TCHAR szBookPath[MAX_PATH] = { 0 };

		if(pszBookPath == 0)
		{
			pszBookPath = szBookPath;
			GetBookmarkFileName(0, pszFilePath, pszBookPath);
		}

		//if(hItem == 0 && pszFilePath)
		//	hItem = CreateBookmarkFileRoot(GVI_ROOT, pszFilePath, hwndGV, FALSE);

		UpdateHighlightsFromConfig(hItem, hwndGV, pszBookPath, RGB(128, 128, 128));

		InvalidateRect(hwndGV, 0, 0);
	}
	else 
	{
		if(hItem)
			GridView_DeleteItem(hwndHV, hItem);
	}
	//UpdateHighlights(

	return TRUE;
}
Ejemplo n.º 4
0
//
//	Open the specified file
//
BOOL HexOpenFile(HWND hwndMain, LPCTSTR szFileName, DWORD fHexViewFlags)
{
	HWND   hwndHV;
	TCITEM tci = { TCIF_PARAM, 0, 0, NULL, 0, 0, 0 };
	BOOL fReuseTab = FALSE;
	int  i;
	
	// is the file already open?!
	if(HexIsOpen(hwndMain, szFileName, &i))
	{
		return HexSetCurFile(hwndMain, i, TRUE);
	}
	
	// shall we use the (untitled) document or create a new window?
	if(TabCtrl_GetItemCount(g_hwndTabView) == 1 && TabCtrl_GetItem(g_hwndTabView, 0, &tci))
	{
		hwndHV = (HWND)tci.lParam;

		// is file (new) and unmodified?
		if(HexView_GetFileName(hwndHV, 0,0) == 0 && HexView_CanUndo(hwndHV) == FALSE && HexView_CanRedo(hwndHV) == FALSE)
		{
			fReuseTab = TRUE;
		}
	}
	
	if(fReuseTab == FALSE)
		hwndHV = CreateHexViewCtrl(hwndMain);

	// 
	if(HexView_OpenFile(hwndHV, szFileName, fHexViewFlags))
	{
		DWORD e = GetLastError();
			
		LoadHighlights(hwndHV);

		UpdateCurFileName(hwndMain, hwndHV, szFileName, FALSE);

		if(fReuseTab == FALSE)
		{
			tci.mask     = TCIF_PARAM | TCIF_TEXT | TCIF_STATE;
			tci.dwState  = TCIS_FILENAME;
			tci.lParam   = (LPARAM)hwndHV;
			tci.pszText  = (WCHAR *)szFileName;//g_szFileTitle;
			
			// insert at the end
			TabCtrl_InsertItem(g_hwndTabView, TabCtrl_GetItemCount(g_hwndTabView), &tci);			
		}

		UpdateMainTabs(g_hwndTabView);
		HexSetCurFile(hwndMain, TabCtrl_GetItemCount(g_hwndTabView)-1, TRUE);

		if(e == ERROR_SHARING_VIOLATION)
		{
			HexInfoBox(TEXT("%s\r\nhas been opened as read-only."), g_szFileName);
			//MessageBox(hwndMain, TEXT("Another "), TEXT("HexEdit"), MB_ICONINFORMATION);
		}

		UpdateHighlight(szFileName, 0, TRUE);
		UpdateTypeView();

		return TRUE;
	}
	else
	{
		DWORD dwError = GetLastError();
		DestroyWindow(hwndHV);
		FmtErrorMsg(hwndMain, MB_OK|MB_ICONWARNING, dwError, TEXT("Error opening \'%s\'\r\n\r\n"), szFileName);
		return FALSE;
	}
}