⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hexwnd.cpp

📁 一百个病毒的源代码 包括熊猫烧香等 极其具有研究价值
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		break;
	case SB_PAGEUP:
		if (iCurLine >= cyBuffer)
			iCurLine -= cyBuffer;
		else
			iCurLine = 0;
		break;
	case SB_PAGEDOWN:
		if (iCurLine <= iNumlines-1-cyBuffer)
			iCurLine += cyBuffer;
		else
			iCurLine = iNumlines-1;
		break;
	case SB_THUMBTRACK:
		iCurLine = (int) (pos * ((float)(iNumlines-1)/(float)iVscrollMax));
		SetScrollPos (hwndVBar, SB_CTL, pos, TRUE);
		if (iCurLine > iNumlines-1)
			iCurLine = iNumlines-1;
		// Make sure the number of empty lines is as small as possible.
		if( iNumlines - iCurLine < cyBuffer )
		{
			iCurLine = ( ( DataArray.GetUpperBound() + 1 ) / iBytesPerLine ) - ( cyBuffer - 1 );
			if( iCurLine < 0 )
				iCurLine = 0;
		}
		repaint();
		return 0;
	default:
		break;
	}
	iVscrollPos = (int) ((float)iCurLine * ((float)iVscrollMax)/(float)(iNumlines-1));
	SetScrollPos (hwndVBar, SB_CTL, iVscrollPos, TRUE);
	if (iCurLine > iNumlines-1)
		iCurLine = iNumlines-1;
	repaint ();
	return 0;
}

//--------------------------------------------------------------------------------------------
// Handler for horizontal scrollbar.
int HexEditorWindow::hscroll (int cmd, int pos)
{
	if (NO_FILE || DataArray.GetLength()==0)
		return 0;

	iHscrollInc = 0;
	switch (cmd)
	{
	case SB_TOP:
		iHscrollInc = -iHscrollPos;
		break;
	case SB_BOTTOM:
		iHscrollInc = iHscrollMax - iHscrollPos;
		break;
	case SB_LINEUP:
		if (iHscrollPos > 0)
			iHscrollInc = -1;
		break;
	case SB_LINEDOWN:
		if (iHscrollPos < iHscrollMax)
			iHscrollInc = 1;
		break;
	case SB_PAGEUP:
		if (iHscrollPos >= cxBuffer)
			iHscrollInc = -cxBuffer;
		else
			iHscrollInc = -iHscrollPos;
		break;
	case SB_PAGEDOWN:
		if (iHscrollPos <= iHscrollMax-cxBuffer)
			iHscrollInc = cxBuffer;
		else
			iHscrollInc = iHscrollMax - iHscrollPos;
		break;
	case SB_THUMBTRACK:
		iHscrollInc = pos - iHscrollPos;
		break;
	default:
		break;
	}
	iHscrollPos += iHscrollInc;
	SetScrollPos (hwndHBar, SB_CTL, iHscrollPos, TRUE);
	InvalidateRect (hwnd, NULL, FALSE);
	UpdateWindow (hwnd);
	return 0;
}

//--------------------------------------------------------------------------------------------
// WM_PAINT handler.
int HexEditorWindow::paint()
{
	PAINTSTRUCT ps;
	HDC hdc = BeginPaint (hwnd, &ps);
	//-------------------------------------------------------
	HideCaret (hwnd);
	// Delete remains of last position.
	int a, b;
	b = min (iCurLine + cyBuffer, iNumlines-1);
	iBkColor = PALETTERGB (GetRValue(iBkColorValue),GetGValue(iBkColorValue),GetBValue(iBkColorValue));
	iTextColor = PALETTERGB (GetRValue(iTextColorValue),GetGValue(iTextColorValue),GetBValue(iTextColorValue));
	SetTextColor (hdc, iTextColor);
	SetBkColor (hdc, iBkColor);
	HPEN pen1 = CreatePen (PS_SOLID, 1, iBkColor);
	HPEN oldpen = (HPEN) SelectObject (hdc, pen1);
	HBRUSH brush1 = CreateSolidBrush (iBkColor);
	HBRUSH oldbrush = (HBRUSH) SelectObject (hdc, brush1);
	// Delete lower border if there are empty lines on screen.
	if ((b-iCurLine+1)*cyChar+CLIENT_BORDER_WIDTH < cyClient-CLIENT_BORDER_WIDTH)
		Rectangle (hdc, CLIENT_BORDER_WIDTH, (b-iCurLine+1)*cyChar+CLIENT_BORDER_WIDTH, cxClient-CLIENT_BORDER_WIDTH,
			cyClient-CLIENT_BORDER_WIDTH);
	// Delete right border.
	Rectangle (hdc, ((iHscrollMax+1)-iHscrollPos)*cxChar+CLIENT_BORDER_WIDTH, CLIENT_BORDER_WIDTH,
		cxClient-CLIENT_BORDER_WIDTH, cyClient-CLIENT_BORDER_WIDTH);
	SelectObject (hdc, oldpen);
	SelectObject (hdc, oldbrush);
	DeleteObject (pen1);
	DeleteObject (brush1);
	
	// Get font.
	HFONT oldfont = (HFONT) SelectObject (hdc, hFont);
	HPEN sep_pen = CreatePen (PS_SOLID, 1, iSepColorValue);
	oldpen = (HPEN) SelectObject (hdc, sep_pen);

	if( Linebuffer.GetSize() < iCharsPerLine )
	{
		// Linebuffer too small.
		if( Linebuffer.SetSize( iCharsPerLine ) )
		{
			Linebuffer.ExpandToSize();
			// Linebuffer successfully resized.
			HBRUSH hbr = CreateSolidBrush( iBmkColor );
			if (iUpdateLine == -1)
			{
				for (a = iCurLine; a <= b; a++)
					print_line( hdc, a, Linebuffer, hbr );
			}
			else
			{
				print_line( hdc, iUpdateLine, Linebuffer, hbr );
			}
			DeleteObject( hbr );
			SelectObject (hdc, oldpen);
			DeleteObject (sep_pen);
			SelectObject (hdc, oldfont);
			// Mark character.
			mark_char (hdc);
			// Draw client-border.
			draw_client_border (hdc);
			ShowCaret (hwnd);
			EndPaint (hwnd, &ps);
			set_caret_pos ();
			set_wnd_title ();
			iUpdateLine = -1;
			return 0;
		}
		else
		{
			// Could not allocate line buffer.
			Rectangle( hdc, 0, 0, cxClient, cyClient );
			char buf[] = "Error: could not allocate line buffer.\nPlease save your changes and restart frhed.";
			RECT r;
			r.top = CLIENT_BORDER_WIDTH;
			r.left = CLIENT_BORDER_WIDTH;
			r.right = cxClient;
			r.bottom = cyClient;
			DrawText( hdc, buf, -1, &r, DT_LEFT );
		}
		
	}
	else
	{
		// Linebuffer large enough.
			HBRUSH hbr = CreateSolidBrush( iBmkColor );
			if (iUpdateLine == -1)
			{
				for (a = iCurLine; a <= b; a++)
					print_line( hdc, a, Linebuffer, hbr );
			}
			else
			{
				print_line( hdc, iUpdateLine, Linebuffer, hbr );
			}
			DeleteObject( hbr );
			SelectObject (hdc, oldpen);
			DeleteObject (sep_pen);
			SelectObject (hdc, oldfont);
			// Mark character.
			mark_char (hdc);
			// Draw client-border.
			draw_client_border (hdc);
			ShowCaret (hwnd);
			EndPaint (hwnd, &ps);
			set_caret_pos ();
			set_wnd_title ();
			iUpdateLine = -1;
			return 0;
	}
	return 0;
}

//--------------------------------------------------------------------------------------------
// Receives WM_COMMAND messages and passes either them to their handler functions or
// processes them here.
int HexEditorWindow::command (int cmd)
{
	HMENU hMenu = GetMenu (hwnd);
	switch( cmd )
	{
//Pabs changed - line insert
	case IDM_FILL_WITH:
		CMD_fw();
		break;
	case IDM_REVERT:
		CMD_revert();
		break;
	case IDM_SAVESELAS:
		CMD_saveselas();
		break;
	case IDM_DELETEFILE:
		CMD_deletefile();
		break;
	case IDM_INSERTFILE:
		CMD_insertfile();
		break;
//end
	case IDM_REPLACE:
		CMD_replace();
		break;

	case IDM_EXPLORERSETTINGS:
		CMD_explorersettings();
		break;

	case IDM_OPEN_TEXT:
		CMD_summon_text_edit();
		break;

	case IDM_FINDPREV:
		CMD_findprev();
		break;

	case IDM_FINDNEXT:
		CMD_findnext();
		break;

	case IDM_BMK_COLOR:
		CMD_color_settings( &iBmkColor );
		break;

	case IDM_RESET_COLORS:
		CMD_colors_to_default();
		break;

	case IDM_EDIT_READONLYMODE:
		if( bReadOnly == FALSE )
			bReadOnly = TRUE;
		else
			bReadOnly = FALSE;
		update_for_new_datasize();
		break;

	case IDM_APPLYTEMPLATE:
		CMD_apply_template();
		break;

	case IDM_PARTIAL_OPEN:
		CMD_open_partially ();
		break;

	case IDM_CLEARALL_BMK:
		CMD_clear_all_bmk ();
		break;

	case IDM_REMOVE_BKM:
		CMD_remove_bkm ();
		break;

	case IDM_BOOKMARK1: case IDM_BOOKMARK2: case IDM_BOOKMARK3: 
		case IDM_BOOKMARK4: case IDM_BOOKMARK5: case IDM_BOOKMARK6: 
		case IDM_BOOKMARK7: case IDM_BOOKMARK8: case IDM_BOOKMARK9: 
			CMD_goto_bookmark (cmd);
		break;

	case IDM_ADDBOOKMARK:
		CMD_add_bookmark ();
		break;

	case IDM_MRU1: case IDM_MRU2: case IDM_MRU3: case IDM_MRU4: case IDM_MRU5:
		case IDM_MRU6: case IDM_MRU7: case IDM_MRU8: case IDM_MRU9:
		CMD_MRU_selected (cmd);
		break;

	case IDM_SELECT_BLOCK:
		CMD_select_block ();
		break;

	case IDM_BINARYMODE:
		CMD_binarymode ();
		break;

	case IDM_COMPARE:
		CMD_compare ();
		break;

	case IDM_READFLOAT:
		{
			char buf[500], buf2[50];
			buf[0] = 0;
			float floatval;
			if (DataArray.GetLength()-iCurByte >= 4)
			{
				// Space enough for float.
				if (iBinaryMode == LITTLEENDIAN_MODE)
				{
					floatval = *((float*)&(DataArray[iCurByte]));
				}
				else // BIGENDIAN_MODE
				{
					char* pf = (char*) &floatval;
					int i;
					for (i=0; i<4; i++)
						pf[i] = DataArray[iCurByte+3-i];
				}
				sprintf (buf, "float size value:\n%f\n", floatval);
			}
			else
				sprintf (buf, "Not enough space for float size value.\n");
			double dval;
			if (DataArray.GetLength()-iCurByte >= 8)
			{
				// Space enough for double.
				if (iBinaryMode == LITTLEENDIAN_MODE)
				{
					dval = *((double*)&(DataArray[iCurByte]));
				}
				else // BIGENDIAN_MODE
				{
					char* pd = (char*) &dval;
					int i;
					for (i=0; i<8; i++)
						pd[i] = DataArray[iCurByte+7-i];
				}
				sprintf (buf2, "\ndouble size value:\n%g\n", dval);
				strcat (buf, buf2);
			}
			else
			{
				sprintf (buf2, "\nNot enough space for double size value.\n");
				strcat (buf, buf2);
			}
			// MessageBox (NULL, buf, "Floating point values", MB_OK | MB_ICONINFORMATION);
			MessageCopyBox (NULL, buf, "Floating point values", MB_ICONINFORMATION, hwnd);
			break;
		}

	case IDM_PROPERTIES:
		CMD_properties ();
		break;

	case IDM_SELECT_ALL:
		CMD_select_all ();
		break;

	case IDA_BACKSPACE:
		CMD_on_backspace ();
		break;

	case IDA_INSERTMODETOGGLE:
		CMD_toggle_insertmode ();
		break;

	case IDA_DELETEKEY:
		CMD_on_deletekey ();
		break;

	case IDM_CHARACTER_SET:
		CMD_character_set ();
		break;

	case IDM_EDIT_MANIPULATEBITS:
		CMD_manipulate_bits ();
		break;

	case IDM_EDIT_APPEND:
		CMD_edit_append ();
		break;

	case IDM_SELTEXT_COLOR:
		CMD_color_settings( &iSelTextColorValue );
		break;

	case IDM_SELBACK_COLOR:
		CMD_color_settings( &iSelBkColorValue );
		break;

	case IDM_SEP_COLOR:
		CMD_color_settings (&iSepColorValue);
		break;

	case IDM_TEXT_COLOR:
		CMD_color_settings (&iTextColorValue);
		break;

	case IDM_BK_COLOR:
		CMD_color_settings (&iBkColorValue);
		break;

	case IDM_VIEW_SETTINGS:
		CMD_view_settings ();
		break;

	case IDA_SELECTPAGEDOWN:
		CMD_select_with_arrowkeys (IDA_SELECTPAGEDOWN);
		break;

	case IDA_SELECTPAGEUP:
		CMD_select_with_arrowkeys (IDA_SELECTPAGEUP);
		break;

	case IDA_SELECTSTARTOFLINE:
		CMD_select_with_arrowkeys (IDA_SELECTSTARTOFLINE);
		break;

	case IDA_SELECTENDOFLINE:
		CMD_select_with_arrowkeys (IDA_SELECTENDOFLINE);
		break;

	case IDA_SELECTSTARTOFFILE:
		CMD_select_with_arrowkeys (IDA_SELECTSTARTOFFILE);
		break;

	case IDA_SELECTENDOFFILE:
		CMD_select_with_arrowkeys (IDA_SELECTENDOFFILE);
		break;

	case IDA_SELECTLEFT:
		CMD_select_with_arrowkeys (IDA_SELECTLEFT);
		break;

	case IDA_SELECTRIGHT:
		CMD_select_with_arrowkeys (IDA_SELECTRIGHT);
		break;

	case IDA_SELECTUP:
		CMD_select_with_arrowkeys (IDA_SELECTUP);
		break;

	case IDA_SELECTDOWN:
		CMD_select_with_arrowkeys (IDA_SELECTDOWN);
		break;

	case IDM_INTERNALSTATUS:
		{
			// Remove break for internal information on F2.
			break;

			char buf[4000], buf2[300];
			sprintf (buf, "Data length: %d\n", DataArray.GetLength ());
			sprintf (buf, "Upper Bound: %d\n", DataArray.GetUpperBound ());
			sprintf (buf2, "Data size: %d\n", DataArray.GetSize ());
			strcat (buf, buf2);
			sprintf (buf2, "cxChar: %d\n", cxChar );
			strcat (buf, buf2);
			sprintf (buf2, "cyChar: %d\n", cyChar );
			strcat (buf, buf2);
			sprintf (buf2, "iNumlines: %d\n", iNumlines);
			strcat (buf, buf2);
			sprintf (buf2, "iCurLine: %d\n", iCurLine);
			strcat (buf, buf2);
			sprintf (buf2, "iCurByte: %d\n", iCurByte);
			strcat (buf, buf2);
			sprintf( buf2, "cyBuffer: %d\n", cyBuffer );
			strcat( buf, buf2 );

			sprintf (buf2, "iMRU_count: %d\n", iMRU_count);
			strcat (buf, buf2);
			int i;
			for (i=0; i<MRUMAX; i++)
			{
				sprintf (buf2, "MRU %d=%s\n", i, &(strMRU[i][0]));
				strcat (buf, buf2);
			}
			MessageBox (NULL, buf, "Internal status", MB_OK);
			break;
		}

	case IDM_EDIT_CUT:
		iCutMode = BST_CHECKED;
		CMD_edit_cut ();
		break;

	case IDM_HELP_TOPICS:
		{
			char path[500];
			strcpy (path, _pgmptr);
			int len = strlen (path);
			path[len-3] = 'h';
			path[len-2] = 'l';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -