Can you add pictures/sounds in a win32 console app?

Reply

Join Date: May 2004
Posts: 217
Reputation: marceta is an unknown quantity at this point 
Solved Threads: 0
marceta marceta is offline Offline
Posting Whiz in Training

Can you add pictures/sounds in a win32 console app?

 
0
  #1
May 3rd, 2004
Hi guys, im new to this forum but congratulations, i looks great

Im making a game for a TAFE class (which i will gladly send to any1). The game is a text based Role Playing Game. I am finished early so i am going to improve my current game. I was wondering whether i could add some sounds and pictures to my monsters.

struct monster
{
int strength;
int dexterity;
int hp;
char name[32];
};

That is my struct and i have an array of 4 monsters and a boss! Could i add something to the array, maybe monsterArray[].picture or monsterArray[].sound . Are there commands that allow pictures and sounds in a console application, if so can someone please tell me of them. Also feel free to get me to send you that game and/or source code!

Cheers, Peter :p
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 141
Reputation: meabed is on a distinguished road 
Solved Threads: 3
Team Colleague
meabed's Avatar
meabed meabed is offline Offline
Junior Poster

Re: Can you add pictures/sounds in a win32 console app?

 
0
  #2
May 3rd, 2004
I think that is helpful to you .
  1. # Microsoft Developer Studio Project File - Name="Sarien" - Package Owner=<4>
  2. # Microsoft Developer Studio Generated Build File, Format Version 6.00
  3.  
  4. # TARGTYPE "Win32 (x86) Console Application" 0x0103
  5.  
  6. CFG=Sarien - Win32 Debug
  7. !MESSAGE This is not a valid makefile. To build this project using NMAKE,
  8. !MESSAGE use the Export Makefile command and run
  9. !MESSAGE
  10. !MESSAGE NMAKE /f "Sarien.mak".
  11. !MESSAGE
  12. !MESSAGE You can specify a configuration when running NMAKE
  13. !MESSAGE by defining the macro CFG on the command line. For example:
  14. !MESSAGE
  15. !MESSAGE NMAKE /f "Sarien.mak" CFG="Sarien - Win32 Debug"
  16. !MESSAGE
  17. !MESSAGE Possible choices for configuration are:
  18. !MESSAGE
  19. !MESSAGE "Sarien - Win32 Release" (based on "Win32 (x86) Console Application")
  20. !MESSAGE "Sarien - Win32 Debug" (based on "Win32 (x86) Console Application")
  21. !MESSAGE
  22.  
  23. # Begin Project
  24. # PROP AllowPerConfigDependencies 0
  25. # PROP Scc_ProjName ""
  26. # PROP Scc_LocalPath ""
  27. CPP=cl.exe
  28. RSC=rc.exe
  29.  
  30. !IF "$(CFG)" == "Sarien - Win32 Release"
  31.  
  32. # PROP BASE Use_MFC 0
  33. # PROP BASE Use_Debug_Libraries 0
  34. # PROP BASE Output_Dir "Release"
  35. # PROP BASE Intermediate_Dir "Release"
  36. # PROP BASE Target_Dir ""
  37. # PROP Use_MFC 0
  38. # PROP Use_Debug_Libraries 0
  39. # PROP Output_Dir "Release"
  40. # PROP Intermediate_Dir "Release"
  41. # PROP Ignore_Export_Lib 0
  42. # PROP Target_Dir ""
  43. # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
  44. # ADD CPP /nologo /MD /W3 /GX /Zi /O1 /I "..\src\include" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "NATIVE_WIN32" /FR /YX /FD /c
  45. # ADD BASE RSC /l 0x416 /d "NDEBUG"
  46. # ADD RSC /l 0x416 /d "NDEBUG"
  47. BSC32=bscmake.exe
  48. # ADD BASE BSC32 /nologo
  49. # ADD BSC32 /nologo
  50. LINK32=link.exe
  51. # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
  52. # ADD LINK32 winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib /nologo /subsystem:windows /debug /machine:I386 /FIXED:NO
  53. # SUBTRACT LINK32 /pdb:none
  54.  
  55. !ELSEIF "$(CFG)" == "Sarien - Win32 Debug"
  56.  
  57. # PROP BASE Use_MFC 0
  58. # PROP BASE Use_Debug_Libraries 1
  59. # PROP BASE Output_Dir "Debug"
  60. # PROP BASE Intermediate_Dir "Debug"
  61. # PROP BASE Target_Dir ""
  62. # PROP Use_MFC 0
  63. # PROP Use_Debug_Libraries 1
  64. # PROP Output_Dir "Debug"
  65. # PROP Intermediate_Dir "Debug"
  66. # PROP Ignore_Export_Lib 0
  67. # PROP Target_Dir ""
  68. # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
  69. # ADD CPP /nologo /MDd /W3 /Gm /Zi /Od /I "..\SRC\INCLUDE" /D "DEBUG" /D "WIN32" /D "_WINDOWS" /D "NATIVE_WIN32" /FR /FD /GZ /c
  70. # SUBTRACT CPP /YX
  71. # ADD BASE RSC /l 0x416 /d "_DEBUG"
  72. # ADD RSC /l 0x409 /d "_DEBUG"
  73. BSC32=bscmake.exe
  74. # ADD BASE BSC32 /nologo
  75. # ADD BSC32 /nologo
  76. LINK32=link.exe
  77. # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
  78. # ADD LINK32 kernel32.lib user32.lib gdi32.lib winmm.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /incremental:no /debug /machine:I386 /pdbtype:sept /FIXED:NO
  79. # SUBTRACT LINK32 /pdb:none
  80.  
  81. !ENDIF
  82.  
  83. # Begin Target
  84.  
  85. # Name "Sarien - Win32 Release"
  86. # Name "Sarien - Win32 Debug"
  87. # Begin Group "Source Files"
  88.  
  89. # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
  90. # Begin Group "CORE_AGI"
  91.  
  92. # PROP Default_Filter "*.C"
  93. # Begin Source File
  94.  
  95. SOURCE=..\src\core\agi.c
  96. # End Source File
  97. # Begin Source File
  98.  
  99. SOURCE=..\src\core\agi_v2.c
  100. # End Source File
  101. # Begin Source File
  102.  
  103. SOURCE=..\src\core\agi_v3.c
  104. # End Source File
  105. # Begin Source File
  106.  
  107. SOURCE=..\SRC\CORE\AGI_V4.C
  108. # End Source File
  109. # Begin Source File
  110.  
  111. SOURCE=..\src\core\checks.c
  112. # End Source File
  113. # Begin Source File
  114.  
  115. SOURCE=..\src\core\console.c
  116. # End Source File
  117. # Begin Source File
  118.  
  119. SOURCE=..\src\core\cycle.c
  120. # End Source File
  121. # Begin Source File
  122.  
  123. SOURCE=..\src\core\font.c
  124. # End Source File
  125. # Begin Source File
  126.  
  127. SOURCE=..\src\core\global.c
  128. # End Source File
  129. # Begin Source File
  130.  
  131. SOURCE=..\src\core\graphics.c
  132. # End Source File
  133. # Begin Source File
  134.  
  135. SOURCE=..\src\core\id.c
  136. # End Source File
  137. # Begin Source File
  138.  
  139. SOURCE=..\SRC\CORE\INV.C
  140. # End Source File
  141. # Begin Source File
  142.  
  143. SOURCE=..\src\core\keyboard.c
  144. # End Source File
  145. # Begin Source File
  146.  
  147. SOURCE=..\src\core\logic.c
  148. # End Source File
  149. # Begin Source File
  150.  
  151. SOURCE=..\src\core\lzw.c
  152. # End Source File
  153. # Begin Source File
  154.  
  155. SOURCE=..\src\core\menu.c
  156. # End Source File
  157. # Begin Source File
  158.  
  159. SOURCE=..\src\core\motion.c
  160. # End Source File
  161. # Begin Source File
  162.  
  163. SOURCE=..\src\core\objects.c
  164. # End Source File
  165. # Begin Source File
  166.  
  167. SOURCE=..\src\core\op_cmd.c
  168. # End Source File
  169. # Begin Source File
  170.  
  171. SOURCE=..\src\core\op_dbg.c
  172. # End Source File
  173. # Begin Source File
  174.  
  175. SOURCE=..\src\core\op_test.c
  176. # End Source File
  177. # Begin Source File
  178.  
  179. SOURCE=..\src\core\patches.c
  180. # End Source File
  181. # Begin Source File
  182.  
  183. SOURCE=..\src\core\picture.c
  184. # End Source File
  185. # Begin Source File
  186.  
  187. SOURCE=..\src\core\picview.c
  188. # End Source File
  189. # Begin Source File
  190.  
  191. SOURCE=..\src\core\rand.c
  192. # End Source File
  193. # Begin Source File
  194.  
  195. SOURCE=..\src\core\savegame.c
  196. # End Source File
  197. # Begin Source File
  198.  
  199. SOURCE=..\src\core\silent.c
  200. # End Source File
  201. # Begin Source File
  202.  
  203. SOURCE=..\src\core\sound.c
  204. # End Source File
  205. # Begin Source File
  206.  
  207. SOURCE=..\src\core\sprite.c
  208. # End Source File
  209. # Begin Source File
  210.  
  211. SOURCE=..\SRC\CORE\TEXT.C
  212. # End Source File
  213. # Begin Source File
  214.  
  215. SOURCE=..\src\core\view.c
  216. # End Source File
  217. # Begin Source File
  218.  
  219. SOURCE=..\src\core\win32\winmain.c
  220. # End Source File
  221. # Begin Source File
  222.  
  223. SOURCE=..\src\core\words.c
  224. # End Source File
  225. # End Group
  226. # Begin Group "CONSOLE"
  227.  
  228. # PROP Default_Filter "*.c"
  229. # Begin Source File
  230.  
  231. SOURCE=..\src\graphics\win32\win32.c
  232. # End Source File
  233. # End Group
  234. # Begin Group "SOUND"
  235.  
  236. # PROP Default_Filter "*.C"
  237. # Begin Source File
  238.  
  239. SOURCE=..\src\sound\win32\sound_win32.c
  240. # End Source File
  241. # End Group
  242. # Begin Group "FILESYS"
  243.  
  244. # PROP Default_Filter "*.C"
  245. # Begin Source File
  246.  
  247. SOURCE=..\src\filesys\win32\fileglob.c
  248. # End Source File
  249. # Begin Source File
  250.  
  251. SOURCE=..\src\filesys\win32\path.c
  252. # End Source File
  253. # End Group
  254. # End Group
  255. # Begin Group "Header Files"
  256.  
  257. # PROP Default_Filter "h;hpp;hxx;hm;inl"
  258. # Begin Source File
  259.  
  260. SOURCE=..\src\include\agi.h
  261. # End Source File
  262. # Begin Source File
  263.  
  264. SOURCE=..\src\include\cli.h
  265. # End Source File
  266. # Begin Source File
  267.  
  268. SOURCE=..\src\include\config.h
  269. # End Source File
  270. # Begin Source File
  271.  
  272. SOURCE=..\src\include\console.h
  273. # End Source File
  274. # Begin Source File
  275.  
  276. SOURCE=..\src\include\defines.h
  277. # End Source File
  278. # Begin Source File
  279.  
  280. SOURCE=..\src\include\enums.h
  281. # End Source File
  282. # Begin Source File
  283.  
  284. SOURCE=..\src\include\font.h
  285. # End Source File
  286. # Begin Source File
  287.  
  288. SOURCE=..\src\include\getopt.h
  289. # End Source File
  290. # Begin Source File
  291.  
  292. SOURCE=..\src\include\graphics.h
  293. # End Source File
  294. # Begin Source File
  295.  
  296. SOURCE=..\src\include\id.h
  297. # End Source File
  298. # Begin Source File
  299.  
  300. SOURCE=..\src\include\includes.h
  301. # End Source File
  302. # Begin Source File
  303.  
  304. SOURCE=..\src\include\keyboard.h
  305. # End Source File
  306. # Begin Source File
  307.  
  308. SOURCE=..\src\include\logic.h
  309. # End Source File
  310. # Begin Source File
  311.  
  312. SOURCE=..\src\include\lzw.h
  313. # End Source File
  314. # Begin Source File
  315.  
  316. SOURCE=..\src\include\machine.h
  317. # End Source File
  318. # Begin Source File
  319.  
  320. SOURCE=..\src\include\menu.h
  321. # End Source File
  322. # Begin Source File
  323.  
  324. SOURCE=..\src\include\objects.h
  325. # End Source File
  326. # Begin Source File
  327.  
  328. SOURCE="..\src\include\op-cmd.h"
  329. # End Source File
  330. # Begin Source File
  331.  
  332. SOURCE="..\src\include\op-dbg.h"
  333. # End Source File
  334. # Begin Source File
  335.  
  336. SOURCE="..\src\include\op-misc.h"
  337. # End Source File
  338. # Begin Source File
  339.  
  340. SOURCE="..\src\include\op-test.h"
  341. # End Source File
  342. # Begin Source File
  343.  
  344. SOURCE=..\src\include\picture.h
  345. # End Source File
  346. # Begin Source File
  347.  
  348. SOURCE=..\src\include\rand.h
  349. # End Source File
  350. # Begin Source File
  351.  
  352. SOURCE=..\src\include\savegame.h
  353. # End Source File
  354. # Begin Source File
  355.  
  356. SOURCE=..\src\include\sound.h
  357. # End Source File
  358. # Begin Source File
  359.  
  360. SOURCE=..\src\include\typedef.h
  361. # End Source File
  362. # Begin Source File
  363.  
  364. SOURCE=..\src\include\view.h
  365. # End Source File
  366. # Begin Source File
  367.  
  368. SOURCE=..\src\include\win32.h
  369. # End Source File
  370. # Begin Source File
  371.  
  372. SOURCE=..\src\include\words.h
  373. # End Source File
  374. # End Group
  375. # Begin Group "Resource Files"
  376.  
  377. # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
  378. # Begin Source File
  379.  
  380. SOURCE=..\src\core\win32\winres.rc
  381. # End Source File
  382. # End Group
  383. # End Target
  384. # End Project
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 141
Reputation: meabed is on a distinguished road 
Solved Threads: 3
Team Colleague
meabed's Avatar
meabed meabed is offline Offline
Junior Poster

Re: Can you add pictures/sounds in a win32 console app?

 
0
  #3
May 3rd, 2004
Introduction
This article focuses on giving an example of using the DirectX API in PC game software development by using a DirectSound wrapper class.

The DirectSound wrapper class
The wrapper class has the functionality to handle various aspects of sound playback.

The structure of the wrapper class
The DirectSound object uses double buffers to manipulate the sound data processing and playback. The DirectSound object creates a single primary buffer to deal with output devices to play the sound data. The DirectSound object creates multiple second buffers to load, store various sound data, and configure sound data performance. The object loads and mixes sound data from the secondary buffers and sends the processed sound data to the primary buffer to play it through the output device.

The wrapper class contains a pointer to the DirectSound object, a primary buffer object (a pointer of type DirectSoundBuffer), and the secondary buffer array (DirectSoundBuffer object array)

DirectSound object in the wrapper class
DirectSound is a COM interface, so the DirectSound object is the COM component object (a pointer to DirectSound). The DirectSound object is the core of sound playback and all of buffers, both primary buffer and secondary buffers are created by it, so it must be instantiated before doing any sound play back.

Because the DirectSound object is a COM object, it can be instantiated by either the generic way of creation COM components, or by calling DirectSoundCreate. In my wrapper class, I find the generic method of creating a COM object is more reliable. Remember: The DirectX interfaces are a subset of the COM interfaces, so before you use them, call CoInitialize/ CoInitializeEx, and call CoUninitialize at the end of your application.

  1. // To start...
  2. BOOL CSoundManager::CoInitializeDSound(void)
  3. {
  4. HRESULT hr;
  5. GUID guID;
  6.  
  7. // Clear the GUID
  8. ::memset(&guID, 0, sizeof(GUID));
  9.  
  10. // Initialize COM service, create STA
  11. hr = ::CoInitialize(NULL);
  12. .................................
  13. .................................
  14. // Create the IDirectSound object with the realiable way (create
  15. // standard COM object)
  16. hr = CoCreateInstance(CLSID_DirectSound, NULL, CLSCTX_INPROC_SERVER,
  17. IID_IDirectSound, (void**)&m_pIDS);
  18. .................................
  19. ................................
  20. // Initialize the IDirectSound object
  21. hr = IDirectSound_Initialize(m_pIDS, &guID);
  22. .................................
  23. .................................
  24. return TRUE;
  25. }
  26.  
  27. // To finish up...
  28. void CSoundManager::CoUnInitializeDSound(void)
  29. {
  30. if(m_pIDS)
  31. {
  32. m_pIDS->Release();
  33. m_pIDS = NULL;
  34. ::CoUninitialize();
  35. }
  36. }

