任務管理器的建立

2021-06-17 18:07:43 字數 3481 閱讀 4447

因為任務管理器中涉及到程序的列舉操作,

①、設計介面、以及列表控制項變數的繫結;

②、列表控制項樣式的指定:

m_tasklist.setextendedstyle(lvs_ex_gridlines | lvs_ex_fullrowselect);

m_tasklist.insertcolumn(0, _t("   程序名稱"), 0, 100);

m_tasklist.insertcolumn(1, _t("   pid"), 0, 60);

m_tasklist.insertcolumn(2, _t("   檔案路徑"), 0, 380);

③、程序列表的獲取:

具體的方法也是多種的,具體見:

int idx = 0;

cstring strid;

handle hprocess = null;

processentry32 info = ;

info.dwsize = sizeof(processentry32);

bool bret = process32first(hsnap, &info);

while(bret) ;

getmodulefilenameex(hprocess, null, szpath, max_path);

m_tasklist.setitemtext(idx, 2, szpath);

}bret = process32next(hsnap, &info);

}return true;

}④、debug 許可權提公升函式:

bool adjustprivileges()

;token_privileges oldtp = ;

dword dwsize = sizeof(token_privileges);

luid luid = ;

if (!openprocesstoken(getcurrentprocess(), token_adjust_privileges | token_query, &htoken))

if (!lookupprivilegevalue(null, se_debug_name, &luid))

tp.privilegecount=1;

tp.privileges[0].luid = luid;

tp.privileges[0].attributes = se_privilege_enabled;

/* adjust token privileges */

if (!adjusttokenprivileges(htoken, false, &tp, sizeof(token_privileges), &oldtp, &dwsize))

// close handles

closehandle(htoken);

return true;

}⑥、選單資源的彈出:

void cmfctestdlg::onnmrclicktasklist(nmhdr *pnmhdr, lresult *presult)

pmenu->trackpopupmenu(tpm_leftalign | tpm_rightbutton, pt.x, pt.y, this);

*presult = 0;

}⑦、選單響應函式的實現:

void cmfctestdlg::onmrefreshlist()

m_tasklist.deleteallitems();

getprocesslist();

}void cmfctestdlg::onmedntask()

else

if ( !bret ) else}}

void cmfctestdlg::onmfindexe()

void cmfctestdlg::onmcopypath()

size_t cbstr = (strpath.getlength()+1)*sizeof(tchar);

hglobal hdata = globalalloc(gmem_moveable, cbstr);

memcpy_s(globallock(hdata), cbstr, strpath.lockbuffer(), cbstr);

globalunlock(hdata);

strpath.unlockbuffer();

uint uiformat = (sizeof(tchar) == sizeof(wchar)) ? cf_unicodetext : cf_text;

if (::setclipboarddata(uiformat, hdata) == null)

closeclipboard();

}⑧、為列表控制項加上程式的字首圖示:

// h 標頭檔案中進行影象列表的定義:

cimagelist m_imglist;

// oninitdialog() 函式中進行影象列表的建立及設定:

m_imglist.create(16, 16, ilc_color24, 10, 10);

m_tasklist.setimagelist(&m_imglist, lvsil_small);

int idx = 0, imgidx = -1;

cstring strid;

handle hprocess = null;

cstring strpath, strsys(_t("systemroot"));

processentry32 info = ;

info.dwsize = sizeof(processentry32);

bool bret = process32first(hsnap, &info);

while(bret) ;

getwindowsdirectory(szwin, max_path);

strpath.replace(strsys, szwin);

}shfileinfo shinfo = ;

shgetfileinfo(strpath, 0, &shinfo, sizeof(shfileinfo), shgfi_smallicon|shgfi_icon);

imgidx = m_imglist.add(shinfo.hicon);

}//進行列表項的插入

idx = m_tasklist.insertitem(m_tasklist.getitemcount(), _t(""), imgidx);

m_tasklist.setitemtext(idx, 0, info.szexefile);

strid.empty();

strid.format(_t("%d"), info.th32processid);

m_tasklist.setitemtext(idx, 1, strid);

m_tasklist.setitemtext(idx, 2, strpath);

//繼續遍歷程序列表

bret = process32next(hsnap, &info);

}return true;

}

任務管理器

dim url systemutil.run e 20111108 20111108 chinese hedexlite.exe process name inputbox 請輸入程序名 程序 hedexlite process list dialog windows 任務管理器 winlistvi...

linux任務管理器

在redhat2.4.20 8下編譯通過 由於本程式視窗部分由glad工具編制,源 不易貼出,現只給出部分 函式的 1,退出 按鈕 函式 void on button9 clicked gtkbutton button,gpointer user data 2,關機 按鈕 函式 void on bu...

遮蔽「任務管理器」

適用於win nt 2k xp,引數key為true,遮蔽 任務管理器 為false,任務管理器 可用 使用方法 disabletaskmgr true procedure disabletaskmgr key boolean var reg tregistry begin reg tregistr...