Ce prog ne tourne que sur Win 2000 ou SUPERIEUR.
Application sans fenetre visible, icone dans taskbar.
Utile contre les fenetres de pub indesirables.
Menu de config sur cette icone avec un clic.
Limite nbr de fenetres IE de 1 a 3 ou sans limite.
Icone change selon limitation choisie.
Si deja 5 fenetres IE et vous reglez sur 2 (exemple),
les fenetres ne seront pas touchees.
Chacun sera libre d'utiliser la dll comme il voudra.
Suffit de respecter les appels comme dans exe fourni.
Source / Exemple :
#include <windows.h>
#include "resource.h"
#include <shellapi.h>
// definition de pointeurs sur fonctions de DLL
typedef void (__stdcall *SETMAX) (DWORD);
typedef void (__stdcall *PREPARE) (VOID);
NOTIFYICONDATA TrayIcon;
HINSTANCE hinst = 0;
HANDLE mutex = 0;
HINSTANCE hdll = 0;
HHOOK hhk = 0;
HOOKPROC VerifIE = 0;
SETMAX SetMax = 0;
PREPARE Prepare = 0;
HWND hmain = 0;
HICON icons[2]; // 0 TOUTES, 1 LIMITATION
HMENU menu = 0;
DWORD maxi = 0; // 0 TOUTES, 3 maxi
char szmaxi[12];
char szappname[] = "LimitIE";
char szTOUTES[] = "TOUTES";
//void onInitMenu()
//{
// CheckMenuItem(menu, 0, MF_BYPOSITION | ((maxi == 1) ? MF_CHECKED: MF_UNCHECKED));
// CheckMenuItem(menu, 2, MF_BYPOSITION | ((maxi == 2) ? MF_CHECKED: MF_UNCHECKED));
// CheckMenuItem(menu, 4, MF_BYPOSITION | ((maxi == 3) ? MF_CHECKED: MF_UNCHECKED));
// CheckMenuItem(menu, 6, MF_BYPOSITION | (maxi ? MF_UNCHECKED: MF_CHECKED));
//}
// desole pour ceux qui n'aiment pas
// mais 15 instructions de moins que le compilo pour si peu
__declspec(naked) void __stdcall onInitMenu()
{
__asm {
mov edx, maxi
mov eax, 400h
mov ecx, menu
cmp edx, 1
jne short LBL1
or eax, 8
LBL1:
push eax
push 0
mov eax, 400h
push ecx
cmp edx, 2
jne short LBL2
or eax, 8
LBL2:
push eax
push 2
mov eax, 400h
push ecx
cmp edx, 3
jne short LBL3
or eax, 8
LBL3:
push eax
push 4
mov eax, 400h
push ecx
or edx, edx
jne short LBL4
or eax, 8
LBL4:
push eax
push 6
push ecx
call dword ptr CheckMenuItem
call dword ptr CheckMenuItem
call dword ptr CheckMenuItem
call dword ptr CheckMenuItem
ret 0
}
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT mssg, WPARAM wParam, LPARAM lParam) {
switch(mssg) {
case WM_CREATE:
TrayIcon.cbSize = sizeof(NOTIFYICONDATA);
- ((DWORD*) szmaxi) = 0x6D204549;
- ((DWORD*) (szmaxi+4)) = 0x20697861;
- ((DWORD*) (szmaxi+8)) = 0x31203A; // "IE maxi : 1"
TrayIcon.hWnd = hwnd;
TrayIcon.uID = 0;
TrayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
TrayIcon.uCallbackMessage = WM_MOUSEMOVE;
TrayIcon.hIcon = icons[1];
strcpy(TrayIcon.szTip, szmaxi);
Shell_NotifyIcon(NIM_ADD, &TrayIcon);
maxi = 1;
menu = GetSubMenu(LoadMenu(hinst, (LPCTSTR) IDMNU_APP), 0);
Prepare(); // fonction travail interne DLL, INDISPENSABLE
SetMax(1);
// ici va mapper la dll dans TOUS les processus
// donc GROS DANGER pour le systeme !!!
hhk = SetWindowsHookEx(WH_CBT, VerifIE, hdll, 0);
return 0;
case WM_MOUSEMOVE:
if(lParam == WM_LBUTTONDOWN) {
POINT pt;
GetCursorPos(&pt);
SetForegroundWindow(hwnd);
TrackPopupMenu(menu, TPM_LEFTALIGN, pt.x, pt.y, 0, hwnd, 0);
}
return 0;
case WM_INITMENUPOPUP:
onInitMenu();
return 0;
case WM_COMMAND:
switch(wParam) {
case ID_MAX1:
if(maxi == 1) break;
maxi = 1;
szmaxi[10] = '1';
goto limit1To3;
case ID_MAX2:
if(maxi == 2) break;
maxi = 2;
szmaxi[10] = '2';
goto limit1To3;
case ID_MAX3:
if(maxi == 3) break;
maxi = 3;
szmaxi[10] = '3';
goto limit1To3;
case ID_TOUS:
if(!maxi) break;
maxi = 0;
TrayIcon.hIcon = icons[0];
strcpy(TrayIcon.szTip, szTOUTES);
goto goModifs;
limit1To3:
TrayIcon.hIcon = icons[1];
strcpy(TrayIcon.szTip, szmaxi);
goModifs:
Shell_NotifyIcon(NIM_MODIFY, &TrayIcon);
SetMax(maxi);
break;
case ID_QUIT:
PostMessage(hwnd, WM_DESTROY, 0, 0);
}
return 0;
case WM_DESTROY:
UnhookWindowsHookEx(hhk); // INDISPENSABLE ICI !!!
Shell_NotifyIcon(NIM_DELETE, &TrayIcon);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, mssg, wParam, lParam);
}
int InitInstance()
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = wc.cbWndExtra = 0;
wc.hInstance = hinst;
wc.hIcon = 0;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(NULL_BRUSH); //(COLOR_BTNFACE + 1)
wc.lpszMenuName = 0;
wc.lpszClassName = szappname;
return RegisterClass(&wc);
}
int ChargeDll()
{
// on charge DLL qui DOIT se trouver dans dossier du prog
// et DOIT porter le MEME NOM !!!
// une DLL avec meme nom d'un autre prog, NEGATIF !!!
char szpath[300], *c;
c = szpath + GetModuleFileName(NULL, szpath, 260);
- (c-3) = 'd'; *(c-2) = 'l'; *(c-1) = 'l';
hdll = LoadLibrary(szpath);
if(hdll == NULL) goto dispErr;
VerifIE = (HOOKPROC) GetProcAddress(hdll, "VerifIE");
if(VerifIE == NULL) goto relLib;
SetMax = (SETMAX) GetProcAddress(hdll, "SetMax");
if(SetMax == NULL) goto relLib;
Prepare = (PREPARE) GetProcAddress(hdll, "Prepare");
if(Prepare == NULL) goto relLib;
return 1;
relLib: FreeLibrary(hdll);
dispErr:
strcpy(c, " est indisponible.");
MessageBox(0, szpath, szappname, MB_ICONEXCLAMATION);
return 0;
}
DWORD VerifWin2KMini()
{
OSVERSIONINFO osvi;
osvi.dwBuildNumber = osvi.dwMajorVersion = 0;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
if(osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) return 0;
return (osvi.dwMajorVersion >= 5);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PTSTR, int) {
MSG msg;
if(!VerifWin2KMini()) return 0;
mutex = CreateMutex(NULL, TRUE, szappname);
if(GetLastError() == ERROR_ALREADY_EXISTS) return 0;
hinst = hInstance;
if(!ChargeDll()) goto relMutex;
icons[0] = LoadIcon(hinst, (LPCTSTR) IDI_APP0); // TOUTES
icons[1] = LoadIcon(hinst, (LPCTSTR) IDI_APP1); // LIMITATION
if(!InitInstance()) goto relLib;
hmain = CreateWindow(szappname, 0, WS_OVERLAPPED, 20, 20, 20, 20, 0, 0, hinst, 0);
while(GetMessage(&msg, 0, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
relLib: FreeLibrary(hdll);
relMutex: ReleaseMutex(mutex);
return 0;
}
Conclusion :
Tout dans zip, projet format VS 2003.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.