Leaked source code of windows server 2003
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.

519 lines
16 KiB

  1. /* (C) Copyright Microsoft Corporation 1991-1994. All Rights Reserved */
  2. /* init.c
  3. *
  4. * init (discardable) utility functions.
  5. */
  6. /* Revision History.
  7. * 4/2/91 LaurieGr (AKA LKG) Ported to WIN32 / WIN16 common code
  8. * 22/Feb/94 LaurieGr merged Motown and Daytona versions
  9. */
  10. #include <windows.h>
  11. #include <mmsystem.h>
  12. #include <shellapi.h>
  13. #include <mmreg.h>
  14. #include <winnls.h>
  15. #include <tchar.h>
  16. #define INCLUDE_OLESTUBS
  17. #include "soundrec.h"
  18. #include "srecids.h"
  19. #include "reg.h"
  20. #define NOMENUHELP
  21. #define NODRAGLIST
  22. #ifdef USE_MMCNTRLS
  23. #include "mmcntrls.h"
  24. #else
  25. #include <commctrl.h>
  26. #include "buttons.h"
  27. #endif
  28. /* globals */
  29. TCHAR gachAppName[12]; // 8-character name
  30. TCHAR gachAppTitle[30]; // full name
  31. TCHAR gachHelpFile[20]; // name of help file
  32. TCHAR gachHtmlHelpFile[20]; // name of help file
  33. TCHAR gachDefFileExt[10]; // default file extension
  34. HBRUSH ghbrPanel = NULL; // color of main window
  35. HANDLE ghAccel;
  36. TCHAR aszNull[2];
  37. TCHAR aszUntitled[32]; // Untitled string resource
  38. // SIZEOF(szUntitled) must be <= SIZEOF(gachFileName)
  39. TCHAR aszFilter[64]; // Common Dialog file list filter
  40. #ifdef FAKEITEMNAMEFORLINK
  41. TCHAR aszFakeItemName[16]; // Wave
  42. #endif
  43. TCHAR aszPositionFormat[32];
  44. TCHAR aszNoZeroPositionFormat[32];
  45. extern UINT guWaveHdrs ; // 1/2 second of buffering?
  46. extern DWORD gdwBufferDeltaMSecs ; // # msecs added to end on record
  47. extern UINT gwMSecsPerBuffer; // 1/8 second. initialised in this file
  48. extern BITMAPBTN tbPlaybar[];
  49. static SZCODE aszDecimal[] = TEXT("sDecimal");
  50. static SZCODE aszLZero[] = TEXT("iLzero");
  51. static SZCODE aszWaveClass[] = TEXT("wavedisplay");
  52. static SZCODE aszNoFlickerClass[] = TEXT("noflickertext");
  53. static SZCODE aszShadowClass[] = TEXT("shadowframe");
  54. static SZCODE aszBufferDeltaSeconds[] = TEXT("BufferDeltaSeconds");
  55. static SZCODE aszNumAsyncWaveHeaders[] = TEXT("NumAsyncWaveHeaders");
  56. static SZCODE aszMSecsPerAsyncBuffer[] = TEXT("MSecsPerAsyncBuffer");
  57. /* FixupNulls(chNull, p)
  58. *
  59. * To facilitate localization, we take a localized string with non-NULL
  60. * NULL substitutes and replacement with a real NULL.
  61. */
  62. void NEAR PASCAL FixupNulls(
  63. TCHAR chNull,
  64. LPTSTR p)
  65. {
  66. while (*p) {
  67. if (*p == chNull)
  68. *p++ = 0;
  69. else
  70. p = CharNext(p);
  71. }
  72. } /* FixupNulls */
  73. /* AppInit(hInst, hPrev)
  74. *
  75. * This is called when the application is first loaded into memory.
  76. * It performs all initialization that doesn't need to be done once
  77. * per instance.
  78. */
  79. BOOL PASCAL AppInit(
  80. HINSTANCE hInst, // instance handle of current instance
  81. HINSTANCE hPrev) // instance handle of previous instance
  82. {
  83. #ifdef OLE1_REGRESS
  84. TCHAR aszClipFormat[32];
  85. #endif
  86. WNDCLASS cls;
  87. UINT i;
  88. /* load strings */
  89. LoadString(hInst, IDS_APPNAME, gachAppName, SIZEOF(gachAppName));
  90. LoadString(hInst, IDS_APPTITLE, gachAppTitle, SIZEOF(gachAppTitle));
  91. LoadString(hInst, IDS_HELPFILE, gachHelpFile, SIZEOF(gachHelpFile));
  92. LoadString(hInst, IDS_HTMLHELPFILE, gachHtmlHelpFile, SIZEOF(gachHtmlHelpFile));
  93. LoadString(hInst, IDS_UNTITLED, aszUntitled, SIZEOF(aszUntitled));
  94. LoadString(hInst, IDS_FILTER, aszFilter, SIZEOF(aszFilter));
  95. LoadString(hInst, IDS_FILTERNULL, aszNull, SIZEOF(aszNull));
  96. LoadString(hInst, IDS_DEFFILEEXT, gachDefFileExt, SIZEOF(gachDefFileExt));
  97. FixupNulls(*aszNull, aszFilter);
  98. #ifdef FAKEITEMNAMEFORLINK
  99. LoadString(hInst, IDS_FAKEITEMNAME, aszFakeItemName, SIZEOF(aszFakeItemName));
  100. #endif
  101. LoadString(hInst, IDS_POSITIONFORMAT, aszPositionFormat, SIZEOF(aszPositionFormat));
  102. LoadString(hInst, IDS_NOZEROPOSITIONFORMAT, aszNoZeroPositionFormat, SIZEOF(aszNoZeroPositionFormat));
  103. ghiconApp = LoadIcon(hInst, MAKEINTRESOURCE(IDI_APP));
  104. #ifdef OLE1_REGRESS
  105. /* Initialize OLE server stuff */
  106. InitVTbls();
  107. // IDS_OBJECTLINK "ObjectLink"
  108. // IDS_OWNERLINK "OwnerLink"
  109. // IDS_NATIVE "Native"
  110. LoadString(hInst, IDS_OBJECTLINK, aszClipFormat, SIZEOF(aszClipFormat));
  111. cfLink = (OLECLIPFORMAT)RegisterClipboardFormat(aszClipFormat);
  112. LoadString(hInst, IDS_OWNERLINK, aszClipFormat, SIZEOF(aszClipFormat));
  113. cfOwnerLink = (OLECLIPFORMAT)RegisterClipboardFormat(aszClipFormat);
  114. LoadString(hInst, IDS_NATIVE, aszClipFormat, SIZEOF(aszClipFormat));
  115. cfNative = (OLECLIPFORMAT)RegisterClipboardFormat(aszClipFormat);
  116. #if 0
  117. cfLink = (OLECLIPFORMAT)RegisterClipboardFormatA("ObjectLink");
  118. cfOwnerLink = (OLECLIPFORMAT)RegisterClipboardFormatA("OwnerLink");
  119. cfNative = (OLECLIPFORMAT)RegisterClipboardFormatA("Native");
  120. #endif
  121. #endif
  122. #ifdef DEBUG
  123. ReadRegistryData(NULL
  124. , TEXT("Debug")
  125. , NULL
  126. , (LPBYTE)&__iDebugLevel
  127. , (DWORD)sizeof(__iDebugLevel));
  128. DPF(TEXT("Debug level = %d\n"),__iDebugLevel);
  129. #endif
  130. ghbrPanel = CreateSolidBrush(RGB_PANEL);
  131. if (hPrev == NULL)
  132. {
  133. /* register the "wavedisplay" window class */
  134. cls.lpszClassName = aszWaveClass;
  135. cls.hCursor = LoadCursor(NULL, IDC_ARROW);
  136. cls.hIcon = NULL;
  137. cls.lpszMenuName = NULL;
  138. cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  139. cls.hInstance = hInst;
  140. cls.style = CS_HREDRAW | CS_VREDRAW;
  141. cls.lpfnWndProc = WaveDisplayWndProc;
  142. cls.cbClsExtra = 0;
  143. cls.cbWndExtra = 0;
  144. if (!RegisterClass(&cls))
  145. return FALSE;
  146. /* register the "noflickertext" window class */
  147. cls.lpszClassName = aszNoFlickerClass;
  148. cls.hCursor = LoadCursor(NULL, IDC_ARROW);
  149. cls.hIcon = NULL;
  150. cls.lpszMenuName = NULL;
  151. cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  152. cls.hInstance = hInst;
  153. cls.style = CS_HREDRAW | CS_VREDRAW;
  154. cls.lpfnWndProc = NFTextWndProc;
  155. cls.cbClsExtra = 0;
  156. cls.cbWndExtra = 0;
  157. if (!RegisterClass(&cls))
  158. return FALSE;
  159. /* register the "shadowframe" window class */
  160. cls.lpszClassName = aszShadowClass;
  161. cls.hCursor = LoadCursor(NULL, IDC_ARROW);
  162. cls.hIcon = NULL;
  163. cls.lpszMenuName = NULL;
  164. cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  165. cls.hInstance = hInst;
  166. cls.style = CS_HREDRAW | CS_VREDRAW;
  167. cls.lpfnWndProc = SFrameWndProc;
  168. cls.cbClsExtra = 0;
  169. cls.cbWndExtra = 0;
  170. if (!RegisterClass(&cls))
  171. return FALSE;
  172. /* register the dialog's window class */
  173. cls.lpszClassName = gachAppName;
  174. cls.hCursor = LoadCursor(NULL, IDC_ARROW);
  175. cls.hIcon = ghiconApp;
  176. cls.lpszMenuName = NULL;
  177. cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  178. cls.hInstance = hInst;
  179. cls.style = CS_HREDRAW | CS_VREDRAW;
  180. cls.lpfnWndProc = DefDlgProc;
  181. cls.cbClsExtra = 0;
  182. cls.cbWndExtra = DLGWINDOWEXTRA;
  183. if (!RegisterClass(&cls))
  184. return FALSE;
  185. }
  186. #ifdef USE_MMCNTRLS
  187. if (!InitTrackBar(hPrev))
  188. return FALSE;
  189. #else
  190. InitCommonControls();
  191. #endif
  192. if (!(ghAccel = LoadAccelerators(hInst, gachAppName)))
  193. return FALSE;
  194. i = DEF_BUFFERDELTASECONDS;
  195. ReadRegistryData(NULL
  196. , (LPTSTR)aszBufferDeltaSeconds
  197. , NULL
  198. , (LPBYTE)&i
  199. , (DWORD)sizeof(i));
  200. if (i > MAX_DELTASECONDS)
  201. i = MAX_DELTASECONDS;
  202. else if (i < MIN_DELTASECONDS)
  203. i = MIN_DELTASECONDS;
  204. gdwBufferDeltaMSecs = i * 1000L;
  205. DPF(TEXT("gdwBufferDeltaMSecs=%lu\n"), gdwBufferDeltaMSecs);
  206. //
  207. // because it really doesn't help in standard mode to stream with
  208. // multiple wave headers (we sorta assume we having a paging device
  209. // to make things work...), we just revert to one big buffer in
  210. // standard mode... might want to check if paging is enabled??
  211. //
  212. // in any case, this helps a LOT when running KRNL286-->the thing
  213. // is buggy and GP faults when lots of discarding, etc
  214. // is going on... like when dealing with large sound objects, eh?
  215. //
  216. i = DEF_NUMASYNCWAVEHEADERS;
  217. ReadRegistryData(NULL
  218. , (LPTSTR)aszNumAsyncWaveHeaders
  219. , NULL
  220. , (LPBYTE)&i
  221. , (DWORD)sizeof(i));
  222. if (i > MAX_WAVEHDRS)
  223. i = MAX_WAVEHDRS;
  224. else if (i < MIN_WAVEHDRS)
  225. i = 1;
  226. guWaveHdrs = i;
  227. DPF(TEXT(" guWaveHdrs=%u\n"), guWaveHdrs);
  228. i = DEF_MSECSPERASYNCBUFFER;
  229. ReadRegistryData(NULL
  230. , (LPTSTR)aszMSecsPerAsyncBuffer
  231. , NULL
  232. , (LPBYTE)&i
  233. , (DWORD)sizeof(i));
  234. if (i > MAX_MSECSPERBUFFER)
  235. i = MAX_MSECSPERBUFFER;
  236. else if (i < MIN_MSECSPERBUFFER)
  237. i = MIN_MSECSPERBUFFER;
  238. gwMSecsPerBuffer = i;
  239. DPF(TEXT(" gwMSecsPerBuffer=%u\n"), gwMSecsPerBuffer);
  240. return TRUE;
  241. } /* AppInit */
  242. /*
  243. * */
  244. void DoOpenFile(void)
  245. {
  246. LPTSTR lpCmdLine = GetCommandLine();
  247. /* increment pointer past the argv[0] */
  248. while ( *lpCmdLine && *lpCmdLine != TEXT(' '))
  249. lpCmdLine = CharNext(lpCmdLine);
  250. if( gfLinked )
  251. {
  252. FileOpen(gachLinkFilename);
  253. }
  254. else if (!gfEmbedded)
  255. {
  256. // skip blanks
  257. while (*lpCmdLine == TEXT(' '))
  258. {
  259. lpCmdLine++;
  260. continue;
  261. }
  262. if(*lpCmdLine)
  263. {
  264. ResolveIfLink(lpCmdLine);
  265. FileOpen(lpCmdLine);
  266. }
  267. }
  268. }
  269. /*
  270. * Dialog box initialization
  271. * */
  272. BOOL PASCAL SoundDialogInit(
  273. HWND hwnd,
  274. int iCmdShow)
  275. {
  276. /* make the window handle global */
  277. ghwndApp = hwnd;
  278. DragAcceptFiles(ghwndApp, TRUE); /* Process dragged and dropped file */
  279. GetIntlSpecs();
  280. /* Hide the window unless we want to display it later */
  281. ShowWindow(ghwndApp,SW_HIDE);
  282. /* remember the window handles of the important controls */
  283. ghwndWaveDisplay = GetDlgItem(hwnd, ID_WAVEDISPLAY);
  284. ghwndScroll = GetDlgItem(hwnd, ID_CURPOSSCRL);
  285. ghwndPlay = GetDlgItem(hwnd, ID_PLAYBTN);
  286. ghwndStop = GetDlgItem(hwnd, ID_STOPBTN);
  287. ghwndRecord = GetDlgItem(hwnd, ID_RECORDBTN);
  288. ghwndForward = GetDlgItem(hwnd, ID_FORWARDBTN);
  289. ghwndRewind = GetDlgItem(hwnd, ID_REWINDBTN);
  290. #ifdef THRESHOLD
  291. ghwndSkipStart = GetDlgItem(hwnd, ID_SKIPSTARTBTN);
  292. ghwndSkipEnd = GetDlgItem(hwnd, ID_SKIPENDBTN);
  293. #endif //THRESHOLD
  294. /* set up scroll bar */
  295. // SetScrollRange(ghwndScroll, SB_CTL, 0, SCROLL_RANGE, TRUE);
  296. SendMessage(ghwndScroll,TBM_SETRANGEMIN, 0, 0);
  297. SendMessage(ghwndScroll,TBM_SETRANGEMAX, 0, SCROLL_RANGE);
  298. SendMessage(ghwndScroll,TBM_SETPOS, TRUE, 0);
  299. /* Set up the bitmap buttons */
  300. BtnCreateBitmapButtons( hwnd,
  301. (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE),
  302. IDR_PLAYBAR,
  303. BBS_TOOLTIPS,
  304. tbPlaybar,
  305. NUM_OF_BUTTONS,
  306. 25,
  307. 17);
  308. //
  309. // OLE2 and command line initialization...
  310. //
  311. InitializeSRS(ghInst);
  312. gfRunWithEmbeddingFlag = gfEmbedded;
  313. //
  314. // Try and init ACM
  315. //
  316. LoadACM();
  317. //
  318. // build the File.New menu
  319. //
  320. //
  321. // create a blank document
  322. //
  323. if (!FileNew(FMT_DEFAULT, TRUE, FALSE))
  324. {
  325. PostMessage(hwnd, WM_CLOSE, 0, 0);
  326. return TRUE;
  327. }
  328. //
  329. // Note, FileNew/FileOpen has the side effect of releasing the
  330. // server when called by the user. For now, do it here. In the future
  331. // Wrapping these calls would suffice.
  332. //
  333. FlagEmbeddedObject(gfEmbedded);
  334. //
  335. // open a file if requested on command line
  336. //
  337. //
  338. // Execute command line verbs here.
  339. //
  340. // Would be nicer just to execute methods that are likewise exportable
  341. // through an OLE interface.
  342. if (gStartParams.fNew)
  343. {
  344. //
  345. // Behavior: If there is a filename specified, create it and
  346. // commit it so we have a named, empty document. Otherwise, we
  347. // start in a normal new state.
  348. //
  349. //TODO: Implement checkbox to set-as default format and not bring up
  350. //TODO: the format selection dialog box.
  351. FileNew(FMT_DEFAULT,TRUE,TRUE);
  352. if (gStartParams.achOpenFilename[0] != 0)
  353. {
  354. lstrcpy(gachFileName, gStartParams.achOpenFilename);
  355. FileSave(FALSE);
  356. }
  357. //
  358. // Behaviour: If -close was specified, all we do is exit.
  359. //
  360. if (gStartParams.fClose)
  361. PostMessage(hwnd,WM_CLOSE,0,0);
  362. }
  363. else if (gStartParams.fPlay)
  364. {
  365. /* Behavior: If there is a file, just open it. If not, ask for the
  366. * filename. Then queue up a play request.
  367. * If -close was specified, then when the play is done the application
  368. * will exit. (see wave.c:YieldStop())
  369. */
  370. if (gStartParams.achOpenFilename[0] != 0)
  371. FileOpen(gStartParams.achOpenFilename);
  372. else
  373. FileOpen(NULL);
  374. AppPlay(gStartParams.fPlay && gStartParams.fClose);
  375. }
  376. else
  377. {
  378. /* case: Both linked and standalone "open" cases are handled
  379. * here. The only unusual case is if -open was specified without
  380. * a filename, meaning the user should be asked for a filename
  381. * first upon app start.
  382. *
  383. * Behaviour: -open and -close has no meaning, unless as a
  384. * verification (i.e. is this a valid wave file). So this
  385. * isn't implemented.
  386. */
  387. if (gStartParams.achOpenFilename[0] != 0)
  388. FileOpen(gStartParams.achOpenFilename);
  389. else if (gStartParams.fOpen)
  390. FileOpen(NULL);
  391. }
  392. if (!gfRunWithEmbeddingFlag) {
  393. ShowWindow(ghwndApp,iCmdShow);
  394. /* set focus to "Record" if the file is empty, "Play" if not */
  395. if (glWaveSamplesValid == 0 && IsWindowEnabled(ghwndRecord))
  396. SetDlgFocus(ghwndRecord);
  397. else if (glWaveSamplesValid > 0 && IsWindowEnabled(ghwndPlay))
  398. SetDlgFocus(ghwndPlay);
  399. else
  400. SetDlgFocus(ghwndScroll);
  401. if (!waveInGetNumDevs() && !waveOutGetNumDevs()) {
  402. /* No recording or playback devices */
  403. ErrorResBox(hwnd, ghInst, MB_ICONHAND | MB_OK,
  404. IDS_APPTITLE, IDS_NOWAVEFORMS);
  405. }
  406. return FALSE; // FALSE because we set the focus above
  407. }
  408. //
  409. // return FALSE, so the dialog manager will not activate us, it is
  410. // ok because we are hidden anyway
  411. //
  412. return FALSE;
  413. } /* SoundDialogInit */
  414. /*
  415. * localisation stuff - decimal point delimiter etc
  416. * */
  417. BOOL FAR PASCAL
  418. GetIntlSpecs()
  419. {
  420. TCHAR szTmp[5];
  421. // find decimal seperator
  422. szTmp[0] = chDecimal;
  423. szTmp[1] = 0;
  424. GetLocaleInfo(LOCALE_USER_DEFAULT
  425. , LOCALE_SDECIMAL
  426. , szTmp
  427. , SIZEOF(szTmp));
  428. chDecimal = szTmp[0];
  429. // leading zeros
  430. szTmp[0] = TEXT('1');
  431. szTmp[1] = 0;
  432. GetLocaleInfo(LOCALE_USER_DEFAULT
  433. , LOCALE_ILZERO
  434. , szTmp
  435. , SIZEOF(szTmp));
  436. gfLZero = _ttoi(szTmp);
  437. szTmp[0] = TEXT('0');
  438. LoadString(ghInst, IDS_RTLENABLED, szTmp, SIZEOF(szTmp));
  439. gfIsRTL = (szTmp[0] != TEXT('0'));
  440. return TRUE;
  441. } /* GetIntlSpecs */