// NoClose_nw (V1.0) : (No Close for a Named Window)
// Disable the close button and the close option of the system menu of a given window
// The given window must have all the keywords given in parameter of the command line.
// Copyright (C) 2009 Philippe RICHARD
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// if you need to contact me : Philippe RICHARD - philrich123 at gmail dot com
//
// NoClose_nw :
// Cet utilitaire permet de faire disparaitre l'option "Fermer" ainsi que le bouton croix de fermeture d'une fenêtre.
// Le titre de la fenêtre doit contenir tous les mots clés passés en paramêtre.
//
// Testé sous Windows XP - SP3
// A compiler avec MinGW : http://www.MinGW.org
#define TAILLEBUFFER 1024
#include
#include
#include
#include
#include
#include
// Une liste simplement chaînée classique pour l'énumération des fenêtres.
typedef struct st_fenele
{
HWND fenetre;
struct st_fenele* suivant;
} t_fenele;
// Deux pointeurs en variable globale pour l'accès à la liste chaînée depuis la fonction CALLBACK et le main().
t_fenele *prem_fen, *cur_fen;
// Fonction CALLBACK d'énumération des fenêtre : elle est appelée avec en paramêtre le handle fenêtre (1 appel par fenêtre).
// On procède au remplissage de la liste chaînée.
BOOL CALLBACK enumerationfenetre(HWND fen, LPARAM parametres)
{
char buffer_titre[TAILLEBUFFER];
t_fenele* element=(t_fenele*) malloc(sizeof(t_fenele));
if ( element != NULL )
{
element->fenetre=fen;
element->suivant=NULL;
if (prem_fen==NULL) prem_fen=element; else cur_fen->suivant = element;
cur_fen=element;
}
return TRUE;
}
int main(int argc, char* argv[])
{
HWND fenetre = GetForegroundWindow();
HMENU sysmenu;
char buffer_titre[TAILLEBUFFER];
int trouve, i;
int code_retour=1;
// Appel sans paramêtres: Les options
if ( argc == 1 )
{
printf("%s (V1.0) Copyright (C) 2009 Philippe RICHARD\nThis program comes with ABSOLUTELY NO WARRANTY.\n", argv[0]);
printf("This is free software, and you are welcome to redistribute it\nunder certain conditions.\n\n");
printf("Utilisation :\n%s mot_cle_1 [mot_cle_2] ... [mot_cle_n]\n\n",argv[0]);
printf("Desactive la croix de fermeture et l'option ''Fermer'' du menu systeme\n");
printf("d'une fenetre dont le titre contient les mots cles passes en parametre\n");
code_retour=0;
}
else
{
prem_fen= cur_fen= NULL;
EnumWindows( enumerationfenetre, 0);
while ( prem_fen != NULL )
{
if ( GetWindowText( prem_fen->fenetre, buffer_titre, TAILLEBUFFER) ) // Titre de la fenêtre
{
if (! strstr( buffer_titre, argv[0]) ) // On ne compare pas si le titre contient le nom de l'utilitaire (en particulier la console l'executant)
{
trouve = 1;
for (i = 1; i < argc; i++) // On test chaque mot clé
{
if ( strstr( buffer_titre, argv[i]) == NULL ) trouve = 0;
}
if (trouve) // Si on a trouvé un fenêtre dont le titre contient tous les mots clés.
{
sysmenu = GetSystemMenu(prem_fen->fenetre, 0); // On récupère le menu système
DeleteMenu( sysmenu, SC_CLOSE, MF_BYCOMMAND); // On supprime la commande SC_CLOSE
DrawMenuBar( prem_fen->fenetre); // On rafraichis la barre.
code_retour= 0; // Code retour = 0 : On a trouvé la fenêtre !
}
}
}
// Libération de la mémoire.
cur_fen=prem_fen;
prem_fen=prem_fen->suivant;
free(cur_fen);
}
return code_retour;
}
}