Jump to content



Ένας lightweight Task Manager: Tasker OutOfSpecs


Dr.Paneas

Recommended Posts

Dedicated to GV banana

Ο κώδικας είναι σε C++, με το Implmentation να έχει γίνει από δύο hackers crAcker και Uranium-239 . Εγώ το έκανα να παίζει και σε Windows 7 γιατί δεν έβλεπε το winsocke32.lib .


#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>

#define NewTask 1
#define HELP 2
#define Exit 3
#define TAB1 4
#define TAB2 5
#define ListB 6
#define CloseTask 7
#define NewTaskk 8
#define TProcess 9
#define CurrentProcs 10
#define ProcN 11
#define NewTaskE 12
#define NewTaskOK 13
#define NewTaskCancel 14
#define NewTaskBrowse 15
#define AboutOK 16
#define PMemory 17
#define TMemory 18
#define AMemory 19
#define IProcess 20
#define PIOK 21
#define ProcName 22
#define ProcID 23
#define ParentPID 24
#define ChToP 25

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

BOOL ShowTasks();
BOOL ShowProcesses();
BOOL BrowseFile(HWND hwnd);

DWORD WINAPI RefreshTasks(LPVOID);
DWORD WINAPI RefreshProcs(LPVOID);
DWORD WINAPI RefreshNProcs(LPVOID);
DWORD WINAPI NewTaskWindow(LPVOID);
DWORD WINAPI AboutWindow(LPVOID);
DWORD WINAPI ProcessInfoWindow(LPVOID);

int TerminateTask(char *TaskTitle, HWND handle);

HWND GetFirstWindowText(char buf[],unsigned int max_out,int *text_written);
int GetNextWindowText(char buf[],unsigned int max_out,HWND* handle);
int KillWindowProcess(HWND handle);
int TaskToProcess(char *TaskTitle, HWND handle);

typedef BOOL (WINAPI *TH32_PROCESS)
(HANDLE hSnapShot, LPPROCESSENTRY32 lppe);

static TH32_PROCESS pProcess32First = NULL;
static TH32_PROCESS pProcess32Next = NULL;

HANDLE hProcessSnap;
HANDLE hProcess;
HANDLE hSnapshot;

PROCESSENTRY32 pe32;

HINSTANCE hDll;

BOOL KillProcess(char *Process);

char szClassName[ ] = "Task_Manager";
char Data[265]; // MAX_PATH+5
char Data2[10];
char FilePath[260]; // MAX_PATH
char PInfo[20] = "Processes: ";
char buff[10];
char TInfo1[35] = "Type the name of the task to open.";
char TInfo2[7] = "Open: ";
char About1[18] = "Tasker OutOfSpecs";
char About2[60] = "Created by crAcker and Uranium-239";
char About3[27] = "Modified by Dr.Paneas 2010";
char PInfos1[20] = "Process Name: ";
char PInfos2[20] = "Process ID: ";
char PInfos3[20] = "Parent Process ID: ";
char PName[150];
char PData[200];

char *ProcsN;

MEMORYSTATUS Memory;

int Procs = 0;

HINSTANCE hThisInstance;

HWND Tab1,
Tab2,
ListBox,
CTask,
NTask,
TProc,
Windows,
ProcsEdit,
hwnd,
NewTaskEdit,
NewTOK,
NewTCancel,
NewTBrowse,
AOK,
PhyskMemory,
MemoryTotal,
MemoryAvail,
IProc,
PINF,
NameP,
IDP,
PPID,
TOProc;

HFONT hFont1,
hFont2,
hFont3;

static HMENU hMenu,
hMenuInfo1,
hMenuInfo2,
hMenuInfo3;

int x = GetSystemMetrics(SM_CXSCREEN)/3,
y = GetSystemMetrics(SM_CYSCREEN)/3,

proc_cnt, thrd_cnt,
Cursel,
choice;

HANDLE TaskR,
ProcsR;

HDC hdc;
PAINTSTRUCT ps;

POINT Point;

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;

wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_WINDOW;

if (!RegisterClassEx (&wincl))
return 0;

hwnd = CreateWindowEx (
WS_EX_CLIENTEDGE | WS_EX_DLGMODALFRAME,
szClassName,
"Tasker OutOfSpecs",
WS_SYSMENU | WS_MINIMIZEBOX,
x,
y,
350,
433,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);

