Suite a une question sur le forum j'ai fait cette petite source qui permet de scanner un repertoire a la recherche de nouveaux fichiers a interval de temps regulier...
Vous pouvez ainsi savoir si des fichiers ont été ajouté ou supprimé d'un repertoire.
Je sais plus qui avez posé la question mais j'espere que cette source pourra l'aider.
T'es trop fort BruNews ;)
Je vais remedier a tout cela...
Des que j'ai une source a faire je te l'envoie avant de la poster maintenant ;)
Nan j'plaisante...
Me suis permis un degraissage, tu remettras commentaires.
exe passe de 44 a 27 Ko, compile maintenant en pur C.
#include <direct.h> et #include <stdio.h> ont disparu.
BOOL CALLBACK DlgProc et non LRESULT.
WM_INITDIALOG doit retourner 1 pour placement correct du focus.
Gaffe a ne pas mettre static sur toutes tes variables internes aux fonctions, seulement quand c'est utile de conserver entre 2 appels sinon tu grossis inutilement le registre data.
Pense aussi a fermer handle avec FindClose().
Tout ton algo reste intact.
#include <windows.h>
#include "resource.h"
typedef struct _ScanProperty {
int interval;
int oldValue;
char extension[20];
char folder[250];
} ScanProperty;
ScanProperty scan;
HINSTANCE hInst;
HWND hDlg, hControl[4];
int FirstScan;
void StatusOfControl(int status)
{ // active ou désactive les control
EnableWindow(hControl[0],status);
EnableWindow(hControl[1],status);
EnableWindow(hControl[2],status);
}
BOOL CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg) {
case WM_INITDIALOG:
hDlg = hWnd;
SetClassLong(hWnd, GCL_HICON, (LONG) LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1)));
hControl[0] = GetDlgItem(hWnd,IDC_INTERVAL);
hControl[1] = GetDlgItem(hWnd,IDC_EXTENSION);
hControl[2] = GetDlgItem(hWnd,IDC_FOLDER);
hControl[3] = GetDlgItem(hWnd,IDC_SCAN);
SetDlgItemText(hWnd,IDC_INTERVAL,"1");
SetDlgItemText(hWnd,IDC_EXTENSION,"*.txt");
SetDlgItemText(hWnd,IDC_FOLDER,"d:\");
return 1;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDC_SCAN:
if(IsWindowEnabled(hControl[0])) {
FirstScan = 1;
scan.extension[0] = '\0';
scan.folder[0] = '\0';
scan.interval = 0;
scan.oldValue = 0;
GetDlgItemText(hWnd,IDC_INTERVAL,scan.extension,50);
scan.interval = atoi(scan.extension);
GetDlgItemText(hWnd,IDC_EXTENSION,scan.extension,20);
GetDlgItemText(hWnd,IDC_FOLDER,scan.folder,250);
MessageBox(hWnd,"Le scan va etre lancé. Cliquez sur Ok pour continuer!","Message OK",MB_OK|MB_ICONINFORMATION);
SetWindowText(hControl[3],"&Arreter");
StatusOfControl(0);
SetTimer(hWnd,WM_TIMER,scan.interval*1000,NULL);
}
else {
KillTimer(hWnd,WM_TIMER);
SetWindowText(hControl[3],"&Démarrer");
StatusOfControl(1);
}
break;
case IDC_APROPOS:
MessageBox(hWnd,"Date: 12/04/2004\nVersion : 1.0\nLangue: Fr\n\nCommentaire:\nScan et analyse les fichiers d'un repertoire\n\nCoded by -=[SheLL]=-","Easy ProgressBar v1.0 by Shell",MB_ICONINFORMATION);
break;
case IDCANCEL:
KillTimer(hWnd,WM_TIMER);
EndDialog(hWnd,IDCANCEL);
break;
}
break;
case WM_TIMER:
ScanRep();
}
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE x, LPSTR y, int z)
{
hInst = hInstance;
return DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc, 0);
}
void ScanRep(ScanProperty scan);
pourquoi tu ne passes pas
void ScanRep(ScanProperty *scan);
serait 1 push de 4 octets au lieu d'en mettre 280 sur la pile.
Tu pourrais meme enlever tout param en mettant
ScanProperty scan; globale en haut du module.
static dans la dlgproc produit cela sans que tu le vois, aucune difference.
chdir => SetCurrentDirectory.
13 avril 2004 à 10:56
Je vais remedier a tout cela...
Des que j'ai une source a faire je te l'envoie avant de la poster maintenant ;)
Nan j'plaisante...
Merci pour vos commentaires ...
A++ et bonne prog all ...
--=[SheLL]=--
13 avril 2004 à 01:29
exe passe de 44 a 27 Ko, compile maintenant en pur C.
#include <direct.h> et #include <stdio.h> ont disparu.
BOOL CALLBACK DlgProc et non LRESULT.
WM_INITDIALOG doit retourner 1 pour placement correct du focus.
Gaffe a ne pas mettre static sur toutes tes variables internes aux fonctions, seulement quand c'est utile de conserver entre 2 appels sinon tu grossis inutilement le registre data.
Pense aussi a fermer handle avec FindClose().
Tout ton algo reste intact.
#include <windows.h>
#include "resource.h"
typedef struct _ScanProperty {
int interval;
int oldValue;
char extension[20];
char folder[250];
} ScanProperty;
ScanProperty scan;
HINSTANCE hInst;
HWND hDlg, hControl[4];
int FirstScan;
void PrintAlert(char *message, int nbFile)
{
char Alerte[500];
char *c = Alerte;
ultoa(nbFile, Alerte, 10);
while(*c) c++;
strcpy(c, message);
MessageBox(0, Alerte,"ALERTE",MB_ICONINFORMATION);
}
void ScanRep()
{
int cpt 0, newFile 0;
char mess[500];
HANDLE hFile;
WIN32_FIND_DATA t_findData;
if(SetCurrentDirectory(scan.folder)) {
hFile = FindFirstFile(scan.extension, &t_findData);
if(hFile != INVALID_HANDLE_VALUE) {
cpt++;
while(FindNextFile(hFile,&t_findData)) cpt++;
FindClose(hFile); // NE PAS OUBLIER !!!
}
}
else {
KillTimer(hDlg,WM_TIMER);
MessageBox(hDlg,"Le repertoire indiqué est inaccessible! Veuillez verifier le chemin!","ERREUR ACCES REPERTOIRE",MB_ICONSTOP);
}
if(cpt != scan.oldValue) {
if(cpt > scan.oldValue) {
strcpy(mess, " nouveau(x) fichier(s) est/sont arrivé(s) dans le repertoire : " );
strcat(mess, scan.folder);
}
else if(cpt < scan.oldValue) {
strcpy(mess, " fichier(s) a/ont été supprimé(s) du repertoire : ");
strcat(mess, scan.folder);
}
newFile = abs(cpt - scan.oldValue);
scan.oldValue = cpt;
if(!FirstScan) PrintAlert(mess,newFile);
else FirstScan = 0;
}
}
void StatusOfControl(int status)
{ // active ou désactive les control
EnableWindow(hControl[0],status);
EnableWindow(hControl[1],status);
EnableWindow(hControl[2],status);
}
BOOL CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg) {
case WM_INITDIALOG:
hDlg = hWnd;
SetClassLong(hWnd, GCL_HICON, (LONG) LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1)));
hControl[0] = GetDlgItem(hWnd,IDC_INTERVAL);
hControl[1] = GetDlgItem(hWnd,IDC_EXTENSION);
hControl[2] = GetDlgItem(hWnd,IDC_FOLDER);
hControl[3] = GetDlgItem(hWnd,IDC_SCAN);
SetDlgItemText(hWnd,IDC_INTERVAL,"1");
SetDlgItemText(hWnd,IDC_EXTENSION,"*.txt");
SetDlgItemText(hWnd,IDC_FOLDER,"d:\");
return 1;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDC_SCAN:
if(IsWindowEnabled(hControl[0])) {
FirstScan = 1;
scan.extension[0] = '\0';
scan.folder[0] = '\0';
scan.interval = 0;
scan.oldValue = 0;
GetDlgItemText(hWnd,IDC_INTERVAL,scan.extension,50);
scan.interval = atoi(scan.extension);
GetDlgItemText(hWnd,IDC_EXTENSION,scan.extension,20);
GetDlgItemText(hWnd,IDC_FOLDER,scan.folder,250);
MessageBox(hWnd,"Le scan va etre lancé. Cliquez sur Ok pour continuer!","Message OK",MB_OK|MB_ICONINFORMATION);
SetWindowText(hControl[3],"&Arreter");
StatusOfControl(0);
SetTimer(hWnd,WM_TIMER,scan.interval*1000,NULL);
}
else {
KillTimer(hWnd,WM_TIMER);
SetWindowText(hControl[3],"&Démarrer");
StatusOfControl(1);
}
break;
case IDC_APROPOS:
MessageBox(hWnd,"Date: 12/04/2004\nVersion : 1.0\nLangue: Fr\n\nCommentaire:\nScan et analyse les fichiers d'un repertoire\n\nCoded by -=[SheLL]=-","Easy ProgressBar v1.0 by Shell",MB_ICONINFORMATION);
break;
case IDCANCEL:
KillTimer(hWnd,WM_TIMER);
EndDialog(hWnd,IDCANCEL);
break;
}
break;
case WM_TIMER:
ScanRep();
}
return 0;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE x, LPSTR y, int z)
{
hInst = hInstance;
return DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc, 0);
}
12 avril 2004 à 23:26
12 avril 2004 à 23:25
12 avril 2004 à 23:23
void ScanRep(ScanProperty scan);
pourquoi tu ne passes pas
void ScanRep(ScanProperty *scan);
serait 1 push de 4 octets au lieu d'en mettre 280 sur la pile.
Tu pourrais meme enlever tout param en mettant
ScanProperty scan; globale en haut du module.
static dans la dlgproc produit cela sans que tu le vois, aucune difference.
chdir => SetCurrentDirectory.
BruNews, Admin CS, MVP Visual C++
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.