| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 
 |  
#include <windows.h>
#include <string>
#include <shellapi.h>
 
OPENFILENAME ofn;
using namespace std;
 
char Progr[]="° Explorateur ° Mars 2005 °";
char rep[MAX_PATH]="";    // répertoire
char szFileName[2048]=""; // fichier
char Ini[MAX_PATH] = "";  // fichier .ini
char szClassName[] = "WindowsApp";
 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BOOL Explorer(HWND hwnd)
{ if (!GetOpenFileName(&ofn)) return false;
  unsigned long length;
  char* pnt = szFileName;
  int PrFois=0;
  char mem[MAX_PATH]="";
  char inter[MAX_PATH]="";
  // ce que renvoie GetOpenFileName est de la forme
  // répertoire \0 fichier 1 \0 fichier 2 \0 ... dernier fichier \0 \0
  // ou un seul fichier \0 \0
  while ( (length = strlen(pnt)) != 0 )
        {     if ( PrFois==0 )      // mémoriser 1er poste
                   { strcpy(mem,pnt); }
              else                  // lancer le programme associé
                   { strcpy(inter,mem);
                     char* fin = inter + strlen(inter) - 1;
                     if ( fin != "\\" ) { strcat(inter,"\\");  }
                     strcat(inter,pnt);
                     ShellExecute(hwnd,NULL,inter,NULL,NULL,SW_SHOWNORMAL);  }
              pnt += length + 1;     // poste suivant
              PrFois++; }
  if ( PrFois==1 )  // si 1 seul fichier sélectionné
       { ShellExecute(hwnd,NULL,mem,NULL,NULL,SW_SHOWNORMAL); }
  strcpy(rep,mem);
  return true;    } // on continuera
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LRESULT CALLBACK WindowProcedure (      HWND hwnd,
                                        UINT message,
                                        WPARAM wParam,
                                        LPARAM lParam)
{   switch (message)      
    {   case WM_DESTROY:
            PostQuitMessage (0);
            break;
        default:                
            return DefWindowProc (hwnd, message, wParam, lParam);    }
    return 0;            }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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_BACKGROUND;
    if (!RegisterClassEx (&wincl))    return 0;
    hwnd = CreateWindowEx (    0,szClassName,Progr,WS_OVERLAPPEDWINDOW,
                               CW_USEDEFAULT,CW_USEDEFAULT,0,0,HWND_DESKTOP,
                               NULL,hThisInstance,NULL           );
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ZeroMemory(&ofn, sizeof(ofn)); // préparation fenêtre explorateur                           
    szFileName[0] = 0;
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = hwnd;
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = MAX_PATH;
    ofn.lpstrTitle=Progr;
    ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
                OFN_ALLOWMULTISELECT | OFN_NODEREFERENCELINKS |
                OFN_LONGNAMES | OFN_SHAREAWARE ;
    ofn.lpstrInitialDir=lpszArgument;
    ofn.lpstrFilter = "Tous\0*\0Executables\0*.bat;*.com;*.exe;*.hta\0Textes\0*.doc;*.rtf;*.txt\0*\0*\0\0";
    GetModuleFileName(0,Ini,sizeof(Ini)-1);
    char suffixe[]="ini";
    for ( int i=0;i<sizeof(suffixe)-1;i++ )
        { Ini[strlen(Ini)-i-1]=suffixe[i]; }
    char fic[_MAX_PATH]=""; // fichiers à lister
    GetPrivateProfileString("Paramètres","Fichiers",false,fic,sizeof(fic),Ini); 
    if ( sizeof(fic)>0 )
         {  for ( int i=0; i<sizeof(fic); i++ )
               { if (fic[i]=='|' ) fic[i]='\0';  }
            ofn.lpstrFilter=fic; }
    if ( lpszArgument[0]=='\0' )
         {  GetPrivateProfileString("Paramètres","Répertoire",false,
                                    rep,sizeof(rep),Ini);
            ofn.lpstrInitialDir=rep;  }
    BOOL EnCours=true;
    while ( EnCours )
        { EnCours=Explorer(hwnd);   }
    WritePrivateProfileString("Paramètres","Répertoire",rep,Ini); }
 
/*######################################################################*/ | 
Partager