能力值:
( LV2,RANK:10 )
|
-
-
5 楼
参考我的代码
主窗口代码:
case WM_INITDIALOG:
hWndtmp=GetDlgItem(hDlg,IDC_SWEEPRESULT);//IDC_SWEEPRESULT为listview ID
etWindowLong(hWndtmp,GWL_WNDPROC,(LONG)SwpLstvwNewProc);
case WM_NOTIFY:
pNotifyInfo=(NMHDR*)lParam;
uEvent=pNotifyInfo->code;
switch(pNotifyInfo->idFrom)
{
case IDC_SWEEPRESULT:
switch(uEvent)
{
case LVN_KEYDOWN:
if(((LPNMLVKEYDOWN)pNotifyInfo)->wVKey=='C'&&GetKeyState(VK_CONTROL)<0)//复制操作
{
LVITEM iTmInfo;
lRsl=SendMessage(pNotifyInfo->hwndFrom,LVM_GETNEXTITEM,-1,LVNI_FOCUSED);
if(lRsl<0)break;
iTmInfo.mask=LVIF_TEXT;
iTmInfo.iItem=(int)lRsl;
iTmInfo.iSubItem=SelectedColumn;
TCHAR strtmp[66];
iTmInfo.pszText=strtmp;
iTmInfo.cchTextMax=66;
SendMessage(pNotifyInfo->hwndFrom,LVM_GETITEM,0,(LPARAM)&iTmInfo);
////////拷贝到剪贴版/////////////
HGLOBAL hCopyboard=GlobalAlloc(GHND,66*sizeof(TCHAR));
if(!hCopyboard){;break;}
PVOID pDataDest=GlobalLock(hCopyboard);
if(!pDataDest){GlobalUnlock(hCopyboard);break;}
memcpy(pDataDest,(PVOID)iTmInfo.pszText,66*sizeof(TCHAR));//不用strtmp而用iTmInfo.pszText,因为该结构里的成员可能已经被LVM_GETITEM替换了
GlobalUnlock(hCopyboard);
OpenClipboard(pNotifyInfo->hwndFrom);
EmptyClipboard();
SetClipboardData(CF_UNICODETEXT,hCopyboard);
CloseClipboard();
}
else if(((LPNMLVKEYDOWN)pNotifyInfo)->wVKey==VK_LEFT)
{
if(SelectedColumn>0&&SelectedRow!=-1){--SelectedColumn;InvalidateRect(pNotifyInfo->hwndFrom,NULL,TRUE);}
break;
}
else if(((LPNMLVKEYDOWN)pNotifyInfo)->wVKey==VK_RIGHT)
{
if(SelectedColumn<2&&SelectedRow!=-1){++SelectedColumn;InvalidateRect(pNotifyInfo->hwndFrom,NULL,TRUE);}
break;
}
break;
case NM_CLICK :
break;
case NM_DBLCLK :
break;
case NM_RCLICK :
{
if(((LPNMITEMACTIVATE) lParam)->iItem<0)break;
//if(((LPNMITEMACTIVATE) lParam)->iSubItem)
HMENU hMenu = LoadMenu(NULL, MAKEINTRESOURCE (IDR_FORCEUI));
HMENU hPopupMenu = GetSubMenu (hMenu, 0);
POINT CursorPos;
BOOL bSlct;
GetCursorPos(&CursorPos);
SetMenuDefaultItem (hPopupMenu, -1, TRUE);//不需要双击选择默认菜单项
//SetForegroundWindow(hDlg);
if(((LPNMITEMACTIVATE) lParam)->iSubItem!=1)EnableMenuItem(hPopupMenu,0,MF_BYPOSITION|MF_GRAYED);
bSlct=TrackPopupMenu(hPopupMenu,TPM_LEFTALIGN|TPM_RETURNCMD|TPM_LEFTBUTTON , CursorPos.x, CursorPos.y, 0, hDlg, NULL);
//SetForegroundWindow (hDlg);
DestroyMenu (hPopupMenu);
DestroyMenu (hMenu);
switch(bSlct)
{
case ID_CEMENUEDITMEM://更改内存数据
{
LPARAM lparamtmp;
UINT pos_x,pos_y;
pos_x=((LPNMITEMACTIVATE) lParam)->ptAction.x;
pos_y=((LPNMITEMACTIVATE) lParam)->ptAction.y;
lparamtmp=(pos_y<<16)|pos_x;
hWndtmp=GetDlgItem(hDlg,IDC_SWEEPRESULT);
SendMessage(hWndtmp, WM_LBUTTONDBLCLK,-1,lparamtmp);
}
break;
case ID_CEMENUDELROW://从列表中删除该栏,就是说下次扫描时这个内存地址对应的数据不会被扫描也不计入到上次扫描值
///////////////////////////
/////////////////////////把g_SwpResult里对应的数据更新
hWndtmp=GetDlgItem(hDlg,IDC_SWEEPRESULT);
SendMessage(hWndtmp,LVM_DELETEITEM,((LPNMITEMACTIVATE) lParam)->iItem,0);
return TRUE;
case IDM_CEMENUCOPY://复制
{
LVITEM iTmInfo;
iTmInfo.mask=LVIF_TEXT;
iTmInfo.iItem=((LPNMITEMACTIVATE) lParam)->iItem;
iTmInfo.iSubItem=((LPNMITEMACTIVATE) lParam)->iSubItem;
TCHAR strtmp[66];
iTmInfo.pszText=strtmp;
iTmInfo.cchTextMax=66;
SendMessage(pNotifyInfo->hwndFrom,LVM_GETITEM,0,(LPARAM)&iTmInfo);
////////拷贝到剪贴版/////////////
HGLOBAL hCopyboard=GlobalAlloc(GHND,66*sizeof(TCHAR));
if(!hCopyboard){;break;}
PVOID pDataDest=GlobalLock(hCopyboard);
if(!pDataDest){GlobalUnlock(hCopyboard);break;}
memcpy(pDataDest,(PVOID)iTmInfo.pszText,66*sizeof(TCHAR));//不用strtmp而用iTmInfo.pszText,因为该结构里的成员可能已经被LVM_GETITEM替换了
GlobalUnlock(hCopyboard);
OpenClipboard(pNotifyInfo->hwndFrom);
EmptyClipboard();
SetClipboardData(CF_UNICODETEXT,hCopyboard);
CloseClipboard();
}
return TRUE;
default:
break;
}//end switch(bSlct)
}//end case NM_RCLICK :
break;
case NM_RDBLCLK ://这些单击消息晚于绘制消息的发送
/*
{
NMITEMACTIVATE *plistactvt=(NMITEMACTIVATE *)lParam;
SelectedColumn=plistactvt->iSubItem;
}
InvalidateRect(pNotifyInfo->hwndFrom,NULL,TRUE);
*/
break;
case LVN_INSERTITEM ://把选择项目设置为新的那项,如果是用消息插入的,那么
case LVN_DELETEITEM:
case LVN_DELETEALLITEMS:
SelectedRow=(int)SendMessage(pNotifyInfo->hwndFrom,LVM_GETNEXTITEM,-1,LVNI_SELECTED);
break;
case LVN_ITEMCHANGED:
{
LPNMLISTVIEW plstvw=(LPNMLISTVIEW)lParam;
if((plstvw->uChanged&LVIF_STATE)&&(plstvw->uNewState & LVIS_SELECTED))
{
SelectedRow=plstvw->iItem;
//SelectedColumn=plstvw->iSubItem;
if(g_MSPosEffect)
{
LVHITTESTINFO hittest;
hittest.flags=LVHT_ONITEM;
hittest.pt.x=g_MousePos.x;
hittest.pt.y=g_MousePos.y;
if(SendMessage(pNotifyInfo->hwndFrom,LVM_SUBITEMHITTEST,0,(LPARAM)&hittest)!=-1){SelectedColumn=hittest.iSubItem;}
g_MSPosEffect=FALSE;
}
}
}
break;
case NM_CUSTOMDRAW :
{
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
switch(lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT ://DWL_MSGRESULT
//return CDRF_NOTIFYITEMDRAW;//要求在画item时通知我们
SetWindowLong(hDlg,DWL_MSGRESULT,CDRF_NOTIFYITEMDRAW);
return TRUE;
case CDDS_ITEMPREPAINT:
//return CDRF_NOTIFYSUBITEMDRAW;//要求在画子项目时通知我们
//SetWindowLong(hDlg,DWL_MSGRESULT,CDRF_NOTIFYSUBITEMDRAW);
lRsl=SelectedRow;//=SendMessage(((NMHDR*)lplvcd)->hwndFrom,LVM_GETNEXTITEM,-1,LVNI_SELECTED);
if(((NMCUSTOMDRAW*)lplvcd)->dwItemSpec==(DWORD_PTR)lRsl)
{
UINT numColumn=3;//有几列
RECT SbItemRect;
TCHAR itemtext[66];
LVITEM iTemNeed;
iTemNeed.iItem=(int)lRsl;
iTemNeed.pszText=itemtext;
iTemNeed.mask=LVIF_TEXT;
iTemNeed.cchTextMax=66;
SetBkMode(((NMCUSTOMDRAW*)lplvcd)->hdc,OPAQUE);//不透明模式才让背景颜色生效
for(UINT i = 0; i < numColumn; i++)
{
iTemNeed.iSubItem=i;
if(i==0)
{
SbItemRect.left=LVIR_BOUNDS ;
SendMessage(((NMHDR*)lplvcd)->hwndFrom,LVM_GETITEMRECT,(WPARAM)lRsl,(LPARAM)&SbItemRect);
}
else
{
SbItemRect.top=i;
SbItemRect.left=LVIR_BOUNDS ;
SendMessage(((NMHDR*)lplvcd)->hwndFrom,LVM_GETSUBITEMRECT,(WPARAM)lRsl,(LPARAM)&SbItemRect);
}
SendMessage(((NMHDR*)lplvcd)->hwndFrom,LVM_GETITEMTEXT,(WPARAM)lRsl,(LPARAM)&iTemNeed);
SbItemRect.left+=6;//让字符跟系统默认的左边对齐
if(i==SelectedColumn)
{
SetBkColor(((NMCUSTOMDRAW*)lplvcd)->hdc,RGB(0,0,0));
SetTextColor(((NMCUSTOMDRAW*)lplvcd)->hdc,RGB(255,255,255));
}
else
{
SetBkColor(((NMCUSTOMDRAW*)lplvcd)->hdc,RGB(255,255,255));
SetTextColor(((NMCUSTOMDRAW*)lplvcd)->hdc,RGB(0,0,0));
}
DrawText(((NMCUSTOMDRAW*)lplvcd)->hdc,iTemNeed.pszText,-1,&SbItemRect,DT_LEFT|DT_NOCLIP|DT_END_ELLIPSIS| DT_VCENTER | DT_SINGLELINE );
}
SetWindowLong(hDlg,DWL_MSGRESULT,CDRF_SKIPDEFAULT);
return TRUE;
}
else break;
case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
lRsl=SendMessage(((NMHDR*)lplvcd)->hwndFrom,LVM_GETNEXTITEM,-1,LVNI_SELECTED);
if(((NMCUSTOMDRAW*)lplvcd)->dwItemSpec==(DWORD_PTR)lRsl&&lplvcd->iSubItem==SelectedColumn)//现在画的是选中的项目
{
lplvcd->clrText=RGB(255,255,255);
lplvcd->clrTextBk=RGB(0,0,0);
//return CDRF_DODEFAULT;
SetWindowLong(hDlg,DWL_MSGRESULT,CDRF_NEWFONT);
return TRUE;
}
else if(((NMCUSTOMDRAW*)lplvcd)->dwItemSpec==(DWORD_PTR)lRsl&&lplvcd->iSubItem!=SelectedColumn)
{
lplvcd->clrText=RGB(0,0,0);
lplvcd->clrTextBk=RGB(255,255,255);
//return CDRF_DODEFAULT;
SetWindowLong(hDlg,DWL_MSGRESULT,CDRF_NEWFONT);
return TRUE;
}
else
break; ;
default:
break;
}// end switch(lplvcd->nmcd.dwDrawStage)
}//end
break;//end NM_CUSTOMDRAW :
default:
break;
}//end switch(uEvent)
break;
default:
break;
}// end switch(pNotifyInfo->idFrom)
break;// end case WM_NOTIFY:
LRESULT SwpLstvwNewProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)//扫描结果显示list, 处理mouse事件以便发送鼠标点击subitem时的位置
{
// static BOOL bInEditState=FALSE;
static HWND hEditInplace=NULL;
static TCHAR iedtstrtmp[32];//从编辑框输入的字符,一旦按回车键,就确认便发送到itemtext上
static int InputValue1;
static unsigned InputValue2;
static BOOL bValidInput=FALSE;
switch(uMsg)
{
case WM_LBUTTONDOWN://让在同一个item上点击鼠标也会发出select改变事件
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
{
g_MousePos.x=LOWORD(lParam);
g_MousePos.y=HIWORD(lParam);
g_MSPosEffect=TRUE;
NMLISTVIEW lstntf;
LVHITTESTINFO itemtest;
itemtest.flags=LVHT_ONITEM ;
itemtest.pt.x=g_MousePos.x;
itemtest.pt.y=g_MousePos.y;
lstntf.hdr.code=LVN_ITEMCHANGED;
lstntf.hdr.hwndFrom=hwnd;
lstntf.hdr.idFrom=IDC_SWEEPRESULT;
#pragma warning( push )
#pragma warning(disable:4244)
lstntf.iItem=SendMessage(hwnd,LVM_HITTEST,0,(LPARAM)&itemtest);
#pragma warning( pop )
lstntf.uChanged=LVIF_STATE;
lstntf.uNewState=LVIS_SELECTED;
SendMessage(GetParent(hwnd),WM_NOTIFY,0,(LPARAM)&lstntf);
InvalidateRect(hwnd,0,TRUE);
break;
}
case WM_LBUTTONDBLCLK://处理编辑项目
{
LVHITTESTINFO itemtest;
INT itmbeinghit;
INT sbitmbeinghit;
itemtest.flags=LVHT_ONITEM ;
itemtest.pt.x=LOWORD(lParam);
itemtest.pt.y=HIWORD(lParam);
#pragma warning( push )
#pragma warning(disable:4244)
itmbeinghit=SendMessage(hwnd,LVM_HITTEST,0,(LPARAM)&itemtest);
#pragma warning( pop )
if(itmbeinghit<0)break;
SendMessage(hwnd,LVM_SUBITEMHITTEST,0,(LPARAM)&itemtest);//返回值是item不是subitem
sbitmbeinghit=itemtest.iSubItem;
if(sbitmbeinghit!=1)break;
RECT itmpos;
itmpos.top=sbitmbeinghit;
itmpos.left=LVIR_BOUNDS;
SendMessage(hwnd,LVM_GETSUBITEMRECT ,(WPARAM)itmbeinghit,(LPARAM)&itmpos);
hEditInplace=CreateWindow(L"EDIT",L"",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_AUTOHSCROLL|ES_LEFT|ES_WANTRETURN ,itmpos.left,itmpos.top,itmpos.right-itmpos.left,itmpos.bottom-itmpos.top,hwnd,NULL,NULL,NULL);
if(!hEditInplace)break;
SetFocus(hEditInplace);
HFONT lstfont=(HFONT)SendMessage(hwnd,WM_GETFONT,0,0);
SendMessage(hEditInplace,WM_SETFONT,(WPARAM)lstfont,0);
LVITEM itminfo;//获取list item上的文字以在edit里显示出来
TCHAR itmtxt[32];
itminfo.mask=LVIF_TEXT;
itminfo.iItem=itmbeinghit;
itminfo.iSubItem=sbitmbeinghit;
itminfo.pszText=itmtxt;
itminfo.cchTextMax=32;
SendMessage(hwnd,LVM_GETITEMTEXT,(WPARAM)itmbeinghit,(LPARAM)&itminfo);
SendMessage(hEditInplace, EM_LIMITTEXT,31, 0L);
SendMessage(hEditInplace, EM_SETEVENTMASK ,0, ENM_CHANGE );//NewWndProcEdit
OldWndProcEdit=GetWindowLong(hEditInplace,GWL_WNDPROC);
#pragma warning( push )
#pragma warning(disable:4311)
SetWindowLong(hEditInplace,GWL_WNDPROC,(LONG)NewWndProcEdit);
#pragma warning( pop )
SetWindowText(hEditInplace,itminfo.pszText);
}
if(wParam==-1)return 0;//表示是由我们模拟的
else break;
case WM_COMMAND:
if(lParam==(LPARAM)hEditInplace&&HIWORD(wParam)==EN_KILLFOCUS){DestroyWindow(hEditInplace);hEditInplace=NULL; break;}
else if(lParam==(LPARAM)hEditInplace&&HIWORD(wParam)==EN_CHANGE)//正在编辑值
{
HRESULT hrtmp;
SendMessage(hEditInplace,WM_GETTEXT ,32,(LPARAM)iedtstrtmp);
if(g_pCESwpCfg->uSwpType==1)//十进制
{
#pragma warning( push )
#pragma warning(disable:4996)
#pragma warning(disable:4995)
if(g_pCESwpCfg->uFormat==1)hrtmp=Text2SignDecNumber(iedtstrtmp, &InputValue1,TRUE);
else hrtmp=Text2UnsignDecNumber(iedtstrtmp, &InputValue2,TRUE);
if(hrtmp!=S_OK){SendMessage(hEditInplace,WM_SETTEXT ,0,(LPARAM)g_pCESwpCfg->swpdata);bValidInput=FALSE;}//输入的字符有问题,恢复为输入前的
else bValidInput=TRUE;
}
else if(g_pCESwpCfg->uSwpType==2)//时六进制
{
hrtmp=Text2HexNumber(iedtstrtmp, &InputValue2,TRUE);
if(hrtmp!=S_OK){SendMessage(hEditInplace,WM_SETTEXT ,0,(LPARAM)g_pCESwpCfg->swpdata);bValidInput=FALSE;}//输入的字符有问题,恢复为输入前的
else bValidInput=TRUE;
}
else//字符串
{
if(g_pCESwpCfg->uFormat==3){bValidInput=TRUE;}
else //unicode,需要截断
{
if(wcslen(iedtstrtmp)>15)
{
iedtstrtmp[15]=L'\0';
SendMessage(hEditInplace,WM_SETTEXT ,0,(LPARAM)iedtstrtmp);
}
bValidInput=TRUE;
}
}
break;
}
else break;
case WM_NOTIFY:
if(((LPNMHDR)lParam)->hwndFrom==hEditInplace&&((LPNMHDR)lParam)->code==EN_MSGFILTER)//用这个消息来表示收到了回车键
{
LVITEM itminfo;
PVOID WriteAddr;
itminfo.iItem=SelectedRow;
itminfo.iSubItem=SelectedColumn;
itminfo.mask=LVIF_TEXT;
itminfo.pszText=iedtstrtmp;
SendMessage(hwnd,LVM_SETITEM,0,(LPARAM)&itminfo);
DestroyWindow(hEditInplace);
hEditInplace=NULL;
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////在下面通过g_CESwpCfg里的转换函数,那数据转换并写入到被调试程序的内存
if(SelectedRow>=0&&SelectedRow<(int)g_SwpRsltList.GetNumber()&&bValidInput)
{
DWORD dwNewProt=PAGE_EXECUTE_READWRITE, dwOldProt;
WriteAddr=g_SwpRsltList[SelectedRow].Address;
if(g_pCESwpCfg->uSwpType==1)//十进制
{
VirtualProtectEx(g_Dbginfo.hProc, WriteAddr, sizeof(int), PAGE_EXECUTE_READWRITE, &dwOldProt);
if(g_pCESwpCfg->uFormat==1)WriteProcessMemory(g_Dbginfo.hProc,WriteAddr,(LPVOID)&InputValue1,sizeof(int),NULL);
else WriteProcessMemory(g_Dbginfo.hProc,WriteAddr,(LPVOID)&InputValue2,sizeof(int),NULL);
VirtualProtectEx(g_Dbginfo.hProc, WriteAddr, sizeof(int), dwOldProt, &dwNewProt);
}
else if(g_pCESwpCfg->uSwpType==2)//时六进制
{
VirtualProtectEx(g_Dbginfo.hProc, WriteAddr, sizeof(int), PAGE_EXECUTE_READWRITE, &dwOldProt);
WriteProcessMemory(g_Dbginfo.hProc,WriteAddr,(LPVOID)&InputValue2,sizeof(int),NULL);
VirtualProtectEx(g_Dbginfo.hProc, WriteAddr, sizeof(int), dwOldProt, &dwNewProt);
}
else//字符串
{
if(g_pCESwpCfg->uFormat==3)
{
CHAR StrTmp[32];
WideCharToMultiByte(CP_ACP,0,iedtstrtmp,-1,StrTmp,32,NULL,NULL);
VirtualProtectEx(g_Dbginfo.hProc, WriteAddr, strlen(StrTmp), PAGE_EXECUTE_READWRITE, &dwOldProt);
WriteProcessMemory(g_Dbginfo.hProc,WriteAddr,(LPVOID)StrTmp,strlen(StrTmp),NULL);
VirtualProtectEx(g_Dbginfo.hProc, WriteAddr, strlen(StrTmp), dwOldProt, &dwNewProt);
}
else //unicode,需要截断
{
VirtualProtectEx(g_Dbginfo.hProc, WriteAddr, wcslen(iedtstrtmp)*2, PAGE_EXECUTE_READWRITE, &dwOldProt);
WriteProcessMemory(g_Dbginfo.hProc,WriteAddr,(LPVOID)iedtstrtmp,wcslen(iedtstrtmp)*2,NULL);
VirtualProtectEx(g_Dbginfo.hProc, WriteAddr, wcslen(iedtstrtmp)*2, dwOldProt, &dwNewProt);
}
}
}
}
break;
case WM_DESTROY:
if(hEditInplace){DestroyWindow(hEditInplace);}
hEditInplace=NULL;
break;
default:
break;
}
#pragma warning( push )
#pragma warning(disable:4312)
return ((WNDPROC)SwpLstvwOldProc)(hwnd,uMsg, wParam, lParam);
#pragma warning( pop )
}
|