📄 export.cpp
字号:
#include "pch.h"
#include "util.h"
#include "main.h"
#include "doc.h"
#include "image.h"
#include "import.h"
#include "export.h"
#include "debug.h"
IMPLEMENT_DYNCREATE ( CExportView , CListView )
BEGIN_MESSAGE_MAP ( CExportView , CListView )
ON_WM_CREATE ( )
ON_WM_KILLFOCUS ( )
ON_COMMAND ( IDM_EDIT_HOOK , OnEditHook )
ON_COMMAND ( IDM_EDIT_UNHOOK , OnEditUnhook )
ON_COMMAND ( IDM_EDIT_SELECT_ALL , OnEditSelectAll )
ON_NOTIFY_REFLECT ( NM_DBLCLK, OnNMDblclk )
ON_UPDATE_COMMAND_UI ( IDM_EDIT_HOOK , OnUpdateEditHook )
ON_UPDATE_COMMAND_UI ( IDM_EDIT_UNHOOK , OnUpdateEditUnhook )
END_MESSAGE_MAP ( )
CExportView::CExportView ( )
{
m_pExport = NULL ;
}
CExportView::~CExportView ( )
{
}
CDancerDoc* CExportView::GetDocument ( )
{
return ( CDancerDoc* ) CView::GetDocument ( ) ;
}
void CExportView::OnInitialUpdate ( )
{
CListView::OnInitialUpdate ( ) ;
GetDocument ( )->m_pExportView = this ;
GetDocument ( )->m_pFrame = ( CMDIChildWnd* ) GetParent ( ) ;
}
int CExportView::OnCreate ( LPCREATESTRUCT lpCreateStruct )
{
if ( -1 == CListView::OnCreate ( lpCreateStruct ) )
return -1 ;
CListCtrl& ctrl = GetListCtrl ( ) ;
// modify style of list control
SetWindowLong (
ctrl.GetSafeHwnd ( ) ,
GWL_STYLE ,
WS_CHILD |
WS_VISIBLE |
LVS_REPORT |
LVS_OWNERDRAWFIXED ) ;
xInsertColumn ( ctrl , 0 , 0 , 40 ) ;
xInsertColumn ( ctrl , 1 , IDS_ORDINAL , 100 ) ;
xInsertColumn ( ctrl , 2 , IDS_FUNCTION , 220 ) ;
xInsertColumn ( ctrl , 3 , IDS_ENTRY , 130 ) ;
return 0 ;
}
void CExportView::Refresh ( Export* pExport )
{
// interactive with selected module
Refresh1 ( ) ;
Refresh2 ( pExport ) ;
Module* pm = m_pExport->m_pModule ;
int i , n = pm->m_arFunction.GetSize ( ) ;
CListCtrl& ctrl = GetListCtrl ( ) ;
ctrl.ShowWindow ( SW_HIDE ) ;
ctrl.DeleteAllItems ( ) ;
CDancerDoc* pd = GetDocument ( ) ;
CMainApp* pMainApp = ( CMainApp* ) AfxGetApp ( ) ;
for ( i = 0 ; i < n ; i++ )
{
Function* f = ( Function* ) pm->m_arFunction [ i ] ;
if ( pMainApp->m_appOption.m_bViewAll == TRUE ||
f->m_bExport == TRUE )
{
ctrl.InsertItem (
LVIF_PARAM ,
i ,
NULL ,
0 ,
0 ,
0 ,
( LPARAM ) f ) ;
}
}
ctrl.ShowWindow ( SW_SHOW ) ;
}
void CExportView::Refresh1 ( )
{
// pre-refresh
if ( m_pExport == NULL ) return ;
Module* pm = m_pExport->m_pModule ;
int i , n = pm->m_arFunction.GetSize ( ) ;
for ( i = 0 ; i < n ; i++ )
{
Function* f = ( Function* ) pm->m_arFunction [ i ] ;
m_pExport->m_arHook [ i ] = f->m_bHook ;
}
}
void CExportView::Refresh2 ( Export* pExport )
{
// post-refresh
m_pExport = pExport ;
Module* pm = pExport->m_pModule ;
int i , n = pExport->m_arHook.GetSize ( ) ;
for ( i = 0 ; i < n ; i++ )
{
Function* f = ( Function* ) pm->m_arFunction [ i ] ;
f->m_bHook = pExport->m_arHook [ i ] ;
f->m_bExport = FALSE ;
}
n = pExport->m_arExport.GetSize ( ) ;
for ( i = 0 ; i < n ; i++ )
{
int in = pExport->m_arExport [ i ] ;
Function* f = ( Function* ) pm->m_arFunction [ in ] ;
f->m_bExport = TRUE ;
}
}
void CExportView::DrawItem ( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
// draw item
CListCtrl& ctrl = GetListCtrl ( ) ;
CDC dc ;
CBrush br ;
CFont fnt ;
CString str ;
LOGFONT lf ;
int i , s , img , w [ 4 ] ;
CRect rc [ 4 ] ,
r = lpDrawItemStruct->rcItem ;
Function* f = ( Function* )
lpDrawItemStruct->itemData ;
dc.Attach ( lpDrawItemStruct->hDC ) ;
// calculate item rect
s = r.left ;
for ( i = 0 ; i < 4 ; i++ )
{
w [ i ] = ctrl.GetColumnWidth ( i ) ;
rc [ i ].top = r.top ;
rc [ i ].bottom = r.bottom ;
rc [ i ].left = s + 2 ;
s += w [ i ] ;
rc [ i ].right = s - 2 ;
}
// set proper background and text color
if ( lpDrawItemStruct->itemState & ODS_SELECTED )
{
dc.SetTextColor ( GetSysColor ( COLOR_HIGHLIGHTTEXT ) ) ;
br.CreateSysColorBrush ( COLOR_HIGHLIGHT ) ;
img = 1 ;
}
else
{
dc.SetTextColor ( ctrl.GetTextColor ( ) ) ;
br.CreateSolidBrush ( ctrl.GetBkColor ( ) ) ;
img = 0 ;
}
// draw background
dc.FillRect ( &r , &br ) ;
if ( f->m_bExport == TRUE ) // bold if imported
{
ctrl.GetFont ( )->GetLogFont ( &lf ) ;
lf.lfWeight = FW_BOLD ;
fnt.CreateFontIndirect ( &lf ) ;
dc.SelectObject ( &fnt ) ;
}
if ( f->m_bHook == TRUE )
{
CMainApp* pp = ( CMainApp* ) AfxGetApp ( ) ;
pp->m_imgList.Draw ( &dc , img , r.TopLeft ( ) , ILD_TRANSPARENT ) ;
}
str.Format ( "%d ( 0x%X )" , f->m_wOrdinal , f->m_wOrdinal ) ;
dc.DrawText ( str , &rc [ 1 ] , DT_VCENTER | DT_LEFT ) ;
CMainApp* pMainApp = ( CMainApp* ) AfxGetApp ( ) ;
if ( f->m_bHasName == TRUE )
{
if ( pMainApp->m_appOption.m_bUndecorate ) dc.DrawText ( f->m_strUnDecorateName , &rc [ 2 ] , DT_VCENTER | DT_LEFT ) ;
else dc.DrawText ( f->m_strName , &rc [ 2 ] , DT_VCENTER | DT_LEFT ) ;
}
else
{
dc.DrawText ( "N/A" , &rc [ 2 ] , DT_VCENTER | DT_LEFT ) ;
}
if ( f->m_bForward == FALSE )
{
str.Format ( "0x%08X" , f->m_dwEntry ) ;
dc.DrawText ( str , &rc [ 3 ] , DT_VCENTER | DT_LEFT ) ;
}
else
{
dc.DrawText ( f->m_strForward , &rc [ 3 ] , DT_VCENTER | DT_LEFT ) ;
}
dc.Detach ( ) ;
}
void CExportView::OnEditHook ( )
{
CListCtrl& ctrl = GetListCtrl ( ) ;
int i , item = -1 , n = ctrl.GetSelectedCount ( ) ;
for ( i = 0 ; i < n ; i++ )
{
item = ctrl.GetNextItem ( item , LVNI_SELECTED ) ;
Function* f = ( Function* ) ctrl.GetItemData ( item ) ;
f->m_bHook = TRUE ; // hook it
}
ctrl.Invalidate ( ) ;
RefreshImport ( ) ;
}
void CExportView::OnEditUnhook ( )
{
CListCtrl& ctrl = GetListCtrl ( ) ;
int i , item = -1 , n = ctrl.GetSelectedCount ( ) ;
for ( i = 0 ; i < n ; i++ )
{
item = ctrl.GetNextItem ( item , LVNI_SELECTED ) ;
Function* f = ( Function* ) ctrl.GetItemData ( item ) ;
f->m_bHook = FALSE ; // unhook it
}
ctrl.Invalidate ( ) ;
RefreshImport ( ) ;
}
void CExportView::RefreshImport ( )
{
// if one or more is hookd , refresh import view with bold , otherwirs , normal
CListCtrl& ctrl = GetListCtrl ( ) ;
int i , n = ctrl.GetItemCount ( ) ;
BOOL ret = FALSE ;
for ( i = 0 ; i < n ; i++ )
{
Function* f = ( Function* ) ctrl.GetItemData ( i ) ;
if ( f->m_bHook == TRUE )
{
ret = TRUE ;
break ;
}
}
GetDocument ( )->m_pImportView->RefreshCurrent ( ret ) ;
}
void CExportView::Refresh ( )
{
Refresh ( m_pExport ) ;
}
void CExportView::OnEditSelectAll ( )
{
CListCtrl& ctrl = GetListCtrl ( ) ;
ctrl.SetItemState ( -1 , LVIS_SELECTED , LVIS_SELECTED ) ;
}
void CExportView::DeselectAll ( )
{
CListCtrl& ctrl = GetListCtrl ( ) ;
ctrl.SetItemState ( -1 , 0 , LVIS_SELECTED ) ;
}
void CExportView::OnKillFocus ( CWnd* pNewWnd )
{
DeselectAll ( ) ;
}
void CExportView::OnNMDblclk ( NMHDR *pNMHDR , LRESULT *pResult )
{
if ( GetDocument ( )->m_pDebugControl->IsDebugging ( ) )
return ;
CListCtrl& ctrl = GetListCtrl ( ) ;
int item = ctrl.GetNextItem ( -1 , LVNI_SELECTED ) ;
if ( item != - 1 )
{
Function* f = ( Function* ) ctrl.GetItemData ( item ) ;
if ( f->m_bHook == FALSE ) OnEditHook ( ) ;
else OnEditUnhook ( ) ;
}
*pResult = 0;
}
void CExportView::OnUpdateEditHook ( CCmdUI* pCmdUI )
{
pCmdUI->Enable ( !GetDocument ( )->m_pDebugControl->IsDebugging ( ) ) ;
}
void CExportView::OnUpdateEditUnhook ( CCmdUI* pCmdUI )
{
pCmdUI->Enable ( !GetDocument ( )->m_pDebugControl->IsDebugging ( ) ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -