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
| #include <stdlib.h>
#include <stdio.h>
#include <SDL\SDL.h>
#include <windows.h>
//Variables globales
static SDL_Surface* ecran = NULL;
static SDL_Event event;
static HWND WDH;
char path[MAX_PATH];
char* chemin = &path[0];
// Prototypes
int getAudioPath (HWND parentWindow, char* chemin); // Sélection et retour du chemin d'un fichier audio
// Fonction main
int main ( int argc, char** argv )
{
int quitter = 0;
// initialize SDL video
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "Unable to init SDL\n" );
return 1;
}
// create a new window
ecran = SDL_SetVideoMode(1280, 680, 32,SDL_HWSURFACE|SDL_DOUBLEBUF);
// clear screen
SDL_FillRect(ecran, 0, SDL_MapRGB(ecran->format, 0, 0, 0)); // fond noir
WDH = GetActiveWindow();
AllowSetForegroundWindow(ASFW_ANY);
// program main loop
while (quitter== 0)
{
// message processing loop
while (SDL_PollEvent(&event))
{
// check for messages
switch (event.type)
{
// exit if the window is closed
case SDL_QUIT:
quitter = 1;
break;
// clic
case SDL_MOUSEBUTTONDOWN:
if (event.button.button==SDL_BUTTON_LEFT) // Clic de souris (gauche)
{
int res = getAudioPath (WDH , chemin); // Sélection du fichier
fprintf(stderr,"res %i, chemin=%s \n", res,chemin);
} // fin clic gauche
break;
if (event.button.button==SDL_BUTTON_RIGHT) // Clic de souris (droit)
{
// juste pour tester le problème !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// désactive les boutons !
} // fin clic droit
break;
// check for keypresses
case SDL_KEYDOWN:
{
// exit if ESCAPE is pressed
if (event.key.keysym.sym == SDLK_ESCAPE) quitter = 1;
}
} // end switch
} // end of message processing
// DRAWING STARTS HERE
// clear screen
SDL_FillRect(ecran, 0, SDL_MapRGB(ecran->format, 0, 0, 0));
// finally, update the screen :)
SDL_Flip(ecran);
} // end main loop
// all is well ;)
printf("Exited cleanly\n");
return 0;
}
// Fonctions
int getAudioPath (HWND parentWindow, char* chemin) // Sélection et retour du chemin d'un fichier audio
{
//Structure nécessaire à la boîte de dialogue d'ouverture
OPENFILENAME toGetFileName;
//Variable qui va recevoir le chemin de la musique
char filePath[MAX_PATH];
*filePath=0;
//Remplissage de la structure
ZeroMemory(&toGetFileName, sizeof(toGetFileName));
toGetFileName.lStructSize = sizeof(toGetFileName);
toGetFileName.hwndOwner = parentWindow;
toGetFileName.hInstance = NULL;
toGetFileName.lpstrFile = filePath;
toGetFileName.nMaxFile = MAX_PATH;
toGetFileName.lpstrInitialDir = "D:\\mp3";
//Avec un filtre de fichiers audio
toGetFileName.lpstrFilter = "Audio File\0*.mp3;*.wav;*.ogg;*.wma\0\0";
toGetFileName.nFilterIndex = 1;
// toGetFileName.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER;
toGetFileName.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER;
//Si l'utilisateur clique sur "Ouvrir"
if(GetOpenFileName(&toGetFileName) == TRUE)
{
strcpy(chemin, filePath );
return 1;
}
else
{
return 0;
}
} |
Partager