Visual C++ FAQ

       

Как сделать, чтобы некотоpое пpиложение


/*apphider.cpp*/ /* Alexey Chubar & Paul Ishenin*/ #pragma hdrstop #include <condefs.h> #include <windows.h> #include <tlhelp32.h> #include <string.h> #include <stdlib.h> USELIB("KERNEL32.lib"); #pragma argsused extern "C" __stdcall DWORD RegisterServiceProcess(DWORD dwProcessID, DWORD dwType); char * ExtractFilePath(const char *Name) { int i = strlen(Name), l = strlen(Name); char *res="\0"; while ((i > 0)&&(Name[i] != '\\')) i--; if (i) { res = (char *)malloc(l - i); strcpy(res, Name + i + 1); res[l-i-1] = '\0'; } return res; } void HideApp(DWORD dwProcessID) { HWND MyHandle = GetTopWindow(0); DWORD WindowProcess; while (MyHandle != NULL) { if ((GetWindowThreadProcessId(MyHandle, &WindowProcess) != 0) && (WindowProcess == dwProcessID)) { ShowWindow(MyHandle, SW_HIDE); } MyHandle = GetNextWindow(MyHandle, GW_HWNDNEXT); } RegisterServiceProcess(dwProcessID, 1); } DWORD __fastcall FindID(const char *FName) { HANDLE h; PROCESSENTRY32 p; h=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); p.dwSize=sizeof(p); if(!Process32First(h,&p)) return -1; if(strcmp(strlwr((char *)FName), strlwr(ExtractFilePath(p.szExeFile)))==0) { CloseHandle(h); return p.th32ProcessID; } while(Process32Next(h,&p)) if(strcmp(strlwr((char *)FName), strlwr(ExtractFilePath(p.szExeFile)))==0) { CloseHandle(h); return p.th32ProcessID; } CloseHandle(h); return -1; } int main(int argc, char* argv[]) { if (argc > 1) { DWORD ProgID=FindID(argv[1]); if(ProgID != (DWORD)-1) HideApp(ProgID); } return 0; }

или

_asm{ mov eax,1 push eax dec eax push eax call dword ptr[pRegisterServiceProcess] }

А теперь более подробно. Невидимость по Alt-Tab:

var WnHnd : Integer; WnHnd := GetWindowLong(Application.Handle, GWL_EXSTYLE); WnHnd := WnHnd or WS_EX_TOOLWINDOW; {Типа Tools-окно} SetWindowLong(Application.Handle, GWL_EXSTYLE, WnHnd);

Невидимость в Панели Задач:

ShowWindow[Async](Application.Handle,SW_HIDE)



Содержание раздела