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.

259 lines
8.1 KiB

  1. /*************************************************************************/
  2. /* Copyright (C) 1999 Microsoft Corporation */
  3. /* File: dvdplay.cpp */
  4. /* Description: Implementation of WinMain for hosting DLL container. */
  5. /* This is simple stub exe, that contains resources and startups an */
  6. /* OLE container. */
  7. /* Author: David Janecek */
  8. /*************************************************************************/
  9. #include "stdafx.h"
  10. #include "tchar.h"
  11. #include <stdio.h>
  12. #include "resource.h"
  13. #include "..\MSMFCnt\MSMFCnt.h"
  14. #include "..\MSMFCnt\MSMFCnt_i.c"
  15. /*************************************************************************/
  16. /* Function: AnotherInstanceRunning */
  17. /* Description: Trys to figure out if we have another instance of this */
  18. /* app running. If so brings it to foregraound and exits. */
  19. /*************************************************************************/
  20. BOOL AnotherInstanceRunning(){
  21. HWND hwnd = ::FindWindow(TEXT("MSMFVideoClass"), TEXT("DVDPlay"));
  22. if(NULL == hwnd){
  23. return(FALSE);
  24. }/* end of if statement */
  25. // OK we have something running
  26. HWND hwndFirstChild = ::GetLastActivePopup(hwnd);
  27. if(::IsIconic(hwnd)){
  28. ::OpenIcon(hwnd);
  29. }/* end of if statement */
  30. ::SetForegroundWindow(hwnd);
  31. if(hwndFirstChild != hwnd){
  32. if(::IsIconic(hwndFirstChild)){
  33. ::OpenIcon(hwndFirstChild);
  34. }/* end of if statement */
  35. ::SetForegroundWindow(hwndFirstChild);
  36. }/* end of if statement */
  37. return(TRUE);
  38. }/* end of function AnotherInstanceRunning */
  39. /*************************************************************************/
  40. /* Function: FindOneOf */
  41. /*************************************************************************/
  42. LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2){
  43. while (p1 != NULL && *p1 != NULL){
  44. LPCTSTR p = p2;
  45. while (p != NULL && *p != NULL){
  46. if (*p1 == *p)
  47. return CharNext(p1);
  48. p = CharNext(p);
  49. }/* end of while loop */
  50. p1 = CharNext(p1);
  51. }/* end of while loop */
  52. return NULL;
  53. }/* end of function FindOnOf */
  54. /*************************************************************************/
  55. /* Function: WinMain */
  56. /* Description: Initializes the object, and sets the script to it */
  57. /*************************************************************************/
  58. #if 0
  59. extern "C" int WINAPI _tWinMain(HINSTANCE /* hInstance */,
  60. HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/){
  61. #else
  62. int APIENTRY WinMain(HINSTANCE /* hInst */,
  63. HINSTANCE /*hPrevInstance*/,
  64. LPSTR /*lpCmdLine*/,
  65. int /*nCmdShow*/){
  66. #endif
  67. try {
  68. BSTR strFileName = NULL;
  69. BSTR strScriptFile = ::SysAllocString(L"dvdlayout.js");
  70. if(AnotherInstanceRunning()){
  71. // only one instance at a time
  72. return(-1);
  73. }/* end of if statement */
  74. TCHAR szTokens[] = _T("-/ ");
  75. LPTSTR lpCmdLine = ::GetCommandLine();
  76. LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
  77. while (lpszToken != NULL)
  78. {
  79. // Read the command line argument
  80. TCHAR opt[MAX_PATH];
  81. #ifdef _UNICODE
  82. _stscanf(lpszToken, TEXT("%ws"), opt);
  83. #else
  84. _stscanf(lpszToken, TEXT("%s"), opt);
  85. #endif
  86. // Set run the default directory name
  87. if (lstrcmpi(opt, _T("play"))==0) {
  88. lpszToken = FindOneOf(lpszToken, szTokens);
  89. TCHAR fileName[MAX_PATH];
  90. #ifdef _UNICODE
  91. _stscanf(lpszToken, TEXT("%ws"), fileName);
  92. //*( _tcsrchr( fileName, '\\' ) + 1 ) = TEXT('\0');
  93. strFileName = SysAllocString(fileName);
  94. #else
  95. _stscanf(lpszToken, "%s", fileName);
  96. #ifdef _DEBUG
  97. ::MessageBox(::GetFocus(), TEXT("test"), fileName, MB_OK);
  98. #endif
  99. // *( _tcsrchr( fileName, '\\' ) + 1 ) = TEXT('\0');
  100. WCHAR strTmpFileName[MAX_PATH];
  101. LONG lLength = _tcslen(fileName) + 1;
  102. ::MultiByteToWideChar(CP_ACP, 0, fileName, lLength, strTmpFileName, MAX_PATH);
  103. strFileName = ::SysAllocString(strTmpFileName);
  104. #endif
  105. }/* end of if statement */
  106. if (lstrcmpi(opt, _T("script"))==0) {
  107. lpszToken = FindOneOf(lpszToken, szTokens);
  108. TCHAR scriptFile[MAX_PATH];
  109. #ifdef _UNICODE
  110. _stscanf(lpszToken, TEXT("%ws"), scriptFile);
  111. if(NULL != strFileName){
  112. ::SysFreeString(strFileName);
  113. }/* end of if statement */
  114. strScriptFile = ::SysAllocString(scriptFile);
  115. #else
  116. _stscanf(lpszToken, "%s", scriptFile);
  117. WCHAR strTmpFileName[MAX_PATH];
  118. LONG lLength = _tcslen(scriptFile) + 1;
  119. ::MultiByteToWideChar(CP_ACP, 0, scriptFile, lLength, strTmpFileName, MAX_PATH);
  120. if(NULL != strFileName){
  121. ::SysFreeString(strFileName);
  122. }/* end of if statement */
  123. strScriptFile = SysAllocString(strTmpFileName);
  124. #endif
  125. }/* end of if statement */
  126. lpszToken = FindOneOf(lpszToken, szTokens);
  127. }/* end of if statement */
  128. HRESULT hr = ::CoInitialize(NULL);
  129. #ifdef _DEBUG
  130. bool fReload;
  131. do {
  132. fReload = false;
  133. #endif
  134. IMSMFBar* pIMFBar = NULL;
  135. hr = ::CoCreateInstance(
  136. CLSID_MSMFBar,
  137. NULL,
  138. CLSCTX_SERVER,
  139. IID_IMSMFBar,
  140. (LPVOID*) &pIMFBar);
  141. if(FAILED(hr)){
  142. return (-2);
  143. }/* end of if statement */
  144. hr = pIMFBar->put_CmdLine(strFileName);
  145. if(SUCCEEDED(hr)){
  146. hr = pIMFBar->put_ScriptFile(strScriptFile);
  147. }/* end of if statement */
  148. if(SUCCEEDED(hr)){
  149. MSG msg;
  150. while (::GetMessage(&msg, 0, 0, 0)){
  151. #ifdef _DEBUG
  152. // enable restarting of the app via F6 key
  153. // did not use F5 since that is overused and if debugging could trigger unvanted behavior
  154. if(WM_KEYUP == msg.message && VK_F6 == msg.wParam){
  155. fReload = true;
  156. ::PostMessage(msg.hwnd, WM_CLOSE, NULL, NULL); // tell our container to close
  157. }/* end of if statement */
  158. #endif
  159. //ATLTRACE2(atlTraceHosting, 20, TEXT("Message = %x \n"), msg.message);
  160. ::DispatchMessage(&msg);
  161. }/* end of while loop */
  162. }/* end of if statement */
  163. // release the site
  164. if(NULL != pIMFBar){
  165. pIMFBar->Release();
  166. pIMFBar = NULL;
  167. }/* end of if statement */
  168. if(NULL != strFileName){
  169. ::SysFreeString(strFileName);
  170. }/* end of if statement */
  171. if(NULL != strScriptFile){
  172. ::SysFreeString(strScriptFile);
  173. }/* end of if statement */
  174. #ifdef _DEBUG
  175. }
  176. while (fReload);
  177. #endif
  178. ::CoUninitialize();
  179. }
  180. catch(...){
  181. return(-1);
  182. }/* end of catch statement */
  183. return 0;
  184. }/* end of function WinMain */
  185. /*************************************************************************/
  186. /* End of file: dvdplay.cpp */
  187. /*************************************************************************/