Bonjour à tous,
Dans beaucoup de mes programmes, lorsqu'une opération assez longue est en cours, j'utilise une petite fenètre indicant l'état et la tache en cours d'exécution.
Fatigué d'avoir à chaque fois a retaper les lignes de code pour cette petite fenètre, j'ai voulu mettre tout ce code dans une DLL, en faisant 3 fonctions:
- une pour créer la fenètre (initialiser)
- une pour changer le texte de l'opération en cours
- et une pour changer la valeur de la progressbar.
Ce qui donne ça :
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <stdlib.h>
HBRUSH FondStatic=(HBRUSH)(COLOR_WINDOW);
HWND Fen_Sync, Tache, Statut, ProgressBar;
__declspec (dllexport) HWND CreateUserForm (char *Name, char* szClassName, HINSTANCE hThisInstance, int ID_LABEL)
{
// Calcule la résolution de l'écran
POINT Ecran = {GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)};
// Crée la fenêtre de synchronisation
Fen_Sync = CreateWindowEx(0, &szClassName[0], &Name[0], WS_OVERLAPPED,
(Ecran.x-277)/2, (Ecran.y-105)/2, 277, 105, HWND_DESKTOP, NULL, hThisInstance, NULL);
//Labels
Tache = CreateWindowEx(0, "STATIC", "Tache :", WS_VISIBLE|WS_CHILD, 10, 25, 200, 13, Fen_Sync, (HMENU)ID_LABEL, hThisInstance, NULL);
Statut = CreateWindowEx(0, "STATIC", "Statut :", WS_VISIBLE|WS_CHILD, 10, 40, 200, 13, Fen_Sync, (HMENU)ID_LABEL, hThisInstance, NULL);
//ProgressBar
typedef VOID (CALLBACK* INITCOMMONCONTROLSEX)(VOID);
INITCOMMONCONTROLSEX InitCommonControlsEx;
HINSTANCE hDLL;
hDLL = LoadLibrary("comctl32.dll");
InitCommonControlsEx = (INITCOMMONCONTROLSEX)GetProcAddress(hDLL, "InitCommonControlsEx");
ProgressBar = CreateWindow(PROGRESS_CLASS, NULL,WS_CHILD|WS_VISIBLE,
10, 57, 250, 10, Fen_Sync, NULL, hThisInstance, NULL);
SendMessage(ProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0,100));
SendMessage(ProgressBar, PBM_SETSTEP, (WPARAM)1, 0);
SendMessage(ProgressBar, PBM_SETPOS, (WPARAM)0, 0);
// Changements des polices
HGDIOBJ PoliceNormale = GetStockObject(DEFAULT_GUI_FONT);
SendMessage(Tache, WM_SETFONT, (WPARAM)PoliceNormale, MAKELPARAM(TRUE, 0));
SendMessage(Statut, WM_SETFONT, (WPARAM)PoliceNormale, MAKELPARAM(TRUE, 0));
ShowWindow(Fen_Sync, 1);
return Fen_Sync;
}
/*
__declspec (dllexport) void ShowForm (char* Name, char* Tache, int Valeur_ProgressBar, int Show)
{
SetWindowText(Fen_Sync, &Name[0]);
SetWindowText(Tache, &Tache[0]);
SendMessage(ProgressBar, PBM_SETPOS, (WPARAM)Valeur_ProgressBar, 0);
ShowWindow(Fen_Sync, Show);
MessageBox(NULL, "ShowForm","Fonction appelée", MB_OK);
}
*/
__declspec (dllexport) void UpdateFormT (char* Tache)
{
SetWindowText(Tache, &Tache[0]);
ShowWindow(Fen_Sync, 1);
UpdateWindow(Fen_Sync);
MessageBox(NULL, "UpdateFormT","Fonction appelée", MB_OK);
}
__declspec (dllexport) void UpdateFormV (int Valeur_ProgressBar)
{
SendMessage(ProgressBar, PBM_SETPOS, (WPARAM)Valeur_ProgressBar, 0);
ShowWindow(Fen_Sync, 1);
UpdateWindow(Fen_Sync);
MessageBox(NULL, "UpdateFormV","Fonction appelée", MB_OK);
}
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
/* Returns TRUE on success, FALSE on failure */
return TRUE;
}
Dev Cpp ne me génère aucune erreur, me crée la lib et la DLL.
Mais qd j'utilise ma DLL, les MsgBox s'affichent bien (donc les fonctions sont appelées),
mais ma fenètre n'apparait pas !!!
Où est le pb ?
Merci à tous. 