IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++Builder Discussion :

ProgressBar liée à l'ouverture d'un fichier


Sujet :

C++Builder

  1. #1
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Juin 2006
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2006
    Messages : 92
    Par défaut ProgressBar liée à l'ouverture d'un fichier
    Salut !

    J'utilise une base de données Excel et j'aimerais la charger au démarrage de mon programme afin d'optimiser la rapidité de mon application, une fois celle-ci lancée.
    J'ai placé un SplashScreen avec une CGauge mais contrairement aux dernières discussions sur ce sujet, j'aimerais incrémenter ma barre de progression en fonction de l'état d'ouverture de mon fichier Excel.
    Est-ce que c'est possible ??

    Merci

  2. #2
    Membre confirmé Avatar de vantoff
    Profil pro
    Étudiant
    Inscrit en
    Juin 2006
    Messages
    85
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2006
    Messages : 85
    Par défaut
    la barre de progression c'est du FUN. Elle permet juste d'accorder du temps à builder pour qu'il se charge. Essai ça

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    void __fastcall TSplash_dlg::VrTimer1Timer(TObject *Sender)
    { 
                  BarreChargement->MinValue = 0;
                  BarreChargement->MaxValue = 10000;
                  PourcentageChargement->MinValue=0;        // Début du taux de chargement
                  PourcentageChargement->MaxValue = 10000;    // Fin du taux de chargement
     
        for (int j=0;j<10000;j++)//boucle d'incrémentation de la barre de chargement
                {
                  BarreChargement->Position++; // Incrémente la position de la Progressbarre à chaque tour
                  PourcentageChargement->AddProgress(1);//incrément le poucentage de Chargement (1 pas par tour)
                }
    }
    Attention: BarreChargement=ProgressBar
    PourcentageChargement=CGauge

  3. #3
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Juin 2006
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2006
    Messages : 92
    Par défaut
    ça je l'avais vu dans les précédentes discussions, merci.
    Mais je tiens à ce que la barre de chargement soit fonction de l'ouverture de mon fichier et non pas juste pour faire joli...

  4. #4
    Membre émérite
    Avatar de bandit boy
    Profil pro
    Inscrit en
    Février 2006
    Messages
    916
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 916
    Par défaut
    Ton ouverture de fichier se fait dans une boucle for ?
    Il te suffit alors de gérer la progression de ta bar selon l'avancement de ta boucle.

  5. #5
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Juin 2006
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2006
    Messages : 92
    Par défaut
    L'ouverture de mon fichier ne se fait pas dans une boucle, sinon j'ouvrirais plusieurs fois mon fichier (à moins de mettre un Flag...)

  6. #6
    Membre émérite
    Avatar de bandit boy
    Profil pro
    Inscrit en
    Février 2006
    Messages
    916
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 916
    Par défaut
    Comment tu ouvres ton fichier?
    As tu un bout de code?

  7. #7
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Juin 2006
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2006
    Messages : 92
    Par défaut
    Dans mon fichier source :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    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
     
    WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
    {
    	Application->Initialize();
     
    	Splash_dlg = new TSplash_dlg(NULL); 	// Crée la fiche dynamiquement
    	Splash_dlg->Show(); 					// Affiche la fiche
    	Splash_dlg->Repaint(); 					// Pour afficher son contenu
     
    	MainForm->OpenDatabase();				//Ouverture de la base de données
     
    	for (int i = 0 ; i < 20 ; i++)		//boucle d'incrémentation de la gauge
    	{
    		Sleep(90);
    		Splash_dlg->CGauge1->AddProgress(5);
    	} 
     
    	Application->CreateForm(__classid(TMainForm), &MainForm);
    		Application->CreateForm(__classid(TForm1), &Form1);
    		Application->CreateForm(__classid(TForm2), &Form2);
    		Application->CreateForm(__classid(TForm3), &Form3);
    		Application->CreateForm(__classid(TForm4), &Form4);
    		Application->CreateForm(__classid(TForm5), &Form5);
     
    	delete Splash_dlg; 	// Supprime la fiche et libère la mémoire utilisée
     
    		Application->Run();
     
    	return 0;
    }

  8. #8
    Membre émérite
    Avatar de bandit boy
    Profil pro
    Inscrit en
    Février 2006
    Messages
    916
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 916
    Par défaut
    Tu charges ton Fichier d'une seule instruction que tu ne contrôles pas, il n'est donc pas possible de connaître à l'avance la taille de ta base. Si tu ne connaîs ni ca, ni la progression il est impossible pour toi d'afficher le taux de chargement.

    Au pire, ce que tu peux faire, c'est lancer en même temps un thread qui fera bouger ton affichage de progression arbitrairement, mais ne connaîssant ni la taille ni l'avancement il est impossible de le faire comme ca, a ma connaissance.

  9. #9
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Juin 2006
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2006
    Messages : 92
    Par défaut
    c'était le but de ma question...
    Le code que je montre ne prend pas en compte l'avancement de l'ouverture du fichier puisque c'est ce que je cherche à savoir. C'est pour ça qu'il n'y avait aucun intérêt à ce que je montre mon code...
    Par contre, connaître la taille du fichier c'est possible.

    Après...

  10. #10
    Membre Expert
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Responsable de compte
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Billets dans le blog
    1
    Par défaut
    bonsoir,
    tu peux également t'inspirer de ce bout de code sortit de l'aide Win32
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    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
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
     
    // ParseALargeFile - parses a large file and uses a progress bar to  
    //   indicate the progress of the parsing operation. 
    // Returns TRUE if successful or FALSE otherwise. 
    // hwndParent - parent window of the progress bar 
    // lpszFileName - name of the file to parse 
    // 
    // Global variable 
    //     g_hinst - instance handle 
    extern HINSTANCE g_hinst; 
     
    BOOL ParseALargeFile(HWND hwndParent, LPSTR lpszFileName) 
    { 
        RECT rcClient;  // client area of parent window 
     
        int cyVScroll;  // height of scroll bar arrow 
        HWND hwndPB;    // handle of progress bar 
        HANDLE hFile;   // handle of file 
        DWORD cb;       // size of file and count of bytes read 
        LPCH pch;       // address of data read from file 
        LPCH pchTmp;    // temporary pointer 
     
        // Ensure that the common control DLL is loaded and create a 
        // progress bar along the bottom of the client area of the 
        // parent window. Base the height of the progress bar on 
     
        // the height of a scroll bar arrow. 
        InitCommonControls(); 
        GetClientRect(hwndParent, &rcClient); 
        cyVScroll = GetSystemMetrics(SM_CYVSCROLL); 
        hwndPB = CreateWindowEx(0, PROGRESS_CLASS, (LPSTR) NULL, 
            WS_CHILD | WS_VISIBLE, rcClient.left, 
            rcClient.bottom - cyVScroll, 
            rcClient.right, cyVScroll, 
            hwndParent, (HMENU) 0, g_hinst, NULL); 
     
        // Open the file for reading, and retrieve the size of the file. 
        hFile = CreateFile(lpszFileName, GENERIC_READ, FILE_SHARE_READ, 
     
            (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, 
            FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL); 
     
        if (hFile == (HANDLE) INVALID_HANDLE_VALUE) 
            return FALSE; 
     
        cb = GetFileSize(hFile, (LPDWORD) NULL); 
     
        // Set the range and increment of the progress bar. 
        SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, cb / 2048)); 
        SendMessage(hwndPB, PBM_SETSTEP, (WPARAM) 1, 0); 
     
        // Parse the file. 
        pch = (LPCH) LocalAlloc(LPTR, sizeof(char) * 2048); 
     
        pchTmp = pch; 
        do { 
            ReadFile(hFile, pchTmp, sizeof(char) * 2048, &cb, 
                (LPOVERLAPPED) NULL); 
            . 
            . // Include here any code that parses the file. 
            . 
     
            // Advance the current position of the progress bar 
            // by the increment. 
            SendMessage(hwndPB, PBM_STEPIT, 0, 0); 
        } while (cb); 
        CloseHandle((HANDLE) hFile); 
     
        DestroyWindow(hwndPB); 
        return TRUE; 
    } 
     // ParseALargeFile - parses a large file and uses a progress bar to  
    //   indicate the progress of the parsing operation. 
    // Returns TRUE if successful or FALSE otherwise. 
    // hwndParent - parent window of the progress bar 
    // lpszFileName - name of the file to parse 
    // 
    // Global variable 
    //     g_hinst - instance handle 
    extern HINSTANCE g_hinst; 
     
    BOOL ParseALargeFile(HWND hwndParent, LPSTR lpszFileName) 
    { 
        RECT rcClient;  // client area of parent window 
     
        int cyVScroll;  // height of scroll bar arrow 
        HWND hwndPB;    // handle of progress bar 
        HANDLE hFile;   // handle of file 
        DWORD cb;       // size of file and count of bytes read 
        LPCH pch;       // address of data read from file 
        LPCH pchTmp;    // temporary pointer 
     
        // Ensure that the common control DLL is loaded and create a 
        // progress bar along the bottom of the client area of the 
        // parent window. Base the height of the progress bar on 
     
        // the height of a scroll bar arrow. 
        InitCommonControls(); 
        GetClientRect(hwndParent, &rcClient); 
        cyVScroll = GetSystemMetrics(SM_CYVSCROLL); 
        hwndPB = CreateWindowEx(0, PROGRESS_CLASS, (LPSTR) NULL, 
            WS_CHILD | WS_VISIBLE, rcClient.left, 
            rcClient.bottom - cyVScroll, 
            rcClient.right, cyVScroll, 
            hwndParent, (HMENU) 0, g_hinst, NULL); 
     
        // Open the file for reading, and retrieve the size of the file. 
        hFile = CreateFile(lpszFileName, GENERIC_READ, FILE_SHARE_READ, 
     
            (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, 
            FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL); 
     
        if (hFile == (HANDLE) INVALID_HANDLE_VALUE) 
            return FALSE; 
     
        cb = GetFileSize(hFile, (LPDWORD) NULL); 
     
        // Set the range and increment of the progress bar. 
        SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, cb / 2048)); 
        SendMessage(hwndPB, PBM_SETSTEP, (WPARAM) 1, 0); 
     
        // Parse the file. 
        pch = (LPCH) LocalAlloc(LPTR, sizeof(char) * 2048); 
     
        pchTmp = pch; 
        do { 
            ReadFile(hFile, pchTmp, sizeof(char) * 2048, &cb, 
                (LPOVERLAPPED) NULL); 
            . 
            . // Include here any code that parses the file. 
            . 
     
            // Advance the current position of the progress bar 
            // by the increment. 
            SendMessage(hwndPB, PBM_STEPIT, 0, 0); 
        } while (cb); 
        CloseHandle((HANDLE) hFile); 
     
        DestroyWindow(hwndPB); 
        return TRUE; 
    }
    cordialement
    vous trouverez mes tutoriels à l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les règles du forum

  11. #11
    Membre confirmé
    Profil pro
    Étudiant
    Inscrit en
    Juin 2006
    Messages
    92
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2006
    Messages : 92
    Par défaut
    Merci pour ton code, c'est assez intéressant. Je me demande par contre comment ça se passe réellement car je veux ouvrir un fichier Excel et j'ai l'impression que dans ton exemple, ça m'obligerait à accéder une deuxième fois au fichier pour contrôler la progress bar. Au final ma progress bar ne suivrait pas le chargement de l'ouverture de mon fichier, non ?

Discussions similaires

  1. Ouverture d'un fichier excel predefini
    Par nberthonneau dans le forum Access
    Réponses: 10
    Dernier message: 13/06/2007, 22h14
  2. [Système] ouverture d'un fichier pdf
    Par joneil dans le forum API standards et tierces
    Réponses: 2
    Dernier message: 17/05/2005, 10h36
  3. Réponses: 2
    Dernier message: 06/04/2005, 12h01
  4. Réponses: 5
    Dernier message: 27/07/2004, 17h04
  5. Réponses: 2
    Dernier message: 22/07/2002, 12h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo