2014-07-22 2 views
-3

리소스 파일과 함께 PlaySound()를 사용하는 방법에 대해 혼란 스럽습니다. 왜냐하면 여기에서 읽고 모든 것을 테스트하기 때문에 wav 파일을 가져올 수 없습니다. 콘솔 프롬프트 u_u에서 소리가납니다. 그래서, 당신이 나를 도울 수 있다면, 나는 매우 감사 할 것입니다. $리소스 파일이 작동하지 않는 PlaySound()

#include <windows.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <time.h> 
#include "resources.h" 

#pragma comment(lib, "Winmm.lib") 

int main() { 

srand (time(NULL)); 

int secreto, num, s1, s2, s3, d1, d2, d3, toque, fama, computer, ntoques, nfamas, fin, pc; 

PlaySound(MAKEINTRESOURCE(sound), NULL, SND_RESOURCE | SND_ASYNC | SND_LOOP); 

printf ("\n\n\t\t***************************************\n\n"); 
printf ("\n\n\t\t** Bienvenido al juego: Toque y Fama **\n\n"); //momento donde se inicia el juego 
printf ("\n\n\t\t***************************************\n\n"); 
secreto = (rand()%899+100); //funcion que permitira aleatoriamente elegir un numero secreto 
printf ("\n\n\n\tEn este juego tienes que adivinar el numero que estoy pensando! \n\n\t\t\tSeras capaz de lograrlo?\n\n\n"); 
printf ("\nPor favor, ingrese un numero de tres cifras\n\n"); 
scanf ("\n%d",&num); //aqui el jugador digita un numero con el fin de adivinar el de su rival 

while ((num<000)||(num<=011)||(num>=1000)) { 
    printf ("\n\nLos digitos ingresados no son de tres cifras"); 
    printf ("\n\nIngrese un nuevo numero: \n\n"); 
    scanf ("%d",&num); 
} 

while (num != secreto) { //se produciran iteraciones siempre que el numero que se digite sea distinto al numero secreto del rival 
    s1= secreto/100; 
    s2= (secreto%100-secreto%100%10)/10; //aqui se hace la division del numero secreto para poder hacer las combinaciones 
    s3= secreto%100%10; 

    d1= num/100; 
    d2= (num%100-num%100%10)/10; //lo mismo se hace con el numero dado por el rival 
    d3= num%100%10; 

    toque = 0; 
    fama = 0; 

    if ((d1==s1)||(d2==s2)||(d3==s3)||(d1==s2)||(d1==s3)||(d2==s1)||(d2==s3)||(d3==s1)||(d3==s2)) { //aca se ven las combinaciones posibles de toques y famas 
     if (d1==s1){ 
      fama=fama+1; 
     } 
     if (d2==s2){ 
      fama=fama+1; 
     } 
     if (d3==s3){ 
      fama=fama+1; 
     } 
     if (d1==s2){ 
      toque=toque+1; 
     } 
     if (d1==s3){ 
      toque=toque+1; 
     } 
     if (d2==s1){ 
      toque=toque+1; 
     } 
     if (d2==s3){ 
      toque=toque+1; 
     } 
     if (d3==s1){ 
      toque=toque+1; 
     } 
     if (d3==s2){ 
      toque=toque+1; 
     } 
     if (toque==1){ 
      printf ("Tu tienes un toque\n"); 
     } 
     if (toque==2||toque==3){ 
      printf ("Tu tienes %d toques\n",toque); 
     } 
     if (fama==1){ 
      printf ("Tu tienes una fama\n"); 
     } 
     if (fama==2||fama==3){ 
      printf ("Tu tienes %d famas\n",fama); 
     } 
    } 
    computer = (rand()%899+100); //esta funcion permitira generar el numero que cumplira la funcion de adivinar el secreto rival 
    printf ("\n\t\t\t*******************\n\n"); 
    printf ("\n\t\t\tTurno de la Maquina\n\n"); 
    printf ("\n\t\t\t*******************\n\n"); 
    printf ("\n\nNo has acertado, estos son mis numeros: \n\n"); 
    printf ("%d\n\n",computer); 
    printf ("\nIngrese cantidad de toques acertados\n\n"); 
    scanf ("\n%d",&ntoques); 

    while ((ntoques<0)||(ntoques>=4)) { 
     printf ("\nLos toques ingresados no son correctos. Favor ingresar nuevamente\n\n"); 
     scanf ("\n%d",&ntoques); 
    } 

    printf ("\nIngrese cantidad de famas acertadas\n\n"); 
    scanf ("\n%d",&nfamas); 

    while ((nfamas<0)||(nfamas>=4)) { 
     printf ("\nLas famas ingresadas no son correctas. Favor ingresar nuevamente\n\n"); 
     scanf ("\n%d",&nfamas); 
    } 

    if (nfamas==3) { 
     pc = 1; 
     fin = secreto; 
     num = fin; 
    } 
    else { 
     printf ("\n\t\t\t*****************\n\n"); 
     printf ("\n\t\t\tTurno del Jugador\n\n"); //se vuelve a la iteracion si no se ha adivinado el numero 
     printf ("\n\t\t\t*****************\n\n"); 
     printf ("\n\nIngresa un nuevo numero: \n\n"); 
     scanf ("\n%d",&num); 

     while ((num<000)||(num<=011)||(num>=1000)) { 
      printf ("\nLos digitos ingresados no son de tres cifras"); 
      printf ("\n\nIngrese un nuevo numero: \n\n"); 
      scanf ("\n%d",&num); 
     } 
    } 
} 
if (pc==1) { 
    printf ("\n\nTe he derrotado\n\n"); //si se adivina, sale de la iteracion y escribe la derrota del jugador 
    printf ("\n\nEl juego ha concluido\n\n"); 
} 
else { 
    printf ("\n\nMe has derrotado\n\n"); //si el jugador adivina el secreto rival, el ordenador escribira esta frase 
    printf ("\n\nEl juego ha concluido\n\n"); 
} 

return 0; 
} 

내 리소스 파일에 다음 줄을

sound WAVE "eric johnson - 017 eric johnson - cliffs of dover441.wav" 

그리고, 헤더 파일 (resources.h), 단순히

#ifndef RESOURCE_H_INCLUDED 
#define RESOURCE_H_INCLUDED 

#define sound 1001 

#endif // RESOURCE_H_INCLUDED 

컴파일을 말한다, 나는 플래그를 추가 -lwinmm -mwindows와 프로그램이 컴파일되지만, 실행하면 나머지 프로그램에서 소리 나 응답을 얻지 못하고 메모리 만 소비하지만 다른 것은 없습니다.

감사합니다. 3.

답변

1

인수를 전달하고 있지만 프로그램에서 사용하고 있지 않습니다. 다음과 같이 변경하십시오.

int main(int argc, const char* argv[]) 
... 
    PlaySound(TEXT(argv[1]), NULL, SND_FILENAME); 

이렇게하면 전달할 파일 이름이 선택됩니다.

EDIT1 확인이 당신은 시작 소리 받아야

PlaySound((LPCTSTR) SND_ALIAS_SYSTEMSTART, NULL, SND_ALIAS_ID); 

를 작동하는 경우 - 기본적으로는 PlaySound는 기본적으로 작동하는지 증명한다. 당신이 어떤 소리도 내지 않으면 틀린 다른 것이있을 것입니다. 로드하는 곡이 메모리에 저장되어 있어야합니다.

, 작업이 작동하는 경우 그 작동하는 경우, 현재 디렉토리에 \ WINDOWS \ 미디어 \의 chimes.wav 복사,

PlaySound(TEXT("SystemStart"), NULL, SND_ALIAS); 

을 시도하고 그래도 문제가 해결되지 않으면

PlaySound(TEXT(".\\chimes.wav"), NULL, SND_FILENAME); 

시도 out은 런타임 디렉토리입니다. 작업을 완료하면 .wav 파일로 시도해보십시오. 작동하는 경우 전체 경로 이름을 사용해보십시오

PlaySound(TEXT("\\Windows\\Media\\Windows Logoff Sound.wav"), NULL, SND_FILENAME); 

작동하는 경우 WAV 파일의 전체 경로를 사용해보십시오.

+0

모든 것을 다시 컴파일하고 기본 및 PlaySound() 행을 변경 한 후에도 문제가 계속 발생합니다. 메모리가 부족하지만 소리가 들립니다. 어쩌면 내가 잘못 했어. 다시 한 번 감사드립니다. –

+0

Edit1에서 테스트 해보기 - 소리가 들리는가요? – cup