Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

DIVERS OUTILS WINDOWS : ENREGISTRER-SOUS...


Information sur la source

Catégorie :Divers Niveau : Débutant Date de création : 24/01/2003 Date de mise à jour : 24/01/2003 15:20:22 Vu / téléchargé: 3 737 / 166

Note :
Aucune note

Commentaire sur cette source (5)
Ajouter un commentaire et/ou une note

Description

Ce source montre l'utilisation de :
- Gestion de la fenêtre enregistrer sous
- Gestion de la fenêtre Sélectionner un répertoire
- Donner l'heure et la date courante
- Enlever les "/" d'une chaine de caractere date (peut servir pour d'autre séparateur)

Trinita,  
 

Source

  • /*******************************************************/
  • /* */
  • /* Plusieurs Méthode Outils */
  • /* */
  • /* LoadDirectory : */
  • /* Fenetre de type Enregistrer Sous */
  • /* */
  • /* SelectDir : */
  • /* Fenetre du type Sélectionner un dir */
  • /* */
  • /* DateJour : */
  • /* Retourne la date courante 01/01/2003 */
  • /* */
  • /* ConvertDate : */
  • /* Converti la chaine date sans les caracteres '/' */
  • /* */
  • /* Créé le 01/12/2002 Par Trinita */
  • /* Modifié le 24/01/2003 */
  • /* Version 1.0.4 */
  • /*******************************************************/
  • #include <windows.h>
  • #include <shlobj.h>
  • #include <time.h>
  • #include <stdio.h>
  • #include <stdlib.h>
  • #include <string.h>
  • #include "tools.h"
  • #define MAIN_LEN 80
  • #define IDC_MAIN_TEXT 100
  • /* Fenêtre ENREGISTRER SOUS */
  • void LoadDirectory(HWND hDlgTools, char szFileName[MAIN_LEN+1])
  • {
  • /* Déclaration des variables */
  • OPENFILENAME ofn;
  • /* Init des variables */
  • ZeroMemory(&ofn, sizeof(ofn));
  • szFileName[0]=0;
  • /* Déclaration de la structure de OPENFILENAME */
  • ofn.lStructSize = sizeof(ofn);
  • ofn.hwndOwner = hDlgTools;
  • // ofn.hInstance =;
  • ofn.lpstrFilter = "Fichiers xls (*.xls)\0Tous (*.*)\0*.*";
  • // ofn.lpstrCustomFilter;
  • // ofn.nMaxCustFilter;
  • // ofn.nFilterIndex;
  • ofn.lpstrFile = szFileName;
  • ofn.nMaxFile = MAIN_LEN+1;
  • // ofn.lpstrFileTitle = "Exportation";
  • // ofn.nMaxFileTitle;
  • ofn.lpstrInitialDir = "c:\\";
  • // ofn.lpstrTitle;
  • ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST |
  • OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT |
  • OFN_NOCHANGEDIR;
  • // ofn.nFileOffset;
  • // ofn.nFileExtension =;
  • ofn.lpstrDefExt = "xls";
  • // ofn.lCustData;
  • // ofn.lpfnHook;
  • ofn.lpTemplateName ="Exportation";
  • /* Ouverture de la fenetre de selection */
  • if ( GetSaveFileName ( &ofn ) )
  • {
  • /* Récupération du nom de fichier */
  • SendMessage(GetDlgItem
  • (hDlgTools,IDC_MAIN_TEXT),WM_GETTEXT,sizeof
  • (szFileName),(LPARAM)
  • szFileName);
  • }
  • }
  • /* Sélection d'un répertoire */
  • HWND hDlgTool;
  • int SelectDir( char szPath[MAX_PATH] )
  • {
  • BROWSEINFO bi;
  • ITEMIDLIST *il;
  • char Buffer[MAX_PATH];
  • bi.hwndOwner=hDlgTool;
  • bi.pidlRoot=NULL;
  • bi.pszDisplayName=&Buffer[0];
  • bi.lpszTitle="Choisissez un répertoire :";
  • bi.ulFlags=0;
  • bi.lpfn=NULL;
  • if( (il=SHBrowseForFolder(&bi)) ==NULL ) return 0;
  • return SHGetPathFromIDList(il, &szPath[0]);
  • }
  • /* Donne la date du jour du PC */
  • /* Format CHAR 11 */
  • void DateJour (char DateCourante[11])
  • {
  • SYSTEMTIME SystemTime;
  • GetSystemTime(&SystemTime); //Initialisation
  • /* La structure
  • SystemTime.wDay => le jour
  • SystemTime.wMonth => le mois
  • SystemTime.wYear => l'année
  • SystemTime.wHour => l'heure
  • SystemTime.wMinute => les minutes
  • SystemTime.wSecond => les secondes
  • SystemTime.wMilliseconds => les milli-secondes
  • */
  • // Construction de la chaine de retour
  • // %02d pour avoir le mois ou le jour sur deux caracteres
  • char*JourCourant=new char;
  • wsprintf(JourCourant,"%02d",SystemTime.wDay);
  • strcpy ( DateCourante, JourCourant );
  • strcat ( DateCourante, "/" );
  • char*MoisCourant=new char;
  • wsprintf(MoisCourant,"%02d",SystemTime.wMonth);
  • strcat ( DateCourante, MoisCourant );
  • strcat ( DateCourante, "/" );
  • char*AnneeCourante=new char;
  • wsprintf(AnneeCourante,"%d",SystemTime.wYear);
  • strcat ( DateCourante, AnneeCourante );
  • return;
  • }
  • /* Converti une chaine char de type date <01/01/2002> au format <01012002> */
  • void ConvertDate ( char ChaineDate[11], char NewChaineDate[9])
  • {
  • char *pointeur;
  • char *separateur = { "/" };
  • char *buffer;
  • buffer = strdup ( ChaineDate );
  • // premier appel, le jour
  • pointeur = strtok( buffer, separateur );
  • strcpy ( NewChaineDate, pointeur );
  • // pour le mois et l'année
  • while( pointeur != NULL )
  • {
  • // Cherche les autres separateur
  • pointeur = strtok( NULL, separateur );
  • if ( pointeur != NULL )
  • {
  • strcat ( NewChaineDate, pointeur );
  • }
  • }
  • return ;
  • }
  • /********************************************************/
  • /* */
  • /* tools.h */
  • /* */
  • /********************************************************/
  • /* prototypage des fonctions tools */
  • void LoadDirectory ( HWND, char [] );
  • int SelectDir( char []);
  • void DateJour (char []);
  • void ConvertDate ( char [], char []);
/*******************************************************/
/*						*/
/* Plusieurs Méthode Outils 				*/
/*						*/
/* LoadDirectory : 					*/
/* Fenetre de type Enregistrer Sous			*/
/*						*/
/* SelectDir     :					*/
/* Fenetre du type Sélectionner un dir 			*/
/*						*/
/* DateJour	  : 				*/
/* Retourne la date courante 01/01/2003			*/
/*						*/
/* ConvertDate	  :				*/
/* Converti la chaine date sans les caracteres '/'	                */
/*						*/
/* Créé le 01/12/2002	Par Trinita			                */
/* Modifié le 24/01/2003				*/
/* Version 1.0.4					*/
/*******************************************************/

#include <windows.h>
#include <shlobj.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "tools.h"

#define	MAIN_LEN		80
#define IDC_MAIN_TEXT	100

/* Fenêtre ENREGISTRER SOUS */
void LoadDirectory(HWND hDlgTools, char szFileName[MAIN_LEN+1])
{
                /* Déclaration des variables */
	OPENFILENAME ofn;
	
	/* Init des variables */				
	ZeroMemory(&ofn, sizeof(ofn));
	szFileName[0]=0;
					
	/* Déclaration de la structure de OPENFILENAME */
	ofn.lStructSize = sizeof(ofn); 
	ofn.hwndOwner = hDlgTools; 
	// ofn.hInstance =; 
	ofn.lpstrFilter = "Fichiers xls (*.xls)\0Tous (*.*)\0*.*"; 
	// ofn.lpstrCustomFilter; 
	// ofn.nMaxCustFilter; 
	// ofn.nFilterIndex; 
	ofn.lpstrFile = szFileName; 
	ofn.nMaxFile = MAIN_LEN+1; 
	// ofn.lpstrFileTitle = "Exportation"; 
	// ofn.nMaxFileTitle; 
	ofn.lpstrInitialDir = "c:\\"; 
	// ofn.lpstrTitle; 
	ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | 
                OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT |   
                OFN_NOCHANGEDIR; 
	// ofn.nFileOffset; 
	// ofn.nFileExtension =; 
	ofn.lpstrDefExt = "xls"; 
	// ofn.lCustData; 
	// ofn.lpfnHook; 
	ofn.lpTemplateName ="Exportation"; 

	/* Ouverture de la fenetre de selection */
	if ( GetSaveFileName ( &ofn ) )
	{
		/* Récupération du nom de fichier */
   		SendMessage(GetDlgItem
                                (hDlgTools,IDC_MAIN_TEXT),WM_GETTEXT,sizeof
                                (szFileName),(LPARAM)
                                szFileName);
	}
}

/* Sélection d'un répertoire */
HWND hDlgTool;

int SelectDir( char szPath[MAX_PATH] )
{
	
	BROWSEINFO bi;
	ITEMIDLIST *il;
	char Buffer[MAX_PATH];

	bi.hwndOwner=hDlgTool;
	bi.pidlRoot=NULL;
	bi.pszDisplayName=&Buffer[0];
	bi.lpszTitle="Choisissez un répertoire :";
	bi.ulFlags=0;
	bi.lpfn=NULL;
	if( (il=SHBrowseForFolder(&bi)) ==NULL ) return 0;
	return SHGetPathFromIDList(il, &szPath[0]);
}

/* Donne la date du jour du PC */
/* Format CHAR 11 */
void DateJour (char DateCourante[11])
{
    
	SYSTEMTIME SystemTime;
	GetSystemTime(&SystemTime);  //Initialisation
	
	/* La structure
	SystemTime.wDay        		=> le jour
	SystemTime.wMonth     		=> le mois
	SystemTime.wYear      		=> l'année
	SystemTime.wHour       		=> l'heure
	SystemTime.wMinute    		=> les minutes
	SystemTime.wSecond  		=> les secondes
	SystemTime.wMilliseconds  	=> les milli-secondes
	*/
	
	// Construction de la chaine de retour
                // %02d pour avoir le mois ou le jour sur deux caracteres
	char*JourCourant=new char;
	wsprintf(JourCourant,"%02d",SystemTime.wDay);
	strcpy ( DateCourante, JourCourant );
		
	strcat ( DateCourante, "/" );
	
	char*MoisCourant=new char;
	wsprintf(MoisCourant,"%02d",SystemTime.wMonth);	
	strcat ( DateCourante, MoisCourant );
		
	strcat ( DateCourante, "/" );
	
	char*AnneeCourante=new char;
	wsprintf(AnneeCourante,"%d",SystemTime.wYear);	
	strcat ( DateCourante, AnneeCourante );	

	return;
	
}

/* Converti une chaine char de type date <01/01/2002> au format <01012002> */
void ConvertDate ( char ChaineDate[11], char NewChaineDate[9])
{
    char	*pointeur;
    char	*separateur = { "/" };
	char 	*buffer;
	
	buffer = strdup ( ChaineDate );

    // premier appel, le jour
    pointeur = strtok( buffer, separateur  );
	strcpy ( NewChaineDate, pointeur );
	
    // pour le mois et l'année
    while( pointeur != NULL ) 
    {
      
      // Cherche les autres separateur
      pointeur = strtok( NULL, separateur  );
      if ( pointeur != NULL )
      {
      	strcat ( NewChaineDate, pointeur );
      }
    }
    
    return ;
}

/********************************************************/
/*							*/
/*					tools.h		*/
/*							*/
/********************************************************/
/* prototypage des fonctions tools */
void LoadDirectory  ( HWND, char [] );
int SelectDir( char []);
void DateJour (char []);
void ConvertDate ( char [], char []);










  

Fichier Zip

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

Commentaires et avis

signaler à un administrateur
Commentaire de BruNews le 24/01/2003 17:12:07 administrateur CS

Salut,
je reprends ta func void DateJour(char DateCourante[11])
On va l'optimiser. EN 1er virer les "new" qui font allouer et d&sallouer de la mémoire alors que le buffer est déjà fourni en param. Ensuite en C on se sert de pointeur pour se rapprocher le + possible de l'asm.
void DateJour (char *DateCourante)
{
  SYSTEMTIME st;
  char *c = DateCourante;
  // ptr 4 octets en plac des new
  GetSystemTime(&st);
  if(st.wDay &lt; 10) {
    *c = '0'; *(c+1) = (char) (st.wDay + 48);
  }
  else ultoa(st.wDay, c, 10); // optimisable aussi
  *(c+2) = '/'; c += 3;
  if(st.wMonth &lt; 10) {
    *c = '0'; *(c+1) = (char) (st.wMonth + 48);
  }
  else ultoa(st.wMonth, c, 10);
  *(c+2) = '/';
  ultoa(st.wYear, c+3, 10);
}
On va faire idem pour ta ConvertDate()
void ConvertDate (char *psrc, char *pdst)
{
  char *c = psrc, *d = pdst;
  while(1) { // sans fin, controler sortie
    if(*c != '/') *d++ = *c;
    if(*c++ == 0) return
  }
}
ciao...

signaler à un administrateur
Commentaire de RaphAstronome le 26/01/2003 18:05:13

Bonjour,

Joli code mais je n'arrive pas à le compiler avec Dev-C++ (GCC) y a t'il une librairie à mettre ou quelque chose du genre.

A bientôt

signaler à un administrateur
Commentaire de Trinita16 le 27/01/2003 09:55:16

il te faut mettre les librairies win32sdk :
Comdlg32.lib, Gdi32.lib, Kernel32.lib, User32.lib, shell32.lib, comctl32.lib.

Avec mon compilateur ça fonctionne tres bien... mais si j 'ai un peu de temps j'essai avec dev-c++

@+ Trinita,

PS : Merci pour l'optimisation de mon code..... :)

signaler à un administrateur
Commentaire de kronemburg le 13/12/2005 15:18:08

c'est "tools.h" qu'il manque !

signaler à un administrateur
Commentaire de Trinita16 le 17/12/2005 11:15:20

je veux pas dire mais t'as pas bien regardé la. Le tools.h est en bas du code :

# /********************************************************/
# /*                            */
# /*                    tools.h        */
# /*                            */
# /********************************************************/
# /* prototypage des fonctions tools */
# void LoadDirectory ( HWND, char [] );
# int SelectDir( char []);
# void DateJour (char []);
# void ConvertDate ( char [], char []);

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,406 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.