begin process at 2012 02 10 18:03:56
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Archive C/C++

 > 

Archives

 > 

Au secours

 > 

File Extension


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

File Extension

dimanche 27 février 2005 à 22:58:17 | File Extension

vez_from_hell

Bonjour

pour commencer je développe un programme de texte (un peu comme bloc notes) mais je ne sais pas comment, lorsque j'enregistre un fichier, donné l'extension à un fichier (comme par exemple .txt avec bloc notes).
J'espere que vous pourrez m'aider
lundi 28 février 2005 à 00:38:16 | Re : File Extension

jeromedu94

il suffit de mettre ton extension dans le nom du fichier.

ex : file = fopen("tonfichier.txt","wt");
lundi 28 février 2005 à 19:43:56 | Re : File Extension

vez_from_hell

je ne comprend pas vraiment, je vais vs donner ma source et pourriez vous me dire comment je pourrais créer un extension de fichier et lorsque je vais cliquer sur ouvrir, ce soit inscrit dans fichier de type(dans la boite de dialogue en bas de nom du fichier) et lorsque j'enregistre je voudrais aussi que ce soit l'extension par défaut (sans avoir besoin de l'ajouter apres le nom du fichier)

voici ma source:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include <windows.hpp>
#include <stdlib.h>
#include <stdio.h>
#include "Main.h"
#include "ReConst.hpp"
#include "reconst.hpp"

 


//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)


{
SetFileName(Reconst_SUntitled);

}

//----------------------------------------------------------------------------
TTextAttributes *__fastcall TForm1::CurrText(void)
{
    return RichEdit1->SelAttributes;
}
//----------------------------------------------------------------------------
int __stdcall EnumFontsProc(TLogFontA &LogFont, TTextMetricA &/*TextMetric*/,
                                int /*FontType*/, Pointer Data)
{
     TCharsetObject *FontCharset;
     FontCharset = new TCharsetObject((int)LogFont.lfCharSet);
     ((TStrings *)Data)->AddObject((AnsiString)LogFont.lfFaceName,FontCharset);
     return 1;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GetFontNames(void)
{    HDC hDC = GetDC(0);
     void * cTmp = (void *)FontName->Items;
     EnumFonts(hDC, NULL, (FONTENUMPROC) EnumFontsProc, (long) cTmp );
     ReleaseDC(0,hDC);
     FontName->Sorted = True;
}
//----------------------------------------------------------------------------
void __fastcall TForm1::SetFileName(const AnsiString FileName)
{
     LPSTR lpBuf = new char[MAX_PATH];
     sprintf(lpBuf, Reconst_SPercent_s.c_str(), ExtractFileName(FileName).c_str(),
             Application->Title.c_str());
     Caption = (AnsiString)lpBuf;
     FFileName = FileName;
     delete lpBuf;
}
//----------------------------------------------------------------------------
void __fastcall TForm1::CheckFileSave(void)
{    if ( RichEdit1->Modified ) {
        switch(MessageBox(Handle, Reconst_SSaveChanges.c_str(),
          Reconst_SConfirmation.c_str(),MB_YESNOCANCEL | MB_ICONQUESTION))
        {  case ID_YES    : Save1Click(this);
           case ID_CANCEL : Abort();
        };
     }
}

//----------------------------------------------------------------------------
void __fastcall TForm1::ShowHint(TObject* /*Sender*/)
{    StatusBar1->SimpleText = Application->Hint;
}
//----------------------------------------------------------------------------

void __fastcall TForm1::NewButtonClick(TObject *Sender)
{
    CheckFileSave();
     SetFileName(Reconst_SUntitled);
     RichEdit1->Lines->Clear();
     RichEdit1->Modified = False;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::OpenButtonClick(TObject *Sender)
{
CheckFileSave();
     if (OpenDialog1->Execute()) {
        RichEdit1->Lines->LoadFromFile(OpenDialog1->FileName);
        SetFileName(OpenDialog1->FileName);
        RichEdit1->SetFocus();
        RichEdit1->Modified = False;
        RichEdit1->ReadOnly = OpenDialog1->Options.Contains(ofReadOnly);
     }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SaveButtonClick(TObject *Sender)
{
if ( !strcmp(FFileName.c_str(), Reconst_SUntitled.c_str()) )
        SaveAs1Click(Sender);
     else
     {
        RichEdit1->Lines->SaveToFile(FFileName);
        RichEdit1->Modified = False;
     }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SaveAs1Click(TObject* /*Sender*/)
{    if ( SaveDialog1->Execute() ) {
        RichEdit1->Lines->SaveToFile(SaveDialog1->FileName);
        SetFileName(SaveDialog1->FileName);
        RichEdit1->Modified = False;
     }
}

//---------------------------------------------------------------------------

void __fastcall TForm1::PrintButtonClick(TObject *Sender)
{
 if ( PrintDialog1->Execute() ) RichEdit1->Print( FFileName );
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
if ( RichEdit1->HandleAllocated() )
        SendMessage(RichEdit1->Handle, EM_UNDO, 0, 0);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Cut1Click(TObject *Sender)
{
RichEdit1->CutToClipboard();       
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Copy1Click(TObject *Sender)
{
RichEdit1->CopyToClipboard();       
}
//---------------------------------------------------------------------------

void __fastcall TForm1::C1Click(TObject *Sender)
{
RichEdit1->PasteFromClipboard();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Font1Click(TObject *Sender)
{
 FontDialog1->Font->Assign( RichEdit1->SelAttributes );
     if ( FontDialog1->Execute() )
        CurrText()->Assign( FontDialog1->Font );

     RichEdit1->SetFocus();       
}
//---------------------------------------------------------------------------
void __fastcall TForm1::New1Click(TObject *Sender)
{   CheckFileSave();
     SetFileName(Reconst_SUntitled);
     RichEdit1->Lines->Clear();
     RichEdit1->Modified = False;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Open1Click(TObject *Sender)
{
  CheckFileSave();
     if (OpenDialog1->Execute()) {
        RichEdit1->Lines->LoadFromFile(OpenDialog1->FileName);
        SetFileName(OpenDialog1->FileName);
        RichEdit1->SetFocus();
        RichEdit1->Modified = False;
        RichEdit1->ReadOnly = OpenDialog1->Options.Contains(ofReadOnly);
     }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Saveas1Click(TObject *Sender)
{
if ( SaveDialog1->Execute() ) {
        // Options + OverwritePrompt = True thus no need to check.
        RichEdit1->Lines->SaveToFile(SaveDialog1->FileName);
        SetFileName(SaveDialog1->FileName);
        RichEdit1->Modified = False;
     }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Save1Click(TObject *Sender)
{
  if ( !strcmp(FFileName.c_str(), Reconst_SUntitled.c_str()) )
        SaveAs1Click(Sender);
     else
     {
        RichEdit1->Lines->SaveToFile(FFileName);
        RichEdit1->Modified = False;
     }       
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Print1Click(TObject *Sender)
{
if ( PrintDialog1->Execute() ) RichEdit1->Print( FFileName );
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Exit1Click(TObject *Sender)
{
CheckFileSave();
Close();
}
//---------------------------------------------------------------------------
__fastcall TCharsetObject::TCharsetObject(int FCharset)
  : TObject()
{
     Charset = FCharset;
}

//---------------------------------------------------------------------------

void __fastcall TForm1::FontNameChange(TObject* /*Sender*/)
{
     TCharsetObject* ChasrsetObject;

     if ( !FUpdating )
     {
        int FontIndex = FontName->ItemIndex;
        if ((FontIndex > -1) & (FontIndex < FontName->Items->Count))
        {
          ChasrsetObject = (TCharsetObject*)FontName->Items->Objects[FontName->ItemIndex];
          CurrText()->Charset = (unsigned char)ChasrsetObject->Charset;
          CurrText()->Name = FontName->Items->Strings[FontName->ItemIndex];
        }
     }
}
//----------------------------------------------------------------------------
void __fastcall TForm1::SelectFont(TObject* /*Sender*/)
{    FontDialog1->Font->Assign( RichEdit1->SelAttributes );
     if ( FontDialog1->Execute() )
        CurrText()->Assign( FontDialog1->Font );

     RichEdit1->SetFocus();
}
//----------------------------------------------------------------------------
void __fastcall TForm1::FormCloseQuery(TObject* /*Sender*/,
     bool & CanClose)
{    try {
       CheckFileSave();
     }
     catch (...) {
       CanClose = False;
     }
}
//----------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
 CheckFileSave();
     for(int n = 0;n < FontName->Items->Count;n++)
       if( FontName->Items->Objects[n] ){
         delete FontName->Items->Objects[n];
         FontName->Items->Objects[n] = NULL;
       }
}
//----------------------------------------------------------------------------
void __fastcall TForm1::Undo1Click(TObject *Sender)
{
if ( RichEdit1->HandleAllocated() )
        SendMessage(RichEdit1->Handle, EM_UNDO, 0, 0);
}
//----------------------------------------------------------------------------


et le fichier .h:
//---------------------------------------------------------------------------

#ifndef MainH
#define MainH
//---------------------------------------------------------------------------
#include <Outline.hpp>
#include <Grids.hpp>
#include <Buttons.hpp>
#include <ExtCtrls.hpp>
#include <StdCtrls.hpp>
#include <ComCtrls.hpp>
#include <Menus.hpp>
#include <Dialogs.hpp>
#include <Forms.hpp>
#include <Controls.hpp>
#include <Graphics.hpp>
#include <Classes.hpp>
#include <SysUtils.hpp>
#include <Messages.hpp>
#include <Windows.hpp>
#include <System.hpp>
#include <ToolWin.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // Composants gérés par l'EDI
        TMainMenu *MainMenu1;
        TMenuItem *File1;
        TRichEdit *RichEdit1;
        TLabel *Label1;
        TSaveDialog *SaveDialog1;
        TOpenDialog *OpenDialog1;
        TPrintDialog *PrintDialog1;
        TMenuItem *New1;
        TMenuItem *Save1;
        TMenuItem *Saveas1;
        TMenuItem *N1;
        TMenuItem *Open1;
        TMenuItem *Print1;
        TMenuItem *N2;
        TComboBox *FontName;
        TCoolBar *CoolBar1;
        TSpeedButton *OpenButton;
        TSpeedButton *SaveAsButton;
        TSpeedButton *NewButton;
        TSpeedButton *SaveButton;
        TSpeedButton *PrintButton;
        TSpeedButton *SpeedButton1;
        TSplitter *Splitter1;
        TBevel *Bevel3;
        TBevel *Bevel1;
        TBevel *Bevel2;
        TMenuItem *Exit1;
        TStatusBar *StatusBar1;
        TMenuItem *Edit1;
        TMenuItem *C1;
        TMenuItem *Copy1;
        TMenuItem *Cut1;
        TMenuItem *N4;
        TMenuItem *About1;
        TMenuItem *N3;
        TMenuItem *Font1;
        TFontDialog *FontDialog1;
        TMenuItem *Undo1;
        TMenuItem *N5;
        void __fastcall NewButtonClick(TObject *Sender);
        void __fastcall OpenButtonClick(TObject *Sender);
        void __fastcall SaveButtonClick(TObject *Sender);
        void __fastcall PrintButtonClick(TObject *Sender);
        void __fastcall SpeedButton1Click(TObject *Sender);
        void __fastcall Cut1Click(TObject *Sender);
        void __fastcall Copy1Click(TObject *Sender);
        void __fastcall C1Click(TObject *Sender);
        void __fastcall Font1Click(TObject *Sender);
 void __fastcall SaveAs1Click(TObject *Sender);
        void __fastcall New1Click(TObject *Sender);
        void __fastcall Open1Click(TObject *Sender);
        void __fastcall Saveas1Click(TObject *Sender);
        void __fastcall Save1Click(TObject *Sender);
        void __fastcall Print1Click(TObject *Sender);
        void __fastcall Exit1Click(TObject *Sender);
        void __fastcall SelectFont(TObject *Sender);
        void __fastcall FontNameChange(TObject *Sender);
        void __fastcall FormCloseQuery(TObject *Sender, bool &CanClose);
        void __fastcall FormDestroy(TObject *Sender);
        void __fastcall Undo1Click(TObject *Sender);
private: // Déclarations utilisateur
                void __fastcall ShowHint(TObject *Sender);
                AnsiString FFileName;
         bool FUpdating;
         TTextAttributes *__fastcall CurrText(void);
         void __fastcall GetFontNames(void);
         void __fastcall SetFileName(const AnsiString FileName);
         void __fastcall CheckFileSave(void);
public:  // Déclarations utilisateur
        virtual __fastcall TForm1(TComponent* Owner);

};
//----------------------------------------------------------------------------
class TCharsetObject : public TObject
{
public:
    int Charset;
    __fastcall TCharsetObject(int FCharset);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

j'espere que vous pourrez m'aider



Cette discussion est classée dans : fichier, file, extension, notes, bloc


Répondre à ce message

Sujets en rapport avec ce message

Problème avec traitement de fichier (cplusplus !) [ par Sianrin ] Voila, j'explique mon problème. Pour voir un peu comment les accès au fichiers se géraient en cplusplus, je me suis mis en tête de faire un programme Enregistrer en HEXA un texte avec gcc !! [ par UncleShu ] /* * Ce programme affiche le fichier en HEXADECIMAL et se copie lui-même avec * une autre exetenstion (.txt). Moi je voudrais qui affiche le fichier * Petit probleme de code en C sur Linux !! [ par UncleShu ] Je voudrais créer un fichier dans le réperoire personnel d'un utilisateur mais mon code ne marche pas !!#include #include #include #define DIR $HOM ouverture de fichier avec les MFC [ par steph76 ] Bonjourvoila je programme une application qui ha beusoin d'ouvrir 1 fichier via httpJ'ai donc fait le code suivantCStdioFile *file;CInternetSession IS Mettre un fichier .exe dans un buffer [ par guiguikun ] Je n'arrive pas a mettre un fichier executable en memoire.sur les 100Ko du fichier, mon buffer ne compte que les 3 premiers octets (caracteres)voici m [C] Transfert de fichier par sockets [ par bonobo78 ] salut ! j'ai un petit pb pour transmettre un fichier via des sockets.En fait, je decoupe le fichier en petit bout de 1024 octets et je transmets chaqu prob avec nom de fichier. [ par kach23 ] bonjour, je debute etje réalise une acquisition de mesure avec builder.je souhaite que le nom du fichier ouvert a chaque acquisition soit different.vo GROS problème avec ' tellg() ' [ par Sanke ] Bonjour à tous, je poste ce message parce que je ne comprends pas ce qui se passe avec tellg() :je m'explique, je lis un fichier ligne à ligne dont vo Pb de gestion de fichier avec fstream [ par Bub325 ] Salut,J'ai deux problème distinct avec fstream, Le premier est que lorsque j'arrive à la fin d'un fichier, je ne peut plus revenir plus haut dans ce d boite de dialogue en C [ par benhamid ] Bonjour, J'ai quelque problème en C, pouvez vous m'aider svp.J'ai des fonctions C suivantes: lecturefichier(FILE * f1) qui lit le fichier f1calcul( Fi


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
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

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,624 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales