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
| #include <windows.h>
#include <string>
char *Chemin_Fic;
char buffer[BUFSIZE];
HWND hwnd_fn;
int Ouvrir(int a,HWND handleF);
BOOL EcritFic(void);
void Info(HWND id,char *msg,char *titre);
....
....
Clic sur un bouton sélection fichier
if(LOWORD(wParam) == mBtSelF)
{
Ouvrir(1,hwnd_fn);
Info(hwnd_fn,Chemin_Fic,"Avant EcritFic:");
EcritFic();
int Ouvrir(int a,HWND handleF) //a=1 = fichier ;a=2= répertoire
{
OPENFILENAME ch;
CHAR szFile[MAX_PATH]={0};
ZeroMemory(&ch, sizeof(OPENFILENAME));
ch.lStructSize = sizeof(OPENFILENAME);
ch.hwndOwner = handleF; // handle fenetre appelant (mere)
ch.lpstrFile = szFile;
ch.nMaxFile = MAX_PATH;
ch.lpstrFilter = "\0*.*\0";
ch.nFilterIndex = 1;
ch.lpstrFile[0] = '\0';
// Permet la multiselection + Creation +...
ch.Flags = OFN_CREATEPROMPT | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST ;
if (GetOpenFileName(&ch)==TRUE)
{
Chemin_Fic=ch.lpstrFile;
return(1);
}
else
{
return(-1);
}
}
BOOL EcritFic(void)
{
Info(hwnd_fn,Chemin_Fic,"Nom Fic Ouv");
LPCTSTR lpFileName;
DWORD dwDesiredAccess;
DWORD dwShareMode;
LPSECURITY_ATTRIBUTES lpSecurityAttributes;
DWORD dwCreationDisposition;
DWORD dwFlagsAndAttributes;
HANDLE hTempFile;
char szTempName[BUFSIZE];
dwDesiredAccess = FILE_ALL_ACCESS;
HANDLE IdFic;
Info(hwnd_fn,Chemin_Fic,"Ouverture ...");
IdFic = CreateFile(Chemin_Fic, // file name
GENERIC_READ | GENERIC_WRITE, // open r-w
0, // do not share
NULL, // default security
CREATE_ALWAYS, // overwrite existing
FILE_ATTRIBUTE_NORMAL,// normal file
NULL); // no template
if (IdFic == INVALID_HANDLE_VALUE)
{
Info(hwnd_fn,"Erreur ouverture !","Seb");
return (false);
}
else
{
Info(hwnd_fn,"Ouverture Ok !","Seb");
}
DWORD La;
char *ch="Essai seb";
WriteFile(IdFic, ch , 8,&La,NULL);
CloseHandle(IdFic) ;
return (true);
}
void Info(HWND id,char *msg,char *titre)
{
LPCTSTR lpText=msg;
LPCTSTR lpCaption=titre;
UINT uType=MB_OK;
if (MessageBox( id,lpText,lpCaption,uType)==IDOK);
} |
Partager