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.

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