1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429 |
- #include "StdAfx.h"
- #include <map>
- #include <vector>
- #include <string>
- #include <algorithm> // std::reverse
- using namespace std;
- #include <commctrl.h>
- #include "SysControl.h"
- #include "AutoFunc.h"
- SysControl::SysControl(void)
- {
- }
- SysControl::~SysControl(void)
- {
- }
- void SysControl::Sethand(HWND Hand)
- {
- m_ResHwnd = Hand;
- }
- bool SysControl::HitMenu(WORD MenuId)
- {
- DWORD wparam = MenuId;
- LRESULT lResult = PostMessage( // returns LRESULT in lResult
- m_ResHwnd, // handle to destination control
- (UINT)WM_COMMAND, // message ID
- (WPARAM)wparam, // = (WPARAM) () wParam;
- (LPARAM)0 // = 0; not used, must be zero
- );
- if (lResult == CB_ERR)
- {
- return false;
- }
- return true;
- }
- bool SysControl::GetHwndTitle(TCHAR *pszTitle, DWORD size)
- {
- AttachThreadInput(
- ::GetWindowThreadProcessId((m_ResHwnd), NULL), //当前焦点窗口的线程ID
- ::GetCurrentThreadId(), //自己的线程ID
- TRUE);
- LRESULT lResult = SendMessage( // returns LRESULT in lResult
- m_ResHwnd, // handle to destination control
- (UINT)WM_GETTEXT, // message ID
- (WPARAM)size, // = (WPARAM) () wParam;
- (LPARAM)pszTitle // = 0; not used, must be zero
- );
- return (lResult != CB_ERR);
- }
- bool SysControl::GetCheckBoxStr(TCHAR *pszTitle, DWORD size)
- {
- AttachThreadInput(
- ::GetWindowThreadProcessId((m_ResHwnd), NULL), //当前焦点窗口的线程ID
- ::GetCurrentThreadId(), //自己的线程ID
- TRUE);
- int ret = GetHwndTitle(pszTitle, size);
- if (ret > 0)
- {
- return true;
- }
- return false;
- }
- bool SysControl::SetCheckBox(INT Set)
- {
- AttachThreadInput(
- ::GetWindowThreadProcessId((m_ResHwnd), NULL), //当前焦点窗口的线程ID
- ::GetCurrentThreadId(), //自己的线程ID
- TRUE);
- LRESULT lResult = SendMessage( // returns LRESULT in lResult
- m_ResHwnd, // handle to destination control
- (UINT)BM_SETCHECK, // message ID
- (WPARAM)Set, // = (WPARAM) () wParam;
- (LPARAM)0 // = 0; not used, must be zero
- );
- return (lResult != CB_ERR);
- }
- // <0:failed,0:Gray,1:not sel,2:sel
- INT SysControl::GetCheckBoxStatus()
- {
- AttachThreadInput(
- ::GetWindowThreadProcessId((m_ResHwnd), NULL), //当前焦点窗口的线程ID
- ::GetCurrentThreadId(), //自己的线程ID
- TRUE);
- LRESULT lResult = SendMessage( // returns LRESULT in lResult
- m_ResHwnd, // handle to destination control
- (UINT)BM_GETCHECK, // message ID
- (WPARAM)0, // = (WPARAM) () wParam;
- (LPARAM)0 // = 0; not used, must be zero
- );
- if (lResult == BST_CHECKED)
- {
- return 2;
- }
- else if (lResult == BST_UNCHECKED)
- {
- return 1;
- }
- else if (lResult == BST_INDETERMINATE)
- {
- return 0;
- }
- return -1;
- }
- INT SysControl::GetListCount()
- {
- AttachThreadInput(
- ::GetWindowThreadProcessId((m_ResHwnd), NULL), //当前焦点窗口的线程ID
- ::GetCurrentThreadId(), //自己的线程ID
- TRUE);
- LRESULT lResult = SendMessage( // returns LRESULT in lResult
- m_ResHwnd, // handle to destination control
- (UINT)LB_GETCOUNT, // message ID
- (WPARAM)0, // = (WPARAM) () wParam;
- (LPARAM)0 // = 0; not used, must be zero
- );
- if (lResult == CB_ERR)
- {
- return -1;
- }
- return (INT)lResult;
- }
- bool SysControl::GetListBoxTitle(DWORD Idx, TCHAR *pszTitle)
- {
- LRESULT lResult = SendMessage( // returns LRESULT in lResult
- m_ResHwnd, // handle to destination control
- (UINT)LB_GETTEXT, // message ID
- (WPARAM)Idx, // = (WPARAM) () wParam;
- (LPARAM)pszTitle // = 0; not used, must be zero
- );
- if (lResult == CB_ERR)
- {
- return false;
- }
- return true;
- }
- bool SysControl::AddStringListBox(TCHAR *pszTitle)
- {
- LRESULT lResult = SendMessage( // returns LRESULT in lResult
- m_ResHwnd, // handle to destination control
- (UINT)LB_ADDSTRING, // message ID
- (WPARAM)0, // = (WPARAM) () wParam;
- (LPARAM)pszTitle // = 0; not used, must be zero
- );
- if (lResult == CB_ERR)
- {
- return false;
- }
- return true;
- }
- INT SysControl::GetComboCount()
- {
- LRESULT lResult = SendMessage( // returns LRESULT in lResult
- m_ResHwnd, // handle to destination control
- (UINT)CB_GETCOUNT, // message ID
- (WPARAM)0, // = (WPARAM) () wParam;
- (LPARAM)0 // = 0; not used, must be zero
- );
- if (lResult == CB_ERR)
- {
- return -1;
- }
- return (INT)lResult;
- }
- INT SysControl::GetComboCurSelIdx()
- {
- LRESULT lResult = SendMessage( // returns LRESULT in lResult
- m_ResHwnd, // handle to destination control
- (UINT)CB_GETCURSEL, // message ID
- (WPARAM)0, // = (WPARAM) () wParam;
- (LPARAM)0 // = 0; not used, must be zero
- );
- if (lResult == CB_ERR)
- {
- return -1;
- }
- return (INT)lResult;
- }
- bool SysControl::GetComboCurSelStr(TCHAR *pszTitle, DWORD size)
- {
- INT CurSel = GetComboCurSelIdx();
- if (CurSel >= 0)
- {
- AttachThreadInput(
- ::GetWindowThreadProcessId((m_ResHwnd), NULL), //当前焦点窗口的线程ID
- ::GetCurrentThreadId(), //自己的线程ID
- TRUE);
- LRESULT lResult = SendMessage( // returns LRESULT in lResult
- m_ResHwnd, // handle to destination control
- (UINT)CB_GETLBTEXT, // message ID
- (WPARAM)CurSel, // = (WPARAM) () wParam;
- (LPARAM)pszTitle // = 0; not used, must be zero
- );
- if (lResult == CB_ERR)
- {
- return false;
- }
- return true;
- }
- return false;
- }
- INT SysControl::SetComboCurSel(const char* pKey)
- {
- LRESULT lResult = SendMessage( // returns LRESULT in lResult
- m_ResHwnd, // handle to destination control
- (UINT)CB_SELECTSTRING, // message ID
- (WPARAM)-1, // = (WPARAM) () wParam;
- (LPARAM)pKey // = 0; not used, must be zero
- );
- if (lResult == CB_ERR)
- {
- return -1;
- }
- return (INT)lResult;
- }
- bool SysControl::SetComboCurSel(DWORD Idx)
- {
- LRESULT lResult = SendMessage( // returns LRESULT in lResult
- m_ResHwnd, // handle to destination control
- (UINT)CB_SETCURSEL, // message ID
- (WPARAM)Idx, // = (WPARAM) () wParam;
- (LPARAM)0 // = 0; not used, must be zero
- );
- return (lResult != CB_ERR);
- }
- BOOL SysControl::IsObjectValid()
- {
- if(m_ResHwnd == NULL)
- {
- return FALSE;
- }
- return IsWindow(m_ResHwnd);
- }
- void SysControl::GetTabControlSelect(int &sel)
- {
- if(m_ResHwnd)
- {
- sel = TabCtrl_GetCurSel(m_ResHwnd);
- }
- }
- BOOL SysControl::SetTabControlSelect(DWORD sel,BOOL real)
- {
- SIZE_T dwBytesWrite, dwBytesRead;
- DWORD dwProcessID;
- HANDLE hProcess;
- BOOL bSuccess,bWriteOK;
- RECT rect = {0};
- int curSelection = -1;
- GetTabControlSelect(curSelection);
- if(curSelection == sel)
- {
- return TRUE;
- }
- GetWindowThreadProcessId(m_ResHwnd,&dwProcessID);
- hProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessID);
- if(!hProcess) //得不到指定进程的句柄
- return FALSE;
- LPVOID lpHeadItemRemote=VirtualAllocEx(hProcess,NULL,sizeof(RECT),MEM_COMMIT,PAGE_READWRITE);
- bWriteOK=::WriteProcessMemory(hProcess,lpHeadItemRemote,(LPVOID)&rect,sizeof(RECT),(SIZE_T*)&dwBytesWrite);
- if(!bWriteOK) //写内存错误
- return FALSE;
- TabCtrl_GetItemRect(m_ResHwnd,sel,lpHeadItemRemote);
- bSuccess=ReadProcessMemory(hProcess,lpHeadItemRemote,&rect,sizeof(RECT),(SIZE_T*)&dwBytesRead);
- if(!bSuccess) //不能在指定进程内读取文本
- return FALSE;
- VirtualFreeEx(hProcess,lpHeadItemRemote,0,MEM_RELEASE);
- CloseHandle(hProcess);
- RECT ParentRect = {0,0,0,0};
- int CurSel = -1;
- int trytime = 10;
- while(CurSel != sel && trytime > 0)
- {
- InputCmds::HitMouse(m_ResHwnd, WM_LBUTTONDOWN, MK_LBUTTON, rect.left + ParentRect.left + 3, rect.top + ParentRect.top + 3, real);
- InputCmds::HitMouse(m_ResHwnd, WM_LBUTTONUP, MK_LBUTTON, rect.left + ParentRect.left + 3, rect.top + ParentRect.top + 3, real);
- Sleep(500);
- GetTabControlSelect(CurSel);
- --trytime;
- }
- return (CurSel == sel);
- }
- INT SysControl::GetTabControlCount()
- {
- return TabCtrl_GetItemCount(m_ResHwnd);;
- }
- bool SysControl::GetTabControlTitles(DWORD Idx,TCHAR *pszTitle,DWORD size)
- {
- SIZE_T dwBytesWrite, dwBytesRead;
- DWORD dwProcessID;
- HANDLE hProcess;
- BOOL bSuccess,bWriteOK;
- int count1 = TabCtrl_GetItemCount(m_ResHwnd);
- if(count1 <= 0)
- {
- return false;
- }
- TCITEM Item = { 0 };
- Item.mask = TCIF_TEXT;//text
- Item.cchTextMax = MAX_PATH;//size
- GetWindowThreadProcessId(m_ResHwnd,&dwProcessID);
- hProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessID);
- if (!hProcess)
- {
- return false;
- }
- LPVOID lpHeadItemRemote=VirtualAllocEx(hProcess,NULL,sizeof(TCITEM),MEM_COMMIT,PAGE_READWRITE);
- LPVOID lpBuffRemote=VirtualAllocEx(hProcess,NULL,MAX_PATH*sizeof(TCHAR),MEM_COMMIT,PAGE_READWRITE);
- Item.pszText = (LPSTR)lpBuffRemote;//buff
- bWriteOK=::WriteProcessMemory(hProcess,lpHeadItemRemote,(LPVOID)&Item,sizeof(TCITEM),(SIZE_T*)&dwBytesWrite);
- if (!bWriteOK)
- {
- return false;
- }
- bool ret = false;
- if(Idx < (DWORD)count1)
- {
- memset(pszTitle, 0, sizeof(TCHAR)*size);
- if(TabCtrl_GetItem(m_ResHwnd,Idx,lpHeadItemRemote))
- {
- bSuccess = ReadProcessMemory(hProcess, lpBuffRemote, pszTitle, size, (SIZE_T*)&dwBytesRead);
- if (bSuccess)
- {
- ret = true;
- }
- }
- }
- VirtualFreeEx(hProcess,lpHeadItemRemote,0,MEM_RELEASE);
- VirtualFreeEx(hProcess,lpBuffRemote,0,MEM_RELEASE);
- CloseHandle(hProcess);
- return ret;
- }
- void SysControl::GetListViewControlSize(INT &Count, INT &Column)
- {
-
- HWND hHeaderCtrl = ListView_GetHeader(m_ResHwnd);
- Column = Header_GetItemCount(hHeaderCtrl);
- Count = ListView_GetItemCount(m_ResHwnd);
- }
- DWORD SysControl::GetListViewControlSelect(INT *pList, DWORD size)
- {
- DWORD Count = 0;
- int Idx = ListView_GetNextItem(m_ResHwnd,-1,LVNI_SELECTED);
- while(Idx >= 0)
- {
- if (Count < size)
- {
- pList[Count++] = Idx;
- }
- else
- {
- return Count;
- }
- Idx = ListView_GetNextItem(m_ResHwnd,Idx,LVNI_SELECTED);
- }
- return Count;
- }
- INT SysControl::ListViewMakeSelection(TCHAR *pszName)
- {
- INT ret = -1;
- INT Count = 0;
- INT Column = 0;
- DWORD dwProcessID;
- HANDLE hProcess;
- SIZE_T dwBytesWrite;
- BOOL bWriteOK;
- AttachThreadInput(
- ::GetWindowThreadProcessId((m_ResHwnd), NULL), //当前焦点窗口的线程ID
- ::GetCurrentThreadId(), //自己的线程ID
- TRUE);
- GetListViewControlSize(Count, Column);
- for (INT i = 0; i < Count; i++)
- {
- for (INT j = 0; j < Column; j++)
- {
- TCHAR szBuf[MAX_PATH] = { 0 };
- if (GetListViewItemContext(i, j, szBuf, MAX_PATH))
- {
- if (_stricmp(szBuf, pszName) == 0)
- {
- //hit line
- LVITEM lvitem;
- GetWindowThreadProcessId(m_ResHwnd, &dwProcessID);
- hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessID);
- if (!hProcess) //得不到指定进程的句柄
- {
- return ret;
- }
- //在指定进程内分配存储空间
- LPVOID lpListItemRemote = VirtualAllocEx(hProcess, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE);
- lvitem.state = LVIS_SELECTED | LVIS_FOCUSED;
- lvitem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
- dwBytesWrite = 0;
- bWriteOK = ::WriteProcessMemory(hProcess, lpListItemRemote, (LPVOID)&lvitem, sizeof(LVITEM), (SIZE_T*)&dwBytesWrite);
- if (!bWriteOK) //写内存错误
- {
- CloseHandle(hProcess);
- return ret;
- }
- InputCmds::MakeFocus(m_ResHwnd, TRUE);
- SendMessage(m_ResHwnd, LVM_SETITEMSTATE, (WPARAM)i, (LPARAM)lpListItemRemote);
- VirtualFreeEx(hProcess, lpListItemRemote, 0, MEM_RELEASE);
- CloseHandle(hProcess);
- return i;
- }
- }
- }
- }
- return ret;
- }
- bool SysControl::ListViewMakeChecked(TCHAR *pszName, BOOL Checked)
- {
- INT Idx = ListViewMakeSelection(pszName);
- if (Idx >= 0)
- {
- //ListView_SetCheckState(m_ResHwnd, Idx, Checked);
- //ListView_SetItemState(m_ResHwnd, Idx, INDEXTOSTATEIMAGEMASK((Checked) ? 2 : 1), LVIS_STATEIMAGEMASK);
- DWORD dwProcessID;
- HANDLE hProcess;
- SIZE_T dwBytesWrite;
- BOOL bWriteOK;
- LVITEM lvitem;
- GetWindowThreadProcessId(m_ResHwnd, &dwProcessID);
- hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessID);
- if (!hProcess) //得不到指定进程的句柄
- {
- return false;
- }
- //在指定进程内分配存储空间
- LPVOID lpListItemRemote = VirtualAllocEx(hProcess, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE);
- lvitem.state = INDEXTOSTATEIMAGEMASK((Checked) ? 2 : 1);
- lvitem.stateMask = (LVIS_STATEIMAGEMASK);
- dwBytesWrite = 0;
- bWriteOK = ::WriteProcessMemory(hProcess, lpListItemRemote, (LPVOID)&lvitem, sizeof(LVITEM), (SIZE_T*)&dwBytesWrite);
- if (!bWriteOK) //写内存错误
- {
- CloseHandle(hProcess);
- return false;
- }
- SendMessage(m_ResHwnd, LVM_SETITEMSTATE, (WPARAM)Idx, (LPARAM)lpListItemRemote);
- VirtualFreeEx(hProcess, lpListItemRemote, 0, MEM_RELEASE);
- CloseHandle(hProcess);
- return true;
- //LV_ITEM _macro_lvi;
- //_macro_lvi.state = INDEXTOSTATEIMAGEMASK((Checked) ? 2 : 1);
- //_macro_lvi.stateMask = (LVIS_STATEIMAGEMASK);
- //SNDMSG((m_ResHwnd), LVM_SETITEMSTATE, (WPARAM)(Idx), (LPARAM)(LV_ITEM *)&_macro_lvi);
- //return true;
- }
- return false;
- }
- bool SysControl::ListViewControlHit(BOOL dbClick, DWORD hang, DWORD lie, BOOL real)
- {
- SIZE_T dwBytesWrite, dwBytesRead;
- DWORD dwProcessID;
- HANDLE hProcess;
- BOOL bSuccess,bWriteOK;
- //AttachThreadInput(
- // ::GetWindowThreadProcessId((m_ResHwnd),NULL), //当前焦点窗口的线程ID
- // ::GetCurrentThreadId(), //自己的线程ID
- // TRUE);
- GetWindowThreadProcessId(m_ResHwnd,&dwProcessID);
- hProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessID);
- if (!hProcess) //得不到指定进程的句柄
- {
- return false;
- }
- POINT pt = {0};
- LPVOID lpHeadItemRemote=VirtualAllocEx(hProcess,NULL,sizeof(POINT),MEM_COMMIT,PAGE_READWRITE);
- if (lpHeadItemRemote == NULL)
- {
- CloseHandle(hProcess);
- return false;
- }
- bWriteOK=::WriteProcessMemory(hProcess,lpHeadItemRemote,(LPVOID)&pt,sizeof(POINT),(SIZE_T*)&dwBytesWrite);
- if(!bWriteOK) //写内存错误
- {
- VirtualFreeEx(hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
- CloseHandle(hProcess);
- return false;
- }
- ListView_GetItemPosition(m_ResHwnd,hang,lpHeadItemRemote);
- bSuccess=ReadProcessMemory(hProcess,lpHeadItemRemote,&pt,sizeof(POINT),(SIZE_T*)&dwBytesRead);
- if(!bSuccess) //不能在指定进程内读取文本
- {
- VirtualFreeEx(hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
- CloseHandle(hProcess);
- return false;
- }
- for (DWORD i = 0; i < lie; i++)
- {
- pt.x += ListView_GetColumnWidth(m_ResHwnd, i);
- }
- VirtualFreeEx(hProcess,lpHeadItemRemote,0,MEM_RELEASE);
- CloseHandle(hProcess);
- RECT rect = { 0, 0, 0, 0 };
- //GetWindowRect(m_ResHwnd,&rect);
- if(dbClick & real)
- {
- InputCmds::HitMouse(m_ResHwnd,WM_LBUTTONDBLCLK,MK_LBUTTON,rect.left + pt.x + 3,rect.top + pt.y + 3,real);
- }
- else if(dbClick)
- {
- InputCmds::HitMouse(m_ResHwnd,WM_LBUTTONDOWN,MK_LBUTTON,rect.left + pt.x + 3,rect.top + pt.y + 3,real);
- InputCmds::HitMouse(m_ResHwnd,WM_LBUTTONUP,MK_LBUTTON,rect.left + pt.x + 3,rect.top + pt.y + 3,real);
- InputCmds::HitMouse(m_ResHwnd,WM_LBUTTONDBLCLK,MK_LBUTTON,rect.left + pt.x + 3,rect.top + pt.y + 3,real);
- }
- else
- {
- InputCmds::HitMouse(m_ResHwnd,WM_LBUTTONDOWN,MK_LBUTTON,rect.left + pt.x + 3,rect.top + pt.y + 3,real);
- InputCmds::HitMouse(m_ResHwnd,WM_LBUTTONUP,MK_LBUTTON,rect.left + pt.x + 3,rect.top + pt.y + 3,real);
- }
- return true;
- }
- bool SysControl::GetListViewItemTitle(DWORD Column, TCHAR *pszTitle, DWORD size)
- {
- const DWORD nMaxLen = 1023;
- TCHAR szBuf[nMaxLen + 1];
- int nLVItemCount;
- int nColumns;
- DWORD dwProcessID;
- HANDLE hProcess;
- HWND hHeaderCtrl;
- HDITEM hdItemLocal;
- SIZE_T dwBytesRead, dwBytesWrite;
- BOOL bSuccess, bWriteOK;
- nLVItemCount = ListView_GetItemCount(m_ResHwnd);
- hHeaderCtrl = ListView_GetHeader(m_ResHwnd);
- nColumns = Header_GetItemCount(hHeaderCtrl);
- if (nColumns <= 0 || (INT)Column >= nColumns) {
- return false;
- }
- GetWindowThreadProcessId(m_ResHwnd, &dwProcessID);
- hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessID);
- if (!hProcess) //得不到指定进程的句柄
- {
- return false;
- }
- //在指定进程内分配存储空间
- LPVOID lpTextRemote = VirtualAllocEx(hProcess, NULL, nMaxLen + 1, MEM_COMMIT, PAGE_READWRITE);
- LPVOID lpHeadItemRemote = VirtualAllocEx(hProcess, NULL, sizeof(HDITEM), MEM_COMMIT, PAGE_READWRITE);
- if ((!lpTextRemote) || (!lpHeadItemRemote)) //不能在指定进程内分配存储空间
- {
- CloseHandle(hProcess);
- return false;
- }
- ZeroMemory(szBuf, nMaxLen + 1);
- bWriteOK = ::WriteProcessMemory(hProcess, lpTextRemote, (LPVOID)szBuf, nMaxLen + 1, (SIZE_T*)&dwBytesWrite);
- if (!bWriteOK) //写内存错误
- {
- VirtualFreeEx(hProcess, lpTextRemote, 0, MEM_RELEASE);
- VirtualFreeEx(hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
- //关闭指定进程句柄
- CloseHandle(hProcess);
- return false;
- }
- hdItemLocal.mask = HDI_TEXT;
- hdItemLocal.cchTextMax = nMaxLen;
- hdItemLocal.pszText = (LPTSTR)lpTextRemote;
- dwBytesWrite = 0;
- bWriteOK = ::WriteProcessMemory(hProcess, lpHeadItemRemote, (LPVOID)&hdItemLocal, sizeof(HDITEM), (SIZE_T*)&dwBytesWrite);
- if (!bWriteOK) //写内存错误
- {
- VirtualFreeEx(hProcess, lpTextRemote, 0, MEM_RELEASE);
- VirtualFreeEx(hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
- //关闭指定进程句柄
- CloseHandle(hProcess);
- return false;
- }
- SendMessage(hHeaderCtrl, HDM_GETITEM, (WPARAM)Column, (LPARAM)lpHeadItemRemote);
- bSuccess = ReadProcessMemory(hProcess, lpTextRemote, szBuf, nMaxLen + 1, (SIZE_T*)&dwBytesRead);
- //从指定进程存储空间读取文本
- if (!bSuccess) //不能在指定进程内读取文本
- {
- VirtualFreeEx(hProcess, lpTextRemote, 0, MEM_RELEASE);
- VirtualFreeEx(hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
- //关闭指定进程句柄
- CloseHandle(hProcess);
- return false;
- }
- strcpy_s(pszTitle, size, szBuf);
- VirtualFreeEx(hProcess, lpTextRemote, 0, MEM_RELEASE);
- VirtualFreeEx(hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
- //关闭指定进程句柄
- CloseHandle(hProcess);
- return true;
- }
- bool SysControl::GetListViewItemContext(DWORD hang, DWORD lie, TCHAR *pszContext, DWORD size)
- //void SysControl::GetAllListViewItems(vector<vector<wstring>> &strlist)
- {
- const DWORD nMaxLen=1023;
- TCHAR szBuf[nMaxLen+1];
- int nLVItemCount;
- int nColumns;
- DWORD dwProcessID;
- HANDLE hProcess;
- HWND hHeaderCtrl;
- LVITEM lvItemLocal;
- SIZE_T dwBytesRead, dwBytesWrite;
- BOOL bSuccess,bWriteOK;
- nLVItemCount = ListView_GetItemCount(m_ResHwnd);
- hHeaderCtrl = ListView_GetHeader(m_ResHwnd);
- nColumns = Header_GetItemCount(hHeaderCtrl);
- if ((INT)hang >= nLVItemCount || (nColumns <= 0 || (INT)lie >= nColumns))
- {
- return false;
- }
- GetWindowThreadProcessId(m_ResHwnd, &dwProcessID);
- hProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessID);
- if (!hProcess) //得不到指定进程的句柄
- {
- return false;
- }
- //在指定进程内分配存储空间
- LPVOID lpTextRemote=VirtualAllocEx(hProcess,NULL,nMaxLen+1,MEM_COMMIT,PAGE_READWRITE);
- LPVOID lpListItemRemote=VirtualAllocEx(hProcess,NULL,sizeof(LVITEM),MEM_COMMIT,PAGE_READWRITE);
- if ((!lpTextRemote) || (!lpListItemRemote)) //不能在指定进程内分配存储空间
- {
- CloseHandle(hProcess);
- return false;
- }
- bool ret = false;
- do{
- ZeroMemory(szBuf,nMaxLen+1);
- bWriteOK= ::WriteProcessMemory(hProcess,lpTextRemote,(LPVOID)szBuf,nMaxLen+1,(SIZE_T*)&dwBytesWrite);
- if (!bWriteOK) //写内存错误
- {
- break;
- }
- lvItemLocal.iItem = hang;
- lvItemLocal.iSubItem = lie;
- lvItemLocal.mask=LVIF_TEXT;
- lvItemLocal.cchTextMax=nMaxLen;
- lvItemLocal.pszText=(LPTSTR)lpTextRemote;
- dwBytesWrite=0;
- bWriteOK=::WriteProcessMemory(hProcess,lpListItemRemote,(LPVOID)&lvItemLocal,sizeof(LVITEM),(SIZE_T*)&dwBytesWrite);
- if (!bWriteOK) //写内存错误
- {
- break;
- }
- SendMessage(m_ResHwnd, LVM_GETITEMTEXT, (WPARAM)hang, (LPARAM)lpListItemRemote);
- bSuccess=ReadProcessMemory(hProcess,lpTextRemote,szBuf,nMaxLen+1,(SIZE_T*)&dwBytesRead);
- //从指定进程存储空间读取文本
- if (!bSuccess) //不能在指定进程内读取文本
- {
- break;
- }
- strcpy_s(pszContext, size, szBuf);
- ret = true;
- } while (0);
- //在指定进程内释放存储空间
- VirtualFreeEx(hProcess,lpListItemRemote,0,MEM_RELEASE);
- VirtualFreeEx(hProcess,lpTextRemote,0,MEM_RELEASE);
- //关闭指定进程句柄
- CloseHandle(hProcess);
- return ret;
- }
- bool SysControl::GetTreeViewNodeName(PVOID hItem,TCHAR *pszBuff)
- {
- SIZE_T dwBytesWrite, dwBytesRead;
- DWORD dwProcessID;
- HANDLE hProcess;
- BOOL bSuccess,bWriteOK;
- memset(pszBuff,0,MAX_PATH*sizeof(TCHAR));
- GetWindowThreadProcessId(m_ResHwnd,&dwProcessID);
- hProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessID);
- if (!hProcess) //得不到指定进程的句柄
- {
- return false;
- }
- TVITEM itemattr = { 0 };
- itemattr.hItem = (HTREEITEM)hItem;
- itemattr.mask = TVIF_TEXT;
- itemattr.cchTextMax = MAX_PATH;
- LPVOID lpHeadItemBuff=VirtualAllocEx(hProcess,NULL,sizeof(TCHAR)*MAX_PATH,MEM_COMMIT,PAGE_READWRITE);
- LPVOID lpHeadItemRemote=VirtualAllocEx(hProcess,NULL,sizeof(TVITEM),MEM_COMMIT,PAGE_READWRITE);
- if (lpHeadItemBuff == NULL || lpHeadItemRemote == NULL)
- {
- CloseHandle(hProcess);
- return false;
- }
- itemattr.pszText = (LPSTR)lpHeadItemBuff;
- bWriteOK=::WriteProcessMemory(hProcess,lpHeadItemRemote,(LPVOID)&itemattr,sizeof(TVITEM),(SIZE_T*)&dwBytesWrite);
- if (!bWriteOK) //写内存错误
- {
- VirtualFreeEx(hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
- VirtualFreeEx(hProcess, lpHeadItemBuff, 0, MEM_RELEASE);
- CloseHandle(hProcess);
- return false;
- }
- //TreeView_GetItem(m_ResHwnd, lpHeadItemRemote);
- BOOL ret = (BOOL)SNDMSG((m_ResHwnd), TVM_GETITEM, 0, (LPARAM)(TV_ITEM *)(lpHeadItemRemote));
- bSuccess=ReadProcessMemory(hProcess,lpHeadItemBuff,pszBuff,sizeof(TCHAR)*MAX_PATH,(SIZE_T*)&dwBytesRead);
- if (!bSuccess) //不能在指定进程内读取文本
- {
- VirtualFreeEx(hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
- VirtualFreeEx(hProcess, lpHeadItemBuff, 0, MEM_RELEASE);
- CloseHandle(hProcess);
- return false;
- }
- VirtualFreeEx(hProcess,lpHeadItemRemote,0,MEM_RELEASE);
- VirtualFreeEx(hProcess,lpHeadItemBuff,0,MEM_RELEASE);
- CloseHandle(hProcess);
- return true;
- }
- PVOID SysControl::FindSpecificTreeNode(PVOID hItem,TCHAR *pszNodeName)
- {
- BOOL ret = FALSE;
- HTREEITEM hFound = NULL;
- while(hItem)
- {
- TCHAR szBuff[MAX_PATH] = { 0 };
- GetTreeViewNodeName(hItem, szBuff);
- if (_strnicmp(szBuff, pszNodeName,strlen(pszNodeName)) == 0)
- {
- //got one
- return hItem;
- }
- //child
- HTREEITEM hChildItem = TreeView_GetChild(m_ResHwnd, ((HTREEITEM)hItem));
- if(hChildItem)
- {
- hFound = (HTREEITEM)FindSpecificTreeNode(hChildItem, pszNodeName);
- if(hFound)
- {
- return hFound;
- }
- }
- hItem = TreeView_GetNextItem(m_ResHwnd, ((HTREEITEM)hItem), TVGN_NEXT);
- }
- return NULL;
- }
- bool SysControl::TreeViewMakeSelection(TCHAR *pszName)
- {
- AttachThreadInput(
- ::GetWindowThreadProcessId((m_ResHwnd), NULL), //当前焦点窗口的线程ID
- ::GetCurrentThreadId(), //自己的线程ID
- TRUE);
- HTREEITEM hItem = TreeView_GetRoot(m_ResHwnd);
- HTREEITEM hFound = (HTREEITEM)FindSpecificTreeNode(hItem, pszName);
- if (hFound)
- {
- InputCmds::MakeFocus(m_ResHwnd, TRUE);
- TreeView_Select(m_ResHwnd, hFound, TVGN_CARET);
- return true;
- }
- return false;
- }
- bool SysControl::TreeViewMakeIdxChecked(DWORD Idx, BOOL Checked)
- {
- SIZE_T dwBytesWrite;
- DWORD dwProcessID;
- HANDLE hProcess;
- BOOL bWriteOK;
- AttachThreadInput(
- ::GetWindowThreadProcessId((m_ResHwnd), NULL), //当前焦点窗口的线程ID
- ::GetCurrentThreadId(), //自己的线程ID
- TRUE);
- //InputCmds::MakeFocus(m_ResHwnd, TRUE);
- //UINT count1 = TreeView_GetCount(m_ResHwnd);
- HTREEITEM hItem = TreeView_GetRoot(m_ResHwnd);
- HTREEITEM hNext = hItem;//= TreeView_GetNextItem(m_ResHwnd,hItem,TVGN_CHILD);
- DWORD firstCount = 0;
- if (hItem)
- {
- while (firstCount < Idx && hNext != NULL)
- {
- hNext = TreeView_GetNextItem(m_ResHwnd, hNext, TVGN_NEXT);
- ++firstCount;
- }
- if (hNext == NULL)
- {
- return false;
- }
- //found idx
- TreeView_Select(m_ResHwnd, hNext, TVGN_CARET);
- //TreeView_SetCheckState(m_ResHwnd, hFound,Checked);
- //TreeView_SetItemState(m_ResHwnd, hFound, INDEXTOSTATEIMAGEMASK((Checked) ? 2 : 1), TVIS_STATEIMAGEMASK);
- GetWindowThreadProcessId(m_ResHwnd, &dwProcessID);
- hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessID);
- if (!hProcess) //得不到指定进程的句柄
- {
- return false;
- }
- TVITEM itemattr = { 0 };
- itemattr.mask = TVIF_HANDLE | TVIF_STATE;
- itemattr.hItem = (hNext);
- itemattr.stateMask = (TVIS_STATEIMAGEMASK);
- itemattr.state = (INDEXTOSTATEIMAGEMASK((Checked) ? 2 : 1));
- LPVOID lpHeadItemRemote = VirtualAllocEx(hProcess, NULL, sizeof(TVITEM), MEM_COMMIT, PAGE_READWRITE);
- if (lpHeadItemRemote == NULL)
- {
- CloseHandle(hProcess);
- return false;
- }
- bWriteOK = ::WriteProcessMemory(hProcess, lpHeadItemRemote, (LPVOID)&itemattr, sizeof(TVITEM), (SIZE_T*)&dwBytesWrite);
- if (!bWriteOK) //写内存错误
- {
- VirtualFreeEx(hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
- CloseHandle(hProcess);
- return false;
- }
- BOOL Sent = (BOOL)SendMessage(m_ResHwnd, TVM_SETITEMW, (WPARAM)0, (LPARAM)lpHeadItemRemote);
- //TVITEM _ms_TVi;
- //_ms_TVi.mask = TVIF_STATE;
- //_ms_TVi.hItem = (hFound);
- //_ms_TVi.stateMask = (TVIS_STATEIMAGEMASK);
- //_ms_TVi.state = (INDEXTOSTATEIMAGEMASK((Checked) ? 2 : 1));
- //SNDMSG((m_ResHwnd), TVM_SETITEM, 0, (LPARAM)(TV_ITEM *)&_ms_TVi);
- VirtualFreeEx(hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
- CloseHandle(hProcess);
- if (Sent == FALSE)
- {
- return false;
- }
- return true;
- }
- return false;
- }
- bool SysControl::TreeViewMakeChecked(TCHAR *pszName, BOOL Checked)
- {
- SIZE_T dwBytesWrite;
- DWORD dwProcessID;
- HANDLE hProcess;
- BOOL bWriteOK;
- AttachThreadInput(
- ::GetWindowThreadProcessId((m_ResHwnd), NULL), //当前焦点窗口的线程ID
- ::GetCurrentThreadId(), //自己的线程ID
- TRUE);
- HTREEITEM hItem = TreeView_GetRoot(m_ResHwnd);
- HTREEITEM hFound = (HTREEITEM)FindSpecificTreeNode(hItem, pszName);
- if (hFound)
- {
- TreeView_Select(m_ResHwnd, hFound, TVGN_CARET);
- //TreeView_SetCheckState(m_ResHwnd, hFound,Checked);
- //TreeView_SetItemState(m_ResHwnd, hFound, INDEXTOSTATEIMAGEMASK((Checked) ? 2 : 1), TVIS_STATEIMAGEMASK);
- GetWindowThreadProcessId(m_ResHwnd, &dwProcessID);
- hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessID);
- if (!hProcess) //得不到指定进程的句柄
- {
- return false;
- }
- TVITEM itemattr = { 0 };
- itemattr.mask = TVIF_STATE;
- itemattr.hItem = (hFound);
- itemattr.stateMask = (TVIS_STATEIMAGEMASK);
- itemattr.state = (INDEXTOSTATEIMAGEMASK((Checked) ? 2 : 1));
- LPVOID lpHeadItemRemote = VirtualAllocEx(hProcess, NULL, sizeof(TVITEM), MEM_COMMIT, PAGE_READWRITE);
- if (lpHeadItemRemote == NULL)
- {
- CloseHandle(hProcess);
- return false;
- }
- bWriteOK = ::WriteProcessMemory(hProcess, lpHeadItemRemote, (LPVOID)&itemattr, sizeof(TVITEM), (SIZE_T*)&dwBytesWrite);
- if (!bWriteOK) //写内存错误
- {
- VirtualFreeEx(hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
- CloseHandle(hProcess);
- return false;
- }
- SendMessage(m_ResHwnd, TVM_SETITEM, (WPARAM)0, (LPARAM)lpHeadItemRemote);
- //TVITEM _ms_TVi;
- //_ms_TVi.mask = TVIF_STATE;
- //_ms_TVi.hItem = (hFound);
- //_ms_TVi.stateMask = (TVIS_STATEIMAGEMASK);
- //_ms_TVi.state = (INDEXTOSTATEIMAGEMASK((Checked) ? 2 : 1));
- //SNDMSG((m_ResHwnd), TVM_SETITEM, 0, (LPARAM)(TV_ITEM *)&_ms_TVi);
- VirtualFreeEx(hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
- CloseHandle(hProcess);
- return true;
- }
- return false;
- }
- bool SysControl::TreeViewGetSelectedItemTitle(TCHAR *pszTitle)
- {
- AttachThreadInput(
- ::GetWindowThreadProcessId((m_ResHwnd), NULL), //当前焦点窗口的线程ID
- ::GetCurrentThreadId(), //自己的线程ID
- TRUE);
- HTREEITEM hItem = TreeView_GetSelection(m_ResHwnd);
- if (hItem)
- {
- return GetTreeViewNodeName(hItem, pszTitle);
- }
- return false;
- }
- bool SysControl::TreeViewMakeCheckedItem(HTREEITEM hFound, BOOL Checked)
- {
- SIZE_T dwBytesWrite;
- DWORD dwProcessID;
- HANDLE hProcess;
- BOOL bWriteOK;
- if (hFound)
- {
- TreeView_Select(m_ResHwnd, hFound, TVGN_CARET);
- //TreeView_SetCheckState(m_ResHwnd, hFound,Checked);
- //TreeView_SetItemState(m_ResHwnd, hFound, INDEXTOSTATEIMAGEMASK((Checked) ? 2 : 1), TVIS_STATEIMAGEMASK);
- GetWindowThreadProcessId(m_ResHwnd, &dwProcessID);
- hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessID);
- if (!hProcess) //得不到指定进程的句柄
- {
- return false;
- }
- TVITEM itemattr = { 0 };
- itemattr.mask = TVIF_STATE;
- itemattr.hItem = (hFound);
- itemattr.stateMask = (TVIS_STATEIMAGEMASK);
- itemattr.state = (INDEXTOSTATEIMAGEMASK((Checked) ? 2 : 1));
- LPVOID lpHeadItemRemote = VirtualAllocEx(hProcess, NULL, sizeof(TVITEM), MEM_COMMIT, PAGE_READWRITE);
- if (lpHeadItemRemote == NULL)
- {
- CloseHandle(hProcess);
- return false;
- }
- bWriteOK = ::WriteProcessMemory(hProcess, lpHeadItemRemote, (LPVOID)&itemattr, sizeof(TVITEM), (SIZE_T*)&dwBytesWrite);
- if (!bWriteOK) //写内存错误
- {
- VirtualFreeEx(hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
- CloseHandle(hProcess);
- return false;
- }
- SendMessage(m_ResHwnd, TVM_SETITEM, (WPARAM)0, (LPARAM)lpHeadItemRemote);
- //TVITEM _ms_TVi;
- //_ms_TVi.mask = TVIF_STATE;
- //_ms_TVi.hItem = (hFound);
- //_ms_TVi.stateMask = (TVIS_STATEIMAGEMASK);
- //_ms_TVi.state = (INDEXTOSTATEIMAGEMASK((Checked) ? 2 : 1));
- //SNDMSG((m_ResHwnd), TVM_SETITEM, 0, (LPARAM)(TV_ITEM *)&_ms_TVi);
- VirtualFreeEx(hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
- CloseHandle(hProcess);
- return true;
- }
- return false;
- }
- BOOL SysControl::TreeViewSelectAB(DWORD firstLevel, DWORD secondLevel)
- {
- AttachThreadInput(
- ::GetWindowThreadProcessId((m_ResHwnd),NULL), //当前焦点窗口的线程ID
- ::GetCurrentThreadId(), //自己的线程ID
- TRUE);
- InputCmds::MakeFocus(m_ResHwnd, TRUE);
- //UINT count1 = TreeView_GetCount(m_ResHwnd);
- HTREEITEM hItem = TreeView_GetRoot(m_ResHwnd);
- HTREEITEM hChild ;//= TreeView_GetNextItem(m_ResHwnd,hItem,TVGN_CHILD);
- DWORD firstCount = 0;
- while(hItem)
- {
- if(firstCount == firstLevel)
- {
- hChild = TreeView_GetNextItem(m_ResHwnd,hItem,TVGN_CHILD);
- DWORD secondCount = 0;
- while(hChild)
- {
- if(secondCount == secondLevel)
- {
- TreeView_Select(m_ResHwnd,hChild,TVGN_CARET);
- return TRUE;
- }
- hChild = TreeView_GetNextItem(m_ResHwnd,hChild,TVGN_NEXT);
- ++secondCount;
- }
- break;
- }
- hItem = TreeView_GetNextItem(m_ResHwnd,hItem,TVGN_NEXT);
- ++firstCount;
- }
- return FALSE;
- }
- bool SysControl::TreeViewMakeCheckedAB(DWORD firstLevel, INT secondLevel)
- {
- AttachThreadInput(
- ::GetWindowThreadProcessId((m_ResHwnd), NULL), //当前焦点窗口的线程ID
- ::GetCurrentThreadId(), //自己的线程ID
- TRUE);
- InputCmds::MakeFocus(m_ResHwnd, FALSE);
- //UINT count1 = TreeView_GetCount(m_ResHwnd);
- HTREEITEM hItem = TreeView_GetRoot(m_ResHwnd);
- HTREEITEM hChild;//= TreeView_GetNextItem(m_ResHwnd,hItem,TVGN_CHILD);
- DWORD firstCount = 0;
- while (hItem)
- {
- if (secondLevel < 0)
- {
- if (firstCount == firstLevel)
- {
- //this is it
- TreeView_Select(m_ResHwnd, hItem, TVGN_CARET);
- return TreeViewMakeCheckedItem(hItem, TRUE);
- }
- hItem = TreeView_GetNextItem(m_ResHwnd, hItem, TVGN_NEXT);
- ++firstCount;
- }
- else
- {
- if (firstCount == firstLevel)
- {
- hChild = TreeView_GetNextItem(m_ResHwnd, hItem, TVGN_CHILD);
- DWORD secondCount = 0;
- while (hChild)
- {
- if (secondCount == secondLevel)
- {
- return TreeViewMakeCheckedItem(hChild, TRUE);
- }
- hChild = TreeView_GetNextItem(m_ResHwnd, hChild, TVGN_NEXT);
- ++secondCount;
- }
- break;
- }
- hItem = TreeView_GetNextItem(m_ResHwnd, hItem, TVGN_NEXT);
- ++firstCount;
- }
- }
- return false;
- }
- BOOL SysControl::TreeViewSelectAB(DWORD firstLevel, INT secondLevel,BOOL Focus)
- {
- AttachThreadInput(
- ::GetWindowThreadProcessId((m_ResHwnd),NULL), //当前焦点窗口的线程ID
- ::GetCurrentThreadId(), //自己的线程ID
- TRUE);
- if (Focus)
- {
- InputCmds::MakeFocus(m_ResHwnd, TRUE);
- }
- else
- {
- InputCmds::MakeFocus(m_ResHwnd, FALSE);
- }
- //UINT count1 = TreeView_GetCount(m_ResHwnd);
- HTREEITEM hItem = TreeView_GetRoot(m_ResHwnd);
- HTREEITEM hChild ;//= TreeView_GetNextItem(m_ResHwnd,hItem,TVGN_CHILD);
- DWORD firstCount = 0;
- while(hItem)
- {
- if (secondLevel < 0)
- {
- if (firstCount == firstLevel)
- {
- //this is it
- TreeView_Select(m_ResHwnd, hItem, TVGN_CARET);
- return TRUE;
- }
- hItem = TreeView_GetNextItem(m_ResHwnd, hItem, TVGN_NEXT);
- ++firstCount;
- }
- else
- {
- if (firstCount == firstLevel)
- {
- hChild = TreeView_GetNextItem(m_ResHwnd, hItem, TVGN_CHILD);
- DWORD secondCount = 0;
- while (hChild)
- {
- if (secondCount == secondLevel)
- {
- TreeView_Select(m_ResHwnd, hChild, TVGN_CARET);
- return TRUE;
- }
- hChild = TreeView_GetNextItem(m_ResHwnd, hChild, TVGN_NEXT);
- ++secondCount;
- }
- break;
- }
- hItem = TreeView_GetNextItem(m_ResHwnd, hItem, TVGN_NEXT);
- ++firstCount;
- }
- }
- return FALSE;
- }
- //BOOL SysControl::HitTreeNode(BOOL dbClick,vector<wstring> &OneTreeRoute,BOOL real)
- //{
- // BOOL ret = FALSE;
- // WCHAR szBuff[MAX_PATH];
- // HTREEITEM hFound = NULL;
- // HTREEITEM hItem = TreeView_GetRoot(m_ResHwnd);
- //
- // vector<wstring> curSelection;
- // GetTreeSelection(curSelection);
- //
- // if(curSelection == OneTreeRoute)
- // {
- // return TRUE;
- // }
- //
- // for(INT i = (INT)OneTreeRoute.size() - 1;i >= 0;i--)
- // {
- // hFound = FindSpecificTreeNode(hItem,(WCHAR*)OneTreeRoute[i].c_str(),szBuff);
- //
- // if(hFound)
- // {
- // ret = TreeView_EnsureVisible(m_ResHwnd,hFound);
- // if(ret == FALSE)//send OK
- // {
- // //do hit
- // ret = HitSpecificTreeNode(dbClick,hFound,real);
- // if(i == OneTreeRoute.size() - 1)
- // {
- // //done
- // //check selection,and return
- // vector<wstring> realSel;
- // int trytime = 50;
- // while(trytime > 0)
- // {
- // GetTreeSelection(realSel);
- // if(realSel.size() > 0)
- // {
- // if(realSel == OneTreeRoute)
- // {
- // return TRUE;
- // }
- // }
- //
- // Sleep(100);
- // --trytime;
- // }
- //
- // break;
- // }
- // else
- // {
- // i = (INT)OneTreeRoute.size() - 1;
- //
- // }
- //
- // }
- // }
- //
- // }
- //
- //
- // return ret;
- //
- //}
|