ShowWindow (hwnd, nFunsterStil);

while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}

return messages.wParam;
}

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;

case WM_CREATE:
hFont1 = CreateFont(14, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, DEFAULT_QUALITY, FF_DONTCARE, "Microsoft Sans Serif");
hFont2 = CreateFont(14, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, DEFAULT_QUALITY, FF_DONTCARE, "Arial");
hFont3 = CreateFont(16, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, DEFAULT_QUALITY, FF_DONTCARE, "Arial");

hMenu = CreateMenu();

hMenuInfo1 = CreateMenu();
hMenuInfo2 = CreateMenu();
hMenuInfo3 = CreateMenu();

AppendMenu(hMenuInfo1, MF_STRING, NewTask, "New Task(Execute...)");
AppendMenu(hMenuInfo1, MF_SEPARATOR, 0, 0);
AppendMenu(hMenuInfo1, MF_STRING, Exit, "Exit");
AppendMenu(hMenu, MF_POPUP, (UINT)hMenuInfo1, "File");

AppendMenu(hMenuInfo2, MF_STRING, HELP, "About");
AppendMenu(hMenu, MF_POPUP, (UINT)hMenuInfo2, "Help");

SetMenu(hwnd, hMenu);

Tab1 = CreateWindowEx(
WS_EX_CLIENTEDGE,
"Button",
"Tasks",
WS_VISIBLE | WS_CHILD | WS_BORDER,
8, 5, 53, 21,
hwnd,
(HMENU)TAB1,
0,
NULL
);

Tab2 = CreateWindowEx(
WS_EX_CLIENTEDGE,
"Button",
"Processes",
WS_VISIBLE | WS_CHILD | WS_BORDER,
66, 5, 73, 21,
hwnd,
(HMENU)TAB2,
0,
NULL
);

ListBox = CreateWindowEx(
0,
"ListBox",
0,
WS_VISIBLE | WS_CHILD | WS_VSCROLL | WS_BORDER | LBS_DISABLENOSCROLL | LBS_STANDARD,
5, 35, 327, 305,
hwnd,
(HMENU)ListB,
0,
NULL
);

CTask = CreateWindowEx(
0,
"Button",
"Close Task",
WS_VISIBLE | WS_CHILD | WS_BORDER,
138, 325, 85, 20,
hwnd,
(HMENU)CloseTask,
0,
NULL
);

NTask = CreateWindowEx(
0,
"Button",
"New Task...",
WS_VISIBLE | WS_CHILD | WS_BORDER,
230, 325, 85, 20,
hwnd,
(HMENU)NewTaskk,
0,
NULL
);

TProc = CreateWindowEx(
0,
"Button",
"Terminate Process",
WS_VISIBLE | WS_CHILD | WS_BORDER,
205, 325, 110, 20,
hwnd,
(HMENU)TProcess,
0,
NULL
);

ProcsEdit = CreateWindowEx(
WS_EX_CLIENTEDGE,
"Edit",
0,
WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL | ES_READONLY,
5, 358, 90, 17,
hwnd,
(HMENU)ProcsN,
0,
NULL
);

PhyskMemory = CreateWindowEx(
WS_EX_CLIENTEDGE,
"Edit",
0,
WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL | ES_READONLY,
105, 358, 125, 17,
hwnd,
(HMENU)PMemory,
0,
NULL
);

IProc = CreateWindowEx(
0,
"Button",
"Information",
WS_VISIBLE | WS_CHILD | WS_BORDER,
130, 325, 70, 20,
hwnd,
(HMENU)IProcess,
0,
NULL
);

TOProc = CreateWindowEx(
0,
"Button",
"Change to Process",
WS_VISIBLE | WS_CHILD | WS_BORDER,
20, 325, 110, 20,
hwnd,
(HMENU)ChToP,
0,
NULL
);


SendMessage(Tab1, WM_SETFONT, (WPARAM)hFont1, 0);
SendMessage(Tab2, WM_SETFONT, (WPARAM)hFont1, 0);
SendMessage(ListBox, WM_SETFONT, (WPARAM)hFont2,0);
SendMessage(CTask, WM_SETFONT, (WPARAM)hFont2,0);
SendMessage(NTask, WM_SETFONT, (WPARAM)hFont2,0);
SendMessage(TProc, WM_SETFONT, (WPARAM)hFont2,0);
SendMessage(ProcsEdit, WM_SETFONT, (WPARAM)hFont2,0);
SendMessage(PhyskMemory, WM_SETFONT, (WPARAM)hFont2,0);
SendMessage(IProc, WM_SETFONT, (WPARAM)hFont2,0);
SendMessage(TOProc, WM_SETFONT, (WPARAM)hFont2,0);

TaskR = CreateThread(NULL, 0, RefreshTasks, 0, 0, NULL);
CreateThread(NULL, 0, RefreshNProcs, 0, 0, NULL);
ShowTasks();
break;

case WM_COMMAND:
switch(LOWORD(wParam))
{
case TAB1:
TerminateThread(ProcsR, 0);
TerminateThread(TaskR, 0);
TaskR = CreateThread(NULL, 0, RefreshTasks, 0, 0, NULL);

ShowTasks();
break;

case TAB2:
TerminateThread(TaskR, 0);
TerminateThread(ProcsR, 0);
ProcsR = CreateThread(NULL, 0, RefreshProcs, 0, 0, NULL);

ShowProcesses();
break;

case CloseTask:
Cursel = SendMessage(ListBox, LB_GETCURSEL, 0, 0);
SendMessage(ListBox, LB_GETTEXT, (WPARAM)Cursel, (LPARAM)Data);

if(!strcmp(Data, "Task-Manager V1.0"))
{
MessageBox(NULL, "You can not close this task !", "Close Task", MB_OK | MB_ICONWARNING);
return 0;
}

TerminateTask(Data, GetForegroundWindow());

break;

case TProcess:
Cursel = SendMessage(ListBox, LB_GETCURSEL, 0, 0);
SendMessage(ListBox, LB_GETTEXT, (WPARAM)Cursel, (LPARAM)Data);

KillProcess(Data);
break;

case NewTaskk:
CreateThread(NULL, 0, NewTaskWindow, 0, 0, NULL);
break;

case IProcess:
Cursel = SendMessage(ListBox, LB_GETCURSEL, 0, 0);
SendMessage(ListBox, LB_GETTEXT, (WPARAM)Cursel, (LPARAM)PName);

if(strcmp(PName, ""))
CreateThread(NULL, 0, ProcessInfoWindow, 0, 0, NULL);
break;

case ChToP:
strcpy(PName, "");

Cursel = SendMessage(ListBox, LB_GETCURSEL, 0, 0);
SendMessage(ListBox, LB_GETTEXT, (WPARAM)Cursel, (LPARAM)PName);

if(!strcmp(PName, "Task-Manager V1.0"))
{
MessageBox(NULL, "You can not change this task to process !", "Invalid Command", MB_OK | MB_ICONWARNING);
return 0;
}

if(strcmp(PName, ""))
{
TaskToProcess(PName, GetForegroundWindow());
}
break;

if(HIWORD(wParam) == 0)
{
case NewTask:
CreateThread(NULL, 0, NewTaskWindow, 0, 0, NULL);
break;

case Exit:
PostQuitMessage(0);
break;

case HELP:
CreateThread(NULL, 0, AboutWindow, 0, 0, NULL);
break;
}
}
break;

default:
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}

BOOL ShowTasks()
{
SendMessage(ListBox, LB_RESETCONTENT, 0, 0);

ShowWindow(TProc, false);
ShowWindow(CTask, true);
ShowWindow(NTask, true);
ShowWindow(IProc, false);
ShowWindow(TOProc, true);

Windows = GetFirstWindowText(Data, sizeof(Data), 0);

SendMessage(ListBox, LB_ADDSTRING, (WPARAM)-1, (LPARAM)Data);

while(Windows)
{
GetNextWindowText(Data, sizeof(Data), &Windows);

if(*Data && IsWindowVisible(Windows))
{
if(strcmp(Data, "Program Manager"))
SendMessage(ListBox, LB_ADDSTRING, (WPARAM)-1, (LPARAM)Data);
}
}
}

BOOL ShowProcesses()
{
SendMessage(ListBox, LB_RESETCONTENT, 0, 0);

ShowWindow(TProc, true);
ShowWindow(CTask, false);
ShowWindow(NTask, false);
ShowWindow(IProc, true);
ShowWindow(TOProc, false);

PROCESSENTRY32 pe32 = {0};

HANDLE hSnapshot = NULL;

HINSTANCE hDll = LoadLibrary("kernel32.dll");

if(hDll == 0)
{
MessageBox(NULL, "Error getting processes !", "Error", MB_OK | MB_ICONERROR);
return 0;
}

pProcess32First = (TH32_PROCESS)GetProcAddress(hDll, "Process32First");
pProcess32Next = (TH32_PROCESS)GetProcAddress(hDll, "Process32Next");

hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if(hSnapshot != (HANDLE) -1)
{
pe32.dwSize = sizeof(PROCESSENTRY32);

int proc_cnt = 0, thrd_cnt = 0;

if(pProcess32First(hSnapshot, &pe32))
{
while(pProcess32Next(hSnapshot, &pe32))
{
SendMessage(ListBox, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)pe32.szExeFile);
}
}
}
CloseHandle (hSnapshot);
}

HWND GetFirstWindowText(char buf[],unsigned int max_out,int *text_written){
HWND ret_val;
ret_val = GetForegroundWindow();
if(!text_written) GetWindowText(ret_val,buf,max_out);
else *text_written = GetWindowText(ret_val,buf,max_out);
return ret_val;
}

int GetNextWindowText(char buf[],unsigned int max_out,HWND* handle){
*handle = GetNextWindow(*handle,GW_HWNDNEXT);
return GetWindowText(*handle,buf,max_out);
}

int KillWindowProcess(HWND handle){
DWORD pid,exit_code;
GetWindowThreadProcessId(handle,&pid);
if(!pid) return 0;

HANDLE hProcess = OpenProcess(PROCESS_TERMINATE,TRUE,pid);
if(!hProcess) return 0;

GetExitCodeProcess(hProcess,&exit_code);

if(!TerminateProcess(hProcess,exit_code)){
CloseHandle(hProcess);
return 0;
}
CloseHandle(hProcess);
return 1;
}

int TerminateTask(char *TaskTitle, HWND handle)
{
char WindowT[MAX_PATH];

int report = 0, ListBN, i;

while(handle = GetNextWindow(handle, GW_HWNDNEXT))
{
GetWindowText(handle, WindowT, sizeof(WindowT));

if(!strcmp(TaskTitle, WindowT))
{
report = 1;

if(SendMessage(handle, WM_CLOSE, 0, 0))
{
MessageBox(NULL, "Error by closing the task !", "Close Task", MB_OK | MB_ICONERROR);
}

else
{
Cursel = SendMessage(ListBox, LB_GETCURSEL, 0, 0);
SendMessage(ListBox, LB_DELETESTRING, (WPARAM)Cursel, 0);
}
}
}

if(report != 1)
MessageBox(NULL, "Task could not found !", "Close Task", MB_OK | MB_ICONWARNING);

report = 0;
return 0;
}

int TaskToProcess(char *TaskTitle, HWND handle)
{
char WindowT[MAX_PATH];

DWORD pid;

while(handle = GetNextWindow(handle, GW_HWNDNEXT))
{
GetWindowText(handle, WindowT, sizeof(WindowT));

if(!strcmp(TaskTitle, WindowT))
{
GetWindowThreadProcessId(handle, &pid);

PROCESSENTRY32 pe32 = {0};

HANDLE hSnapshot = NULL;

HINSTANCE hDll = LoadLibrary("kernel32.dll");

if(hDll == 0)
{
MessageBox(NULL, "Error getting processes !", "Error", MB_OK | MB_ICONERROR);
return 0;
}

pProcess32First = (TH32_PROCESS)GetProcAddress(hDll, "Process32First");
pProcess32Next = (TH32_PROCESS)GetProcAddress(hDll, "Process32Next");

hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if(hSnapshot != (HANDLE) -1)
{
pe32.dwSize = sizeof(PROCESSENTRY32);

int proc_cnt = 0, thrd_cnt = 0;

if(pProcess32First(hSnapshot, &pe32))
{
while(pProcess32Next(hSnapshot, &pe32))
{
if(pe32.th32ProcessID == pid)
{
TerminateThread(TaskR, 0);
TerminateThread(ProcsR, 0);

ShowProcesses();
SendMessage(ListBox, LB_SELECTSTRING, 0, (LPARAM)pe32.szExeFile);
ProcsR = CreateThread(NULL, 0, RefreshProcs, 0, 0, NULL);
}
}
}
}
CloseHandle(hSnapshot);
}
}
return 0;
}

DWORD WINAPI RefreshTasks(LPVOID)
{
while(1)
{
Sleep(4000);

SendMessage(ListBox, LB_RESETCONTENT, 0, 0);

Windows = GetFirstWindowText(Data, sizeof(Data), 0);

SendMessage(ListBox, LB_ADDSTRING, (WPARAM)-1, (LPARAM)Data);

while(Windows)
{
GetNextWindowText(Data, sizeof(Data), &Windows);

if(*Data && IsWindowVisible(Windows))
{
if(strcmp(Data, "Program Manager"))
SendMessage(ListBox, LB_ADDSTRING, (WPARAM)-1, (LPARAM)Data);
}
}
}
}

DWORD WINAPI RefreshProcs(LPVOID)
{
while(1)
{
Sleep(5500);

SendMessage(ListBox, LB_RESETCONTENT, 0, 0);

PROCESSENTRY32 pe32 = {0};

HANDLE hSnapshot = NULL;

HINSTANCE hDll = LoadLibrary("kernel32.dll");

if(hDll == 0)
{
MessageBox(NULL, "Error getting processes !", "Error", MB_OK | MB_ICONERROR);
return 0;
}

pProcess32First = (TH32_PROCESS)GetProcAddress(hDll, "Process32First");
pProcess32Next = (TH32_PROCESS)GetProcAddress(hDll, "Process32Next");

hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if(hSnapshot != (HANDLE) -1)
{
pe32.dwSize = sizeof(PROCESSENTRY32);

int proc_cnt = 0, thrd_cnt = 0;

if(pProcess32First(hSnapshot, &pe32))
{
while(pProcess32Next(hSnapshot, &pe32))
{
SendMessage(ListBox, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)pe32.szExeFile);
}
}
}
CloseHandle(hSnapshot);
}
}

BOOL KillProcess(char *Process)
{
int report;

hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

pe32.dwSize = sizeof(PROCESSENTRY32);

Process32First(hProcessSnap, &pe32);

while(Process32Next(hProcessSnap, &pe32))
{
if(!strcmp(pe32.szExeFile, Process))
{
report = 1;

hProcess = OpenProcess(PROCESS_TERMINATE, 0, pe32.th32ProcessID);

if(TerminateProcess(hProcess, 0) == 0)
{
MessageBox(NULL, "Terminating process failed !", "KillProcess", MB_OK | MB_ICONERROR);
}

else
{
SendMessage(ListBox, LB_DELETESTRING, (LPARAM)Cursel, 0);
}
}
}

CloseHandle(hProcess);
CloseHandle(hProcessSnap);

if(report == 0)
MessageBox(NULL, "Process cannot be found !", "KillProcess", MB_OK | MB_ICONWARNING);

report = 0;
}

DWORD WINAPI RefreshNProcs(LPVOID)
{
while(1)
{
PROCESSENTRY32 pe32 = {0};

HANDLE hSnapshot = NULL;

HINSTANCE hDll = LoadLibrary("kernel32.dll");

if(hDll == 0)
{
MessageBox(NULL, "Error getting processes !", "Error", MB_OK | MB_ICONERROR);
return 0;
}

pProcess32First = (TH32_PROCESS)GetProcAddress(hDll, "Process32First");
pProcess32Next = (TH32_PROCESS)GetProcAddress(hDll, "Process32Next");

hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if(hSnapshot != (HANDLE) -1)
{
pe32.dwSize = sizeof(PROCESSENTRY32);

int proc_cnt = 0, thrd_cnt = 0;

if(pProcess32First(hSnapshot, &pe32))
{
while(pProcess32Next(hSnapshot, &pe32))
{
Procs = Procs + 1;
}
}
}

CloseHandle(hSnapshot);

ProcsN = itoa(Procs, buff, 10);

sprintf(PInfo, "Processes: %s", ProcsN);

SendMessage(ProcsEdit, WM_SETTEXT, 0, (LPARAM)PInfo);

Procs = 0;

GlobalMemoryStatus(&Memory);

sprintf(Data, "Physical Memory: %d%%", Memory.dwMemoryLoad);
SendMessage(PhyskMemory, WM_SETTEXT, 0, (LPARAM)Data);

Sleep(2000);
}
}

LRESULT CALLBACK NewTaskP(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;

case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);

SelectObject(hdc, hFont3);

SetTextColor(hdc, RGB(0, 0, 0));
SetBkMode(hdc, TRANSPARENT);

TextOut(hdc, 50, 15, TInfo1, strlen(TInfo1));
TextOut(hdc, 10, 50, TInfo2, strlen(TInfo2));

EndPaint(hwnd, &ps);
break;

case WM_CREATE:
NewTaskEdit = CreateWindowEx(
0,
"Edit",
0,
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
50, 50, 230, 20,
hwnd,
(HMENU)NewTaskE,
0,
NULL
);

NewTOK = CreateWindowEx(
0,
"Button",
"OK",
WS_VISIBLE | WS_CHILD | WS_BORDER,
90, 100, 60, 20,
hwnd,
(HMENU)NewTaskOK,
0,
NULL
);

NewTCancel = CreateWindowEx(
0,
"Button",
"Cancel",
WS_VISIBLE | WS_CHILD,
155, 100, 60, 20,
hwnd,
(HMENU)NewTaskCancel,
0,
NULL
);

NewTBrowse = CreateWindowEx(
0,
"Button",
"Browse...",
WS_VISIBLE | WS_CHILD,
220, 100, 60, 20,
hwnd,
(HMENU)NewTaskBrowse,
0,
NULL
);

SendMessage(NewTaskEdit, WM_SETFONT, (WPARAM)hFont1, 0);
SendMessage(NewTOK, WM_SETFONT, (WPARAM)hFont1, 0);
SendMessage(NewTCancel, WM_SETFONT, (WPARAM)hFont1, 0);
SendMessage(NewTBrowse, WM_SETFONT, (WPARAM)hFont1, 0);
break;

case WM_COMMAND:
switch(LOWORD(wParam))
{
case NewTaskBrowse:
BrowseFile(hwnd);

if(strcmp(FilePath, ""))
SetDlgItemText(hwnd, NewTaskE, FilePath);
break;

case NewTaskOK:
GetDlgItemText(hwnd, NewTaskE, Data, sizeof(Data));

if(strcmp(Data, ""))
{
ShellExecute(NULL, NULL, Data, NULL, NULL, SW_SHOWNORMAL);
PostQuitMessage(0);
break;
}

else
MessageBox(NULL, "You have not specified an task to open !", "Invalid Path", MB_OK | MB_ICONWARNING);
break;

case NewTaskCancel:
PostQuitMessage(0);
break;
}

default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
}

DWORD WINAPI NewTaskWindow(LPVOID)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;

wincl.hInstance = 0;
wincl.lpszClassName = "NewTask";
wincl.lpfnWndProc = NewTaskP;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);

wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH)COLOR_WINDOW;

RegisterClassEx(&wincl);

hwnd = CreateWindowEx (
WS_EX_CLIENTEDGE,
"NewTask",
"New Task",
WS_SYSMENU | WS_VISIBLE,
x+25,
y+40,
300,
160,
HWND_DESKTOP,
NULL,
0,
NULL
);

while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
}

LRESULT CALLBACK AboutP(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;

case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);

SelectObject(hdc, hFont3);

SetTextColor(hdc, RGB(0, 0, 0));
SetBkMode(hdc, TRANSPARENT);

TextOut(hdc, 67, 8, About1, strlen(About1));
TextOut(hdc, 39, 30, About2, strlen(About2));
TextOut(hdc, 83, 60, About3, strlen(About3));

EndPaint(hwnd, &ps);
break;

case WM_CREATE:
AOK = CreateWindowEx(
0,
"Button",
"OK",
WS_VISIBLE | WS_CHILD | WS_BORDER,
103, 100, 80, 20,
hwnd,
(HMENU)AboutOK,
0,
NULL
);

SendMessage(AOK, WM_SETFONT, (WPARAM)hFont1, 0);
break;

case WM_COMMAND:
switch(LOWORD(wParam))
{
case AboutOK:
PostQuitMessage(0);
break;
}

default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
}

DWORD WINAPI AboutWindow(LPVOID)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;

wincl.hInstance = 0;
wincl.lpszClassName = "About";
wincl.lpfnWndProc = AboutP;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);

wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH)COLOR_WINDOW;

RegisterClassEx(&wincl);

