Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5310 lines
163 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // MAIN.CPP
  4. //
  5. // Main window of multimedia framework
  6. //
  7. // Copyright (c) Microsoft Corporation 1997
  8. //
  9. // 12/14/97 David Stewart / dstewart
  10. //
  11. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  12. #include <windows.h>
  13. #include <windowsx.h>
  14. #include <commctrl.h>
  15. #include <TCHAR.H>
  16. #include "resource.h"
  17. #include "objbase.h"
  18. #include "initguid.h"
  19. #include "sink.h"
  20. #include "dib.h"
  21. #include "resource.h"
  22. #include "mbutton.h"
  23. #include "knob.h"
  24. #include "winuser.h"
  25. #include "img.h"
  26. #include "frame.h"
  27. #include <htmlhelp.h>
  28. #include "..\cdopt\cdopt.h"
  29. #include "..\cdnet\cdnet.h"
  30. #include "mmenu.h"
  31. #include <stdio.h>
  32. #include "shellico.h"
  33. #include <shellapi.h>
  34. #include "..\cdplay\playres.h"
  35. #include "wininet.h"
  36. //Support for new WM_DEVICECHANGE behaviour in NT5
  37. /////////////////////////////////////////////////
  38. #include <objbase.h>
  39. #include <setupapi.h>
  40. #include <cfgmgr32.h>
  41. #include <initguid.h>
  42. #include <dbt.h>
  43. #include <devguid.h>
  44. #include <mmddkp.h>
  45. #include <ks.h>
  46. #include <ksmedia.h>
  47. HDEVNOTIFY DeviceEventContext = NULL;
  48. BOOL bUseHandle = FALSE; //Indicates whether a handle is being used for device notification,
  49. //instead of the general KSCATEGORY_AUDIO
  50. BOOL Volume_DeviceChange_Init(HWND hWnd, DWORD dwMixerID);
  51. void Volume_DeviceChange_Cleanup();
  52. //////////////////////////////////////////////////////
  53. //////////////////////////////////////////////////////
  54. // Next 2 lines added to add multimon support
  55. #define COMPILE_MULTIMON_STUBS
  56. #include "multimon.h"
  57. ////////////////////////////////////////////////////////////////////////////////////////////
  58. // #defines for main ui and call-downs to cd player unit
  59. #define IDC_LEDWINDOW IDC_LED
  60. #define WM_LED_INFO_PAINT (WM_USER+2000) //wparam = bool (allow self-draw), lparam = vol info
  61. #define WM_LED_MUTE (WM_USER+2001) //wparam = unused, lparam = bool (mute)
  62. #define WM_LED_DOWNLOAD (WM_USER+2002) //wparam = unused, lparam = download flag
  63. //command ids from cdplayer
  64. #define ID_CDUPDATE IDM_NET_CD
  65. //battery power limit, stated as a percentage
  66. #define BATTERY_PERCENTAGE_LIMIT 10
  67. //helpers for detecting where the mouse is hitting
  68. #define TITLEBAR_HEIGHT 15
  69. #define TITLEBAR_YOFFSET_LARGE 7
  70. #define TITLEBAR_YOFFSET_SMALL 4
  71. #define SYSMENU_XOFFSET 7
  72. #define SYSMENU_WIDTH 12
  73. //volume bar timer stuff
  74. #define VOLUME_PERSIST_TIMER_RATE 2000
  75. #define VOLUME_PERSIST_TIMER_EVENT 1000
  76. #define SYSTIMERID 1001
  77. //don't remove the parens on these, or My Dear Aunt Sally will getcha
  78. #define IDM_HOMEMENU_BASE (LAST_SEARCH_MENU_ID + 1)
  79. #define IDM_NETMENU_BASE (LAST_SEARCH_MENU_ID + 100)
  80. #define IDM_TRACKLIST_BASE 10000
  81. #define IDM_DISCLIST_BASE 20000
  82. #define TYPICAL_DISPLAY_AREA 48 //this value is the offset for large fonts
  83. #define EDGE_CURVE_WIDTH 24
  84. #define EDGE_CURVE_HEIGHT 26
  85. #define VENDORLOGO_WIDTH 44
  86. #define VENDORLOGO_HEIGHT 22
  87. #define LOGO_Y_OFFSET 10
  88. //if button is re-hit within the time limit, don't allow it to trigger
  89. #define MENU_TIMER_RATE 400
  90. //ie autosearch url
  91. #define REG_KEY_SEARCHURL TEXT("Software\\Microsoft\\Internet Explorer\\SearchUrl")
  92. #define REG_KEY_SHELLSETTINGS REG_KEY_NEW_FRAMEWORK TEXT("\\Settings")
  93. #define REG_KEY_SHELLENABLE TEXT("Tray")
  94. #define PLAYCOMMAND1 TEXT("/play")
  95. #define PLAYCOMMAND2 TEXT("-play")
  96. #define TRAYCOMMAND1 TEXT("/tray")
  97. #define TRAYCOMMAND2 TEXT("-tray")
  98. //////////////////////////////////////////////////////////////////////////////////////
  99. // Gradient stuff
  100. #ifndef SPI_GETGRADIENTCAPTIONS
  101. //from nt50 version of winuser.h
  102. #define SPI_GETGRADIENTCAPTIONS 0x1008
  103. #define COLOR_GRADIENTACTIVECAPTION 27
  104. #define COLOR_GRADIENTINACTIVECAPTION 28
  105. #endif
  106. typedef BOOL (WINAPI *GRADIENTPROC)(HDC,PTRIVERTEX,ULONG,PUSHORT,ULONG,ULONG);
  107. ////////////////////////////////////////////////////////////////////////////////////////////
  108. // Main functions in this file, forward-declared
  109. LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
  110. BOOL LoadComponents(void);
  111. void AddComponent(IMMComponent*);
  112. void CleanUp(void);
  113. void InitComponents(HWND);
  114. BOOL CreateToolTips(HWND);
  115. ////////////////////////////////////////////////////////////////////////////////////////////
  116. // Globals to this file
  117. //Component information ... we only have one component now ...
  118. //this is in here to handle eventual move to multi-component design
  119. PCOMPNODE pCompList = NULL; //head of component list
  120. PCOMPNODE pCompListTail = NULL; //tail of component list
  121. PCOMPNODE pNodeCurrent = NULL; //currently selected component
  122. int nNumComps = 0; //number of components
  123. HWND hwndCurrentComp = NULL; //window handle of current component
  124. HINSTANCE hInst = NULL; //global instance of exe
  125. int g_nColorMode = COLOR_VERYHI; //global containing color mode (hi contract, 16 color, etc)
  126. HWND hwndMain = NULL; //main window handle
  127. HWND g_hwndTT = NULL; //tooltips
  128. HHOOK g_hhk = NULL; //tooltips message hook
  129. TCHAR g_tooltext[MAX_PATH]; //tooltip text holder
  130. HANDLE hbmpMain = NULL; //main window bitmap, normal size
  131. HANDLE hbmpMainRestore = NULL; //main window bitmap, restored size
  132. HANDLE hbmpMainSmall = NULL; //main window bitmap, small size
  133. HANDLE hbmpMainNoBar = NULL; //main window bitmap, normal with no title bar
  134. BITMAP bmMain; //bitmap metrics for normal size
  135. BITMAP bmMainRestore; //bitmap metrics for restored size
  136. BITMAP bmMainSmall; //bitmap metrics for small size
  137. BITMAP bmMainNoBar; //bitmap metrics for no bar size
  138. HPALETTE hpalMain = NULL; //Palette of application
  139. BOOL fPlaying = FALSE; //Play state of CD for play/pause
  140. BOOL fIntro = FALSE; //Intro mode state
  141. BOOL fShellMode = FALSE; //are we in shell icon mode?
  142. int nCDMode = IDM_MODE_NORMAL; //Current mode of CD (starts on normal mode)
  143. int nDispAreaOffset = 0; //Display area offset for large font mode
  144. CustomMenu* g_pMenu = NULL; //Pointer to current custom menu
  145. UINT nLastMenu = 0; //ID of last button to display a menu
  146. BOOL fBlockMenu = 0; //Flag to block menu re-entry
  147. BOOL fOptionsDlgUp = FALSE; //is options dialog active?
  148. LPCDTITLE pSingleTitle = NULL; //Disc ID for a direct download from tree control
  149. LPCDOPT g_pOptions = NULL; //for download callbacks when dialog is up
  150. LPCDDATA g_pData = NULL; //for callbacks to cd when dialog is up
  151. TCHAR szAppName[MAX_PATH/2]; //IDS_APPNAME "Deluxe CD Player"
  152. DWORD dwLastMixID = (DWORD)-1; //Last mixer ID
  153. HMIXEROBJ hmix = NULL; //current open mixer handle
  154. TCHAR szLineName[MIXER_LONG_NAME_CHARS];//current volume line name
  155. MIXERCONTROLDETAILS mixerlinedetails; //current volume details
  156. MIXERCONTROLDETAILS mutelinedetails; //current mute details
  157. DWORD mixervalue[2]; //current volume level
  158. LONG lCachedBalance = 0; //last balance level
  159. BOOL fmutevalue; //current mute value
  160. HANDLE hMutex = NULL; //hMutex to prevent multiple instances of EXE
  161. int g_nViewMode = VIEW_MODE_NORMAL; //view mode setting (default to normal)
  162. WORD wDefButtonID = IDB_OPTIONS; //default button
  163. HCURSOR hCursorMute = NULL; //mute button cursor
  164. HMODULE hmImage = NULL; //module handle of dll with gradient function
  165. GRADIENTPROC fnGradient = NULL; //gradient function
  166. UINT g_uTaskbarRestart = 0; //registered message for taskbar re-creation
  167. UINT giVolDevChange = 0; //registered message for mmsystem device change
  168. #ifdef UNICODE
  169. #define CANONFUNCTION "InternetCanonicalizeUrlW"
  170. #else
  171. #define CANONFUNCTION "InternetCanonicalizeUrlA"
  172. #endif
  173. ////////////////////////////////////////////////////////////////////////////////////////////
  174. // Structures and defines for custom button controls
  175. #define NUM_BUTTONS 16
  176. typedef struct BUTTONINFO
  177. {
  178. int id; //id of control
  179. POINT uixy; //x, y location on screen
  180. POINT uixy2; //x, y location when restored or small
  181. int width; //width of control in bitmap and on screen
  182. int height; //height of control in bitmap and on screen
  183. int width2; //width of control on screen when restored
  184. int nIconID; //id of icon, if any
  185. int nToolTipID; //id of tooltip string
  186. BOOL fBlockTab; //true = don't tab stop here
  187. DWORD dwStyle; //style for toolkit, see mbutton.h
  188. } BUTTONINFO, *LPBUTTONINFO;
  189. BUTTONINFO biButtons[NUM_BUTTONS];
  190. ////////////////////////////////////////////////////////////////////////////////////////////
  191. // * GetSettings
  192. // Reads the x and y positions of app for startup
  193. // Also gets the view mode
  194. ////////////////////////////////////////////////////////////////////////////////////////////
  195. void GetSettings(int& x, int& y)
  196. {
  197. x = CW_USEDEFAULT;
  198. y = CW_USEDEFAULT;
  199. g_nViewMode = VIEW_MODE_NORMAL;
  200. LPCDOPT pOpt = GetCDOpt();
  201. if( pOpt )
  202. {
  203. LPCDOPTIONS pOptions = pOpt->GetCDOpts();
  204. LPCDOPTDATA pOptionData = pOptions->pCDData;
  205. x = pOptionData->dwWindowX;
  206. y = pOptionData->dwWindowY;
  207. g_nViewMode = pOptionData->dwViewMode;
  208. nCDMode = pOptionData->dwPlayMode;
  209. if (nCDMode < IDM_MODE_NORMAL)
  210. {
  211. nCDMode = IDM_MODE_NORMAL;
  212. }
  213. }
  214. }
  215. ////////////////////////////////////////////////////////////////////////////////////////////
  216. // * SetSettings
  217. // Sets X, Y and view mode of app on shutdown
  218. ////////////////////////////////////////////////////////////////////////////////////////////
  219. void SetSettings(int x, int y)
  220. {
  221. LPCDOPT pOpt = GetCDOpt();
  222. if(pOpt)
  223. {
  224. LPCDOPTIONS pOptions = pOpt->GetCDOpts();
  225. LPCDOPTDATA pOptionData = pOptions->pCDData;
  226. pOptionData->dwWindowX = x;
  227. pOptionData->dwWindowY = y;
  228. pOptionData->dwViewMode = g_nViewMode;
  229. pOptionData->dwPlayMode = nCDMode;
  230. pOpt->UpdateRegistry();
  231. }
  232. }
  233. ////////////////////////////////////////////////////////////////////////////////////////////
  234. // * GetXOffset
  235. // Returns 0 normally, or size of a single border if captions are turned on
  236. ////////////////////////////////////////////////////////////////////////////////////////////
  237. int GetXOffset()
  238. {
  239. #ifndef MMFW_USE_CAPTION
  240. return 0;
  241. #else
  242. return GetSystemMetrics(SM_CXFIXEDFRAME);
  243. #endif
  244. }
  245. ////////////////////////////////////////////////////////////////////////////////////////////
  246. // * GetYOffset
  247. // Returns 0 normally, or size of a single border if captions are turned on
  248. ////////////////////////////////////////////////////////////////////////////////////////////
  249. int GetYOffset()
  250. {
  251. #ifndef MMFW_USE_CAPTION
  252. return 0;
  253. #else
  254. return GetSystemMetrics(SM_CYFIXEDFRAME);
  255. #endif
  256. }
  257. ////////////////////////////////////////////////////////////////////////////////////////////
  258. // * GetYOffsetCaption
  259. // Returns 0 normally, or size of a caption if captions are turned on
  260. ////////////////////////////////////////////////////////////////////////////////////////////
  261. int GetYOffsetCaption()
  262. {
  263. #ifndef MMFW_USE_CAPTION
  264. return 0;
  265. #else
  266. return GetSystemMetrics(SM_CYCAPTION);
  267. #endif
  268. }
  269. ////////////////////////////////////////////////////////////////////////////////////////////
  270. // * DetermineColorMode
  271. // Sets the g_nColorMode variable for use in creating the bumps for the app
  272. ////////////////////////////////////////////////////////////////////////////////////////////
  273. void DetermineColorMode()
  274. {
  275. g_nColorMode = COLOR_VERYHI;
  276. HDC hdcScreen = GetDC(NULL);
  277. UINT uBPP = GetDeviceCaps(hdcScreen, PLANES) * GetDeviceCaps(hdcScreen, BITSPIXEL);
  278. ReleaseDC(NULL, hdcScreen);
  279. switch (uBPP)
  280. {
  281. case 8 :
  282. {
  283. g_nColorMode = COLOR_256;
  284. }
  285. break;
  286. case 4 :
  287. {
  288. g_nColorMode = COLOR_16;
  289. }
  290. break;
  291. case 2 :
  292. {
  293. g_nColorMode = COLOR_HICONTRAST;
  294. }
  295. break;
  296. }
  297. //check directly for accessibility mode
  298. HIGHCONTRAST hi_con;
  299. ZeroMemory(&hi_con,sizeof(hi_con));
  300. hi_con.cbSize = sizeof(hi_con);
  301. SystemParametersInfo(SPI_GETHIGHCONTRAST,sizeof(hi_con),&hi_con,0);
  302. if (hi_con.dwFlags & HCF_HIGHCONTRASTON)
  303. {
  304. g_nColorMode = COLOR_HICONTRAST;
  305. }
  306. }
  307. ////////////////////////////////////////////////////////////////////////////////////////////
  308. // * SetPalette
  309. // Sets the palette for the app, generated from all bitmaps in the application and DLLs
  310. ////////////////////////////////////////////////////////////////////////////////////////////
  311. HPALETTE SetPalette()
  312. {
  313. #define NUMPALCOLORS 94
  314. BYTE byVals[NUMPALCOLORS][3] = {
  315. 6, 6, 6,
  316. 18, 19, 45,
  317. 25, 40, 1,
  318. 17, 46, 46,
  319. 49, 7, 7,
  320. 45, 52, 3,
  321. 49, 49, 49,
  322. 24, 24, 91,
  323. 0, 90, 8,
  324. 1, 108, 5,
  325. 55, 67, 2,
  326. 33, 76, 76,
  327. 94, 29, 24,
  328. 102, 18, 102,
  329. 93, 94, 23,
  330. 78, 78, 78,
  331. 84, 84, 108,
  332. 78, 111, 111,
  333. 109, 80, 80,
  334. 108, 107, 79,
  335. 120, 120, 120,
  336. 15, 9, 157,
  337. 17, 8, 246,
  338. 55, 93, 175,
  339. 20, 91, 231,
  340. 83, 39, 167,
  341. 92, 16, 223,
  342. 96, 94, 150,
  343. 88, 87, 217,
  344. 0, 157, 15,
  345. 0, 153, 51,
  346. 0, 190, 18,
  347. 10, 155, 120,
  348. 6, 252, 17,
  349. 9, 236, 92,
  350. 127, 135, 35,
  351. 83, 142, 117,
  352. 92, 241, 21,
  353. 87, 223, 81,
  354. 14, 171, 171,
  355. 39, 147, 223,
  356. 18, 252, 157,
  357. 15, 244, 236,
  358. 87, 137, 136,
  359. 80, 184, 184,
  360. 112, 141, 141,
  361. 106, 170, 153,
  362. 119, 171, 168,
  363. 87, 155, 213,
  364. 101, 218, 170,
  365. 90, 233, 226,
  366. 154, 19, 24,
  367. 155, 26, 109,
  368. 138, 116, 8,
  369. 170, 98, 101,
  370. 243, 18, 6,
  371. 245, 10, 96,
  372. 233, 89, 17,
  373. 229, 103, 101,
  374. 154, 39, 161,
  375. 163, 26, 249,
  376. 158, 77, 159,
  377. 149, 94, 254,
  378. 234, 20, 160,
  379. 234, 29, 242,
  380. 233, 76, 163,
  381. 218, 81, 244,
  382. 163, 151, 10,
  383. 157, 156, 102,
  384. 164, 214, 45,
  385. 165, 242, 87,
  386. 223, 174, 17,
  387. 228, 160, 77,
  388. 242, 232, 15,
  389. 233, 218, 102,
  390. 138, 138, 138,
  391. 142, 141, 176,
  392. 148, 180, 180,
  393. 174, 141, 140,
  394. 169, 130, 168,
  395. 181, 179, 136,
  396. 176, 176, 177,
  397. 172, 170, 220,
  398. 133, 207, 177,
  399. 171, 236, 233,
  400. 231, 169, 157,
  401. 252, 170, 253,
  402. 247, 243, 168,
  403. 202, 204, 204,
  404. 201, 201, 243,
  405. 208, 238, 238,
  406. 246, 212, 212,
  407. 248, 244, 198,
  408. 250, 250, 250
  409. };
  410. struct
  411. {
  412. LOGPALETTE lp;
  413. PALETTEENTRY ape[NUMPALCOLORS-1];
  414. } pal;
  415. LOGPALETTE* pLP = (LOGPALETTE*)&pal;
  416. pLP->palVersion = 0x300;
  417. pLP->palNumEntries = NUMPALCOLORS;
  418. for (int i = 0; i < pLP->palNumEntries; i++)
  419. {
  420. pLP->palPalEntry[i].peRed = byVals[i][0];
  421. pLP->palPalEntry[i].peGreen = byVals[i][1];
  422. pLP->palPalEntry[i].peBlue = byVals[i][2];
  423. pLP->palPalEntry[i].peFlags = 0;
  424. }
  425. return (CreatePalette(pLP));
  426. }
  427. ////////////////////////////////////////////////////////////////////////////////////////////
  428. // * GetCurrentCDDrive
  429. // returns the drive number of the cd that is currently selected in the cdplayer ui
  430. ////////////////////////////////////////////////////////////////////////////////////////////
  431. int GetCurrentCDDrive()
  432. {
  433. IMMComponentAutomation* pAuto = NULL;
  434. HRESULT hr = pNodeCurrent->pComp->QueryInterface(IID_IMMComponentAutomation,(void**)&pAuto);
  435. if ((SUCCEEDED(hr)) && (pAuto != NULL))
  436. {
  437. MMMEDIAID mmMedia;
  438. mmMedia.nDrive = -1;
  439. pAuto->OnAction(MMACTION_GETMEDIAID,&mmMedia);
  440. pAuto->Release();
  441. return (mmMedia.nDrive);
  442. }
  443. return -1;
  444. }
  445. ////////////////////////////////////////////////////////////////////////////////////////////
  446. // * InitCDVol
  447. // Sets up the mixer structures for the current cd drive
  448. ////////////////////////////////////////////////////////////////////////////////////////////
  449. BOOL InitCDVol(HWND hwndCallback, LPCDOPTIONS pCDOpts)
  450. {
  451. //figure out which drive we're on
  452. int nDrive = GetCurrentCDDrive();
  453. //return if the drive is bogus
  454. if (nDrive < 0)
  455. {
  456. return FALSE;
  457. }
  458. //get the cdunit info from the options
  459. CDUNIT* pCDUnit = pCDOpts->pCDUnitList;
  460. //scan the list to find the one we want
  461. for (int index = 0; index < nDrive; index++)
  462. {
  463. pCDUnit = pCDUnit->pNext;
  464. }
  465. //check to see if we already have an open mixer
  466. if (hmix!=NULL)
  467. {
  468. //we've been here before ... may not need to be here now,
  469. //if both the mixer id and the control id are the same
  470. if ((dwLastMixID == pCDUnit->dwMixID) &&
  471. (mixerlinedetails.dwControlID == pCDUnit->dwVolID))
  472. {
  473. return FALSE;
  474. }
  475. //a change is coming, go ahead and close this mixer
  476. mixerClose((HMIXER)hmix);
  477. }
  478. //remember our last mixer id
  479. dwLastMixID = pCDUnit->dwMixID;
  480. //open the mixer
  481. mixerOpen((HMIXER*)(&hmix),pCDUnit->dwMixID,(DWORD_PTR)hwndCallback,0,CALLBACK_WINDOW|MIXER_OBJECTF_MIXER);
  482. Volume_DeviceChange_Init(hwndCallback, pCDUnit->dwMixID);
  483. MIXERLINE mlDst;
  484. MMRESULT mmr;
  485. int newDest;
  486. ZeroMemory(&mlDst, sizeof(mlDst));
  487. mlDst.cbStruct = sizeof(mlDst);
  488. mlDst.dwDestination = pCDUnit->dwMixID;
  489. mmr = mixerGetLineInfo((HMIXEROBJ)hmix
  490. , &mlDst
  491. , MIXER_GETLINEINFOF_DESTINATION);
  492. //save the details of the volume line
  493. mixerlinedetails.cbStruct = sizeof(mixerlinedetails);
  494. mixerlinedetails.dwControlID = pCDUnit->dwVolID;
  495. mixerlinedetails.cChannels = mlDst.cChannels;
  496. mixerlinedetails.hwndOwner = 0;
  497. mixerlinedetails.cMultipleItems = 0;
  498. mixerlinedetails.cbDetails = sizeof(mixervalue);
  499. mixerlinedetails.paDetails = &mixervalue[0];
  500. //save the details of the mute line
  501. mutelinedetails.cbStruct = sizeof(mutelinedetails);
  502. mutelinedetails.dwControlID = pCDUnit->dwMuteID;
  503. mutelinedetails.cChannels = 1;
  504. mutelinedetails.hwndOwner = 0;
  505. mutelinedetails.cMultipleItems = 0;
  506. mutelinedetails.cbDetails = sizeof(fmutevalue);
  507. mutelinedetails.paDetails = &fmutevalue;
  508. //save the name of the volume line
  509. _tcscpy(szLineName,pCDUnit->szVolName);
  510. return TRUE;
  511. }
  512. ////////////////////////////////////////////////////////////////////////////////////////////
  513. // * GetVolume
  514. ////////////////////////////////////////////////////////////////////////////////////////////
  515. DWORD GetVolume()
  516. {
  517. //get the value of this mixer control line
  518. ZeroMemory(mixervalue,sizeof(DWORD)*2);
  519. mixerGetControlDetails(hmix,&mixerlinedetails,MIXER_GETCONTROLDETAILSF_VALUE);
  520. return ((mixervalue[0] > mixervalue[1]) ? mixervalue[0] : mixervalue[1]);
  521. }
  522. ////////////////////////////////////////////////////////////////////////////////////////////
  523. // * SetVolume
  524. ////////////////////////////////////////////////////////////////////////////////////////////
  525. void SetVolume(DWORD dwVol)
  526. {
  527. LONG lBalance = 0;
  528. //if this is a stereo device, we need to check the balance
  529. if (mixerlinedetails.cChannels > 1)
  530. {
  531. ZeroMemory(mixervalue,sizeof(DWORD)*2);
  532. mixerGetControlDetails(hmix,&mixerlinedetails,MIXER_GETCONTROLDETAILSF_VALUE);
  533. LONG lDiv = (LONG)(max(mixervalue[0], mixervalue[1]) - 0);
  534. //
  535. // if we're pegged, don't try to calculate the balance.
  536. //
  537. if (mixervalue[0] == 0 && mixervalue[1] == 0)
  538. lBalance = lCachedBalance;
  539. else if (mixervalue[0] == 0)
  540. lBalance = 32;
  541. else if (mixervalue[1] == 0)
  542. lBalance = -32;
  543. else if (lDiv > 0)
  544. {
  545. lBalance = (32 * ((LONG)mixervalue[1]-(LONG)mixervalue[0]))
  546. / lDiv;
  547. //
  548. // we always lose precision doing this.
  549. //
  550. if (lBalance > 0) lBalance++;
  551. if (lBalance < 0) lBalance--;
  552. //if we lost precision above, we can get it back by checking
  553. //the previous value of our balance. We're usually only off by
  554. //one if this is the result of a rounding error. Otherwise,
  555. //we probably have a different balance because the user set it.
  556. if (((lCachedBalance - lBalance) == 1) ||
  557. ((lCachedBalance - lBalance) == -1))
  558. {
  559. lBalance = lCachedBalance;
  560. }
  561. }
  562. else
  563. lBalance = 0;
  564. }
  565. //save this balance setting so we can use it if we're pegged later
  566. lCachedBalance = lBalance;
  567. //
  568. // Recalc channels based on Balance vs. Volume
  569. //
  570. mixervalue[0] = dwVol;
  571. mixervalue[1] = dwVol;
  572. if (lBalance > 0)
  573. mixervalue[0] -= (lBalance * (LONG)(mixervalue[1]-0))
  574. / 32;
  575. else if (lBalance < 0)
  576. mixervalue[1] -= (-lBalance * (LONG)(mixervalue[0]-0))
  577. / 32;
  578. mixerSetControlDetails(hmix,&mixerlinedetails,MIXER_SETCONTROLDETAILSF_VALUE);
  579. }
  580. ////////////////////////////////////////////////////////////////////////////////////////////
  581. // * GetMute
  582. ////////////////////////////////////////////////////////////////////////////////////////////
  583. BOOL GetMute()
  584. {
  585. if (mutelinedetails.dwControlID != DWORD(-1))
  586. {
  587. mixerGetControlDetails(hmix,&mutelinedetails,MIXER_GETCONTROLDETAILSF_VALUE);
  588. }
  589. else
  590. {
  591. //mixer line doesn't exist, assume not muted
  592. fmutevalue = FALSE;
  593. }
  594. return (fmutevalue);
  595. }
  596. ////////////////////////////////////////////////////////////////////////////////////////////
  597. // * SetMute
  598. // Implemented as a toggle from current state
  599. ////////////////////////////////////////////////////////////////////////////////////////////
  600. void SetMute()
  601. {
  602. if (mutelinedetails.dwControlID != DWORD(-1))
  603. {
  604. if (GetMute())
  605. {
  606. //muted, so unmute
  607. fmutevalue = FALSE;
  608. mixerSetControlDetails(hmix,&mutelinedetails,MIXER_SETCONTROLDETAILSF_VALUE);
  609. }
  610. else
  611. {
  612. //not muted, so mute
  613. fmutevalue = TRUE;
  614. MMRESULT mmr = mixerSetControlDetails(hmix,&mutelinedetails,MIXER_SETCONTROLDETAILSF_VALUE);
  615. }
  616. }
  617. }
  618. ////////////////////////////////////////////////////////////////////////////////////////////
  619. // * CanStartShell()
  620. // Checks to see if we can launch if wanting to do so in shell mode
  621. // Returns FALSE only if asking for "tray mode" and if reg setting is FALSE (or not present)
  622. ////////////////////////////////////////////////////////////////////////////////////////////
  623. BOOL CanStartShell()
  624. {
  625. BOOL retval = TRUE; //default to allowing launch
  626. fShellMode = FALSE;
  627. //if asking for permission to launch try, see if the registry setting is there
  628. HKEY hKeySettings;
  629. long lResult = ::RegOpenKeyEx( HKEY_CURRENT_USER,
  630. REG_KEY_SHELLSETTINGS,
  631. 0, KEY_READ, &hKeySettings );
  632. if (lResult == ERROR_SUCCESS)
  633. {
  634. DWORD fEnable = FALSE;
  635. DWORD dwType = REG_DWORD;
  636. DWORD dwCbData = sizeof(fEnable);
  637. lResult = ::RegQueryValueEx( hKeySettings, REG_KEY_SHELLENABLE, NULL,
  638. &dwType, (LPBYTE)&fEnable, &dwCbData );
  639. if (fEnable)
  640. {
  641. fShellMode = TRUE;
  642. }
  643. RegCloseKey(hKeySettings);
  644. //check for the query on the command line
  645. TCHAR szCommand[MAX_PATH];
  646. _tcscpy(szCommand,GetCommandLine());
  647. _tcslwr(szCommand);
  648. if ((_tcsstr(szCommand,TRAYCOMMAND1) != NULL)
  649. ||
  650. (_tcsstr(szCommand,TRAYCOMMAND2) != NULL))
  651. {
  652. //user wants to check try status ... base on fenable
  653. retval = (BOOL)fEnable;
  654. }
  655. } //end if regkey
  656. return (retval);
  657. }
  658. ////////////////////////////////////////////////////////////////////////////////////////////
  659. // * ShellOnly()
  660. // Returns TRUE if we should not make the main UI visible.
  661. ////////////////////////////////////////////////////////////////////////////////////////////
  662. BOOL ShellOnly()
  663. {
  664. BOOL retval = FALSE;
  665. if (fShellMode)
  666. {
  667. //check for the query on the command line
  668. TCHAR szCommand[MAX_PATH];
  669. _tcscpy(szCommand,GetCommandLine());
  670. _tcslwr(szCommand);
  671. if ((_tcsstr(szCommand,TRAYCOMMAND1) != NULL)
  672. ||
  673. (_tcsstr(szCommand,TRAYCOMMAND2) != NULL))
  674. {
  675. retval = TRUE;
  676. }
  677. }
  678. return (retval);
  679. }
  680. ////////////////////////////////////////////////////////////////////////////////////////////
  681. // * IsOnlyInstance
  682. // Check to see if this is the only instance, based on the webcd mutex
  683. ////////////////////////////////////////////////////////////////////////////////////////////
  684. BOOL IsOnlyInstance()
  685. {
  686. hMutex = CreateMutex(NULL,TRUE,WEBCD_MUTEX);
  687. if (GetLastError()==ERROR_ALREADY_EXISTS)
  688. {
  689. if (hMutex!=NULL)
  690. {
  691. ReleaseMutex(hMutex);
  692. CloseHandle(hMutex);
  693. hMutex = NULL;
  694. }
  695. //send the command line to the app that is already running
  696. HWND hwndFind = FindWindow(FRAMEWORK_CLASS, NULL);
  697. if (hwndFind)
  698. {
  699. //we only want to do this if NOT "autoplayed" ... that is, if /play is on the
  700. //command line, don't refocus us ... see bug 1244
  701. //(the old cdplayer implements it this way, too!)
  702. TCHAR szCommand[MAX_PATH];
  703. _tcscpy(szCommand,GetCommandLine());
  704. _tcslwr(szCommand);
  705. if ((_tcsstr(szCommand,PLAYCOMMAND1) == NULL)
  706. &&
  707. (_tcsstr(szCommand,PLAYCOMMAND2) == NULL))
  708. {
  709. //get the most recent "child" window
  710. hwndFind = GetLastActivePopup(hwndFind);
  711. //bring the window up if it is iconic
  712. if (IsIconic(hwndFind))
  713. {
  714. ShowWindow(hwndFind,SW_RESTORE);
  715. }
  716. //display the window
  717. ShowWindow(hwndFind,SW_SHOW); //this "wakes up" if in shell mode in other inst.
  718. BringWindowToTop(hwndFind);
  719. SetForegroundWindow(hwndFind);
  720. }
  721. //forward the command line found to the second instance,
  722. //only if it is NOT an "autoplay" message -- we'll scan that instead
  723. TCHAR tempCmdLine[MAX_PATH];
  724. _tcscpy(tempCmdLine,GetCommandLine());
  725. if (_tcslen(tempCmdLine) > 0)
  726. {
  727. if (tempCmdLine[_tcslen(tempCmdLine)-1] != TEXT('\\'))
  728. {
  729. COPYDATASTRUCT cpds;
  730. cpds.dwData = 0L;
  731. cpds.cbData = (_tcslen(GetCommandLine()) + 1) * sizeof(TCHAR);
  732. cpds.lpData = LocalAlloc(LPTR,cpds.cbData);
  733. if (cpds.lpData == NULL) {
  734. // Error - not enough memory to continue
  735. return (FALSE);
  736. }
  737. _tcscpy((LPTSTR)cpds.lpData, GetCommandLine());
  738. SendMessage(hwndFind, WM_COPYDATA, 0, (LPARAM)(LPVOID)&cpds);
  739. LocalFree((HLOCAL)cpds.lpData);
  740. } //end if not autoplay command line
  741. } //end if non-0 command line
  742. } //end if found other window
  743. return (FALSE);
  744. }
  745. return (TRUE);
  746. }
  747. ////////////////////////////////////////////////////////////////////////////////////////////
  748. // * CalculateDispAreaOffset
  749. // Figures out how big the display area should be if we're not in standard font mode
  750. ////////////////////////////////////////////////////////////////////////////////////////////
  751. void CalculateDispAreaOffset(IMMComponent* pComp)
  752. {
  753. if (!pComp)
  754. {
  755. return;
  756. }
  757. MMCOMPDATA mmComp;
  758. mmComp.dwSize = sizeof(mmComp);
  759. pComp->GetInfo(&mmComp);
  760. //mmComp.rect (height) contains the min height of the display area on this monitor
  761. //for the largest view ... other views seem to be OK with different font settings
  762. //calculate how big the view must be compared to its normal min size
  763. nDispAreaOffset = (mmComp.rect.bottom - mmComp.rect.top) - TYPICAL_DISPLAY_AREA;
  764. //don't let the display area shrink, only grow
  765. if (nDispAreaOffset < 0)
  766. {
  767. nDispAreaOffset = 0;
  768. }
  769. }
  770. ////////////////////////////////////////////////////////////////////////////////////////////
  771. // * BuildFrameworkBitmaps
  772. // Creates the bitmaps for normal, restored, and small sizes
  773. ////////////////////////////////////////////////////////////////////////////////////////////
  774. BOOL BuildFrameworkBitmaps()
  775. {
  776. POINT ptSys = {SYSMENU_XOFFSET,TITLEBAR_YOFFSET_LARGE};
  777. RECT rectMain = {0,0,480,150};
  778. RECT rectView = {10,25,472,98};
  779. RECT rectSeps[2] = {93,97,95,146,302,97,304,146};
  780. rectView.bottom += nDispAreaOffset;
  781. rectMain.bottom += nDispAreaOffset;
  782. for (UINT i = 0; i < sizeof(rectSeps) / sizeof(RECT); i++)
  783. {
  784. rectSeps[i].top += nDispAreaOffset;
  785. rectSeps[i].bottom += nDispAreaOffset;
  786. }
  787. HDC hdcMain = GetDC(hwndMain);
  788. hbmpMain = BuildFrameBitmap(hdcMain,&rectMain,&rectView,VIEW_MODE_NORMAL,&ptSys,rectSeps,2,&bmMain);
  789. //"no title bar" mode
  790. ptSys.x = SYSMENU_XOFFSET;
  791. ptSys.y = TITLEBAR_YOFFSET_LARGE;
  792. SetRect(&rectMain,0,0,480,134);
  793. SetRect(&rectView,10,9,472,82);
  794. SetRect(&rectSeps[0],93,81,95,130);
  795. SetRect(&rectSeps[1],302,81,304,130);
  796. hbmpMainNoBar = BuildFrameBitmap(hdcMain,&rectMain,&rectView,VIEW_MODE_NOBAR,&ptSys,rectSeps,2,&bmMainNoBar);
  797. //"restored" mode
  798. ptSys.x = SYSMENU_XOFFSET;
  799. ptSys.y = TITLEBAR_YOFFSET_SMALL;
  800. SetRect(&rectMain,0,0,393,50);
  801. SetRect(&rectView,301,21,386,43);
  802. SetRect(&rectSeps[0],92,25,101,38);
  803. SetRect(&rectSeps[1],211,25,220,38);
  804. hbmpMainRestore = BuildFrameBitmap(hdcMain,&rectMain,&rectView,VIEW_MODE_RESTORE,&ptSys,rectSeps,2,&bmMainRestore);
  805. //"very small" mode, no title bar
  806. SetRect(&rectMain,0,0,393,38);
  807. SetRect(&rectView,301,9,386,30);
  808. SetRect(&rectSeps[0],92,13,101,26);
  809. SetRect(&rectSeps[1],211,13,220,26);
  810. hbmpMainSmall = BuildFrameBitmap(hdcMain,&rectMain,&rectView,VIEW_MODE_SMALL,&ptSys,rectSeps,2,&bmMainSmall);
  811. ReleaseDC(hwndMain,hdcMain);
  812. return TRUE;
  813. }
  814. ////////////////////////////////////////////////////////////////////////////////////////////
  815. // * SetCurvedEdges
  816. // Changes clipping region of an HWND to have curved corners
  817. ////////////////////////////////////////////////////////////////////////////////////////////
  818. void SetCurvedEdges(HWND hwnd)
  819. {
  820. RECT rect;
  821. GetWindowRect(hwnd,&rect);
  822. //set the rect to "client" coordinates
  823. rect.bottom = rect.bottom - rect.top;
  824. rect.right = rect.right - rect.left;
  825. rect.top = 0;
  826. rect.left = 0;
  827. HRGN region = CreateRoundRectRgn(GetXOffset(),
  828. GetYOffsetCaption() + GetYOffset(),
  829. (rect.right - GetXOffset())+1,
  830. (rect.bottom - GetYOffset())+1,
  831. EDGE_CURVE_WIDTH,
  832. EDGE_CURVE_HEIGHT);
  833. SetWindowRgn(hwnd,region,TRUE);
  834. }
  835. ////////////////////////////////////////////////////////////////////////////////////////////
  836. // * SetNoBarMode(HWND hwnd)
  837. // Changes the view mode to have no title bar
  838. ////////////////////////////////////////////////////////////////////////////////////////////
  839. void SetNoBarMode(HWND hwnd)
  840. {
  841. g_nViewMode = VIEW_MODE_NOBAR;
  842. HDWP hdwp = BeginDeferWindowPos(NUM_BUTTONS+3);
  843. //move/size/hide buttons
  844. for (int i = 0; i < NUM_BUTTONS; i++)
  845. {
  846. hdwp = DeferWindowPos(hdwp,GetDlgItem(hwnd,biButtons[i].id),hwnd,
  847. biButtons[i].uixy.x,
  848. biButtons[i].uixy.y - (bmMain.bmHeight - bmMainNoBar.bmHeight),
  849. biButtons[i].width,
  850. biButtons[i].height,
  851. SWP_NOACTIVATE|SWP_NOZORDER);
  852. if (biButtons[i].dwStyle == MBS_SYSTEMTYPE)
  853. {
  854. ShowWindow(GetDlgItem(hwnd,biButtons[i].id),SW_HIDE);
  855. }
  856. }
  857. //move volume and mute
  858. hdwp = DeferWindowPos(hdwp,GetDlgItem(hwnd,IDB_VOLUME),hwnd,
  859. 403,
  860. (93+nDispAreaOffset) - (bmMain.bmHeight - bmMainNoBar.bmHeight),
  861. 45,
  862. 45,
  863. SWP_NOACTIVATE|SWP_NOZORDER);
  864. hdwp = DeferWindowPos(hdwp,GetDlgItem(hwnd,IDB_MUTE),hwnd,
  865. 450,
  866. (122+nDispAreaOffset) - (bmMain.bmHeight - bmMainNoBar.bmHeight),
  867. 13,
  868. 13,
  869. SWP_NOACTIVATE|SWP_NOZORDER);
  870. //move display screen
  871. hdwp = DeferWindowPos(hdwp,hwndCurrentComp,hwnd,24,32-(bmMain.bmHeight - bmMainNoBar.bmHeight),431,56+nDispAreaOffset,SWP_NOACTIVATE|SWP_NOZORDER);
  872. InvalidateRect(GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW),NULL,TRUE);
  873. //size main window
  874. int sx = GetXOffset()*2;
  875. int sy = (GetYOffset()*2) + GetYOffsetCaption();
  876. SetWindowPos(hwnd,NULL,0,0,
  877. bmMainNoBar.bmWidth+sx,
  878. bmMainNoBar.bmHeight+sy,
  879. SWP_NOMOVE|SWP_NOZORDER);
  880. SetCurvedEdges(hwnd);
  881. InvalidateRect(hwnd,NULL,TRUE);
  882. EndDeferWindowPos(hdwp);
  883. }
  884. ////////////////////////////////////////////////////////////////////////////////////////////
  885. // * SetRestoredMode
  886. // Changes the view mode to restored
  887. ////////////////////////////////////////////////////////////////////////////////////////////
  888. void SetRestoredMode(HWND hwnd)
  889. {
  890. if (g_nViewMode == VIEW_MODE_NORMAL)
  891. {
  892. //pre-blit the new button sizes
  893. CMButton* pButton;
  894. pButton = GetMButtonFromID(hwnd,IDB_PLAY);
  895. pButton->PreDrawUpstate(biButtons[2].width2,biButtons[2].height);
  896. pButton = GetMButtonFromID(hwnd,IDB_STOP);
  897. pButton->PreDrawUpstate(biButtons[3].width2,biButtons[3].height);
  898. pButton = GetMButtonFromID(hwnd,IDB_EJECT);
  899. pButton->PreDrawUpstate(biButtons[4].width2,biButtons[4].height);
  900. pButton = GetMButtonFromID(hwnd,IDB_TRACK);
  901. pButton->PreDrawUpstate(biButtons[10].width2,biButtons[10].height);
  902. }
  903. g_nViewMode = VIEW_MODE_RESTORE;
  904. HDWP hdwp = BeginDeferWindowPos(NUM_BUTTONS+2);
  905. //move/size/hide buttons
  906. for (int i = 0; i < NUM_BUTTONS; i++)
  907. {
  908. if (biButtons[i].uixy2.x != 0)
  909. {
  910. hdwp = DeferWindowPos(hdwp,GetDlgItem(hwnd,biButtons[i].id),hwnd,
  911. biButtons[i].uixy2.x,
  912. biButtons[i].uixy2.y,
  913. biButtons[i].width2,
  914. biButtons[i].height,
  915. SWP_NOACTIVATE|SWP_NOZORDER);
  916. }
  917. else
  918. {
  919. ShowWindow(GetDlgItem(hwnd,biButtons[i].id),SW_HIDE); //prevents tabbing
  920. }
  921. if (biButtons[i].dwStyle == MBS_SYSTEMTYPE)
  922. {
  923. ShowWindow(GetDlgItem(hwnd,biButtons[i].id),SW_SHOW);
  924. }
  925. }
  926. //move display screen
  927. hdwp = DeferWindowPos(hdwp,hwndCurrentComp,hwnd,303,24,81,17,SWP_NOACTIVATE|SWP_NOZORDER);
  928. InvalidateRect(GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW),NULL,TRUE);
  929. //size main window
  930. int sx = GetXOffset()*2;
  931. int sy = (GetYOffset()*2) + GetYOffsetCaption();
  932. SetWindowPos(hwnd,NULL,0,0,
  933. bmMainRestore.bmWidth+sx,
  934. bmMainRestore.bmHeight+sy,
  935. SWP_NOMOVE|SWP_NOZORDER);
  936. ShowWindow(GetDlgItem(hwnd,IDB_VOLUME),SW_HIDE);
  937. ShowWindow(GetDlgItem(hwnd,IDB_MUTE),SW_HIDE);
  938. ShowWindow(GetDlgItem(hwnd,IDB_SET_NORMAL_MODE),SW_SHOW);
  939. ShowWindow(GetDlgItem(hwnd,IDB_SET_TINY_MODE),SW_HIDE);
  940. SetCurvedEdges(hwnd);
  941. InvalidateRect(hwnd,NULL,TRUE);
  942. EndDeferWindowPos(hdwp);
  943. }
  944. ////////////////////////////////////////////////////////////////////////////////////////////
  945. // * SetNormalMode
  946. // Changes the view mode to normal
  947. ////////////////////////////////////////////////////////////////////////////////////////////
  948. void SetNormalMode(HWND hwnd)
  949. {
  950. //going from restore to max
  951. g_nViewMode = VIEW_MODE_NORMAL;
  952. //pre-blit the new button sizes
  953. CMButton* pButton;
  954. pButton = GetMButtonFromID(hwnd,IDB_PLAY);
  955. pButton->PreDrawUpstate(biButtons[2].width,biButtons[2].height);
  956. pButton = GetMButtonFromID(hwnd,IDB_STOP);
  957. pButton->PreDrawUpstate(biButtons[3].width,biButtons[3].height);
  958. pButton = GetMButtonFromID(hwnd,IDB_EJECT);
  959. pButton->PreDrawUpstate(biButtons[4].width,biButtons[4].height);
  960. pButton = GetMButtonFromID(hwnd,IDB_TRACK);
  961. pButton->PreDrawUpstate(biButtons[10].width,biButtons[10].height);
  962. HDWP hdwp = BeginDeferWindowPos(NUM_BUTTONS+3);
  963. //move/size/show buttons
  964. for (int i = 0; i < NUM_BUTTONS; i++)
  965. {
  966. ShowWindow(GetDlgItem(hwnd,biButtons[i].id),SW_SHOW);
  967. hdwp = DeferWindowPos(hdwp,GetDlgItem(hwnd,biButtons[i].id),hwnd,
  968. biButtons[i].uixy.x,
  969. biButtons[i].uixy.y,
  970. biButtons[i].width,
  971. biButtons[i].height,
  972. SWP_NOACTIVATE|SWP_NOZORDER);
  973. }
  974. //move volume and mute
  975. hdwp = DeferWindowPos(hdwp,GetDlgItem(hwnd,IDB_VOLUME),hwnd,
  976. 403,
  977. 93+nDispAreaOffset,
  978. 45,
  979. 45,
  980. SWP_NOACTIVATE|SWP_NOZORDER);
  981. hdwp = DeferWindowPos(hdwp,GetDlgItem(hwnd,IDB_MUTE),hwnd,
  982. 450,
  983. 122+nDispAreaOffset,
  984. 13,
  985. 13,
  986. SWP_NOACTIVATE|SWP_NOZORDER);
  987. //move display screen
  988. hdwp = DeferWindowPos(hdwp,hwndCurrentComp,hwnd,24,32,431,56+nDispAreaOffset,SWP_NOACTIVATE|SWP_NOZORDER);
  989. InvalidateRect(GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW),NULL,TRUE);
  990. ShowWindow(GetDlgItem(hwnd,IDB_VOLUME),SW_SHOW);
  991. ShowWindow(GetDlgItem(hwnd,IDB_MUTE),SW_SHOW);
  992. ShowWindow(GetDlgItem(hwnd,IDB_SET_NORMAL_MODE),SW_HIDE);
  993. ShowWindow(GetDlgItem(hwnd,IDB_SET_TINY_MODE),SW_SHOW);
  994. //Resize window
  995. int sx = GetXOffset()*2;
  996. int sy = (GetYOffset()*2) + GetYOffsetCaption();
  997. SetWindowPos(hwnd,NULL,0,0,
  998. bmMain.bmWidth+sx,
  999. bmMain.bmHeight+sy,
  1000. SWP_NOMOVE|SWP_NOZORDER);
  1001. SetCurvedEdges(hwnd);
  1002. InvalidateRect(hwnd,NULL,TRUE);
  1003. EndDeferWindowPos(hdwp);
  1004. }
  1005. ////////////////////////////////////////////////////////////////////////////////////////////
  1006. // * SetSmallMode
  1007. // Changes the view mode to small
  1008. ////////////////////////////////////////////////////////////////////////////////////////////
  1009. void SetSmallMode(HWND hwnd)
  1010. {
  1011. g_nViewMode = VIEW_MODE_SMALL;
  1012. HDWP hdwp = BeginDeferWindowPos(NUM_BUTTONS+2);
  1013. //move/size/hide buttons
  1014. for (int i = 0; i < NUM_BUTTONS; i++)
  1015. {
  1016. if (biButtons[i].uixy2.x != 0)
  1017. {
  1018. hdwp = DeferWindowPos(hdwp,GetDlgItem(hwnd,biButtons[i].id),hwnd,
  1019. biButtons[i].uixy2.x,
  1020. biButtons[i].uixy2.y - (bmMainRestore.bmHeight - bmMainSmall.bmHeight),
  1021. biButtons[i].width2,
  1022. biButtons[i].height,
  1023. SWP_NOACTIVATE|SWP_NOZORDER);
  1024. }
  1025. if (biButtons[i].dwStyle == MBS_SYSTEMTYPE)
  1026. {
  1027. ShowWindow(GetDlgItem(hwnd,biButtons[i].id),SW_HIDE);
  1028. }
  1029. }
  1030. //move display screen
  1031. hdwp = DeferWindowPos(hdwp,hwndCurrentComp,hwnd,303,24-(bmMainRestore.bmHeight - bmMainSmall.bmHeight),81,17,SWP_NOACTIVATE|SWP_NOZORDER);
  1032. InvalidateRect(GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW),NULL,TRUE);
  1033. //size main window
  1034. int sx = GetXOffset()*2;
  1035. int sy = (GetYOffset()*2) + GetYOffsetCaption();
  1036. SetWindowPos(hwnd,NULL,0,0,
  1037. bmMainSmall.bmWidth+sx,
  1038. bmMainSmall.bmHeight+sy,
  1039. SWP_NOMOVE|SWP_NOZORDER);
  1040. SetCurvedEdges(hwnd);
  1041. InvalidateRect(hwnd,NULL,TRUE);
  1042. EndDeferWindowPos(hdwp);
  1043. }
  1044. ////////////////////////////////////////////////////////////////////////////////////////////
  1045. // * AdjustForMultimon
  1046. // Will move the app onto the primary display if its x,y settings are not on a monitor
  1047. ////////////////////////////////////////////////////////////////////////////////////////////
  1048. void AdjustForMultimon(HWND hwnd)
  1049. {
  1050. RECT rect;
  1051. GetWindowRect(hwnd,&rect);
  1052. int cxWnd = rect.right - rect.left;
  1053. int cyWnd = rect.bottom - rect.top;
  1054. // Check if the app's rect is visible is any of the monitors
  1055. if( NULL == MonitorFromRect( &rect, 0L ) )
  1056. {
  1057. //The window is not visible. Let's center it in the primary monitor.
  1058. //Note: the window could be in this state if (1) the display mode was changed from
  1059. //a high-resolution to a lower resolution, with the cdplayer in the corner. Or,
  1060. //(2) the multi-mon configuration was rearranged.
  1061. RECT rcDesktop;
  1062. GetWindowRect( GetDesktopWindow(), &rcDesktop );
  1063. int cxDesktop = (rcDesktop.right - rcDesktop.left);
  1064. int cyDesktop = (rcDesktop.bottom - rcDesktop.top);
  1065. int x = (cxDesktop - cxWnd) / 2; //center in x
  1066. int y = (cyDesktop - cyWnd) / 3; //and a little towards the top
  1067. SetWindowPos(hwnd,NULL,x,y,0,0,SWP_NOSIZE|SWP_NOZORDER);
  1068. }
  1069. }
  1070. ////////////////////////////////////////////////////////////////////////////////////////////
  1071. // * WinMain
  1072. // Entry point for application
  1073. ////////////////////////////////////////////////////////////////////////////////////////////
  1074. int WINAPI WinMain(HINSTANCE hInstEXE, HINSTANCE hInstEXEPrev, PSTR lpszCmdLine, int nCmdShow)
  1075. {
  1076. //first thing, must check tray icon state
  1077. if (!CanStartShell())
  1078. {
  1079. return (0);
  1080. }
  1081. if (!IsOnlyInstance())
  1082. {
  1083. //can't have more than one of these
  1084. return (0);
  1085. }
  1086. //save the global hinstance
  1087. hInst = hInstEXE;
  1088. DetermineColorMode();
  1089. //start our linked list of components
  1090. pCompList = new COMPNODE;
  1091. ZeroMemory(pCompList,sizeof(COMPNODE));
  1092. pCompListTail = pCompList;
  1093. //load the app name
  1094. LoadString(hInstEXE,IDS_APPNAME,szAppName,sizeof(szAppName)/sizeof(TCHAR));
  1095. //init the networking component (this just inits some crit sections)
  1096. CDNET_Init(hInstEXE);
  1097. //load components from registry
  1098. if (!LoadComponents())
  1099. {
  1100. CleanUp();
  1101. return (0);
  1102. }
  1103. //register our main window class
  1104. WNDCLASSEX wc;
  1105. ATOM atomClassName;
  1106. ZeroMemory(&wc, sizeof(wc));
  1107. wc.cbSize = sizeof(wc);
  1108. wc.lpszClassName = FRAMEWORK_CLASS;
  1109. wc.lpfnWndProc = MainWndProc;
  1110. wc.hInstance = hInstEXE;
  1111. wc.style = CS_DBLCLKS;
  1112. wc.hIcon = LoadIcon(hInstEXE, MAKEINTRESOURCE(IDI_MMFW));
  1113. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  1114. wc.hbrBackground = NULL;
  1115. wc.lpszMenuName = NULL;
  1116. wc.hIconSm = (HICON)LoadImage(hInstEXE, MAKEINTRESOURCE(IDI_MMFW), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
  1117. atomClassName = RegisterClassEx(&wc);
  1118. int x = CW_USEDEFAULT;
  1119. int y = CW_USEDEFAULT;
  1120. GetSettings(x,y);
  1121. hpalMain = SetPalette();
  1122. #ifndef MMFW_USE_CAPTION
  1123. DWORD dwStyle = WS_POPUP|WS_SYSMENU|WS_MINIMIZEBOX|WS_CLIPCHILDREN;
  1124. #else
  1125. DWORD dwStyle = WS_POPUP|WS_SYSMENU|WS_MINIMIZEBOX|WS_CAPTION|WS_CLIPCHILDREN;
  1126. #endif
  1127. //create our main window
  1128. HWND hwnd = CreateWindowEx(WS_EX_APPWINDOW,
  1129. MAKEINTATOM(atomClassName),
  1130. szAppName,
  1131. dwStyle,
  1132. x,
  1133. y,
  1134. 0,
  1135. 0,
  1136. NULL,
  1137. NULL,
  1138. hInstEXE,
  1139. NULL);
  1140. if (hwnd == NULL)
  1141. {
  1142. //major failure here!
  1143. CleanUp();
  1144. return 0;
  1145. }
  1146. hwndMain = hwnd;
  1147. //tell our sink what our main window is
  1148. CFrameworkNotifySink::m_hwndTitle = hwnd;
  1149. //create the bitmaps of the main ui
  1150. if (!BuildFrameworkBitmaps())
  1151. {
  1152. //failure -- can't create bitmaps for framework
  1153. CleanUp();
  1154. return 0;
  1155. }
  1156. int bmWidth = bmMain.bmWidth;
  1157. int bmHeight = bmMain.bmHeight;
  1158. //set window size to match the width and height of the correct mode's bitmap
  1159. switch (g_nViewMode)
  1160. {
  1161. case VIEW_MODE_RESTORE :
  1162. {
  1163. bmWidth = bmMainRestore.bmWidth;
  1164. bmHeight = bmMainRestore.bmHeight;
  1165. }
  1166. break;
  1167. case VIEW_MODE_SMALL :
  1168. {
  1169. bmWidth = bmMainSmall.bmWidth;
  1170. bmHeight = bmMainSmall.bmHeight;
  1171. }
  1172. break;
  1173. case VIEW_MODE_NOBAR :
  1174. {
  1175. bmWidth = bmMainNoBar.bmWidth;
  1176. bmHeight = bmMainNoBar.bmHeight;
  1177. }
  1178. break;
  1179. }
  1180. int sx = GetXOffset()*2;
  1181. int sy = (GetYOffset()*2) + GetYOffsetCaption();
  1182. SetWindowPos(hwnd,NULL,0,0,bmWidth+sx,bmHeight+sy,SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
  1183. //check the window pos against multimon
  1184. AdjustForMultimon(hwnd);
  1185. SetCurvedEdges(hwnd);
  1186. //Send us a message to set the initial mode of the player
  1187. SendMessage(hwnd,WM_COMMAND,MAKEWPARAM(nCDMode,0),0);
  1188. //show us!
  1189. if (!ShellOnly())
  1190. {
  1191. ShowWindow(hwnd, nCmdShow);
  1192. UpdateWindow(hwnd);
  1193. LPCDDATA pCDData = GetCDData();
  1194. if (pCDData)
  1195. {
  1196. pCDData->Initialize(hwnd);
  1197. pCDData->CheckDatabase(hwnd);
  1198. }
  1199. }
  1200. if (fShellMode)
  1201. {
  1202. CreateShellIcon(hInst,hwnd,pNodeCurrent,szAppName);
  1203. }
  1204. //main message loop
  1205. MSG msg;
  1206. for (;;)
  1207. {
  1208. if (PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
  1209. {
  1210. if (msg.message == WM_QUIT)
  1211. break;
  1212. /*
  1213. if (hAccelApp && TranslateAccelerator(hwndApp, hAccelApp, &msg))
  1214. continue;
  1215. */
  1216. if (!IsDialogMessage(hwnd,&msg))
  1217. {
  1218. TranslateMessage(&msg);
  1219. DispatchMessage(&msg);
  1220. } //end if dialg msg
  1221. }
  1222. else
  1223. {
  1224. WaitMessage();
  1225. }
  1226. } //end for
  1227. //get outta here!
  1228. CleanUp();
  1229. return ((int)msg.wParam);
  1230. }
  1231. ////////////////////////////////////////////////////////////////////////////////////////////
  1232. // * ShowNewComponentWindow
  1233. // Displays the chosen component
  1234. // (Sort of a holdover from the old multi-component days, but it also serves to
  1235. // initialize the first component loaded)
  1236. ////////////////////////////////////////////////////////////////////////////////////////////
  1237. void ShowNewComponentWindow(PCOMPNODE pNode, HWND hwnd)
  1238. {
  1239. if (pNode == NULL)
  1240. {
  1241. return;
  1242. }
  1243. //don't bother if we're already there
  1244. if (pNode->hwndComp == hwndCurrentComp)
  1245. {
  1246. return;
  1247. }
  1248. if (hwndCurrentComp != NULL)
  1249. {
  1250. ShowWindow(hwndCurrentComp,SW_HIDE);
  1251. }
  1252. hwndCurrentComp = pNode->hwndComp;
  1253. ShowWindow(hwndCurrentComp,SW_SHOW);
  1254. pNodeCurrent = pNode;
  1255. MMCOMPDATA mmComp;
  1256. mmComp.dwSize = sizeof(mmComp);
  1257. pNode->pComp->GetInfo(&mmComp);
  1258. if (_tcslen(pNode->szTitle)==0)
  1259. {
  1260. _tcscpy(pNode->szTitle,mmComp.szName);
  1261. }
  1262. SetWindowText(hwnd,szAppName);
  1263. //also set icons
  1264. if (mmComp.hiconLarge != NULL)
  1265. {
  1266. SendMessage(hwnd, WM_SETICON, TRUE, (LPARAM)mmComp.hiconLarge);
  1267. }
  1268. if (mmComp.hiconSmall != NULL)
  1269. {
  1270. SendMessage(hwnd, WM_SETICON, FALSE, (LPARAM)mmComp.hiconSmall);
  1271. }
  1272. }
  1273. ////////////////////////////////////////////////////////////////////////////////////////////
  1274. // * InitButtonProperties
  1275. // Set up the button info structure for all the transport buttons
  1276. //
  1277. // Should Fix: this is pretty ugly and hard-coded. Implement to read from some kind of
  1278. // easily-editable resource for when layout changes come?
  1279. ////////////////////////////////////////////////////////////////////////////////////////////
  1280. void InitButtonProperties()
  1281. {
  1282. //set up each button's properties
  1283. ZeroMemory(biButtons,sizeof(BUTTONINFO)*NUM_BUTTONS);
  1284. //order of buttons in this array affects the tab order
  1285. biButtons[0].id = IDB_OPTIONS;
  1286. biButtons[0].nToolTipID = IDB_TT_OPTIONS;
  1287. biButtons[0].uixy.x = 11;
  1288. biButtons[0].uixy.y = 102 + nDispAreaOffset;
  1289. biButtons[0].width = 76;
  1290. biButtons[0].height = 19;
  1291. biButtons[0].uixy2.x = 9;
  1292. biButtons[0].uixy2.y = 23;
  1293. biButtons[0].width2 = 76;
  1294. biButtons[0].dwStyle = MBS_STANDARDLEFT | MBS_DROPRIGHT;
  1295. biButtons[1].id = IDB_NET;
  1296. biButtons[1].nToolTipID = IDB_TT_NET;
  1297. biButtons[1].uixy.x = 11;
  1298. biButtons[1].uixy.y = 125 + nDispAreaOffset;
  1299. biButtons[1].width = 76;
  1300. biButtons[1].height = 19;
  1301. biButtons[1].dwStyle = MBS_STANDARDLEFT | MBS_DROPRIGHT;
  1302. biButtons[2].id = IDB_PLAY;
  1303. biButtons[2].nToolTipID = IDB_TT_PLAY;
  1304. biButtons[2].uixy.x = 103;
  1305. biButtons[2].uixy.y = 102 + nDispAreaOffset;
  1306. biButtons[2].width = 64;
  1307. biButtons[2].height = 19;
  1308. biButtons[2].uixy2.x = 102;
  1309. biButtons[2].uixy2.y = 23;
  1310. biButtons[2].width2 = 34;
  1311. biButtons[2].dwStyle = MBS_STANDARDLEFT | MBS_STANDARDRIGHT;
  1312. biButtons[2].nIconID = IDI_ICON_PLAY;
  1313. biButtons[3].id = IDB_STOP;
  1314. biButtons[3].nToolTipID = IDB_TT_STOP;
  1315. biButtons[3].uixy.x = 174;
  1316. biButtons[3].uixy.y = 102 + nDispAreaOffset;
  1317. biButtons[3].width = 64;
  1318. biButtons[3].height = 19;
  1319. biButtons[3].uixy2.x = 136;
  1320. biButtons[3].uixy2.y = 23;
  1321. biButtons[3].width2 = 34;
  1322. biButtons[3].dwStyle = MBS_STANDARDLEFT | MBS_STANDARDRIGHT;
  1323. biButtons[3].nIconID = IDI_ICON_STOP;
  1324. biButtons[4].id = IDB_EJECT;
  1325. biButtons[4].nToolTipID = IDB_TT_EJECT;
  1326. biButtons[4].uixy.x = 245;
  1327. biButtons[4].uixy.y = 102 + nDispAreaOffset;
  1328. biButtons[4].width = 51;
  1329. biButtons[4].height = 19;
  1330. biButtons[4].uixy2.x = 170;
  1331. biButtons[4].uixy2.y = 23;
  1332. biButtons[4].width2 = 34;
  1333. biButtons[4].dwStyle = MBS_STANDARDLEFT | MBS_STANDARDRIGHT;
  1334. biButtons[4].nIconID = IDI_ICON_EJECT;
  1335. biButtons[5].id = IDB_REW;
  1336. biButtons[5].nToolTipID = IDB_TT_REW;
  1337. biButtons[5].uixy.x = 103;
  1338. biButtons[5].uixy.y = 125 + nDispAreaOffset;
  1339. biButtons[5].width = 33;
  1340. biButtons[5].height = 19;
  1341. biButtons[5].dwStyle = MBS_STANDARDLEFT | MBS_TOGGLERIGHT;
  1342. biButtons[5].nIconID = IDI_ICON_REW;
  1343. biButtons[6].id = IDB_FFWD;
  1344. biButtons[6].nToolTipID = IDB_TT_FFWD;
  1345. biButtons[6].uixy.x = 136;
  1346. biButtons[6].uixy.y = 125 + nDispAreaOffset;
  1347. biButtons[6].width = 31;
  1348. biButtons[6].height = 19;
  1349. biButtons[6].dwStyle = MBS_TOGGLELEFT | MBS_STANDARDRIGHT;
  1350. biButtons[6].nIconID = IDI_ICON_FFWD;
  1351. biButtons[7].id = IDB_PREVTRACK;
  1352. biButtons[7].nToolTipID = IDB_TT_PREVTRACK;
  1353. biButtons[7].uixy.x = 174;
  1354. biButtons[7].uixy.y = 125 + nDispAreaOffset;
  1355. biButtons[7].width = 33;
  1356. biButtons[7].height = 19;
  1357. biButtons[7].dwStyle = MBS_STANDARDLEFT | MBS_TOGGLERIGHT;
  1358. biButtons[7].nIconID = IDI_ICON_PREV;
  1359. biButtons[8].id = IDB_NEXTTRACK;
  1360. biButtons[8].nToolTipID = IDB_TT_NEXTTRACK;
  1361. biButtons[8].uixy.x = 207;
  1362. biButtons[8].uixy.y = 125 + nDispAreaOffset;
  1363. biButtons[8].width = 31;
  1364. biButtons[8].height = 19;
  1365. biButtons[8].dwStyle = MBS_TOGGLELEFT | MBS_STANDARDRIGHT;
  1366. biButtons[8].nIconID = IDI_ICON_NEXT;
  1367. biButtons[9].id = IDB_MODE;
  1368. biButtons[9].nToolTipID = IDB_TT_MODE;
  1369. biButtons[9].uixy.x = 245;
  1370. biButtons[9].uixy.y = 125 + nDispAreaOffset;
  1371. biButtons[9].width = 51;
  1372. biButtons[9].height = 19;
  1373. biButtons[9].dwStyle = MBS_STANDARDLEFT | MBS_DROPRIGHT;
  1374. biButtons[9].nIconID = IDI_MODE_NORMAL;
  1375. biButtons[10].id = IDB_TRACK;
  1376. biButtons[10].nToolTipID = IDB_TT_TRACK;
  1377. biButtons[10].uixy.x = 312;
  1378. biButtons[10].uixy.y = 102 + nDispAreaOffset;
  1379. biButtons[10].width = 76;
  1380. biButtons[10].height = 19;
  1381. biButtons[10].uixy2.x = 221;
  1382. biButtons[10].uixy2.y = 23;
  1383. biButtons[10].width2 = 72;
  1384. biButtons[10].dwStyle = MBS_STANDARDLEFT | MBS_DROPRIGHT;
  1385. biButtons[11].id = IDB_DISC;
  1386. biButtons[11].nToolTipID = IDB_TT_DISC;
  1387. biButtons[11].uixy.x = 312;
  1388. biButtons[11].uixy.y = 125 + nDispAreaOffset;
  1389. biButtons[11].width = 76;
  1390. biButtons[11].height = 19;
  1391. biButtons[11].dwStyle = MBS_STANDARDLEFT | MBS_DROPRIGHT;
  1392. biButtons[12].id = IDB_CLOSE;
  1393. biButtons[12].nToolTipID = IDB_TT_CLOSE;
  1394. biButtons[12].uixy.x = 456;
  1395. biButtons[12].uixy.y = 7;
  1396. biButtons[12].width = 15;
  1397. biButtons[12].height = 14;
  1398. biButtons[12].fBlockTab = TRUE;
  1399. biButtons[12].uixy2.x = 371;
  1400. biButtons[12].uixy2.y = 4;
  1401. biButtons[12].width2 = 15;
  1402. biButtons[12].dwStyle = MBS_SYSTEMTYPE;
  1403. biButtons[12].nIconID = IDB_CLOSE;
  1404. biButtons[13].id = IDB_MINIMIZE;
  1405. biButtons[13].nToolTipID = IDB_TT_MINIMIZE;
  1406. biButtons[13].uixy.x = 427;
  1407. biButtons[13].uixy.y = 7;
  1408. biButtons[13].width = 14;
  1409. biButtons[13].height = 14;
  1410. biButtons[13].fBlockTab = TRUE;
  1411. biButtons[13].uixy2.x = 343;
  1412. biButtons[13].uixy2.y = 4;
  1413. biButtons[13].width2 = 14;
  1414. biButtons[13].dwStyle = MBS_SYSTEMTYPE;
  1415. biButtons[13].nIconID = IDB_MINIMIZE;
  1416. biButtons[14].id = IDB_SET_TINY_MODE;
  1417. biButtons[14].nToolTipID = IDB_TT_RESTORE;
  1418. biButtons[14].uixy.x = 442;
  1419. biButtons[14].uixy.y = 7;
  1420. biButtons[14].width = 14;
  1421. biButtons[14].height = 14;
  1422. biButtons[14].fBlockTab = TRUE;
  1423. biButtons[14].uixy2.x = 357;
  1424. biButtons[14].uixy2.y = 4;
  1425. biButtons[14].width2 = 14;
  1426. biButtons[14].dwStyle = MBS_SYSTEMTYPE;
  1427. biButtons[14].nIconID = IDB_SET_TINY_MODE;
  1428. biButtons[15].id = IDB_SET_NORMAL_MODE;
  1429. biButtons[15].nToolTipID = IDB_TT_MAXIMIZE;
  1430. biButtons[15].uixy.x = 442;
  1431. biButtons[15].uixy.y = 7;
  1432. biButtons[15].width = 14;
  1433. biButtons[15].height = 14;
  1434. biButtons[15].fBlockTab = TRUE;
  1435. biButtons[15].uixy2.x = 357;
  1436. biButtons[15].uixy2.y = 4;
  1437. biButtons[15].width2 = 14;
  1438. biButtons[15].dwStyle = MBS_SYSTEMTYPE;
  1439. biButtons[15].nIconID = IDB_SET_NORMAL_MODE;
  1440. }
  1441. ////////////////////////////////////////////////////////////////////////////////////////////
  1442. // * CreateMuteButton
  1443. // Make the little mute button guy
  1444. ////////////////////////////////////////////////////////////////////////////////////////////
  1445. void CreateMuteButton(HWND hwndOwner)
  1446. {
  1447. //first load mute button's cursor
  1448. hCursorMute = LoadCursor(hInst,MAKEINTRESOURCE(IDC_MUTE));
  1449. CMButton* pButton = NULL;
  1450. TCHAR szCaption[MAX_PATH];
  1451. LoadString(hInst,IDB_MUTE,szCaption,sizeof(szCaption)/sizeof(TCHAR));
  1452. int yOffset = 122+nDispAreaOffset;
  1453. if (g_nViewMode == VIEW_MODE_NOBAR)
  1454. {
  1455. yOffset -= 16;
  1456. }
  1457. pButton = CreateMButton(szCaption,IDB_MUTE,WS_VISIBLE|WS_TABSTOP,
  1458. MBS_SYSTEMTYPE,
  1459. 450,
  1460. yOffset,
  1461. 13,
  1462. 13,
  1463. hwndOwner,
  1464. FALSE, //create original, not subclass
  1465. IDB_MUTE,
  1466. IDB_TT_MUTE,
  1467. hInst);
  1468. //hide this button in small mode
  1469. if ((g_nViewMode==VIEW_MODE_RESTORE)||((g_nViewMode==VIEW_MODE_SMALL)))
  1470. {
  1471. ShowWindow(pButton->GetHWND(),SW_HIDE);
  1472. }
  1473. //set up tool tip
  1474. TOOLINFO ti;
  1475. ti.cbSize = sizeof(TOOLINFO);
  1476. ti.uFlags = TTF_IDISHWND;
  1477. ti.hwnd = hwndOwner;
  1478. ti.uId = (UINT_PTR)(pButton->GetHWND());
  1479. ti.hinst = hInst;
  1480. ti.lpszText = LPSTR_TEXTCALLBACK;
  1481. SendMessage(g_hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  1482. //make sure button is in correct state if muted on start up
  1483. SendMessage(pButton->GetHWND(),BM_SETSTATE,(WPARAM)GetMute(),0);
  1484. SendMessage(GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW),WM_LED_MUTE,0,GetMute());
  1485. }
  1486. ////////////////////////////////////////////////////////////////////////////////////////////
  1487. // * CreateVolumeKnob
  1488. // Put up the volume knob that EVERYONE LOVES
  1489. ////////////////////////////////////////////////////////////////////////////////////////////
  1490. void CreateVolumeKnob(HWND hwndOwner)
  1491. {
  1492. LPCDOPT pOpt = GetCDOpt();
  1493. if( pOpt )
  1494. {
  1495. LPCDOPTIONS pCDOpts = pOpt->GetCDOpts();
  1496. InitCDVol(hwndOwner,pCDOpts);
  1497. //ok, this is bad, but I have the options here and the only other thing
  1498. //I need from them is the "topmost" setting for the main window ...
  1499. //so I'll go ahead and take care of that here rather than recreating
  1500. //this struct somewhere or making it global.
  1501. SetWindowPos(hwndOwner,
  1502. pCDOpts->pCDData->fTopMost ? HWND_TOPMOST : HWND_NOTOPMOST,
  1503. 0,0,0,0,
  1504. SWP_NOMOVE|SWP_NOSIZE);
  1505. DWORD dwVol = GetVolume();
  1506. int yOffset = 93+nDispAreaOffset;
  1507. if (g_nViewMode == VIEW_MODE_NOBAR)
  1508. {
  1509. yOffset -= 16;
  1510. }
  1511. CKnob* pKnob = CreateKnob(WS_VISIBLE | WS_TABSTOP,
  1512. 0xFFFF,
  1513. dwVol,
  1514. 403,
  1515. yOffset,
  1516. 45,
  1517. 45,
  1518. hwndOwner,
  1519. IDB_VOLUME,
  1520. hInst);
  1521. TOOLINFO ti;
  1522. ti.cbSize = sizeof(TOOLINFO);
  1523. ti.uFlags = TTF_IDISHWND;
  1524. ti.hwnd = hwndOwner;
  1525. ti.uId = (UINT_PTR)(pKnob->GetHWND());
  1526. ti.hinst = hInst;
  1527. ti.lpszText = LPSTR_TEXTCALLBACK;
  1528. SendMessage(g_hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  1529. if ((g_nViewMode==VIEW_MODE_RESTORE)||((g_nViewMode==VIEW_MODE_SMALL)))
  1530. {
  1531. ShowWindow(pKnob->GetHWND(),SW_HIDE);
  1532. }
  1533. CreateMuteButton(hwndOwner);
  1534. }
  1535. else
  1536. {
  1537. //fix for bug 886 ... turns off mute line in case of cdopt.dll failure
  1538. SendMessage(GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW),WM_LED_MUTE,0,FALSE);
  1539. }
  1540. }
  1541. ////////////////////////////////////////////////////////////////////////////////////////////
  1542. // * CreateButtonWindows
  1543. // Put the transport control buttons onto the screen
  1544. ////////////////////////////////////////////////////////////////////////////////////////////
  1545. void CreateButtonWindows(HWND hwndOwner)
  1546. {
  1547. InitMButtons(hInst,hwndOwner);
  1548. InitButtonProperties();
  1549. for (int i = 0; i < NUM_BUTTONS; i++)
  1550. {
  1551. DWORD wsTab = biButtons[i].fBlockTab ? 0 : WS_TABSTOP;
  1552. CMButton* pButton = NULL;
  1553. TCHAR szCaption[MAX_PATH];
  1554. LoadString(hInst,biButtons[i].id,szCaption,sizeof(szCaption)/sizeof(TCHAR));
  1555. int x, y, width;
  1556. int nView = SW_SHOW;
  1557. switch (g_nViewMode)
  1558. {
  1559. case VIEW_MODE_NORMAL :
  1560. {
  1561. x = biButtons[i].uixy.x;
  1562. y = biButtons[i].uixy.y;
  1563. width = biButtons[i].width;
  1564. if (biButtons[i].id == IDB_SET_NORMAL_MODE)
  1565. {
  1566. nView = SW_HIDE;
  1567. }
  1568. }
  1569. break;
  1570. case VIEW_MODE_NOBAR :
  1571. {
  1572. x = biButtons[i].uixy.x;
  1573. y = biButtons[i].uixy.y - 16;
  1574. width = biButtons[i].width;
  1575. if (biButtons[i].dwStyle == MBS_SYSTEMTYPE)
  1576. {
  1577. nView = SW_HIDE;
  1578. }
  1579. }
  1580. break;
  1581. case VIEW_MODE_RESTORE :
  1582. {
  1583. x = biButtons[i].uixy2.x;
  1584. y = biButtons[i].uixy2.y;
  1585. width = biButtons[i].width2;
  1586. if (biButtons[i].id == IDB_SET_TINY_MODE)
  1587. {
  1588. nView = SW_HIDE;
  1589. }
  1590. }
  1591. break;
  1592. case VIEW_MODE_SMALL :
  1593. {
  1594. x = biButtons[i].uixy2.x;
  1595. y = biButtons[i].uixy2.y - 12;
  1596. width = biButtons[i].width2;
  1597. }
  1598. break;
  1599. }
  1600. //for buttons that aren't going to blit in smaller modes
  1601. if (width == 0)
  1602. {
  1603. //set to normal width
  1604. width = biButtons[i].width;
  1605. nView = SW_HIDE;
  1606. }
  1607. pButton = CreateMButton(szCaption,biButtons[i].nIconID,WS_VISIBLE|wsTab,
  1608. biButtons[i].dwStyle,
  1609. x,
  1610. y,
  1611. width,
  1612. biButtons[i].height,
  1613. hwndOwner,
  1614. FALSE, //create original, not subclass
  1615. biButtons[i].id,
  1616. biButtons[i].nToolTipID,
  1617. hInst);
  1618. //hide system buttons in small mode
  1619. if (g_nViewMode == VIEW_MODE_SMALL)
  1620. {
  1621. if (biButtons[i].dwStyle == MBS_SYSTEMTYPE)
  1622. {
  1623. ShowWindow(pButton->GetHWND(),SW_HIDE);
  1624. }
  1625. }
  1626. if (nView == SW_HIDE)
  1627. {
  1628. ShowWindow(pButton->GetHWND(),SW_HIDE);
  1629. }
  1630. TOOLINFO ti;
  1631. ti.cbSize = sizeof(TOOLINFO);
  1632. ti.uFlags = TTF_IDISHWND;
  1633. ti.hwnd = hwndOwner;
  1634. ti.uId = (UINT_PTR)(pButton->GetHWND());
  1635. ti.hinst = hInst;
  1636. ti.lpszText = LPSTR_TEXTCALLBACK;
  1637. SendMessage(g_hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  1638. //set focus and default to first control
  1639. if (i == 0)
  1640. {
  1641. SetFocus(pButton->GetHWND());
  1642. }
  1643. } //end for buttons
  1644. SendMessage(hwndOwner, DM_SETDEFID, biButtons[0].id, 0);
  1645. }
  1646. ////////////////////////////////////////////////////////////////////////////////////////////
  1647. // * VolPersistTimerProc
  1648. // When we're done displaying the volume, tell CD player to repaint normally
  1649. ////////////////////////////////////////////////////////////////////////////////////////////
  1650. void CALLBACK VolPersistTimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
  1651. {
  1652. //turn on painting in the led window
  1653. SendMessage(GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW),WM_LED_INFO_PAINT,1,0);
  1654. InvalidateRect(hwndCurrentComp,NULL,FALSE);
  1655. KillTimer(hwnd,idEvent);
  1656. }
  1657. ////////////////////////////////////////////////////////////////////////////////////////////
  1658. // * IsNetOK
  1659. // Returns TRUE if it is OK to do networking-related stuff (i.e. the database is all right)
  1660. ////////////////////////////////////////////////////////////////////////////////////////////
  1661. BOOL IsNetOK(HWND hwnd)
  1662. {
  1663. DWORD dwRet = FALSE;
  1664. LPCDDATA pData = GetCDData();
  1665. if (pData)
  1666. {
  1667. if (SUCCEEDED(pData->CheckDatabase(hwnd)))
  1668. {
  1669. dwRet = TRUE;
  1670. }
  1671. }
  1672. return (dwRet);
  1673. }
  1674. ////////////////////////////////////////////////////////////////////////////////////////////
  1675. // * IsDownloading
  1676. // Check on the networking thread to see if it is active
  1677. ////////////////////////////////////////////////////////////////////////////////////////////
  1678. BOOL IsDownloading()
  1679. {
  1680. BOOL retcode = FALSE;
  1681. ICDNet* pICDNet = NULL;
  1682. if (SUCCEEDED(CDNET_CreateInstance(NULL, IID_ICDNet, (void**)&pICDNet)))
  1683. {
  1684. retcode = pICDNet->IsDownloading();
  1685. pICDNet->Release();
  1686. }
  1687. return (retcode);
  1688. }
  1689. ////////////////////////////////////////////////////////////////////////////////////////////
  1690. // * CancelDownload
  1691. // Tell the networking thread to quit as soon as it can
  1692. ////////////////////////////////////////////////////////////////////////////////////////////
  1693. void CancelDownload()
  1694. {
  1695. ICDNet* pICDNet = NULL;
  1696. if (SUCCEEDED(CDNET_CreateInstance(NULL, IID_ICDNet, (void**)&pICDNet)))
  1697. {
  1698. pICDNet->CancelDownload();
  1699. pICDNet->Release();
  1700. }
  1701. }
  1702. ////////////////////////////////////////////////////////////////////////////////////////////
  1703. // * EndDownloadThreads
  1704. // Kills the download threads on shutdown
  1705. ////////////////////////////////////////////////////////////////////////////////////////////
  1706. void EndDownloadThreads()
  1707. {
  1708. //optimization: don't bother if CDNET.DLL is not loaded
  1709. if (GetModuleHandle(TEXT("CDNET.DLL")))
  1710. {
  1711. if (IsDownloading())
  1712. {
  1713. CancelDownload();
  1714. }
  1715. }
  1716. }
  1717. ////////////////////////////////////////////////////////////////////////////////////////////
  1718. // * MenuButtonTimerProc
  1719. // Big ol' hack to make the menus that drop down from button seem like real menus ...
  1720. // if the user hits the button before the timeout time, we don't redisplay the menu
  1721. ////////////////////////////////////////////////////////////////////////////////////////////
  1722. void CALLBACK MenuButtonTimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
  1723. {
  1724. //single-shot timer turns off the "block menu" flag
  1725. fBlockMenu = FALSE;
  1726. nLastMenu = 0;
  1727. KillTimer(hwnd,idEvent);
  1728. }
  1729. ////////////////////////////////////////////////////////////////////////////////////////////
  1730. // * BlockMenu
  1731. // Turns on the button/menu hack
  1732. ////////////////////////////////////////////////////////////////////////////////////////////
  1733. void BlockMenu(HWND hwnd)
  1734. {
  1735. fBlockMenu = TRUE;
  1736. SetTimer(hwnd,nLastMenu,MENU_TIMER_RATE,(TIMERPROC)MenuButtonTimerProc);
  1737. }
  1738. ////////////////////////////////////////////////////////////////////////////////////////////
  1739. // * NormalizeNameForMenuDisplay
  1740. // This function turns a string like "Twist & Shout" into
  1741. // "Twist && Shout" because otherwise it will look like
  1742. // "Twist _Shout" in the menu due to the accelerator char
  1743. //
  1744. // Defined in cdplayer.lib
  1745. //
  1746. ////////////////////////////////////////////////////////////////////////////////////////////
  1747. extern "C" void NormalizeNameForMenuDisplay(TCHAR* szInput, TCHAR* szOutput, DWORD cbLen);
  1748. ////////////////////////////////////////////////////////////////////////////////////////////
  1749. // * DrawButton
  1750. // Response to WM_DRAWITEM on buttons
  1751. ////////////////////////////////////////////////////////////////////////////////////////////
  1752. void DrawButton(UINT idCtl, LPDRAWITEMSTRUCT lpdis)
  1753. {
  1754. CMButton* pButton = GetMButtonFromID(hwndMain,idCtl);
  1755. if (pButton!=NULL)
  1756. {
  1757. pButton->Draw(lpdis);
  1758. }
  1759. //special case ... if the button is one of the scanner buttons,
  1760. //forward this message to the component
  1761. if ((idCtl==IDB_REW) || (idCtl==IDB_FFWD))
  1762. {
  1763. switch (idCtl)
  1764. {
  1765. case IDB_REW : idCtl = IDM_PLAYBAR_SKIPBACK; break;
  1766. case IDB_FFWD : idCtl = IDM_PLAYBAR_SKIPFORE; break;
  1767. }
  1768. lpdis->CtlID = idCtl;
  1769. SendMessage(hwndCurrentComp,WM_DRAWITEM,idCtl,(LPARAM)lpdis);
  1770. }
  1771. if (
  1772. (idCtl == IDB_OPTIONS) ||
  1773. (idCtl == IDB_MODE) ||
  1774. (idCtl == IDB_TRACK) ||
  1775. (idCtl == IDB_NET) ||
  1776. (idCtl == IDB_DISC)
  1777. )
  1778. {
  1779. if (lpdis->itemState & ODS_SELECTED)
  1780. {
  1781. if ((fBlockMenu) && (nLastMenu == idCtl))
  1782. {
  1783. return;
  1784. }
  1785. HWND hwnd = hwndMain;
  1786. RECT rect;
  1787. AllocCustomMenu(&g_pMenu);
  1788. CustomMenu* pSearchSubMenu = NULL;
  1789. CustomMenu* pProviderSubMenu = NULL;
  1790. if (!g_pMenu)
  1791. {
  1792. return;
  1793. }
  1794. if (idCtl == IDB_OPTIONS)
  1795. {
  1796. g_pMenu->AppendMenu(IDM_OPTIONS,hInst,IDM_OPTIONS);
  1797. g_pMenu->AppendMenu(IDM_PLAYLIST,hInst,IDM_PLAYLIST);
  1798. g_pMenu->AppendSeparator();
  1799. if (!IsNetOK(hwnd))
  1800. {
  1801. EnableMenuItem(g_pMenu->GetMenuHandle(),
  1802. IDM_PLAYLIST,
  1803. MF_BYCOMMAND | MF_GRAYED);
  1804. }
  1805. if (g_nViewMode == VIEW_MODE_NORMAL)
  1806. {
  1807. g_pMenu->AppendMenu(IDM_TINY,hInst,IDM_TINY);
  1808. }
  1809. else
  1810. {
  1811. g_pMenu->AppendMenu(IDM_NORMAL,hInst,IDM_NORMAL);
  1812. }
  1813. g_pMenu->AppendSeparator();
  1814. g_pMenu->AppendMenu(IDM_HELP,hInst,IDM_HELP);
  1815. g_pMenu->AppendMenu(IDM_ABOUT,hInst,IDM_ABOUT);
  1816. g_pMenu->AppendSeparator();
  1817. g_pMenu->AppendMenu(IDM_EXIT,hInst,IDM_EXIT);
  1818. } //end if options
  1819. if (idCtl == IDB_NET)
  1820. {
  1821. AllocCustomMenu(&pSearchSubMenu);
  1822. AllocCustomMenu(&pProviderSubMenu);
  1823. MMMEDIAID mmMedia;
  1824. mmMedia.nDrive = -1;
  1825. IMMComponentAutomation* pAuto = NULL;
  1826. HRESULT hr = pNodeCurrent->pComp->QueryInterface(IID_IMMComponentAutomation,(void**)&pAuto);
  1827. pAuto->OnAction(MMACTION_GETMEDIAID,&mmMedia);
  1828. pAuto->Release();
  1829. BOOL fContinue = TRUE;
  1830. //append static menu choices
  1831. if (IsDownloading())
  1832. {
  1833. g_pMenu->AppendMenu(IDM_NET_CANCEL,hInst,IDM_NET_CANCEL);
  1834. }
  1835. else
  1836. {
  1837. g_pMenu->AppendMenu(IDM_NET_UPDATE,hInst,IDM_NET_UPDATE);
  1838. if (mmMedia.dwMediaID == 0)
  1839. {
  1840. //need to gray out menu
  1841. MENUITEMINFO mmi;
  1842. mmi.cbSize = sizeof(mmi);
  1843. mmi.fMask = MIIM_STATE;
  1844. mmi.fState = MFS_GRAYED;
  1845. HMENU hMenu = g_pMenu->GetMenuHandle();
  1846. SetMenuItemInfo(hMenu,IDM_NET_UPDATE,FALSE,&mmi);
  1847. }
  1848. }
  1849. //if networking is not allowed, gray it out ...
  1850. //don't worry about cancel case, it won't be there
  1851. if (!IsNetOK(hwnd))
  1852. {
  1853. EnableMenuItem(g_pMenu->GetMenuHandle(),
  1854. IDM_NET_UPDATE,
  1855. MF_BYCOMMAND | MF_GRAYED);
  1856. }
  1857. //don't allow searching if title isn't available
  1858. LPCDDATA pData = GetCDData();
  1859. if (pData)
  1860. {
  1861. if (pData->QueryTitle(mmMedia.dwMediaID))
  1862. {
  1863. pSearchSubMenu->AppendMenu(IDM_NET_BAND,hInst,IDM_NET_BAND);
  1864. pSearchSubMenu->AppendMenu(IDM_NET_CD,hInst,IDM_NET_CD);
  1865. pSearchSubMenu->AppendMenu(IDM_NET_ROLLINGSTONE_ARTIST,hInst,IDM_NET_ROLLINGSTONE_ARTIST);
  1866. pSearchSubMenu->AppendMenu(IDM_NET_BILLBOARD_ARTIST,hInst,IDM_NET_BILLBOARD_ARTIST);
  1867. pSearchSubMenu->AppendMenu(IDM_NET_BILLBOARD_ALBUM,hInst,IDM_NET_BILLBOARD_ALBUM);
  1868. g_pMenu->AppendMenu(hInst,IDM_NET_SEARCH_HEADING,pSearchSubMenu);
  1869. }
  1870. } //end if pdata
  1871. //display any provider home pages
  1872. DWORD i = 0;
  1873. LPCDOPT pOpt = GetCDOpt();
  1874. if( pOpt )
  1875. {
  1876. LPCDOPTIONS pCDOpts = pOpt->GetCDOpts();
  1877. LPCDPROVIDER pProviderList = pCDOpts->pProviderList;
  1878. while (pProviderList!=NULL)
  1879. {
  1880. TCHAR szProviderMenu[MAX_PATH];
  1881. TCHAR szHomePageFormat[MAX_PATH/2];
  1882. LoadString(hInst,IDS_HOMEPAGEFORMAT,szHomePageFormat,sizeof(szHomePageFormat)/sizeof(TCHAR));
  1883. wsprintf(szProviderMenu,szHomePageFormat,pProviderList->szProviderName);
  1884. pProviderSubMenu->AppendMenu(IDM_HOMEMENU_BASE+i,szProviderMenu);
  1885. pProviderList = pProviderList->pNext;
  1886. i++;
  1887. } //end while
  1888. g_pMenu->AppendMenu(hInst,IDM_NET_PROVIDER_HEADING,pProviderSubMenu);
  1889. } //end home pages
  1890. //display internet-loaded disc menus
  1891. if (pData)
  1892. {
  1893. if (pData->QueryTitle(mmMedia.dwMediaID))
  1894. {
  1895. LPCDTITLE pCDTitle = NULL;
  1896. hr = pData->LockTitle(&pCDTitle,mmMedia.dwMediaID);
  1897. if (SUCCEEDED(hr))
  1898. {
  1899. for (i = 0; i < pCDTitle->dwNumMenus; i++)
  1900. {
  1901. if (i==0)
  1902. {
  1903. g_pMenu->AppendSeparator();
  1904. }
  1905. TCHAR szDisplayNet[MAX_PATH];
  1906. NormalizeNameForMenuDisplay(pCDTitle->pMenuTable[i].szMenuText,szDisplayNet,sizeof(szDisplayNet));
  1907. g_pMenu->AppendMenu(i + IDM_NETMENU_BASE,szDisplayNet);
  1908. }
  1909. pData->UnlockTitle(pCDTitle,FALSE);
  1910. }
  1911. } //end if query title
  1912. }
  1913. } //end if net
  1914. if (idCtl == IDB_MODE)
  1915. {
  1916. g_pMenu->AppendMenu(IDM_MODE_NORMAL,hInst,IDI_MODE_NORMAL,IDM_MODE_NORMAL);
  1917. g_pMenu->AppendMenu(IDM_MODE_RANDOM,hInst,IDI_MODE_RANDOM,IDM_MODE_RANDOM);
  1918. g_pMenu->AppendMenu(IDM_MODE_REPEATONE,hInst,IDI_MODE_REPEATONE,IDM_MODE_REPEATONE);
  1919. g_pMenu->AppendMenu(IDM_MODE_REPEATALL,hInst,IDI_MODE_REPEATALL,IDM_MODE_REPEATALL);
  1920. g_pMenu->AppendMenu(IDM_MODE_INTRO,hInst,IDI_MODE_INTRO,IDM_MODE_INTRO);
  1921. g_pMenu->SetMenuDefaultItem(nCDMode,FALSE);
  1922. } //end if mode
  1923. if (idCtl==IDB_TRACK)
  1924. {
  1925. IMMComponentAutomation* pAuto = NULL;
  1926. HRESULT hr = pNodeCurrent->pComp->QueryInterface(IID_IMMComponentAutomation,(void**)&pAuto);
  1927. if ((SUCCEEDED(hr)) && (pAuto != NULL))
  1928. {
  1929. int i = 0;
  1930. while (SUCCEEDED(hr))
  1931. {
  1932. MMTRACKORDISC mmTrack;
  1933. mmTrack.nNumber = i++;
  1934. hr = pAuto->OnAction(MMACTION_GETTRACKINFO,&mmTrack);
  1935. if (SUCCEEDED(hr))
  1936. {
  1937. g_pMenu->AppendMenu(mmTrack.nID + IDM_TRACKLIST_BASE, mmTrack.szName);
  1938. if (mmTrack.fCurrent)
  1939. {
  1940. g_pMenu->SetMenuDefaultItem(mmTrack.nID + IDM_TRACKLIST_BASE,FALSE);
  1941. } //end if current
  1942. } //end if ok
  1943. } //end while
  1944. pAuto->Release();
  1945. }
  1946. } //end if track
  1947. if (idCtl == IDB_DISC)
  1948. {
  1949. IMMComponentAutomation* pAuto = NULL;
  1950. HRESULT hr = pNodeCurrent->pComp->QueryInterface(IID_IMMComponentAutomation,(void**)&pAuto);
  1951. int i = 0;
  1952. if ((SUCCEEDED(hr)) && (pAuto != NULL))
  1953. {
  1954. while (SUCCEEDED(hr))
  1955. {
  1956. MMTRACKORDISC mmDisc;
  1957. mmDisc.nNumber = i++;
  1958. hr = pAuto->OnAction(MMACTION_GETDISCINFO,&mmDisc);
  1959. if (SUCCEEDED(hr))
  1960. {
  1961. g_pMenu->AppendMenu(mmDisc.nID + IDM_DISCLIST_BASE, mmDisc.szName);
  1962. if (mmDisc.fCurrent)
  1963. {
  1964. g_pMenu->SetMenuDefaultItem(mmDisc.nID + IDM_DISCLIST_BASE,FALSE);
  1965. } //end if current
  1966. }
  1967. }
  1968. pAuto->Release();
  1969. }
  1970. if (i > 0)
  1971. {
  1972. g_pMenu->AppendSeparator();
  1973. }
  1974. g_pMenu->AppendMenu(IDM_OPENVIRTUALCD,hInst,IDM_OPENVIRTUALCD);
  1975. } //end if disc
  1976. //push down to under button
  1977. HWND hwndButton = pButton->GetHWND();
  1978. GetClientRect(hwndButton,&rect);
  1979. //convert whole rect to screen coordinates
  1980. ClientToScreen(hwndButton,(LPPOINT)&rect);
  1981. ClientToScreen(hwndButton,((LPPOINT)&rect)+1);
  1982. KillTimer(hwnd,nLastMenu);
  1983. nLastMenu = idCtl;
  1984. fBlockMenu = TRUE;
  1985. pButton->SetMenuingState(TRUE);
  1986. if (g_pMenu)
  1987. {
  1988. g_pMenu->TrackPopupMenu(0,rect.left,rect.bottom,hwnd,&rect);
  1989. }
  1990. else
  1991. {
  1992. BlockMenu(hwnd);
  1993. }
  1994. pButton->SetMenuingState(FALSE);
  1995. if (g_pMenu)
  1996. {
  1997. g_pMenu->Destroy();
  1998. g_pMenu = NULL;
  1999. }
  2000. if (pProviderSubMenu)
  2001. {
  2002. pProviderSubMenu->Destroy();
  2003. pProviderSubMenu = NULL;
  2004. }
  2005. if (pSearchSubMenu)
  2006. {
  2007. pSearchSubMenu->Destroy();
  2008. pSearchSubMenu = NULL;
  2009. }
  2010. } //end if selected
  2011. } //end if right button
  2012. return;
  2013. }
  2014. ////////////////////////////////////////////////////////////////////////////////////////////
  2015. // * OnNCHitTest
  2016. // How we pretend that we have a real caption
  2017. ////////////////////////////////////////////////////////////////////////////////////////////
  2018. UINT OnNCHitTest(HWND hwnd, short x, short y, BOOL fButtonDown)
  2019. {
  2020. UINT ht = HTCLIENT;
  2021. if (!fButtonDown)
  2022. {
  2023. ht = FORWARD_WM_NCHITTEST(hwnd, x, y, DefWindowProc );
  2024. }
  2025. RECT rect;
  2026. GetClientRect(hwnd,&rect);
  2027. rect.bottom = rect.top + TITLEBAR_HEIGHT +
  2028. (g_nViewMode == VIEW_MODE_NORMAL ? TITLEBAR_YOFFSET_LARGE :
  2029. TITLEBAR_YOFFSET_SMALL);
  2030. POINT pt;
  2031. pt.x = (LONG)x;
  2032. pt.y = (LONG)y;
  2033. ScreenToClient(hwnd,&pt);
  2034. if (PtInRect(&rect,pt))
  2035. {
  2036. ht = HTCAPTION;
  2037. }
  2038. rect.left = SYSMENU_XOFFSET;
  2039. rect.right = SYSMENU_XOFFSET + SYSMENU_WIDTH;
  2040. //check for a system-menu hit.
  2041. if (PtInRect(&rect,pt))
  2042. {
  2043. ht = HTSYSMENU;
  2044. }
  2045. //always a caption hit in small mode or nobar mode
  2046. if (g_nViewMode >= VIEW_MODE_SMALL)
  2047. {
  2048. ht = HTCAPTION;
  2049. }
  2050. SetWindowLongPtr(hwnd, DWLP_MSGRESULT, ht);
  2051. return (ht);
  2052. }
  2053. ////////////////////////////////////////////////////////////////////////////////////////////
  2054. // * FillGradient
  2055. // from kernel's caption.c
  2056. // Allows us to have the cool gradient caption bar that you get for free otherwise
  2057. ////////////////////////////////////////////////////////////////////////////////////////////
  2058. void FillGradient(HDC hdc, LPCRECT prc, COLORREF rgbLeft, COLORREF rgbRight)
  2059. {
  2060. TRIVERTEX avert[2];
  2061. static GRADIENT_RECT auRect[1] = {0,1};
  2062. #define GetCOLOR16(RGB, clr) ((COLOR16)(Get ## RGB ## Value(clr) << 8))
  2063. avert[0].Red = GetCOLOR16(R, rgbLeft);
  2064. avert[0].Green = GetCOLOR16(G, rgbLeft);
  2065. avert[0].Blue = GetCOLOR16(B, rgbLeft);
  2066. avert[1].Red = GetCOLOR16(R, rgbRight);
  2067. avert[1].Green = GetCOLOR16(G, rgbRight);
  2068. avert[1].Blue = GetCOLOR16(B, rgbRight);
  2069. avert[0].x = prc->left;
  2070. avert[0].y = prc->top;
  2071. avert[1].x = prc->right;
  2072. avert[1].y = prc->bottom;
  2073. //only load once, when needed. Freed in "CleanUp" call
  2074. if (hmImage == NULL)
  2075. {
  2076. hmImage = LoadLibrary(TEXT("MSIMG32.DLL"));
  2077. if (hmImage!=NULL)
  2078. {
  2079. fnGradient = (GRADIENTPROC)GetProcAddress(hmImage,"GradientFill");
  2080. }
  2081. }
  2082. if (fnGradient!=NULL)
  2083. {
  2084. fnGradient(hdc, avert, 2, (PUSHORT)auRect, 1, 0x00000000);
  2085. return;
  2086. }
  2087. BOOL fActiveWindow = FALSE;
  2088. if (hwndMain == GetForegroundWindow())
  2089. {
  2090. fActiveWindow = TRUE;
  2091. }
  2092. HBRUSH hbrush = CreateSolidBrush(GetSysColor(fActiveWindow ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION));
  2093. FillRect(hdc,prc,hbrush);
  2094. DeleteObject(hbrush);
  2095. }
  2096. ////////////////////////////////////////////////////////////////////////////////////////////
  2097. // * DrawTitleBar
  2098. // Blits the title bar to the screen
  2099. ////////////////////////////////////////////////////////////////////////////////////////////
  2100. void DrawTitleBar(HDC hdc, HWND hwnd, BOOL fActiveWindow, BOOL fExludeRect)
  2101. {
  2102. if (g_nViewMode >= VIEW_MODE_SMALL)
  2103. {
  2104. return; //no title bar in these views
  2105. }
  2106. RECT rect;
  2107. HBRUSH hbrush;
  2108. //convert the client rect of the minimize button into the rect within the
  2109. //main display area
  2110. RECT minButtonRect;
  2111. RECT mainWndRect;
  2112. GetWindowRect(hwnd,&mainWndRect);
  2113. HWND hwndButton = GetDlgItem(hwnd,IDB_MINIMIZE);
  2114. if (!hwndButton)
  2115. {
  2116. return; //must have been called before button was created
  2117. }
  2118. GetWindowRect(hwndButton,&minButtonRect);
  2119. HDC memDC = CreateCompatibleDC(hdc);
  2120. HBITMAP hbmp = CreateCompatibleBitmap(hdc,
  2121. (g_nViewMode == VIEW_MODE_NORMAL ? bmMain.bmWidth : bmMainRestore.bmWidth),
  2122. (g_nViewMode == VIEW_MODE_NORMAL ? bmMain.bmHeight : bmMainRestore.bmHeight));
  2123. HBITMAP holdbmp = (HBITMAP)SelectObject(memDC, hbmp);
  2124. BOOL fGradient = FALSE;
  2125. SystemParametersInfo(SPI_GETGRADIENTCAPTIONS,0,&fGradient,0);
  2126. //we just need the left-hand side.
  2127. //to get it, we take the width of the window and subtract the offset
  2128. //from the right of the window
  2129. minButtonRect.left = (mainWndRect.right - mainWndRect.left) -
  2130. (mainWndRect.right - minButtonRect.left);
  2131. rect.left = SYSMENU_XOFFSET + SYSMENU_WIDTH + 1;
  2132. rect.right = minButtonRect.left - (GetXOffset()*2) - 1;
  2133. rect.top = (g_nViewMode == VIEW_MODE_NORMAL ? TITLEBAR_YOFFSET_LARGE :
  2134. TITLEBAR_YOFFSET_SMALL);
  2135. rect.bottom = rect.top + TITLEBAR_HEIGHT;
  2136. if (fGradient)
  2137. {
  2138. DWORD dwStartColor = GetSysColor(fActiveWindow ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION);
  2139. DWORD dwFinishColor = GetSysColor(fActiveWindow ? COLOR_GRADIENTACTIVECAPTION : COLOR_GRADIENTINACTIVECAPTION);
  2140. FillGradient(memDC,&rect,dwStartColor,dwFinishColor);
  2141. }
  2142. else
  2143. {
  2144. hbrush = CreateSolidBrush(GetSysColor(fActiveWindow ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION));
  2145. FillRect(memDC,&rect,hbrush);
  2146. DeleteObject(hbrush);
  2147. }
  2148. TCHAR s[MAX_PATH];
  2149. GetWindowText(hwnd,s,MAX_PATH-1);
  2150. SetBkMode(memDC,TRANSPARENT);
  2151. SetTextColor(memDC, GetSysColor(fActiveWindow ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT));
  2152. //create title bar font
  2153. NONCLIENTMETRICS metrics;
  2154. metrics.cbSize = sizeof(metrics);
  2155. SystemParametersInfo(SPI_GETNONCLIENTMETRICS,sizeof(metrics),&metrics,0);
  2156. if (IS_DBCS_CHARSET(metrics.lfCaptionFont.lfCharSet))
  2157. {
  2158. metrics.lfCaptionFont.lfHeight = (-9 * STANDARD_PIXELS_PER_INCH) / 72;
  2159. } else {
  2160. metrics.lfCaptionFont.lfHeight = (-8 * STANDARD_PIXELS_PER_INCH) / 72;
  2161. }
  2162. HFONT hTitleFont = CreateFontIndirect(&metrics.lfCaptionFont);
  2163. HFONT hOrgFont = (HFONT)SelectObject(memDC, hTitleFont);
  2164. ExtTextOut( memDC, rect.left + 3, rect.top, 0, NULL, s, _tcslen(s), NULL );
  2165. SelectObject(memDC,hOrgFont);
  2166. BitBlt(hdc,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top-1,memDC,rect.left,rect.top,SRCCOPY);
  2167. if (fExludeRect)
  2168. {
  2169. ExcludeClipRect(hdc,rect.left,rect.top,rect.right,rect.bottom-1);
  2170. }
  2171. SelectObject(memDC, holdbmp);
  2172. DeleteObject(hbmp);
  2173. SelectObject(memDC, hOrgFont);
  2174. DeleteDC(memDC);
  2175. DeleteObject(hTitleFont);
  2176. }
  2177. ////////////////////////////////////////////////////////////////////////////////////////////
  2178. // * DrawVolume
  2179. // Tells the cdplayer to start showing the volume setting
  2180. ////////////////////////////////////////////////////////////////////////////////////////////
  2181. void DrawVolume(DWORD level)
  2182. {
  2183. //we just have the led window draw it
  2184. HWND ledWnd = GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW);
  2185. MMONVOLCHANGED mmVolChange;
  2186. mmVolChange.dwNewVolume = level;
  2187. mmVolChange.fMuted = FALSE;
  2188. mmVolChange.szLineName = szLineName;
  2189. SendMessage(ledWnd,WM_LED_INFO_PAINT,0,(LPARAM)&mmVolChange);
  2190. }
  2191. ////////////////////////////////////////////////////////////////////////////////////////////
  2192. // * OnToolTipNotify
  2193. // Called from tool tips to get the text they need to display
  2194. ////////////////////////////////////////////////////////////////////////////////////////////
  2195. VOID OnToolTipNotify(LPARAM lParam)
  2196. {
  2197. LPTOOLTIPTEXT lpttt;
  2198. HWND hwndCtrl;
  2199. if ((((LPNMHDR) lParam)->code) == TTN_NEEDTEXT)
  2200. {
  2201. hwndCtrl = (HWND)((LPNMHDR)lParam)->idFrom;
  2202. lpttt = (LPTOOLTIPTEXT) lParam;
  2203. if (hwndCtrl == GetDlgItem(hwndMain,IDB_VOLUME))
  2204. {
  2205. GetWindowText(hwndCtrl,g_tooltext,sizeof(g_tooltext)/sizeof(TCHAR));
  2206. }
  2207. else
  2208. {
  2209. CMButton* pButton = GetMButtonFromHWND(hwndCtrl);
  2210. if (pButton)
  2211. {
  2212. LoadString(hInst,pButton->GetToolTipID(),g_tooltext,sizeof(g_tooltext)/sizeof(TCHAR));
  2213. }
  2214. }
  2215. lpttt->lpszText = g_tooltext;
  2216. }
  2217. return;
  2218. }
  2219. ////////////////////////////////////////////////////////////////////////////////////////////
  2220. // * GetNumBatchedTitles
  2221. // Get the number of titles currently in the batch queue
  2222. ////////////////////////////////////////////////////////////////////////////////////////////
  2223. DWORD GetNumBatchedTitles()
  2224. {
  2225. LPCDDATA pData = GetCDData();
  2226. DWORD dwReturn = 0;
  2227. if (pData)
  2228. {
  2229. dwReturn = pData->GetNumBatched();
  2230. }
  2231. return (dwReturn);
  2232. }
  2233. ////////////////////////////////////////////////////////////////////////////////////////////
  2234. // * HandleBadServiceProvider
  2235. // Put up message box if the provider did not pass validation
  2236. ////////////////////////////////////////////////////////////////////////////////////////////
  2237. void HandleBadServiceProvider(HWND hwndParent)
  2238. {
  2239. TCHAR szError[MAX_PATH];
  2240. LoadString(hInst,IDS_BADPROVIDER,szError,sizeof(szError)/sizeof(TCHAR));
  2241. MessageBox(hwndParent,szError,szAppName,MB_ICONEXCLAMATION|MB_OK);
  2242. }
  2243. ////////////////////////////////////////////////////////////////////////////////////////////
  2244. // * NormalizeNameForURL
  2245. // Changes a name to a "normalized" name for URL
  2246. ////////////////////////////////////////////////////////////////////////////////////////////
  2247. void NormalizeNameForURL(LPCTSTR szName, LPTSTR szOutput, DWORD cbOutputLen)
  2248. {
  2249. typedef BOOL (PASCAL *CANPROC)(LPCTSTR, LPTSTR, LPDWORD, DWORD);
  2250. CANPROC canProc = NULL;
  2251. _tcscpy(szOutput,szName); //init URL with passed-in value
  2252. //if possible, canonicalize the URL
  2253. HMODULE hNet = LoadLibrary(TEXT("WININET.DLL"));
  2254. if (hNet!=NULL)
  2255. {
  2256. canProc = (CANPROC)GetProcAddress(hNet,CANONFUNCTION);
  2257. if (canProc!=NULL)
  2258. {
  2259. BOOL f = canProc(szName,szOutput,&cbOutputLen,0);
  2260. }
  2261. FreeLibrary(hNet);
  2262. }
  2263. }
  2264. ////////////////////////////////////////////////////////////////////////////////////////////
  2265. // * OpenBrowserURL
  2266. // Opens a URL in the default browser
  2267. ////////////////////////////////////////////////////////////////////////////////////////////
  2268. void OpenBrowserURL(TCHAR* szURL)
  2269. {
  2270. ShellExecute(NULL,_TEXT("open"),szURL,NULL,_TEXT(""),SW_NORMAL);
  2271. }
  2272. ////////////////////////////////////////////////////////////////////////////////////////////
  2273. // * ProgressDlgProc
  2274. // Main proc for download progress dialog
  2275. // Should Fix: Put in own file
  2276. ////////////////////////////////////////////////////////////////////////////////////////////
  2277. INT_PTR CALLBACK ProgressDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  2278. {
  2279. BOOL fReturnVal = TRUE;
  2280. static HWND hwndAnimate = NULL;
  2281. static HANDLE hLogo = NULL;
  2282. static LPCDOPT pOpts = NULL;
  2283. static fOneDownloaded = FALSE;
  2284. static LPCDPROVIDER pCurrent = NULL;
  2285. switch (msg)
  2286. {
  2287. default:
  2288. fReturnVal = FALSE;
  2289. break;
  2290. case WM_INITDIALOG:
  2291. {
  2292. fOneDownloaded = FALSE;
  2293. BOOL fSingle = FALSE;
  2294. DWORD dwDiscID = (DWORD)-1; //use batch
  2295. if (lParam == 0)
  2296. {
  2297. if (!pSingleTitle)
  2298. {
  2299. EndDialog(hDlg,-1);
  2300. return FALSE;
  2301. }
  2302. fSingle = TRUE;
  2303. dwDiscID = pSingleTitle->dwTitleID;
  2304. lParam = 1;
  2305. }
  2306. if (IsDownloading())
  2307. {
  2308. //if we're downloading on the Main UI, put up a "waiting" message for now
  2309. TCHAR szWaiting[MAX_PATH];
  2310. LoadString(hInst,IDS_WAITINGFORDOWNLOAD,szWaiting,sizeof(szWaiting)/sizeof(TCHAR));
  2311. SendDlgItemMessage(hDlg,IDC_STATIC_INFO,WM_SETTEXT,0,(LPARAM)szWaiting);
  2312. }
  2313. //set the range
  2314. SendDlgItemMessage(hDlg, IDC_METER, PBM_SETRANGE, 0, MAKELPARAM(0, lParam));
  2315. SendDlgItemMessage(hDlg, IDC_METER, PBM_SETPOS, 0, 0);
  2316. //proceed with the download
  2317. MMNET mmNet;
  2318. mmNet.discid = dwDiscID;
  2319. mmNet.hwndCallback = hDlg; //call back to this guy
  2320. mmNet.fForceNet = fSingle;
  2321. mmNet.pData = (void*)GetCDData();
  2322. if (fSingle)
  2323. {
  2324. mmNet.pData2 = (void*)pSingleTitle;
  2325. }
  2326. else
  2327. {
  2328. mmNet.pData2 = NULL;
  2329. }
  2330. SendMessage(hwndCurrentComp,WM_COMMAND,MAKEWPARAM(ID_CDUPDATE,0),(LPARAM)&mmNet);
  2331. pOpts = GetCDOpt();
  2332. if (!hLogo)
  2333. {
  2334. //get the path to the vendor logo file
  2335. if (pOpts)
  2336. {
  2337. LPCDOPTIONS pOptions = NULL;
  2338. pOptions = pOpts->GetCDOpts();
  2339. if (pOptions)
  2340. {
  2341. if (pOptions->pCurrentProvider!=NULL)
  2342. {
  2343. hLogo = OpenDIB(pOptions->pCurrentProvider->szProviderLogo,(HFILE)-1);
  2344. pCurrent = pOptions->pCurrentProvider;
  2345. } //end if current provider ok
  2346. } //end if poptions ok
  2347. } //end if popts created
  2348. }
  2349. fReturnVal = TRUE;
  2350. }
  2351. break;
  2352. case WM_PAINT :
  2353. {
  2354. HDC hdc;
  2355. PAINTSTRUCT ps;
  2356. hdc = BeginPaint( hDlg, &ps );
  2357. RECT progressrect, mainrect;
  2358. GetWindowRect(GetDlgItem(hDlg,IDC_METER),&progressrect);
  2359. GetWindowRect(hDlg,&mainrect);
  2360. mainrect.top = mainrect.top + GetSystemMetrics(SM_CYCAPTION);
  2361. //turn on animation if it is not visible
  2362. if (!hwndAnimate)
  2363. {
  2364. hwndAnimate = Animate_Create(hDlg,
  2365. IDI_ICON_ANI_DOWN,
  2366. WS_CHILD|ACS_TRANSPARENT,
  2367. hInst);
  2368. //headers don't have Animate_OpenEx yet,
  2369. //so just do the straight call
  2370. SendMessage(hwndAnimate,ACM_OPEN,(WPARAM)hInst,
  2371. (LPARAM)MAKEINTRESOURCE(IDI_ICON_ANI_DOWN));
  2372. //move to the top/left of the window, equidistant from top and progress indicator
  2373. RECT anirect;
  2374. GetWindowRect(hwndAnimate,&anirect);
  2375. MoveWindow(hwndAnimate,
  2376. progressrect.left - mainrect.left - 3,
  2377. ((progressrect.top - mainrect.top)
  2378. - (anirect.bottom - anirect.top)) - LOGO_Y_OFFSET,
  2379. anirect.right - anirect.left,
  2380. anirect.bottom - anirect.top,
  2381. FALSE);
  2382. Animate_Play(hwndAnimate,0,-1,-1);
  2383. ShowWindow(hwndAnimate,SW_SHOW);
  2384. //move "info" window
  2385. MoveWindow(GetDlgItem(hDlg,IDC_STATIC_INFO),
  2386. (progressrect.left - mainrect.left) + (anirect.right - anirect.left) + 3,
  2387. ((progressrect.top - mainrect.top)
  2388. - (anirect.bottom - anirect.top)) - LOGO_Y_OFFSET,
  2389. ((progressrect.right - mainrect.left) - VENDORLOGO_WIDTH - 3)
  2390. - ((progressrect.left - mainrect.left) + (anirect.right - anirect.left) + 3),
  2391. anirect.bottom - anirect.top,
  2392. FALSE);
  2393. }
  2394. if (hLogo)
  2395. {
  2396. DibBlt(hdc,
  2397. (progressrect.right - mainrect.left) - (VENDORLOGO_WIDTH + 5),
  2398. ((progressrect.top - mainrect.top)
  2399. - VENDORLOGO_HEIGHT) - LOGO_Y_OFFSET,
  2400. -1,
  2401. -1,
  2402. hLogo,
  2403. 0,0,
  2404. SRCCOPY,0);
  2405. }
  2406. EndPaint(hDlg,&ps);
  2407. return 0;
  2408. }
  2409. break;
  2410. //try to launch provider home page
  2411. case WM_LBUTTONUP :
  2412. {
  2413. if ((hLogo) && (pCurrent))
  2414. {
  2415. RECT progressrect, mainrect;
  2416. GetWindowRect(GetDlgItem(hDlg,IDC_METER),&progressrect);
  2417. GetWindowRect(hDlg,&mainrect);
  2418. mainrect.top = mainrect.top + GetSystemMetrics(SM_CYCAPTION);
  2419. RECT logoRect;
  2420. SetRect(&logoRect,
  2421. (progressrect.right - mainrect.left) - VENDORLOGO_WIDTH,
  2422. ((progressrect.top - mainrect.top)
  2423. - VENDORLOGO_HEIGHT) - LOGO_Y_OFFSET,
  2424. (progressrect.right - mainrect.left),
  2425. (progressrect.top - mainrect.top) - LOGO_Y_OFFSET);
  2426. POINT pt;
  2427. pt.x = LOWORD(lParam);
  2428. pt.y = HIWORD(lParam);
  2429. if (PtInRect(&logoRect,pt))
  2430. {
  2431. OpenBrowserURL(pCurrent->szProviderHome);
  2432. }
  2433. }
  2434. }
  2435. break;
  2436. case WM_DESTROY :
  2437. {
  2438. if (hwndAnimate)
  2439. {
  2440. DestroyWindow(hwndAnimate);
  2441. hwndAnimate = NULL;
  2442. }
  2443. if (hLogo)
  2444. {
  2445. GlobalFree(hLogo);
  2446. hLogo = NULL;
  2447. }
  2448. }
  2449. break;
  2450. case WM_NET_DB_UPDATE_BATCH :
  2451. {
  2452. LPCDOPT pOpts = GetCDOpt();
  2453. if (pOpts)
  2454. {
  2455. pOpts->DownLoadCompletion(0,NULL);
  2456. }
  2457. }
  2458. break;
  2459. case WM_NET_DB_UPDATE_DISC :
  2460. {
  2461. LPCDOPT pOpts = GetCDOpt();
  2462. if (pOpts)
  2463. {
  2464. pOpts->DiscChanged((LPCDUNIT)lParam);
  2465. }
  2466. }
  2467. break;
  2468. case WM_NET_CHANGEPROVIDER :
  2469. {
  2470. LPCDPROVIDER pProv = (LPCDPROVIDER)lParam;
  2471. if (pProv!=NULL)
  2472. {
  2473. pCurrent = pProv;
  2474. if (hLogo)
  2475. {
  2476. GlobalFree(hLogo);
  2477. hLogo = NULL;
  2478. }
  2479. hLogo = OpenDIB(pCurrent->szProviderLogo,(HFILE)-1);
  2480. InvalidateRect(hDlg,NULL,FALSE);
  2481. UpdateWindow(hDlg);
  2482. } //end if provider ok
  2483. }
  2484. break;
  2485. case WM_NET_STATUS :
  2486. {
  2487. //until at least one title is downloaded, we need to do
  2488. //something to entertain the user, so go ahead and show the
  2489. //downloading text
  2490. if (!fOneDownloaded)
  2491. {
  2492. TCHAR progstr[MAX_PATH];
  2493. LoadString((HINSTANCE)wParam,(UINT)lParam,progstr,sizeof(progstr)/sizeof(TCHAR));
  2494. SendDlgItemMessage(hDlg,IDC_STATIC_INFO,WM_SETTEXT,0,(LPARAM)progstr);
  2495. }
  2496. }
  2497. break;
  2498. case WM_NET_DONE :
  2499. {
  2500. fOneDownloaded = TRUE;
  2501. if (lParam == (LPARAM)-1)
  2502. {
  2503. HandleBadServiceProvider(hDlg);
  2504. EndDialog(hDlg,0);
  2505. break;
  2506. }
  2507. if (lParam == 0)
  2508. {
  2509. EndDialog(hDlg,0);
  2510. break;
  2511. }
  2512. else
  2513. {
  2514. MMNET mmNet;
  2515. mmNet.discid = (DWORD)lParam;
  2516. mmNet.hwndCallback = hDlg;
  2517. mmNet.pData = (void*)GetCDData();
  2518. mmNet.pData2 = NULL;
  2519. mmNet.fForceNet = FALSE;
  2520. SendMessage(hwndCurrentComp,WM_COMMAND,MAKEWPARAM(ID_CDUPDATE,0),(LPARAM)&mmNet);
  2521. LPCDDATA pData = GetCDData();
  2522. //try to display that we found a title
  2523. if (!pData)
  2524. {
  2525. break;
  2526. }
  2527. //
  2528. // Try to read in title from the options database
  2529. //
  2530. if (!pData->QueryTitle((DWORD)(lParam)))
  2531. {
  2532. break;
  2533. }
  2534. //
  2535. // We found an entry for this disc, so copy all the information
  2536. // from the title database
  2537. LPCDTITLE pCDTitle = NULL;
  2538. if (FAILED(pData->LockTitle(&pCDTitle,(DWORD)(lParam))))
  2539. {
  2540. break;
  2541. }
  2542. TCHAR foundstr[MAX_PATH];
  2543. TCHAR formatstr[MAX_PATH];
  2544. LoadString(hInst,IDS_FOUND,formatstr,sizeof(formatstr)/sizeof(TCHAR));
  2545. wsprintf(foundstr,formatstr,pCDTitle->szTitle,pCDTitle->szArtist);
  2546. SendDlgItemMessage(hDlg,IDC_STATIC_INFO,WM_SETTEXT,0,(LPARAM)foundstr);
  2547. }
  2548. }
  2549. break;
  2550. case WM_NET_INCMETER :
  2551. {
  2552. LRESULT dwPos = SendDlgItemMessage(hDlg,IDC_METER,PBM_GETPOS,0,0);
  2553. SendDlgItemMessage(hDlg, IDC_METER, PBM_SETPOS, (WPARAM)++dwPos, 0);
  2554. }
  2555. break;
  2556. case WM_NET_DB_FAILURE :
  2557. {
  2558. TCHAR szDBError[MAX_PATH];
  2559. LoadString(hInst,IDS_DB_FAILURE,szDBError,sizeof(szDBError)/sizeof(TCHAR));
  2560. MessageBox(hDlg,szDBError,szAppName,MB_ICONERROR|MB_OK);
  2561. }
  2562. break;
  2563. case WM_NET_NET_FAILURE :
  2564. {
  2565. TCHAR szNetError[MAX_PATH];
  2566. LoadString(hInst,IDS_NET_FAILURE,szNetError,sizeof(szNetError)/sizeof(TCHAR));
  2567. MessageBox(hDlg,szNetError,szAppName,MB_ICONERROR|MB_OK);
  2568. }
  2569. break;
  2570. case WM_COMMAND :
  2571. {
  2572. if (LOWORD(wParam) == IDCANCEL)
  2573. {
  2574. CancelDownload();
  2575. EndDialog(hDlg,-1);
  2576. }
  2577. }
  2578. }
  2579. return fReturnVal;
  2580. }
  2581. ////////////////////////////////////////////////////////////////////////////////////////////
  2582. // * HandleDiscsNotFound
  2583. // Ask the user if they want to nuke unfound batched titles, or save them for another time
  2584. ////////////////////////////////////////////////////////////////////////////////////////////
  2585. void HandleDiscsNotFound(HWND hwndParent)
  2586. {
  2587. DWORD dwNumNotFound = GetNumBatchedTitles();
  2588. if (dwNumNotFound == 0)
  2589. {
  2590. return;
  2591. }
  2592. TCHAR szNotFound[MAX_PATH];
  2593. if (dwNumNotFound > 1)
  2594. {
  2595. TCHAR szFormat[MAX_PATH];
  2596. LoadString(hInst,IDS_NOTFOUND,szFormat,sizeof(szFormat)/sizeof(TCHAR));
  2597. wsprintf(szNotFound,szFormat,dwNumNotFound);
  2598. }
  2599. else
  2600. {
  2601. LoadString(hInst,IDS_NOTFOUND1,szNotFound,sizeof(szNotFound)/sizeof(TCHAR));
  2602. }
  2603. int nAnswer = MessageBox(hwndParent,szNotFound,szAppName,MB_YESNO|MB_ICONQUESTION);
  2604. if (nAnswer == IDNO)
  2605. {
  2606. LPCDDATA pData = GetCDData();
  2607. if (pData)
  2608. {
  2609. pData->DumpBatch();
  2610. }
  2611. } //if said "no" to keeping batch
  2612. }
  2613. ////////////////////////////////////////////////////////////////////////////////////////////
  2614. // * OptionsDownloadCallback
  2615. // Called from the options dialog to do batches or single downloads
  2616. ////////////////////////////////////////////////////////////////////////////////////////////
  2617. DWORD CALLBACK OptionsDownloadCallback(LPCDTITLE pTitle, LPARAM lParam, HWND hwndParent)
  2618. {
  2619. if (pTitle == NULL)
  2620. {
  2621. DWORD dwNumBatched = GetNumBatchedTitles();
  2622. if (dwNumBatched > 0)
  2623. {
  2624. DialogBoxParam(hInst,MAKEINTRESOURCE(IDD_DOWNLOADPROGRESS),
  2625. hwndParent,ProgressDlgProc,dwNumBatched);
  2626. }
  2627. HandleDiscsNotFound(hwndParent);
  2628. //refresh the number of batched titles
  2629. return GetNumBatchedTitles();
  2630. }
  2631. else
  2632. {
  2633. pSingleTitle = pTitle;
  2634. INT_PTR status = DialogBoxParam(hInst,MAKEINTRESOURCE(IDD_DOWNLOADPROGRESS),
  2635. hwndParent,ProgressDlgProc,0);
  2636. //update the UI
  2637. LPCDOPT pOpts = GetCDOpt();
  2638. if (pOpts)
  2639. {
  2640. LPCDUNIT pUnit = pOpts->GetCDOpts()->pCDUnitList;
  2641. while (pUnit!=NULL)
  2642. {
  2643. if (pUnit->dwTitleID == pSingleTitle->dwTitleID)
  2644. {
  2645. pUnit->fDownLoading = FALSE;
  2646. pOpts->DiscChanged(pUnit);
  2647. break;
  2648. }
  2649. pUnit = pUnit->pNext;
  2650. }
  2651. }
  2652. //if download wasn't canceled, check for disc id in database
  2653. if (status != -1)
  2654. {
  2655. LPCDDATA pData = GetCDData();
  2656. if (!pData->QueryTitle(pSingleTitle->dwTitleID))
  2657. {
  2658. TCHAR szNotFound[MAX_PATH];
  2659. LoadString(hInst,IDS_TITLE_NOT_FOUND,szNotFound,sizeof(szNotFound)/sizeof(TCHAR));
  2660. MessageBox(hwndParent,szNotFound,szAppName,MB_ICONINFORMATION|MB_OK);
  2661. }
  2662. else
  2663. {
  2664. if (pOpts)
  2665. {
  2666. LPCDOPTIONS pCDOpts = pOpts->GetCDOpts();
  2667. pCDOpts->dwBatchedTitles = GetNumBatchedTitles();
  2668. pOpts->DownLoadCompletion(1,&(pSingleTitle->dwTitleID));
  2669. } //end if OK to update batch number
  2670. }
  2671. }
  2672. return 0;
  2673. }
  2674. return 0;
  2675. }
  2676. ////////////////////////////////////////////////////////////////////////////////////////////
  2677. // * OptionsApply
  2678. // Called from the options dialog when appy is hit, or by main UI when OK is hit
  2679. ////////////////////////////////////////////////////////////////////////////////////////////
  2680. void CALLBACK OptionsApply(LPCDOPTIONS pCDOpts)
  2681. {
  2682. if (!pCDOpts)
  2683. {
  2684. return;
  2685. }
  2686. //tell the CD player to rescan its settings ...
  2687. //most of the settings are for it
  2688. IMMComponentAutomation* pAuto = NULL;
  2689. HRESULT hr = pNodeCurrent->pComp->QueryInterface(IID_IMMComponentAutomation,(void**)&pAuto);
  2690. if ((SUCCEEDED(hr)) && (pAuto != NULL))
  2691. {
  2692. pAuto->OnAction(MMACTION_READSETTINGS,pCDOpts->pCDData);
  2693. pAuto->Release();
  2694. }
  2695. LPCDUNIT pUnit = pCDOpts->pCDUnitList;
  2696. LPCDDATA pData = GetCDData();
  2697. while (pUnit!=NULL)
  2698. {
  2699. BOOL fRemove = FALSE;
  2700. if (pData)
  2701. {
  2702. fRemove = !(pData->QueryTitle(pUnit->dwTitleID));
  2703. }
  2704. if ((pUnit->fChanged) || (fRemove))
  2705. {
  2706. if ((pUnit->dwTitleID != 0) && (pUnit->dwTitleID != (DWORD)-1))
  2707. {
  2708. //tell the cd player that a title was updated, perhaps the ones in the drive
  2709. MMNET mmNet;
  2710. mmNet.discid = pUnit->dwTitleID;
  2711. mmNet.hwndCallback = hwndMain;
  2712. mmNet.pData = (void*)GetCDData();
  2713. mmNet.pData2 = NULL;
  2714. mmNet.fForceNet = FALSE;
  2715. SendMessage(hwndCurrentComp,WM_COMMAND,MAKEWPARAM(ID_CDUPDATE,0),(LPARAM)&mmNet);
  2716. }
  2717. }
  2718. pUnit = pUnit->pNext;
  2719. }
  2720. SetWindowPos(hwndMain,
  2721. pCDOpts->pCDData->fTopMost ? HWND_TOPMOST : HWND_NOTOPMOST,
  2722. 0,0,0,0,
  2723. SWP_NOMOVE|SWP_NOSIZE);
  2724. //may have changed cd volume line
  2725. if (InitCDVol(hwndMain, pCDOpts))
  2726. {
  2727. //when the volume line changes, we need to update the knob
  2728. DWORD dwVol = GetVolume();
  2729. CKnob* pKnob = GetKnobFromID(hwndMain,IDB_VOLUME);
  2730. if (pKnob!=NULL)
  2731. {
  2732. pKnob->SetPosition(dwVol,TRUE);
  2733. }
  2734. SendMessage(GetDlgItem(hwndMain,IDB_MUTE),BM_SETSTATE,(WPARAM)GetMute(),0);
  2735. SendMessage(GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW),WM_LED_MUTE,0,GetMute());
  2736. } //if vol line changed
  2737. //may have turned on/off shell mode
  2738. //we only care if the main UI is visible (i.e. not in shell-only mode)
  2739. if (IsWindowVisible(hwndMain))
  2740. {
  2741. if (fShellMode != pCDOpts->pCDData->fTrayEnabled)
  2742. {
  2743. fShellMode = pCDOpts->pCDData->fTrayEnabled;
  2744. if (fShellMode)
  2745. {
  2746. CreateShellIcon(hInst,hwndMain,pNodeCurrent,szAppName);
  2747. }
  2748. else
  2749. {
  2750. DestroyShellIcon();
  2751. } //end shellmode
  2752. } //end if shellmode changed in options
  2753. } //end main ui visible
  2754. }
  2755. ////////////////////////////////////////////////////////////////////////////////////////////
  2756. // * HandleMixerControlChange
  2757. // Updates UI when sndvol32 or other apps change our mixerline
  2758. ////////////////////////////////////////////////////////////////////////////////////////////
  2759. void HandleMixerControlChange(DWORD dwLineID)
  2760. {
  2761. if (dwLineID == mixerlinedetails.dwControlID)
  2762. {
  2763. DWORD dwVol = GetVolume();
  2764. CKnob* pKnob = GetKnobFromID(hwndMain,IDB_VOLUME);
  2765. //possible to get this change before knob is up
  2766. if (pKnob!=NULL)
  2767. {
  2768. pKnob->SetPosition(dwVol,TRUE);
  2769. }
  2770. }
  2771. if (dwLineID == mutelinedetails.dwControlID)
  2772. {
  2773. SendMessage(GetDlgItem(hwndMain,IDB_MUTE),BM_SETSTATE,(WPARAM)GetMute(),0);
  2774. SendMessage(GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW),WM_LED_MUTE,0,GetMute());
  2775. }
  2776. }
  2777. ////////////////////////////////////////////////////////////////////////////////////////////
  2778. // * ChildPaletteProc
  2779. // Updates child windows when palette changes
  2780. ////////////////////////////////////////////////////////////////////////////////////////////
  2781. BOOL CALLBACK ChildPaletteProc(HWND hwnd, LPARAM lParam)
  2782. {
  2783. InvalidateRect(hwnd,NULL,FALSE);
  2784. UpdateWindow(hwnd);
  2785. return TRUE;
  2786. }
  2787. ////////////////////////////////////////////////////////////////////////////////////////////
  2788. // * HandlePaletteChange
  2789. // Updates window when palette changes
  2790. ////////////////////////////////////////////////////////////////////////////////////////////
  2791. int HandlePaletteChange()
  2792. {
  2793. HDC hdc = GetDC(hwndMain);
  2794. HPALETTE hOldPal = SelectPalette(hdc,hpalMain,FALSE);
  2795. UINT i = RealizePalette(hdc);
  2796. if (i)
  2797. {
  2798. //update child windows "by hand", since they are clipped
  2799. EnumChildWindows(hwndMain,ChildPaletteProc,0);
  2800. //update main window
  2801. InvalidateRect(hwndMain,NULL,FALSE);
  2802. UpdateWindow(hwndMain);
  2803. }
  2804. SelectPalette(hdc,hOldPal,TRUE);
  2805. RealizePalette(hdc);
  2806. ReleaseDC(hwndMain,hdc);
  2807. return i;
  2808. }
  2809. ////////////////////////////////////////////////////////////////////////////////////////////
  2810. // * HandleDisplayChange
  2811. // Figures out if we need to recalc all bitmaps and does so ...
  2812. ////////////////////////////////////////////////////////////////////////////////////////////
  2813. void HandleDisplayChange()
  2814. {
  2815. int nOrgColorMode = g_nColorMode;
  2816. DetermineColorMode();
  2817. //only do anythhing if they changed modes
  2818. if (g_nColorMode != nOrgColorMode)
  2819. {
  2820. //nuke all child windows
  2821. for (int i = 0; i < NUM_BUTTONS; i++)
  2822. {
  2823. DestroyWindow(GetDlgItem(hwndMain,biButtons[i].id));
  2824. }
  2825. DestroyWindow(GetDlgItem(hwndMain,IDB_MUTE));
  2826. DestroyWindow(GetDlgItem(hwndMain,IDB_VOLUME));
  2827. UninitMButtons();
  2828. //nuke the bitmaps
  2829. GlobalFree(hbmpMain);
  2830. GlobalFree(hbmpMainRestore);
  2831. GlobalFree(hbmpMainSmall);
  2832. GlobalFree(hbmpMainNoBar);
  2833. DeleteObject(hpalMain);
  2834. hpalMain = SetPalette();
  2835. //rebuild the bitmaps
  2836. BuildFrameworkBitmaps();
  2837. //recreate the windows
  2838. CreateButtonWindows(hwndMain);
  2839. CreateVolumeKnob(hwndMain);
  2840. }
  2841. }
  2842. ////////////////////////////////////////////////////////////////////////////////////////////
  2843. // * DoPaint
  2844. // Handles the WM_PAINT for the main UI, actually a multimon paint callback
  2845. ////////////////////////////////////////////////////////////////////////////////////////////
  2846. BOOL CALLBACK DoPaint(HMONITOR hmonitor, HDC hdc, LPRECT lprcMonitor, LPARAM lData)
  2847. {
  2848. HWND hwnd = (HWND)lData;
  2849. HPALETTE hpalOld = SelectPalette(hdc, hpalMain, FALSE);
  2850. RealizePalette(hdc);
  2851. BOOL fActiveWindow = FALSE;
  2852. if (hwnd == GetForegroundWindow())
  2853. {
  2854. fActiveWindow = TRUE;
  2855. }
  2856. DrawTitleBar(hdc, hwnd, fActiveWindow, TRUE);
  2857. HANDLE hbmpView;
  2858. BITMAP* pBM = &bmMain;
  2859. switch (g_nViewMode)
  2860. {
  2861. case VIEW_MODE_NORMAL :
  2862. {
  2863. hbmpView = hbmpMain;
  2864. }
  2865. break;
  2866. case VIEW_MODE_RESTORE :
  2867. {
  2868. hbmpView = hbmpMainRestore;
  2869. pBM = &bmMainRestore;
  2870. }
  2871. break;
  2872. case VIEW_MODE_SMALL :
  2873. {
  2874. hbmpView = hbmpMainSmall;
  2875. pBM = &bmMainSmall;
  2876. }
  2877. break;
  2878. case VIEW_MODE_NOBAR :
  2879. {
  2880. hbmpView = hbmpMainNoBar;
  2881. pBM = &bmMainNoBar;
  2882. }
  2883. break;
  2884. }
  2885. DibBlt(hdc,
  2886. 0,
  2887. 0,
  2888. -1,
  2889. -1,
  2890. hbmpView,
  2891. 0,0,
  2892. SRCCOPY,0);
  2893. //reset the clipping region that was set in DrawTitleBar for reverse paint
  2894. RECT rcParent;
  2895. GetClientRect( hwnd, &rcParent );
  2896. HRGN region = CreateRectRgn(rcParent.left,rcParent.top,rcParent.right,rcParent.bottom);
  2897. SelectClipRgn(hdc, region);
  2898. DeleteObject(region);
  2899. SelectPalette(hdc, hpalOld, TRUE);
  2900. RealizePalette(hdc);
  2901. return TRUE;
  2902. }
  2903. ////////////////////////////////////////////////////////////////////////////////////////////
  2904. // * SetPlayButtonState
  2905. // Handles the play button's icon
  2906. ////////////////////////////////////////////////////////////////////////////////////////////
  2907. void SetPlayButtonState(BOOL fIntroMode)
  2908. {
  2909. CMButton* pButton = GetMButtonFromID(hwndMain,IDB_PLAY);
  2910. if (pButton)
  2911. {
  2912. if ((fPlaying) && (fIntroMode))
  2913. {
  2914. pButton->SetIcon(IDI_MODE_INTRO);
  2915. pButton->SetToolTipID(IDB_TT_INTRO);
  2916. SetWindowText(pButton->GetHWND(),TEXT("2"));
  2917. }
  2918. if ((fPlaying) && (fIntro) && (!fIntroMode))
  2919. {
  2920. pButton->SetIcon(IDI_ICON_PAUSE);
  2921. pButton->SetToolTipID(IDB_TT_PAUSE);
  2922. SetWindowText(pButton->GetHWND(),TEXT("1"));
  2923. }
  2924. }
  2925. fIntro = fIntroMode;
  2926. //need to save playback mode at this point
  2927. LPCDOPT pOpt = GetCDOpt();
  2928. if(pOpt)
  2929. {
  2930. LPCDOPTIONS pOptions = pOpt->GetCDOpts();
  2931. LPCDOPTDATA pOptionData = pOptions->pCDData;
  2932. pOptionData->dwPlayMode = nCDMode;
  2933. pOpt->UpdateRegistry();
  2934. }
  2935. }
  2936. ////////////////////////////////////////////////////////////////////////////////////////////
  2937. // * GetSearchURL
  2938. // Returns the standard IE "autosearch" URL
  2939. ////////////////////////////////////////////////////////////////////////////////////////////
  2940. BOOL GetSearchURL(TCHAR* szSearchURL)
  2941. {
  2942. BOOL fRet = FALSE;
  2943. HKEY hKeySearch = NULL;
  2944. long lResult = ::RegOpenKeyEx( HKEY_CURRENT_USER,
  2945. REG_KEY_SEARCHURL,
  2946. 0, KEY_READ, &hKeySearch );
  2947. if (lResult == ERROR_SUCCESS)
  2948. {
  2949. DWORD dwCbData = MAX_PATH;
  2950. DWORD dwType = REG_SZ;
  2951. lResult = ::RegQueryValueEx( hKeySearch, TEXT(""), NULL,
  2952. &dwType, (LPBYTE)szSearchURL, &dwCbData );
  2953. if (lResult == ERROR_SUCCESS)
  2954. {
  2955. fRet = TRUE;
  2956. }
  2957. RegCloseKey(hKeySearch);
  2958. }
  2959. return (fRet);
  2960. }
  2961. ////////////////////////////////////////////////////////////////////////////////////////////
  2962. // * OpenVirtualCD
  2963. // Switches over to "Virtual CD mode" --
  2964. // basically a mode where we are playing back an ASX playlist of cached audio files
  2965. ////////////////////////////////////////////////////////////////////////////////////////////
  2966. void OpenVirtualCD()
  2967. {
  2968. //display dialog
  2969. //if dialog successful, switch UI to msdxm.ocx mode
  2970. }
  2971. ////////////////////////////////////////////////////////////////////////////////////////////
  2972. // * HandleCommand
  2973. // Handles all WM_COMMAND message for the main app
  2974. ////////////////////////////////////////////////////////////////////////////////////////////
  2975. void HandleCommand(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  2976. {
  2977. //handle system commands
  2978. if ((LOWORD(wParam) >= SC_SIZE) && (LOWORD(wParam) <= SC_CONTEXTHELP))
  2979. {
  2980. SendMessage(hwnd,WM_SYSCOMMAND,(WPARAM)LOWORD(wParam),0);
  2981. return;
  2982. }
  2983. switch (LOWORD(wParam))
  2984. {
  2985. case IDM_EXIT :
  2986. {
  2987. //if the shell icon is showing, then closing the app means hiding it
  2988. if (fShellMode)
  2989. {
  2990. ShowWindow(hwnd,SW_HIDE);
  2991. }
  2992. else
  2993. {
  2994. SendMessage(hwnd, WM_CLOSE, 0, 0);
  2995. }
  2996. return;
  2997. } //end exit
  2998. break;
  2999. case IDM_EXIT_SHELL :
  3000. {
  3001. //if the shell icon wanted us to shut down, but the main ui is visible, just
  3002. //nuke shell mode
  3003. if (IsWindowVisible(hwnd))
  3004. {
  3005. DestroyShellIcon();
  3006. fShellMode = FALSE;
  3007. }
  3008. else
  3009. {
  3010. SendMessage(hwnd, WM_CLOSE, 0, 0);
  3011. }
  3012. return;
  3013. }
  3014. break;
  3015. }
  3016. IMMComponentAutomation* pAuto = NULL;
  3017. HRESULT hr = pNodeCurrent->pComp->QueryInterface(IID_IMMComponentAutomation,(void**)&pAuto);
  3018. if ((SUCCEEDED(hr)) && (pAuto != NULL))
  3019. {
  3020. if ((LOWORD(wParam) >= IDM_TRACKLIST_BASE) && (LOWORD(wParam) < IDM_TRACKLIST_SHELL_BASE))
  3021. {
  3022. MMCHANGETRACK mmTrack;
  3023. mmTrack.nNewTrack = LOWORD(wParam) - IDM_TRACKLIST_BASE;
  3024. pAuto->OnAction(MMACTION_SETTRACK,&mmTrack);
  3025. }
  3026. if ((LOWORD(wParam) >= IDM_TRACKLIST_SHELL_BASE) && (LOWORD(wParam) < IDM_DISCLIST_BASE))
  3027. {
  3028. MMCHANGETRACK mmTrack;
  3029. mmTrack.nNewTrack = LOWORD(wParam) - IDM_TRACKLIST_SHELL_BASE;
  3030. pAuto->OnAction(MMACTION_SETTRACK,&mmTrack);
  3031. //play it if we're not playing
  3032. if (!fPlaying)
  3033. {
  3034. pAuto->OnAction(MMACTION_PLAY,NULL);
  3035. }
  3036. }
  3037. if ((LOWORD(wParam) >= IDM_DISCLIST_BASE) && (LOWORD(wParam) < IDM_NET_UPDATE))
  3038. {
  3039. MMCHANGEDISC mmDisc;
  3040. mmDisc.nNewDisc = LOWORD(wParam) - IDM_DISCLIST_BASE;
  3041. pAuto->OnAction(MMACTION_SETDISC,&mmDisc);
  3042. }
  3043. if ((LOWORD(wParam) >= IDM_HOMEMENU_BASE) && (LOWORD(wParam) < IDM_NETMENU_BASE))
  3044. {
  3045. int i = LOWORD(wParam) - IDM_HOMEMENU_BASE;
  3046. LPCDOPT pOpt = GetCDOpt();
  3047. if( pOpt )
  3048. {
  3049. LPCDOPTIONS pCDOpts = pOpt->GetCDOpts();
  3050. LPCDPROVIDER pProviderList = pCDOpts->pProviderList;
  3051. for (int x = 0; x < i; x++)
  3052. {
  3053. pProviderList = pProviderList->pNext;
  3054. }
  3055. OpenBrowserURL(pProviderList->szProviderHome);
  3056. }
  3057. }
  3058. if ((LOWORD(wParam) >= IDM_NETMENU_BASE) && (LOWORD(wParam) < IDM_OPTIONS))
  3059. {
  3060. MMMEDIAID mmMedia;
  3061. mmMedia.nDrive = -1;
  3062. pAuto->OnAction(MMACTION_GETMEDIAID,&mmMedia);
  3063. LPCDDATA pData = GetCDData();
  3064. if (!pData)
  3065. {
  3066. return;
  3067. }
  3068. if (!pData->QueryTitle(mmMedia.dwMediaID))
  3069. {
  3070. return;
  3071. }
  3072. LPCDTITLE pCDTitle = NULL;
  3073. hr = pData->LockTitle(&pCDTitle,mmMedia.dwMediaID);
  3074. if (FAILED(hr))
  3075. {
  3076. return;
  3077. }
  3078. LPCDMENU pCDMenu = &(pCDTitle->pMenuTable[LOWORD(wParam)-IDM_NETMENU_BASE]);
  3079. if (pCDMenu->szMenuQuery)
  3080. {
  3081. OpenBrowserURL(pCDMenu->szMenuQuery);
  3082. }
  3083. pData->UnlockTitle(pCDTitle,FALSE);
  3084. }
  3085. switch (LOWORD(wParam))
  3086. {
  3087. case IDM_NET_UPDATE :
  3088. {
  3089. MMNET mmNet;
  3090. mmNet.discid = 0; //use current disc
  3091. mmNet.hwndCallback = hwnd;
  3092. mmNet.pData = (void*)GetCDData();
  3093. mmNet.pData2 = NULL;
  3094. mmNet.fForceNet = FALSE;
  3095. SendMessage(hwndCurrentComp,WM_COMMAND,MAKEWPARAM(ID_CDUPDATE,0),(LPARAM)&mmNet);
  3096. }
  3097. break;
  3098. case IDM_NET_CANCEL :
  3099. {
  3100. CancelDownload();
  3101. }
  3102. break;
  3103. case IDM_NET_ROLLINGSTONE_ARTIST :
  3104. case IDM_NET_BILLBOARD_ALBUM :
  3105. case IDM_NET_BILLBOARD_ARTIST :
  3106. {
  3107. MMMEDIAID mmMedia;
  3108. mmMedia.nDrive = -1;
  3109. pAuto->OnAction(MMACTION_GETMEDIAID,&mmMedia);
  3110. TCHAR szQuery[MAX_PATH*4];
  3111. LPCDDATA pData = GetCDData();
  3112. if (!pData)
  3113. {
  3114. break;
  3115. }
  3116. if (!pData->QueryTitle(mmMedia.dwMediaID))
  3117. {
  3118. return;
  3119. }
  3120. LPCDTITLE pCDTitle = NULL;
  3121. hr = pData->LockTitle(&pCDTitle,mmMedia.dwMediaID);
  3122. if (FAILED(hr))
  3123. {
  3124. break;
  3125. }
  3126. //normalize (canonize) the title and artist names
  3127. TCHAR szArtist[CDSTR*3];
  3128. TCHAR szTitle[CDSTR*3];
  3129. NormalizeNameForURL(pCDTitle->szArtist,szArtist,sizeof(szArtist));
  3130. NormalizeNameForURL(pCDTitle->szTitle,szTitle,sizeof(szTitle));
  3131. pData->UnlockTitle(pCDTitle,FALSE);
  3132. if ((LOWORD(wParam) == IDM_NET_BILLBOARD_ARTIST))
  3133. {
  3134. TCHAR szFormat[MAX_PATH];
  3135. LoadString(hInst,IDS_BILLBOARD_FORMAT_ARTIST,szFormat,sizeof(szFormat)/sizeof(TCHAR));
  3136. wsprintf(szQuery,szFormat,szArtist);
  3137. }
  3138. else if ((LOWORD(wParam) == IDM_NET_ROLLINGSTONE_ARTIST))
  3139. {
  3140. TCHAR szFormat[MAX_PATH];
  3141. LoadString(hInst,IDS_ROLLINGSTONE_FORMAT_ARTIST,szFormat,sizeof(szFormat)/sizeof(TCHAR));
  3142. wsprintf(szQuery,szFormat,szArtist);
  3143. }
  3144. else
  3145. {
  3146. TCHAR szFormat[MAX_PATH];
  3147. LoadString(hInst,IDS_BILLBOARD_FORMAT_ALBUM,szFormat,sizeof(szFormat)/sizeof(TCHAR));
  3148. wsprintf(szQuery,szFormat,szArtist,szTitle);
  3149. }
  3150. OpenBrowserURL(szQuery);
  3151. }
  3152. break;
  3153. case IDM_NET_CD :
  3154. {
  3155. MMMEDIAID mmMedia;
  3156. mmMedia.nDrive = -1;
  3157. pAuto->OnAction(MMACTION_GETMEDIAID,&mmMedia);
  3158. TCHAR szQuery[MAX_PATH*4];
  3159. LPCDDATA pData = GetCDData();
  3160. if (!pData)
  3161. {
  3162. break;
  3163. }
  3164. if (!pData->QueryTitle(mmMedia.dwMediaID))
  3165. {
  3166. return;
  3167. }
  3168. LPCDTITLE pCDTitle = NULL;
  3169. hr = pData->LockTitle(&pCDTitle,mmMedia.dwMediaID);
  3170. if (FAILED(hr))
  3171. {
  3172. break;
  3173. }
  3174. TCHAR szSearchURL[MAX_PATH];
  3175. if (!GetSearchURL(szSearchURL))
  3176. {
  3177. break;
  3178. }
  3179. TCHAR szTemp[MAX_PATH*2];
  3180. TCHAR szTemp2[MAX_PATH*2];
  3181. wsprintf(szTemp,TEXT("%s %s"),pCDTitle->szArtist,pCDTitle->szTitle);
  3182. NormalizeNameForURL(szTemp,szTemp2,sizeof(szTemp2));
  3183. wsprintf(szQuery,szSearchURL,szTemp2);
  3184. pData->UnlockTitle(pCDTitle,FALSE);
  3185. OpenBrowserURL(szQuery);
  3186. }
  3187. break;
  3188. case IDM_NET_BAND :
  3189. {
  3190. MMMEDIAID mmMedia;
  3191. mmMedia.nDrive = -1;
  3192. pAuto->OnAction(MMACTION_GETMEDIAID,&mmMedia);
  3193. TCHAR szQuery[MAX_PATH*3];
  3194. LPCDDATA pData = GetCDData();
  3195. if (!pData)
  3196. {
  3197. break;
  3198. }
  3199. if (!pData->QueryTitle(mmMedia.dwMediaID))
  3200. {
  3201. return;
  3202. }
  3203. LPCDTITLE pCDTitle = NULL;
  3204. hr = pData->LockTitle(&pCDTitle,mmMedia.dwMediaID);
  3205. if (FAILED(hr))
  3206. {
  3207. break;
  3208. }
  3209. TCHAR szSearchURL[MAX_PATH];
  3210. if (!GetSearchURL(szSearchURL))
  3211. {
  3212. break;
  3213. }
  3214. TCHAR szArtist[CDSTR*3];
  3215. NormalizeNameForURL(pCDTitle->szArtist,szArtist,sizeof(szArtist));
  3216. wsprintf(szQuery,szSearchURL,szArtist);
  3217. pData->UnlockTitle(pCDTitle,FALSE);
  3218. OpenBrowserURL(szQuery);
  3219. }
  3220. break;
  3221. case IDM_MODE_NORMAL :
  3222. {
  3223. nCDMode = LOWORD(wParam);
  3224. SendMessage(hwndCurrentComp,WM_COMMAND,MAKEWPARAM(IDM_OPTIONS_NORMAL,0),(LPARAM)0);
  3225. InvalidateRect(hwndCurrentComp,NULL,FALSE);
  3226. UpdateWindow(hwndCurrentComp);
  3227. CMButton* pButton = GetMButtonFromID(hwnd,IDB_MODE);
  3228. if (pButton)
  3229. {
  3230. pButton->SetIcon(IDI_MODE_NORMAL);
  3231. }
  3232. SetPlayButtonState(FALSE);
  3233. }
  3234. break;
  3235. case IDM_MODE_REPEATONE :
  3236. {
  3237. nCDMode = LOWORD(wParam);
  3238. SendMessage(hwndCurrentComp,WM_COMMAND,MAKEWPARAM(IDM_OPTIONS_REPEAT_SINGLE,0),(LPARAM)0);
  3239. InvalidateRect(hwndCurrentComp,NULL,FALSE);
  3240. UpdateWindow(hwndCurrentComp);
  3241. CMButton* pButton = GetMButtonFromID(hwnd,IDB_MODE);
  3242. if (pButton)
  3243. {
  3244. pButton->SetIcon(IDI_MODE_REPEATONE);
  3245. }
  3246. SetPlayButtonState(FALSE);
  3247. }
  3248. break;
  3249. case IDM_MODE_REPEATALL :
  3250. {
  3251. nCDMode = LOWORD(wParam);
  3252. SendMessage(hwndCurrentComp,WM_COMMAND,MAKEWPARAM(IDM_OPTIONS_CONTINUOUS,0),(LPARAM)0);
  3253. InvalidateRect(hwndCurrentComp,NULL,FALSE);
  3254. UpdateWindow(hwndCurrentComp);
  3255. CMButton* pButton = GetMButtonFromID(hwnd,IDB_MODE);
  3256. if (pButton)
  3257. {
  3258. pButton->SetIcon(IDI_MODE_REPEATALL);
  3259. }
  3260. SetPlayButtonState(FALSE);
  3261. }
  3262. break;
  3263. case IDM_MODE_RANDOM :
  3264. {
  3265. nCDMode = LOWORD(wParam);
  3266. SendMessage(hwndCurrentComp,WM_COMMAND,MAKEWPARAM(IDM_OPTIONS_RANDOM,0),(LPARAM)0);
  3267. InvalidateRect(hwndCurrentComp,NULL,FALSE);
  3268. UpdateWindow(hwndCurrentComp);
  3269. CMButton* pButton = GetMButtonFromID(hwnd,IDB_MODE);
  3270. if (pButton)
  3271. {
  3272. pButton->SetIcon(IDI_MODE_RANDOM);
  3273. }
  3274. SetPlayButtonState(FALSE);
  3275. }
  3276. break;
  3277. case IDM_MODE_INTRO :
  3278. {
  3279. nCDMode = LOWORD(wParam);
  3280. SendMessage(hwndCurrentComp,WM_COMMAND,MAKEWPARAM(IDM_OPTIONS_INTRO,0),(LPARAM)0);
  3281. InvalidateRect(hwndCurrentComp,NULL,FALSE);
  3282. UpdateWindow(hwndCurrentComp);
  3283. CMButton* pButton = GetMButtonFromID(hwnd,IDB_MODE);
  3284. if (pButton)
  3285. {
  3286. pButton->SetIcon(IDI_MODE_INTRO);
  3287. }
  3288. SetPlayButtonState(TRUE);
  3289. }
  3290. break;
  3291. case IDM_HELP :
  3292. {
  3293. char chDst[MAX_PATH];
  3294. WideCharToMultiByte(CP_ACP, 0, HELPFILENAME,
  3295. -1, chDst, MAX_PATH, NULL, NULL);
  3296. HtmlHelpA(GetDesktopWindow(), chDst, HH_DISPLAY_TOPIC, 0);
  3297. }
  3298. break;
  3299. case IDM_ABOUT :
  3300. {
  3301. ShellAbout( hwnd, szAppName, TEXT(""), LoadIcon(hInst, MAKEINTRESOURCE(IDI_MMFW)));
  3302. }
  3303. break;
  3304. case IDM_NORMAL :
  3305. {
  3306. SetNormalMode(hwnd);
  3307. }
  3308. break;
  3309. case IDM_TINY :
  3310. {
  3311. SetRestoredMode(hwnd);
  3312. }
  3313. break;
  3314. case IDB_MUTE :
  3315. {
  3316. //fix for bug 220 ... if mute button is set from "SetMute" during a button
  3317. //click, it will get ANOTHER button click when it's focus is killed, so we
  3318. //need to make sure it stays in the right state at the right time
  3319. if (GetFocus()==GetDlgItem(hwndMain,IDB_MUTE))
  3320. {
  3321. SetMute();
  3322. }
  3323. else
  3324. {
  3325. SendMessage(GetDlgItem(hwndMain,IDB_MUTE),BM_SETSTATE,(WPARAM)GetMute(),0);
  3326. }
  3327. }
  3328. break;
  3329. case IDM_OPENVIRTUALCD :
  3330. {
  3331. OpenVirtualCD();
  3332. }
  3333. break;
  3334. case IDM_PLAYLIST :
  3335. case IDM_OPTIONS :
  3336. {
  3337. CDOPT_PAGE nStartSheet = CDOPT_PAGE_PLAY;
  3338. if (LOWORD(wParam) == IDM_PLAYLIST)
  3339. {
  3340. nStartSheet = CDOPT_PAGE_PLAYLIST;
  3341. }
  3342. LPCDOPT pOpt = GetCDOpt();
  3343. if( pOpt )
  3344. {
  3345. LPCDOPTIONS pCDOpts = pOpt->GetCDOpts();
  3346. LPCDDATA pData = GetCDData();
  3347. if( pData )
  3348. {
  3349. //go through and set media ids for each drive
  3350. LPCDUNIT pUnit = pCDOpts->pCDUnitList;
  3351. int nCurrDrive = 0;
  3352. while (pUnit!=NULL)
  3353. {
  3354. MMMEDIAID mmMedia;
  3355. mmMedia.nDrive = nCurrDrive;
  3356. pAuto->OnAction(MMACTION_GETMEDIAID,&mmMedia);
  3357. MMNETQUERY mmNetQuery;
  3358. mmNetQuery.nDrive = nCurrDrive++;
  3359. mmNetQuery.szNetQuery = pUnit->szNetQuery;
  3360. pAuto->OnAction(MMACTION_GETNETQUERY,&mmNetQuery);
  3361. pUnit->dwTitleID = mmMedia.dwMediaID;
  3362. pUnit->dwNumTracks = mmMedia.dwNumTracks;
  3363. if (IsDownloading())
  3364. {
  3365. pUnit->fDownLoading = TRUE;
  3366. }
  3367. else
  3368. {
  3369. pUnit->fDownLoading = FALSE;
  3370. }
  3371. pUnit = pUnit->pNext;
  3372. }
  3373. //set the number of batched titles and the callback functions
  3374. pCDOpts->dwBatchedTitles = GetNumBatchedTitles();
  3375. pCDOpts->pfnDownloadTitle = OptionsDownloadCallback;
  3376. pCDOpts->pfnOptionsCallback = OptionsApply;
  3377. fOptionsDlgUp = TRUE;
  3378. HRESULT hr = pOpt->OptionsDialog(hwnd, pData, nStartSheet);
  3379. fOptionsDlgUp = FALSE;
  3380. if (hr == S_OK) //don't use succeeded macro here, S_FALSE is also valid
  3381. {
  3382. OptionsApply(pCDOpts);
  3383. }
  3384. } //if pdata
  3385. }
  3386. }
  3387. break;
  3388. case IDB_PLAY :
  3389. {
  3390. if (fPlaying)
  3391. {
  3392. if (fIntro)
  3393. {
  3394. //set to normal mode
  3395. SendMessage(hwnd,WM_COMMAND,MAKEWPARAM(IDM_MODE_NORMAL,0),0);
  3396. //set button back to regular icon
  3397. CMButton* pButton = GetMButtonFromID(hwnd,IDB_PLAY);
  3398. if (pButton)
  3399. {
  3400. pButton->SetIcon(IDI_ICON_PAUSE);
  3401. pButton->SetToolTipID(IDB_TT_PAUSE);
  3402. SetWindowText(pButton->GetHWND(),TEXT("1"));
  3403. }
  3404. }
  3405. else
  3406. {
  3407. pAuto->OnAction(MMACTION_PAUSE,NULL);
  3408. }
  3409. }
  3410. else
  3411. {
  3412. pAuto->OnAction(MMACTION_PLAY,NULL);
  3413. }
  3414. }
  3415. break;
  3416. case IDB_EJECT :
  3417. {
  3418. pAuto->OnAction(MMACTION_UNLOADMEDIA,NULL);
  3419. }
  3420. break;
  3421. case IDB_FFWD :
  3422. {
  3423. pAuto->OnAction(MMACTION_FFWD,NULL);
  3424. }
  3425. break;
  3426. case IDB_NEXTTRACK :
  3427. {
  3428. pAuto->OnAction(MMACTION_NEXTTRACK,NULL);
  3429. }
  3430. break;
  3431. case IDB_PREVTRACK :
  3432. {
  3433. pAuto->OnAction(MMACTION_PREVTRACK,NULL);
  3434. }
  3435. break;
  3436. case IDB_REW :
  3437. {
  3438. pAuto->OnAction(MMACTION_REWIND,NULL);
  3439. }
  3440. break;
  3441. case IDB_STOP :
  3442. {
  3443. pAuto->OnAction(MMACTION_STOP,NULL);
  3444. }
  3445. break;
  3446. case IDB_MINIMIZE :
  3447. {
  3448. ShowWindow(hwnd,SW_MINIMIZE);
  3449. //see \\redrum\slmro\proj\win\src\CORE\user\mssyscmd.c
  3450. PlaySound(TEXT("Minimize"),NULL,SND_ALIAS|SND_NODEFAULT|SND_ASYNC|SND_NOWAIT|SND_NOSTOP);
  3451. }
  3452. break;
  3453. case IDB_SET_NORMAL_MODE :
  3454. {
  3455. SetNormalMode(hwnd);
  3456. }
  3457. break;
  3458. case IDB_SET_TINY_MODE :
  3459. {
  3460. SetRestoredMode(hwnd);
  3461. }
  3462. break;
  3463. case IDB_CLOSE :
  3464. {
  3465. //if the shell icon is showing, then closing the app means hiding it
  3466. if (fShellMode)
  3467. {
  3468. ShowWindow(hwnd,SW_HIDE);
  3469. }
  3470. else
  3471. {
  3472. SendMessage(hwnd, WM_CLOSE, 0, 0);
  3473. }
  3474. }
  3475. break;
  3476. }
  3477. if (pAuto)
  3478. {
  3479. pAuto->Release();
  3480. pAuto = NULL;
  3481. }
  3482. }
  3483. }
  3484. ////////////////////////
  3485. // Handles device change message from WinMM, All we need to do here is close any open
  3486. // Mixer Handles, re-compute mixer ID and control ID's and re-Open appropriately
  3487. //
  3488. void WinMMDeviceChangeHandler(HWND hWnd)
  3489. {
  3490. LPCDOPT pOpt = GetCDOpt();
  3491. if (hmix) // Close open mixer handle
  3492. {
  3493. mixerClose((HMIXER)hmix);
  3494. hmix = NULL;
  3495. }
  3496. if(pOpt)
  3497. {
  3498. LPCDOPTIONS pCDOpts = pOpt->GetCDOpts();
  3499. pOpt->MMDeviceChanged();
  3500. InitCDVol(hwndMain,pCDOpts);
  3501. }
  3502. }
  3503. ////////////////////////////////////////////////////////////////////////////////////////////
  3504. // * HandlePowerBroadcast
  3505. // On VxD drivers, you can't "suspend" with an open mixer device. Bug 1132.
  3506. //
  3507. // If lParam == 1, this is a device remove
  3508. //
  3509. ////////////////////////////////////////////////////////////////////////////////////////////
  3510. BOOL HandlePowerBroadcast(HWND hWnd, WPARAM wParam, LPARAM lParam)
  3511. {
  3512. BOOL fRet = TRUE;
  3513. switch (wParam)
  3514. {
  3515. case PBT_APMQUERYSTANDBY:
  3516. case PBT_APMQUERYSUSPEND:
  3517. {
  3518. if (hmix)
  3519. {
  3520. mixerClose((HMIXER)hmix);
  3521. hmix = NULL;
  3522. }
  3523. } //end case power off
  3524. break;
  3525. case PBT_APMSTANDBY :
  3526. case PBT_APMSUSPEND :
  3527. {
  3528. //actually suspending, go ahead and stop the cd
  3529. if (fPlaying)
  3530. {
  3531. IMMComponentAutomation* pAuto = NULL;
  3532. if (pNodeCurrent)
  3533. {
  3534. HRESULT hr = pNodeCurrent->pComp->QueryInterface(IID_IMMComponentAutomation,(void**)&pAuto);
  3535. if ((SUCCEEDED(hr)) && (pAuto != NULL))
  3536. {
  3537. //at this point, we can actually stop the CD
  3538. pAuto->OnAction(MMACTION_STOP,NULL);
  3539. //release the automation object
  3540. pAuto->Release();
  3541. }
  3542. } //end if pnodecurrent
  3543. } //end if playing
  3544. }
  3545. break;
  3546. case PBT_APMQUERYSTANDBYFAILED:
  3547. case PBT_APMRESUMESTANDBY:
  3548. case PBT_APMQUERYSUSPENDFAILED:
  3549. case PBT_APMRESUMESUSPEND:
  3550. {
  3551. WinMMDeviceChangeHandler(hWnd);
  3552. } //end case power on
  3553. break;
  3554. } //end switch
  3555. return fRet;
  3556. }
  3557. ////////////////////////////////////////////////////////////////////////////////////////////
  3558. // * HandleSysMenuInit
  3559. // Make sure the system menu only shows the correct choices
  3560. ////////////////////////////////////////////////////////////////////////////////////////////
  3561. void HandleSysMenuInit(HWND hwnd, HMENU hmenu)
  3562. {
  3563. //always gray out
  3564. EnableMenuItem(hmenu,SC_SIZE, MF_BYCOMMAND|MF_GRAYED);
  3565. EnableMenuItem(hmenu,SC_MAXIMIZE,MF_BYCOMMAND|MF_GRAYED);
  3566. //always enable
  3567. EnableMenuItem(hmenu,SC_CLOSE,MF_BYCOMMAND|MF_ENABLED);
  3568. //enable or gray based on minimize state
  3569. if (IsIconic(hwnd))
  3570. {
  3571. EnableMenuItem(hmenu,SC_RESTORE, MF_BYCOMMAND|MF_ENABLED);
  3572. EnableMenuItem(hmenu,SC_MOVE, MF_BYCOMMAND|MF_GRAYED);
  3573. EnableMenuItem(hmenu,SC_MINIMIZE,MF_BYCOMMAND|MF_GRAYED);
  3574. }
  3575. else
  3576. {
  3577. EnableMenuItem(hmenu,SC_RESTORE, MF_BYCOMMAND|MF_GRAYED);
  3578. EnableMenuItem(hmenu,SC_MOVE, MF_BYCOMMAND|MF_ENABLED);
  3579. EnableMenuItem(hmenu,SC_MINIMIZE,MF_BYCOMMAND|MF_ENABLED);
  3580. }
  3581. }
  3582. ////////////////////////////////////////////////////////////////////////////////////////////
  3583. // * SysMenuTimerProc
  3584. // Make sure the system menu only shows on a single click
  3585. ////////////////////////////////////////////////////////////////////////////////////////////
  3586. void CALLBACK SysMenuTimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
  3587. {
  3588. KillTimer(hwnd,idEvent);
  3589. POINTS pts;
  3590. RECT rect;
  3591. //make sure the menu shows up in a good-looking place
  3592. GetClientRect(hwnd,&rect);
  3593. rect.left = SYSMENU_XOFFSET;
  3594. rect.right = SYSMENU_XOFFSET + SYSMENU_WIDTH;
  3595. rect.bottom = rect.top + TITLEBAR_HEIGHT +
  3596. (g_nViewMode == VIEW_MODE_NORMAL ? TITLEBAR_YOFFSET_LARGE :
  3597. TITLEBAR_YOFFSET_SMALL);
  3598. ClientToScreen(hwnd,(LPPOINT)&rect);
  3599. ClientToScreen(hwnd,((LPPOINT)&rect)+1);
  3600. pts.x = (short)rect.left;
  3601. pts.y = (short)rect.bottom;
  3602. HMENU hSysMenu = GetSystemMenu(hwnd,FALSE);
  3603. TPMPARAMS tpm;
  3604. tpm.cbSize = sizeof(tpm);
  3605. memcpy(&(tpm.rcExclude),&rect,sizeof(RECT));
  3606. TrackPopupMenuEx(hSysMenu,0,pts.x,pts.y,hwnd,&tpm);
  3607. }
  3608. BOOL HandleKeyboardAppCommand(HWND hwnd, short cmd)
  3609. {
  3610. BOOL fHandled = FALSE;
  3611. switch (cmd)
  3612. {
  3613. case APPCOMMAND_VOLUME_MUTE :
  3614. {
  3615. SetMute();
  3616. fHandled = TRUE;
  3617. }
  3618. break;
  3619. case APPCOMMAND_VOLUME_DOWN :
  3620. {
  3621. SendMessage(GetDlgItem(hwnd,IDB_VOLUME),WM_KEYDOWN,VK_DOWN,0);
  3622. fHandled = TRUE;
  3623. }
  3624. break;
  3625. case APPCOMMAND_VOLUME_UP :
  3626. {
  3627. SendMessage(GetDlgItem(hwnd,IDB_VOLUME),WM_KEYDOWN,VK_UP,0);
  3628. fHandled = TRUE;
  3629. }
  3630. break;
  3631. case APPCOMMAND_MEDIA_NEXTTRACK :
  3632. {
  3633. SendMessage(hwnd,WM_COMMAND,MAKEWPARAM(IDB_NEXTTRACK,0),(LPARAM)0);
  3634. fHandled = TRUE;
  3635. }
  3636. break;
  3637. case APPCOMMAND_MEDIA_PREVIOUSTRACK :
  3638. {
  3639. SendMessage(hwnd,WM_COMMAND,MAKEWPARAM(IDB_PREVTRACK,0),(LPARAM)0);
  3640. fHandled = TRUE;
  3641. }
  3642. break;
  3643. case APPCOMMAND_MEDIA_STOP :
  3644. {
  3645. SendMessage(hwnd,WM_COMMAND,MAKEWPARAM(IDB_STOP,0),(LPARAM)0);
  3646. fHandled = TRUE;
  3647. }
  3648. break;
  3649. case APPCOMMAND_MEDIA_PLAY_PAUSE :
  3650. {
  3651. SendMessage(hwnd,WM_COMMAND,MAKEWPARAM(IDB_PLAY,0),(LPARAM)0);
  3652. fHandled = TRUE;
  3653. }
  3654. break;
  3655. default:
  3656. {
  3657. fHandled = FALSE;
  3658. }
  3659. break;
  3660. } //end switch
  3661. return fHandled;
  3662. }
  3663. ////////////////////////////////////////////////////////////////////////////////////////////
  3664. // * MainWndProc
  3665. // Main window's message switcher
  3666. ////////////////////////////////////////////////////////////////////////////////////////////
  3667. LRESULT CALLBACK MainWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  3668. {
  3669. switch (iMsg)
  3670. {
  3671. //we're being created, start up
  3672. case WM_CREATE :
  3673. {
  3674. hwndMain = hwnd;
  3675. g_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
  3676. giVolDevChange = RegisterWindowMessage(TEXT("winmm_devicechange"));
  3677. CreateToolTips(hwnd);
  3678. InitComponents(hwnd);
  3679. CreateButtonWindows(hwnd);
  3680. CreateVolumeKnob(hwnd);
  3681. //if no disc in player, gray out the track button
  3682. IMMComponentAutomation* pAuto = NULL;
  3683. HRESULT hr = pNodeCurrent->pComp->QueryInterface(IID_IMMComponentAutomation,(void**)&pAuto);
  3684. if ((SUCCEEDED(hr)) && (pAuto != NULL))
  3685. {
  3686. MMMEDIAID mmMedia;
  3687. mmMedia.nDrive = -1;
  3688. pAuto->OnAction(MMACTION_GETMEDIAID,&mmMedia);
  3689. pAuto->Release();
  3690. if (mmMedia.dwMediaID == 0)
  3691. {
  3692. EnableWindow(GetDlgItem(hwnd,IDB_TRACK),FALSE);
  3693. }
  3694. }
  3695. }
  3696. break;
  3697. case SHELLMESSAGE_CDICON :
  3698. {
  3699. return (ShellIconHandeMessage(lParam));
  3700. }
  3701. break;
  3702. //called from sndvol32 or other apps that change mixer
  3703. case MM_MIXM_CONTROL_CHANGE :
  3704. {
  3705. HandleMixerControlChange((DWORD)lParam);
  3706. }
  3707. break;
  3708. //palette changed
  3709. case WM_PALETTECHANGED :
  3710. case WM_QUERYNEWPALETTE :
  3711. {
  3712. return (HandlePaletteChange());
  3713. }
  3714. break;
  3715. //autoplay copied command line when second instance running
  3716. case WM_COPYDATA :
  3717. {
  3718. SendMessage(hwndCurrentComp,WM_COPYDATA,wParam,lParam);
  3719. }
  3720. break;
  3721. //new keyboard interface
  3722. case WM_APPCOMMAND :
  3723. {
  3724. return HandleKeyboardAppCommand(hwnd,GET_APPCOMMAND_LPARAM(lParam));
  3725. }
  3726. break;
  3727. //activation/deactivation -- need to repaint title
  3728. case WM_ACTIVATE :
  3729. {
  3730. HDC hdc = GetDC(hwnd);
  3731. DrawTitleBar(hdc,hwnd,LOWORD(wParam),FALSE);
  3732. ReleaseDC(hwnd,hdc);
  3733. }
  3734. break;
  3735. //check for switch to tiny mode
  3736. case WM_NCLBUTTONDBLCLK :
  3737. case WM_LBUTTONDBLCLK :
  3738. {
  3739. KillTimer(hwnd,SYSTIMERID);
  3740. if (((int)wParam == HTSYSMENU) && (iMsg == WM_NCLBUTTONDBLCLK))
  3741. {
  3742. break; //don't allow this on a sys menu double-click
  3743. }
  3744. switch (g_nViewMode)
  3745. {
  3746. case VIEW_MODE_NORMAL : SetNoBarMode(hwnd); break;
  3747. case VIEW_MODE_NOBAR : SetNormalMode(hwnd); break;
  3748. case VIEW_MODE_RESTORE : SetSmallMode(hwnd); break;
  3749. case VIEW_MODE_SMALL : SetRestoredMode(hwnd); break;
  3750. } //end switch on view mode
  3751. }
  3752. break;
  3753. //handle left click on system menu
  3754. //need to set timer to handle double-click
  3755. case WM_NCLBUTTONDOWN :
  3756. {
  3757. if ((int)wParam == HTSYSMENU)
  3758. {
  3759. SetTimer(hwnd,SYSTIMERID,GetDoubleClickTime()+100,(TIMERPROC)SysMenuTimerProc);
  3760. }
  3761. }
  3762. break;
  3763. //handle right click on system menu or caption
  3764. //no need for timer on double-click
  3765. case WM_NCRBUTTONDOWN :
  3766. {
  3767. if (((int)wParam == HTCAPTION) || ((int)wParam == HTSYSMENU))
  3768. {
  3769. POINTS pts = MAKEPOINTS(lParam);
  3770. HMENU hSysMenu = GetSystemMenu(hwnd,FALSE);
  3771. TrackPopupMenu(hSysMenu,0,pts.x,pts.y,0,hwnd,NULL);
  3772. }
  3773. }
  3774. break;
  3775. case WM_INITMENU :
  3776. {
  3777. HandleSysMenuInit(hwnd,(HMENU)wParam);
  3778. }
  3779. break;
  3780. case WM_POWERBROADCAST:
  3781. {
  3782. return (HandlePowerBroadcast(hwnd,wParam,0));
  3783. }
  3784. break;
  3785. //check for mouse in title bar
  3786. case WM_NCHITTEST :
  3787. {
  3788. return (OnNCHitTest(hwnd, LOWORD(lParam), HIWORD(lParam),FALSE));
  3789. }
  3790. break;
  3791. case WM_NET_DB_UPDATE_BATCH :
  3792. {
  3793. LPCDOPT pOpts = GetCDOpt();
  3794. if (pOpts)
  3795. {
  3796. pOpts->DownLoadCompletion(0,NULL);
  3797. }
  3798. }
  3799. break;
  3800. case WM_NET_DB_UPDATE_DISC :
  3801. {
  3802. LPCDOPT pOpts = GetCDOpt();
  3803. if (pOpts)
  3804. {
  3805. pOpts->DiscChanged((LPCDUNIT)lParam);
  3806. }
  3807. }
  3808. break;
  3809. //download finished on a disc
  3810. case WM_NET_INCMETER : //download finished on discid <lparam>
  3811. {
  3812. //lparam == -1 means the provider failed the validation check
  3813. if (lParam == (LPARAM)-1)
  3814. {
  3815. SendMessage(GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW),WM_LED_DOWNLOAD,0,(LPARAM)FALSE);
  3816. HandleBadServiceProvider(hwnd);
  3817. break;
  3818. }
  3819. if (lParam != 0)
  3820. {
  3821. MMNET mmNet;
  3822. mmNet.discid = (DWORD)(lParam);
  3823. mmNet.hwndCallback = hwnd;
  3824. mmNet.pData = (void*)GetCDData();
  3825. mmNet.pData2 = NULL;
  3826. mmNet.fForceNet = FALSE;
  3827. SendMessage(hwndCurrentComp,WM_COMMAND,MAKEWPARAM(ID_CDUPDATE,0),(LPARAM)&mmNet);
  3828. LPCDOPT pOpt = GetCDOpt();
  3829. if (pOpt)
  3830. {
  3831. LPCDUNIT pUnit = pOpt->GetCDOpts()->pCDUnitList;
  3832. int nCurrDrive = 0;
  3833. while (pUnit!=NULL)
  3834. {
  3835. if (pUnit->dwTitleID == mmNet.discid)
  3836. {
  3837. pUnit->fDownLoading = FALSE;
  3838. break;
  3839. }
  3840. pUnit = pUnit->pNext;
  3841. }
  3842. LPCDOPTIONS pCDOpts = pOpt->GetCDOpts();
  3843. pCDOpts->dwBatchedTitles = GetNumBatchedTitles();
  3844. pOpt->DownLoadCompletion(1,&(mmNet.discid));
  3845. }
  3846. //put up a message box if the title still isn't available
  3847. IMMComponentAutomation* pAuto = NULL;
  3848. HRESULT hr = pNodeCurrent->pComp->QueryInterface(IID_IMMComponentAutomation,(void**)&pAuto);
  3849. if ((SUCCEEDED(hr)) && (pAuto != NULL))
  3850. {
  3851. MMMEDIAID mmMedia;
  3852. mmMedia.nDrive = -1;
  3853. pAuto->OnAction(MMACTION_GETMEDIAID,&mmMedia);
  3854. pAuto->Release();
  3855. if (mmNet.discid == mmMedia.dwMediaID)
  3856. {
  3857. LPCDDATA pData = GetCDData();
  3858. if (!pData->QueryTitle(mmNet.discid))
  3859. {
  3860. TCHAR szNotFound[MAX_PATH];
  3861. LoadString(hInst,IDS_TITLE_NOT_FOUND,szNotFound,sizeof(szNotFound)/sizeof(TCHAR));
  3862. MessageBox(hwnd,szNotFound,szAppName,MB_ICONINFORMATION|MB_OK);
  3863. }
  3864. } //end if disc is same as what is showing in player
  3865. } //end if pauto ok
  3866. }
  3867. }
  3868. break;
  3869. case WM_NET_DB_FAILURE :
  3870. {
  3871. TCHAR szDBError[MAX_PATH];
  3872. LoadString(hInst,IDS_DB_FAILURE,szDBError,sizeof(szDBError)/sizeof(TCHAR));
  3873. MessageBox(hwnd,szDBError,szAppName,MB_ICONERROR|MB_OK);
  3874. }
  3875. break;
  3876. case WM_NET_NET_FAILURE :
  3877. {
  3878. TCHAR szNetError[MAX_PATH];
  3879. LoadString(hInst,IDS_NET_FAILURE,szNetError,sizeof(szNetError)/sizeof(TCHAR));
  3880. MessageBox(hwnd,szNetError,szAppName,MB_ICONERROR|MB_OK);
  3881. }
  3882. break;
  3883. case WM_NET_DONE :
  3884. {
  3885. if (lParam == 0)
  3886. {
  3887. //if lparam is 0, download is done ... nuke the animation
  3888. SendMessage(GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW),WM_LED_DOWNLOAD,0,(LPARAM)FALSE);
  3889. }
  3890. }
  3891. break;
  3892. //Network status callback
  3893. case WM_NET_STATUS : //download information string in <lparam>
  3894. {
  3895. //we basically just ignore the string messages and start
  3896. //the animation if one isn't going already
  3897. SendMessage(GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW),WM_LED_DOWNLOAD,0,(LPARAM)TRUE);
  3898. }
  3899. break;
  3900. case WM_NET_CHANGEPROVIDER :
  3901. {
  3902. SendMessage(GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW),WM_NET_CHANGEPROVIDER,wParam,lParam);
  3903. }
  3904. break;
  3905. //change the title bar contents
  3906. case WM_SIZE :
  3907. {
  3908. if (wParam != SIZE_MINIMIZED)
  3909. {
  3910. TCHAR szText[MAX_PATH];
  3911. _tcscpy(szText,szAppName);
  3912. if (pNodeCurrent)
  3913. {
  3914. if (_tcslen(pNodeCurrent->szTitle) > 0)
  3915. {
  3916. wsprintf(szText,TEXT("%s - %s"),pNodeCurrent->szTitle,szAppName);
  3917. }
  3918. }
  3919. SetWindowText(hwnd,szText);
  3920. }
  3921. }
  3922. break;
  3923. //notification that the current disc drive is different
  3924. case WM_DISCCHANGED :
  3925. {
  3926. LPCDOPT pOpt = GetCDOpt();
  3927. if( pOpt )
  3928. {
  3929. LPCDOPTIONS pCDOpts = pOpt->GetCDOpts();
  3930. if (InitCDVol(hwnd,pCDOpts))
  3931. {
  3932. DWORD dwVol = GetVolume();
  3933. CKnob* pKnob = GetKnobFromID(hwndMain,IDB_VOLUME);
  3934. if (pKnob!=NULL)
  3935. {
  3936. pKnob->SetPosition(dwVol,(BOOL)lParam);
  3937. }
  3938. SendMessage(GetDlgItem(hwnd,IDB_MUTE),BM_SETSTATE,(WPARAM)GetMute(),0);
  3939. SendMessage(GetDlgItem(hwndCurrentComp,IDC_LEDWINDOW),WM_LED_MUTE,0,GetMute());
  3940. }
  3941. } //end if popt
  3942. //if no disc in player, gray out the track button
  3943. IMMComponentAutomation* pAuto = NULL;
  3944. HRESULT hr = pNodeCurrent->pComp->QueryInterface(IID_IMMComponentAutomation,(void**)&pAuto);
  3945. if ((SUCCEEDED(hr)) && (pAuto != NULL))
  3946. {
  3947. MMMEDIAID mmMedia;
  3948. mmMedia.nDrive = -1;
  3949. pAuto->OnAction(MMACTION_GETMEDIAID,&mmMedia);
  3950. pAuto->Release();
  3951. if (mmMedia.dwMediaID == 0)
  3952. {
  3953. EnableWindow(GetDlgItem(hwnd,IDB_TRACK),FALSE);
  3954. }
  3955. }
  3956. }
  3957. break;
  3958. case WM_SYSCOLORCHANGE :
  3959. case WM_DISPLAYCHANGE :
  3960. {
  3961. //user may have turned on high-contrast mode,
  3962. //or changed the display depth. Either way,
  3963. //it may be time to change bitmaps
  3964. HandleDisplayChange();
  3965. }
  3966. break;
  3967. case WM_ERASEBKGND :
  3968. {
  3969. EnumDisplayMonitors((HDC)wParam, NULL, DoPaint, (LPARAM)hwnd);
  3970. return TRUE;
  3971. }
  3972. break;
  3973. case WM_SETCURSOR :
  3974. {
  3975. if ((HWND)wParam == GetDlgItem(hwnd,IDB_MUTE))
  3976. {
  3977. if (hCursorMute)
  3978. {
  3979. SetCursor(hCursorMute);
  3980. return TRUE;
  3981. }
  3982. }
  3983. }
  3984. break;
  3985. case WM_HELP :
  3986. {
  3987. char chDst[MAX_PATH];
  3988. WideCharToMultiByte(CP_ACP, 0, HELPFILENAME,
  3989. -1, chDst, MAX_PATH, NULL, NULL);
  3990. HtmlHelpA(GetDesktopWindow(), chDst, HH_DISPLAY_TOPIC, 0);
  3991. }
  3992. break;
  3993. case WM_CLOSE :
  3994. {
  3995. if ((fShellMode) && IsWindowVisible(hwnd))
  3996. {
  3997. ShowWindow(hwnd,SW_HIDE);
  3998. return 0;
  3999. }
  4000. }
  4001. break;
  4002. case WM_PAINT :
  4003. {
  4004. //multi-mon paint
  4005. HDC hdc;
  4006. PAINTSTRUCT ps;
  4007. hdc = BeginPaint( hwnd, &ps );
  4008. EnumDisplayMonitors(hdc, NULL, DoPaint, (LPARAM)hwnd);
  4009. EndPaint(hwnd, &ps);
  4010. return 0;
  4011. }
  4012. break;
  4013. //default push putton handler
  4014. case DM_SETDEFID :
  4015. {
  4016. wDefButtonID = (WORD)wParam;
  4017. }
  4018. break;
  4019. case DM_GETDEFID :
  4020. {
  4021. return (MAKELRESULT(wDefButtonID,DC_HASDEFID));
  4022. }
  4023. break;
  4024. //custom menu accel handler
  4025. case WM_MENUCHAR :
  4026. {
  4027. if (g_pMenu)
  4028. {
  4029. return (g_pMenu->MenuChar((TCHAR)LOWORD(wParam),(UINT)HIWORD(wParam),(HMENU)lParam));
  4030. }
  4031. }
  4032. break;
  4033. //custom menu handler
  4034. case WM_MEASUREITEM :
  4035. {
  4036. if (lParam == 0) return (0);
  4037. if (g_pMenu)
  4038. {
  4039. g_pMenu->MeasureItem(hwnd,(LPMEASUREITEMSTRUCT)lParam);
  4040. }
  4041. }
  4042. break;
  4043. //custom menu/button handler
  4044. case WM_DRAWITEM :
  4045. {
  4046. if (lParam == 0) return (0);
  4047. if (wParam == 0)
  4048. {
  4049. if (g_pMenu)
  4050. {
  4051. g_pMenu->DrawItem(hwnd,(LPDRAWITEMSTRUCT)lParam);
  4052. return (1);
  4053. }
  4054. }
  4055. else
  4056. {
  4057. DrawButton((UINT)wParam,(LPDRAWITEMSTRUCT)lParam);
  4058. return (1);
  4059. }
  4060. return (0);
  4061. }
  4062. //notify is either from tool tip or volume knob
  4063. case WM_NOTIFY :
  4064. {
  4065. if ((((LPNMHDR)lParam)->code) == TTN_NEEDTEXT)
  4066. {
  4067. OnToolTipNotify(lParam);
  4068. }
  4069. else
  4070. {
  4071. if ((int)wParam == IDB_VOLUME)
  4072. {
  4073. CKnob* pKnob = GetKnobFromID(hwnd,IDB_VOLUME);
  4074. DWORD dwNewVol = pKnob->GetPosition();
  4075. DrawVolume(pKnob->GetPosition());
  4076. if ((((LPNMHDR)lParam)->code) == TRUE)
  4077. {
  4078. SetVolume(dwNewVol);
  4079. }
  4080. //reset timer to repaint client area
  4081. KillTimer(hwnd,VOLUME_PERSIST_TIMER_EVENT);
  4082. SetTimer(hwnd,VOLUME_PERSIST_TIMER_EVENT,VOLUME_PERSIST_TIMER_RATE,(TIMERPROC)VolPersistTimerProc);
  4083. } //end if knob
  4084. } //end else
  4085. }
  4086. break;
  4087. //menu going away
  4088. case WM_EXITMENULOOP :
  4089. {
  4090. BlockMenu(hwnd);
  4091. }
  4092. break;
  4093. //command message
  4094. case WM_COMMAND :
  4095. {
  4096. HandleCommand(hwnd, iMsg, wParam, lParam);
  4097. }
  4098. break;
  4099. case WM_DEVICECHANGE :
  4100. {
  4101. //if plug-and-play sends this, pass it along to the component
  4102. PDEV_BROADCAST_DEVICEINTERFACE bdi = (PDEV_BROADCAST_DEVICEINTERFACE)lParam;
  4103. PDEV_BROADCAST_HANDLE bh = (PDEV_BROADCAST_HANDLE)lParam;
  4104. //If we have an handle on the device then we get a DEV_BROADCAST_HDR structure as the lParam.
  4105. //Or else it means that we have registered for the general audio category KSCATEGORY_AUDIO.
  4106. if(bUseHandle)
  4107. {
  4108. if(!DeviceEventContext || !bh ||
  4109. bh->dbch_devicetype != DBT_DEVTYP_HANDLE)
  4110. {
  4111. return (SendMessage(hwndCurrentComp,WM_DEVICECHANGE,wParam,lParam));
  4112. }
  4113. }
  4114. else if (!DeviceEventContext || !bdi ||
  4115. bdi->dbcc_devicetype != DBT_DEVTYP_DEVICEINTERFACE ||
  4116. !IsEqualGUID(KSCATEGORY_AUDIO, bdi->dbcc_classguid) ||
  4117. !(*bdi->dbcc_name)
  4118. )
  4119. {
  4120. return (SendMessage(hwndCurrentComp,WM_DEVICECHANGE,wParam,lParam));
  4121. }
  4122. //Handle device changes to the mixer device.
  4123. switch(wParam)
  4124. {
  4125. //send "1" in lparam to indicate that this is a device remove and not a power request
  4126. case DBT_DEVICEQUERYREMOVE:
  4127. HandlePowerBroadcast(hwndMain, PBT_APMQUERYSUSPEND, (LPARAM)1);
  4128. break;
  4129. case DBT_DEVICEQUERYREMOVEFAILED:
  4130. HandlePowerBroadcast(hwndMain, PBT_APMQUERYSUSPENDFAILED, (LPARAM)1);
  4131. break;
  4132. default:
  4133. break;
  4134. }
  4135. }
  4136. case WM_WININICHANGE :
  4137. {
  4138. return (SendMessage(hwndCurrentComp,WM_WININICHANGE,wParam,lParam));
  4139. }
  4140. //we're done
  4141. case WM_ENDSESSION :
  4142. case WM_DESTROY :
  4143. {
  4144. if ((iMsg == WM_ENDSESSION) && (!wParam))
  4145. {
  4146. return 0;
  4147. }
  4148. if (hMutex)
  4149. {
  4150. ReleaseMutex(hMutex);
  4151. CloseHandle(hMutex);
  4152. hMutex = NULL;
  4153. }
  4154. //if playing and we don't want to be, stop it
  4155. //BE VERY PARANOID and check all variables, this is an RTMCRIT bug fix
  4156. LPCDOPT pOpt = GetCDOpt();
  4157. if (pOpt)
  4158. {
  4159. LPCDOPTIONS pOptions = pOpt->GetCDOpts();
  4160. if (pOptions)
  4161. {
  4162. LPCDOPTDATA pOptionData = pOptions->pCDData;
  4163. if (pOptionData)
  4164. {
  4165. if (pOptionData->fExitStop)
  4166. {
  4167. IMMComponentAutomation* pAuto = NULL;
  4168. if (pNodeCurrent)
  4169. {
  4170. HRESULT hr = pNodeCurrent->pComp->QueryInterface(IID_IMMComponentAutomation,(void**)&pAuto);
  4171. if ((SUCCEEDED(hr)) && (pAuto != NULL))
  4172. {
  4173. //at this point, we can actually stop the CD
  4174. pAuto->OnAction(MMACTION_STOP,NULL);
  4175. //release the automation object
  4176. pAuto->Release();
  4177. }
  4178. } //end if pnodecurrent
  4179. } //end if "stop on exit"
  4180. } //end if option data ok
  4181. } //end if options OK
  4182. } //end if opt OK
  4183. //make sure we're not downloading
  4184. EndDownloadThreads();
  4185. //Unregister the WM_DEVICECHANGE notification
  4186. Volume_DeviceChange_Cleanup();
  4187. //close the volume mixer
  4188. mixerClose((HMIXER)hmix);
  4189. //delete any GDI objects
  4190. GlobalFree(hbmpMain);
  4191. GlobalFree(hbmpMainRestore);
  4192. GlobalFree(hbmpMainSmall);
  4193. GlobalFree(hbmpMainNoBar);
  4194. DeleteObject(hpalMain);
  4195. //shut down the button class
  4196. UninitMButtons();
  4197. //save window state
  4198. if (!IsIconic(hwnd))
  4199. {
  4200. RECT rect;
  4201. GetWindowRect(hwnd,&rect);
  4202. SetSettings(rect.left,rect.top);
  4203. }
  4204. PostQuitMessage(0);
  4205. return (0);
  4206. }
  4207. }
  4208. if (iMsg == g_uTaskbarRestart)
  4209. {
  4210. if (fShellMode)
  4211. {
  4212. CreateShellIcon(hInst,hwndMain,pNodeCurrent,szAppName);
  4213. }
  4214. }
  4215. if (iMsg == giVolDevChange)
  4216. {
  4217. WinMMDeviceChangeHandler(hwnd);
  4218. }
  4219. return (DefWindowProc(hwnd, iMsg, wParam, lParam));
  4220. }
  4221. ////////////////////////////////////////////////////////////////////////////////////////////
  4222. // * LoadComponents
  4223. // Load registered componets from registry
  4224. // This code modified from the original MFC-based "Jazz" implementation, with blessings
  4225. // from todorfay <g>
  4226. ////////////////////////////////////////////////////////////////////////////////////////////
  4227. BOOL LoadComponents( void )
  4228. {
  4229. BOOL fSuccess = FALSE;
  4230. IMMComponent* pIComponent = NULL;
  4231. TCHAR szError[MAX_PATH];
  4232. if( SUCCEEDED(CDPLAY_CreateInstance(NULL, IID_IMMComponent, (void**)&pIComponent)) )
  4233. {
  4234. fSuccess = TRUE;
  4235. AddComponent(pIComponent);
  4236. }
  4237. else
  4238. {
  4239. TCHAR strMsg[MAX_PATH];
  4240. LoadString(hInst,IDS_ERRORLOADINGCOMP,szError,sizeof(szError)/sizeof(TCHAR));
  4241. TCHAR strReinstall[MAX_PATH];
  4242. LoadString(hInst,IDS_REINSTALL,strReinstall,sizeof(strReinstall)/sizeof(TCHAR));
  4243. wsprintf(strMsg,TEXT("%s\n\n%s"), szError, strReinstall);
  4244. MessageBox(NULL, strMsg, szAppName, MB_OK|MB_ICONERROR );
  4245. }
  4246. return fSuccess;
  4247. }
  4248. ////////////////////////////////////////////////////////////////////////////////////////////
  4249. // * AddComponent
  4250. // Add a component to the list of comps
  4251. ////////////////////////////////////////////////////////////////////////////////////////////
  4252. void AddComponent(IMMComponent* pComponent)
  4253. {
  4254. pCompListTail->pComp = pComponent;
  4255. pCompListTail->pSink = new CFrameworkNotifySink(pCompListTail);
  4256. pCompListTail->pSink->AddRef();
  4257. PCOMPNODE pNew = new COMPNODE;
  4258. pNew->pComp = NULL;
  4259. pNew->pNext = NULL;
  4260. pNew->hwndComp = NULL;
  4261. pNew->pSink = NULL;
  4262. pNew->szTitle[0] = '\0';
  4263. pCompListTail->pNext = pNew;
  4264. pCompListTail = pNew;
  4265. }
  4266. ////////////////////////////////////////////////////////////////////////////////////////////
  4267. // * CleanUp
  4268. // Get rid of anything that might have been around, like linked list, mutex, bitmaps, etc.
  4269. ////////////////////////////////////////////////////////////////////////////////////////////
  4270. void CleanUp(void)
  4271. {
  4272. if (pCompList)
  4273. {
  4274. while (pCompList->pNext != NULL)
  4275. {
  4276. PCOMPNODE pTemp = pCompList;
  4277. pCompList = pTemp->pNext;
  4278. if (pTemp->pComp)
  4279. {
  4280. pTemp->pComp->Release();
  4281. pTemp->pSink->Release();
  4282. }
  4283. delete pTemp;
  4284. }
  4285. delete pCompList;
  4286. pCompList = NULL;
  4287. }
  4288. if (g_pOptions)
  4289. {
  4290. g_pOptions->Release();
  4291. }
  4292. if (g_pData)
  4293. {
  4294. g_pData->Release();
  4295. }
  4296. if (g_hhk)
  4297. {
  4298. UnhookWindowsHookEx(g_hhk);
  4299. g_hhk = NULL;
  4300. }
  4301. if (hmImage)
  4302. {
  4303. FreeLibrary(hmImage);
  4304. }
  4305. if (fShellMode)
  4306. {
  4307. DestroyShellIcon();
  4308. }
  4309. CDNET_Uninit();
  4310. }
  4311. ////////////////////////////////////////////////////////////////////////////////////////////
  4312. // * InitComponents
  4313. // Initialize components by calling their INIT functions and setting their window sizes
  4314. ////////////////////////////////////////////////////////////////////////////////////////////
  4315. void InitComponents(HWND hwnd)
  4316. {
  4317. PCOMPNODE pList = pCompList;
  4318. RECT rect;
  4319. while (pList->pNext!=NULL)
  4320. {
  4321. IMMComponent* pComp = pList->pComp;
  4322. if (pComp)
  4323. {
  4324. nNumComps++;
  4325. pComp->Init(pList->pSink,hwnd,&rect,&(pList->hwndComp),&(pList->hmenuComp));
  4326. CalculateDispAreaOffset(pComp);
  4327. switch (g_nViewMode)
  4328. {
  4329. case VIEW_MODE_NORMAL :
  4330. {
  4331. SetRect(&rect,24,32,455,88+nDispAreaOffset);
  4332. }
  4333. break;
  4334. case VIEW_MODE_RESTORE :
  4335. {
  4336. SetRect(&rect,303,24,384,41);
  4337. }
  4338. break;
  4339. case VIEW_MODE_SMALL :
  4340. {
  4341. SetRect(&rect,303,12,384,29);
  4342. }
  4343. break;
  4344. case VIEW_MODE_NOBAR :
  4345. {
  4346. SetRect(&rect,24,16,455,72+nDispAreaOffset);
  4347. }
  4348. break;
  4349. }
  4350. SetWindowPos(pList->hwndComp,
  4351. hwnd,
  4352. rect.left,
  4353. rect.top,
  4354. rect.right - rect.left,
  4355. rect.bottom - rect.top,
  4356. SWP_NOZORDER|SWP_NOACTIVATE);
  4357. //size ledwindow to maximum size
  4358. HWND hwndLED = GetDlgItem(pList->hwndComp,IDC_LEDWINDOW);
  4359. if (hwndLED)
  4360. {
  4361. SetRect(&rect,24,32,455,88+nDispAreaOffset);
  4362. SetWindowPos(hwndLED,
  4363. pList->hwndComp,
  4364. 0,
  4365. 0,
  4366. rect.right - rect.left,
  4367. rect.bottom - rect.top,
  4368. SWP_NOZORDER|SWP_NOACTIVATE);
  4369. InvalidateRect(hwndLED,NULL,FALSE);
  4370. UpdateWindow(hwndLED);
  4371. }
  4372. if (!hwndCurrentComp)
  4373. {
  4374. ShowNewComponentWindow(pList, hwnd);
  4375. }
  4376. } //end if comp ok
  4377. pList = pList->pNext;
  4378. } //end while
  4379. }
  4380. ////////////////////////////////////////////////////////////////////////////////////////////
  4381. // * GetToolTipMsgProc
  4382. // Msg hook for tool tips so they know when to pop up
  4383. ////////////////////////////////////////////////////////////////////////////////////////////
  4384. LRESULT CALLBACK GetToolTipMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
  4385. {
  4386. MSG *lpmsg;
  4387. lpmsg = (MSG *) lParam;
  4388. if (nCode < 0 || !(IsChild(hwndMain, lpmsg->hwnd)))
  4389. {
  4390. return (CallNextHookEx(g_hhk, nCode, wParam, lParam));
  4391. }
  4392. switch (lpmsg->message)
  4393. {
  4394. case WM_MOUSEMOVE:
  4395. case WM_LBUTTONDOWN:
  4396. case WM_LBUTTONUP:
  4397. case WM_RBUTTONDOWN:
  4398. case WM_RBUTTONUP:
  4399. if (g_hwndTT != NULL)
  4400. {
  4401. MSG msg;
  4402. msg.lParam = lpmsg->lParam;
  4403. msg.wParam = lpmsg->wParam;
  4404. msg.message = lpmsg->message;
  4405. msg.hwnd = lpmsg->hwnd;
  4406. SendMessage(g_hwndTT, TTM_RELAYEVENT, 0,
  4407. (LPARAM) (LPMSG) &msg);
  4408. }
  4409. break;
  4410. default: break;
  4411. }
  4412. return (CallNextHookEx(g_hhk, nCode, wParam, lParam));
  4413. }
  4414. ////////////////////////////////////////////////////////////////////////////////////////////
  4415. // * CreateToolTips
  4416. // Common control setup code to init tool tips
  4417. ////////////////////////////////////////////////////////////////////////////////////////////
  4418. BOOL CreateToolTips(HWND hwnd)
  4419. {
  4420. InitCommonControls();
  4421. g_hwndTT = CreateWindowEx(0, TOOLTIPS_CLASS, (LPTSTR) NULL,
  4422. TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  4423. CW_USEDEFAULT, hwnd, (HMENU) NULL, hInst, NULL);
  4424. if (g_hwndTT == NULL)
  4425. return FALSE;
  4426. // Install a hook procedure to monitor the message stream for mouse
  4427. // messages intended for the controls in main window
  4428. g_hhk = SetWindowsHookEx(WH_GETMESSAGE, GetToolTipMsgProc,
  4429. (HINSTANCE) NULL, GetCurrentThreadId());
  4430. if (g_hhk == NULL)
  4431. return FALSE;
  4432. return TRUE;
  4433. }
  4434. //WM_DEVICECHANGE support/////////////////////////////////////////////////////////////////////////
  4435. //////////////////////////////////////////////////////////////////////////////////////////////////
  4436. void Volume_DeviceChange_Cleanup()
  4437. {
  4438. if (DeviceEventContext)
  4439. {
  4440. UnregisterDeviceNotification(DeviceEventContext);
  4441. DeviceEventContext = 0;
  4442. }
  4443. bUseHandle = FALSE;
  4444. return;
  4445. }
  4446. /*
  4447. **************************************************************************************************
  4448. Volume_GetDeviceHandle()
  4449. given a mixerID this functions opens its corresponding device handle. This handle can be used
  4450. to register for DeviceNotifications.
  4451. dwMixerID -- The mixer ID
  4452. phDevice -- a pointer to a handle. This pointer will hold the handle value if the function is
  4453. successful
  4454. return values -- If the handle could be obtained successfully the return vlaue is TRUE.
  4455. **************************************************************************************************
  4456. */
  4457. BOOL Volume_GetDeviceHandle(DWORD dwMixerID, HANDLE *phDevice)
  4458. {
  4459. MMRESULT mmr;
  4460. ULONG cbSize=0;
  4461. TCHAR *szInterfaceName=NULL;
  4462. //Query for the Device interface name
  4463. mmr = mixerMessage((HMIXER)dwMixerID, DRV_QUERYDEVICEINTERFACESIZE, (DWORD_PTR)&cbSize, 0L);
  4464. if(MMSYSERR_NOERROR == mmr)
  4465. {
  4466. szInterfaceName = (TCHAR *)GlobalAllocPtr(GHND, (cbSize+1)*sizeof(TCHAR));
  4467. if(!szInterfaceName)
  4468. {
  4469. return FALSE;
  4470. }
  4471. mmr = mixerMessage((HMIXER)dwMixerID, DRV_QUERYDEVICEINTERFACE, (DWORD_PTR)szInterfaceName, cbSize);
  4472. if(MMSYSERR_NOERROR != mmr)
  4473. {
  4474. GlobalFreePtr(szInterfaceName);
  4475. return FALSE;
  4476. }
  4477. }
  4478. else
  4479. {
  4480. return FALSE;
  4481. }
  4482. //Get an handle on the device interface name.
  4483. *phDevice = CreateFile(szInterfaceName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
  4484. NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  4485. GlobalFreePtr(szInterfaceName);
  4486. if(INVALID_HANDLE_VALUE == *phDevice)
  4487. {
  4488. return FALSE;
  4489. }
  4490. return TRUE;
  4491. }
  4492. /* Volume_DeviceChange_Init()
  4493. * First time initialization for WM_DEVICECHANGE messages
  4494. *
  4495. * On NT 5.0, you have to register for device notification
  4496. */
  4497. BOOL Volume_DeviceChange_Init(HWND hWnd, DWORD dwMixerID)
  4498. {
  4499. DEV_BROADCAST_HANDLE DevBrodHandle;
  4500. DEV_BROADCAST_DEVICEINTERFACE dbi;
  4501. HANDLE hMixerDevice=NULL;
  4502. MMRESULT mmr;
  4503. //If we had registered already for device notifications, unregister ourselves.
  4504. Volume_DeviceChange_Cleanup();
  4505. //If we get the device handle register for device notifications on it.
  4506. if(Volume_GetDeviceHandle(dwMixerID, &hMixerDevice))
  4507. {
  4508. memset(&DevBrodHandle, 0, sizeof(DEV_BROADCAST_HANDLE));
  4509. DevBrodHandle.dbch_size = sizeof(DEV_BROADCAST_HANDLE);
  4510. DevBrodHandle.dbch_devicetype = DBT_DEVTYP_HANDLE;
  4511. DevBrodHandle.dbch_handle = hMixerDevice;
  4512. DeviceEventContext = RegisterDeviceNotification(hWnd, &DevBrodHandle,
  4513. DEVICE_NOTIFY_WINDOW_HANDLE);
  4514. if(hMixerDevice)
  4515. {
  4516. CloseHandle(hMixerDevice);
  4517. hMixerDevice = NULL;
  4518. }
  4519. if(DeviceEventContext)
  4520. {
  4521. bUseHandle = TRUE;
  4522. return TRUE;
  4523. }
  4524. }
  4525. if(!DeviceEventContext)
  4526. {
  4527. //Register for notifications from all audio devices. KSCATEGORY_AUDIO gives notifications
  4528. //on device arrival and removal. We cannot identify which device the notification has arrived for
  4529. //but we can take some precautionary measures on these messages so that we do not crash.
  4530. dbi.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
  4531. dbi.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
  4532. dbi.dbcc_reserved = 0;
  4533. dbi.dbcc_classguid = KSCATEGORY_AUDIO;
  4534. dbi.dbcc_name[0] = TEXT('\0');
  4535. DeviceEventContext = RegisterDeviceNotification(hWnd,
  4536. (PVOID)&dbi,
  4537. DEVICE_NOTIFY_WINDOW_HANDLE);
  4538. if(!DeviceEventContext)
  4539. return FALSE;
  4540. }
  4541. return TRUE;
  4542. }
  4543. //WM_DEVICECHANGE support ends////////////////////////////////////////////////////////////////////
  4544. //////////////////////////////////////////////////////////////////////////////////////////////////