예제 #1
0
파일: OpenSave.c 프로젝트: avplayer/avdbg
BOOL HexeditOpenFile(HWND hwnd, LPCTSTR szFile, DWORD openFlags)
{
	TCHAR *name;
	TCHAR *fp;

	GetFullPathName(szFile, MAX_PATH, g_szFileName, &fp);

	name = _tcsrchr(g_szFileName, '\\');
	_tcscpy(g_szFileTitle, name ? name+1 : szFile);

	return HexOpenFile(hwnd, g_szFileName, openFlags);//, g_szFileTitle);
}
예제 #2
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;
}