hwnd = CreateWindowEx (
0,
"About",
"About",
WS_SYSMENU | WS_VISIBLE,
x+25,
y+40,
300,
160,
HWND_DESKTOP,
NULL,
0,
NULL
);

while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
}

LRESULT CALLBACK ProcINF(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;

case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);

SelectObject(hdc, hFont3);

SetTextColor(hdc, RGB(0, 0, 0));
SetBkMode(hdc, TRANSPARENT);

EndPaint(hwnd, &ps);
break;

case WM_CREATE:
PINF = CreateWindowEx(
0,
"Button",
"OK",
WS_VISIBLE | WS_CHILD | WS_BORDER,
102, 130, 80, 20,
hwnd,
(HMENU)PIOK,
0,
NULL
);

NameP = CreateWindowEx(
0,
"Edit",
0,
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL | ES_READONLY,
12, 25, 200, 20,
hwnd,
(HMENU)ProcName,
0,
NULL
);

IDP = CreateWindowEx(
0,
"Edit",
0,
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL | ES_READONLY,
12, 50, 200, 20,
hwnd,
(HMENU)ProcID,
0,
NULL
);

PPID = CreateWindowEx(
0,
"Edit",
0,
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL | ES_READONLY,
12, 74, 200, 20,
hwnd,
(HMENU)ParentPID,
0,
NULL
);

SendMessage(PINF, WM_SETFONT, (WPARAM)hFont1, 0);
SendMessage(NameP, WM_SETFONT, (WPARAM)hFont1, 0);
SendMessage(IDP, WM_SETFONT, (WPARAM)hFont1, 0);
SendMessage(PPID, WM_SETFONT, (WPARAM)hFont1, 0);

hSnapshot = NULL;

hDll = LoadLibrary("kernel32.dll");

if(hDll == 0)
{
MessageBox(NULL, "Error getting processes !", "Error", MB_OK | MB_ICONERROR);
return 0;
}

pProcess32First = (TH32_PROCESS)GetProcAddress(hDll, "Process32First");
pProcess32Next = (TH32_PROCESS)GetProcAddress(hDll, "Process32Next");

hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if(hSnapshot != (HANDLE) -1)
{
pe32.dwSize = sizeof(PROCESSENTRY32);

proc_cnt = 0, thrd_cnt = 0;

if(pProcess32First(hSnapshot, &pe32))
{
while(pProcess32Next(hSnapshot, &pe32))
{
if(!strcmp(PName, pe32.szExeFile))
{
sprintf(PData, "Process Name: %s", pe32.szExeFile);

SetDlgItemText(hwnd, ProcName, PData);

sprintf(PData, "Process ID: %d", pe32.th32ProcessID);

SetDlgItemText(hwnd, ProcID, PData);

sprintf(PData, "Parent Process ID: %d", pe32.th32ParentProcessID);

SetDlgItemText(hwnd, ParentPID, PData);
}
}
}
}
CloseHandle(hSnapshot);
break;

case WM_COMMAND:
switch(LOWORD(wParam))
{
case PIOK:
PostQuitMessage(0);
break;
}

default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
}

DWORD WINAPI ProcessInfoWindow(LPVOID)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;

wincl.hInstance = 0;
wincl.lpszClassName = "ProcInf";
wincl.lpfnWndProc = ProcINF;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);

wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH)COLOR_WINDOW;

RegisterClassEx(&wincl);

hwnd = CreateWindowEx (
0,
"ProcInf",
"Process Information",
WS_SYSMENU | WS_VISIBLE,
x+30,
y+40,
290,
200,
HWND_DESKTOP,
NULL,
0,
NULL
);

while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
}

BOOL BrowseFile(HWND hwnd)
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
FilePath[0] = 0;
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "All Files\0*.*\0";
ofn.lpstrFile = FilePath;
ofn.nMaxFile = 260;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "all";
GetOpenFileName(&ofn);
}

Κατεβάστε το *.exe απο το rar:

[ATTACH]7563[/ATTACH]

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Δημιουργία...

Important Information

Ο ιστότοπος theLab.gr χρησιμοποιεί cookies για να διασφαλίσει την καλύτερη εμπειρία σας κατά την περιήγηση. Μπορείτε να προσαρμόσετε τις ρυθμίσεις των cookies σας , διαφορετικά θα υποθέσουμε ότι είστε εντάξει για να συνεχίσετε.