Primary Buffer
The primary buffer is a DirectSoundBuffer object, and its main task is to receive the processed sound data from the DirectSound object and send it to the output device to play. The primary’s format settings determine the sound play effect of the output device. The primary’s format is a WAVEFORMATEX structure and must be set before play.

Second Buffer
The second buffer loads sound data and sets the sound performance, then sends the sound to the DirectSound object. The second buffer is a DirectSoundBuffer object and is created by the DirectSound object.

In my library, I use a wrapper class of DirectSoundBuffer for the second buffer. This wrapper class has the DirectSoundBuffer object, and the methods to set sound performances, such as adjustment of volume, frequency and channel.

A special feature of the DirectSoundBuffer wrapper class is the special sound effect of Fade-In (volume up step by step) and Fade-Out (volume down step by step).

To avoid the concurrency of incoming function calls, a mutex object is used in the DirectSoundBuffer wrapper class to synchronize the function calls.

Timer Event
The DirectSound wrapper class needs a timer to monitor and manipulate the sound status and performance in a special time interval. The DirectSound wrapper class is a generic class, so it is hard to use a windows timer in the class. As an alternative, a waitable timer is used in the class. A thread is created to check the timer event when the class object is instantiated.

The test program
The test program is a Dialog box application written in MFC. It tests the various wrapper class features, such as volume, frequency, channel, looping, mixing and fade-in and fade-out, etc.
Attached Files
File Type: zip dxsnd.zip (375.3 KB, 34 views)
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 141
Reputation: meabed is on a distinguished road 
Solved Threads: 3
Team Colleague
meabed's Avatar
meabed meabed is offline Offline
Junior Poster

Re: Can you add pictures/sounds in a win32 console app?

 
0
  #4
May 3rd, 2004
Introduction
Loading images under windows can always be a painful process, especially if the image formats are like JPEG, GIF or PNG. There's always the Imgdecmp library, that does a good job, but its also a bit of a bother with the documentation being so thin and all that. The other day I was trying to load a bitmap from my device using LoadImage, but somehow I kept getting the dreaded "The handle is invalid" error. So I did a search on the MFC code that ships with the PPC SDK in hope of finding a piece of code that will help me solve the puzzle.

One thing led to another. I suddenly came across HBITMAP SHLoadImageFile(LPCTSTR pszFileName) in aygshell.h. Bingo! I had suddenly uncovered an undocumented API! No trace of it in MSDN, a search in Google produced nothing!! Since then, I've tried this API with gif's and bmp's also and I guess it will work fine for jpeg's and png's too. Here's a code sample...

  1. // assuming code is in the OnDraw method of a view....
  2.  
  3. CBitmap bitmap;
  4.  
  5. // Attach the bitmap object to the HBITMAP returned by SHLoadImageFile
  6. bitmap.Attach(SHLoadImageFile(_T("/My Documents/mcdonalds.gif")));
  7.  
  8. BITMAP bmpInfo;
  9. bitmap.GetBitmap(&bmpInfo);
  10.  
  11. CDC bitmapDC;
  12. bitmapDC.CreateCompatibleDC(pDC);
  13. CBitmap* pOldBitmap = bitmapDC.SelectObject(&bitmap);
  14.  
  15. pDC->BitBlt(0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, &bitmapDC,
  16. 0, 0, SRCCOPY);
  17.  
  18. bitmapDC.SelectObject(pOldBitmap);
  19. bitmap.DeleteObject();

That's all for now.
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 217
Reputation: marceta is an unknown quantity at this point 
Solved Threads: 0
marceta marceta is offline Offline
Posting Whiz in Training

Re: Can you add pictures/sounds in a win32 console app?

 
0
  #5
May 4th, 2004
umm... THX a lot for trying mate but im not really that advanced at programming yet (im makinging a DOS 32 app thing). Ive included my source code (so far), if anyone could have a look and tell me if i could do this i would really appreciate it! Also any other suggestions to improve it would be greatly appreciated!
Attached Files
File Type: cpp Hannibals_Castle.cpp (15.4 KB, 25 views)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC