Sthplus.c
上传用户:qzstjx
上传日期:2007-01-06
资源大小:84k
文件大小:10k
源码类别:

mpeg/mp3

开发平台:

Visual C++

  1. /***************************************************************************
  2. |   STHVCD plugins SDK 99.7.22 |
  3. | All rights reserved HEROSOFT Co.,Ltd |
  4. ***************************************************************************/
  5. #include <windows.h>
  6. #include "STHPLUS.H"
  7. #include "resource.h"
  8. HANDLE hDLLInstance=NULL;
  9. BOOL APIENTRY DllMain(HANDLE hInst, DWORD fdwReason, LPVOID lpReserved)
  10. {
  11. static int cProcessesAttached;
  12. if(fdwReason==DLL_PROCESS_ATTACH)
  13. {
  14. if(cProcessesAttached)
  15. {
  16. cProcessesAttached++;
  17. return(TRUE);// Not the first initialization.
  18. }
  19. cProcessesAttached++;
  20. hDLLInstance=hInst;
  21. }
  22. if(fdwReason==DLL_PROCESS_DETACH)
  23. {
  24. cProcessesAttached--;
  25. if(cProcessesAttached)
  26. return TRUE;
  27. }
  28. return TRUE;
  29. }
  30. /////////////////////// SthVCD Face Plus //////////////////
  31. HWND hDLLWnd =NULL;
  32. HWND hMainWnd =NULL;
  33. HANDLE hMainInstance =NULL;
  34. HMENU hPopMenu =NULL;
  35. GETSTHVCDSTATUSPROC GetSthVCDStatus =NULL;
  36. char  szDLLClass[] ="Plus Window";
  37. ///////////////////////////////////////////////////////////
  38. INT Support=CAPSPLUS_VIDEO|CAPSPLUS_AUDIO|CAPSPLUS_CD;
  39. INT APIENTRY QueryPlusCaps(void)
  40. { //This Plus DLL for Video or Audio or CD
  41. return Support;
  42. }
  43. long APIENTRY WndProc(HWND hwnd,UINT message,UINT wParam,LONG lParam);
  44. HWND APIENTRY CreatePlusWindow(HANDLE hMainInstance,HWND hwnd,int Flags,FARPROC GetStatusCallBack)
  45. { //Success or not
  46. WNDCLASS  wndclass;
  47. HMENU hMenu;
  48. if((Flags&Support)==0) return 0;
  49. hMainInstance =hMainInstance;
  50. hMainWnd =hwnd;
  51. (FARPROC)GetSthVCDStatus=GetStatusCallBack;
  52. hMenu =LoadMenu(hDLLInstance,MAKEINTRESOURCE(IDR_MENU));
  53. hPopMenu =GetSubMenu(hMenu,0);
  54. //Create Class
  55. wndclass.style =CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
  56. wndclass.lpfnWndProc =(WNDPROC)WndProc;
  57. wndclass.cbClsExtra =0;
  58. wndclass.cbWndExtra =0;
  59. wndclass.hInstance =hMainInstance;
  60. wndclass.hIcon =NULL;
  61. // wndclass.hCursor =LoadCursor(NULL,IDC_ARROW);
  62. wndclass.hCursor =LoadCursor(hDLLInstance, MAKEINTRESOURCE(IDC_HAND1));
  63. wndclass.hbrBackground =(HBRUSH)COLOR_WINDOW;
  64. wndclass.lpszMenuName =NULL;
  65. wndclass.lpszClassName =szDLLClass;
  66. RegisterClass(&wndclass);
  67. // Create Window
  68. hDLLWnd=CreateWindow(szDLLClass,"STHVCD Plus",
  69. WS_POPUP | WS_VISIBLE,
  70. 40, 20,
  71. 352, 240,
  72. NULL,NULL,hMainInstance,NULL);
  73. //Hide the Window.
  74. ShowWindow(hDLLWnd,SW_SHOW);
  75. UpdateWindow(hDLLWnd);
  76. return hDLLWnd;
  77. }
  78. void APIENTRY ReleasePlusWindow(void)
  79. {
  80. if(hDLLWnd==NULL) return;
  81. //Destory Window
  82. DestroyWindow(hDLLWnd);
  83. //Delete Class
  84. UnregisterClass(szDLLClass,hMainInstance);
  85. //Clear
  86. hDLLWnd=0;
  87. }
  88. void HandleCommand(UINT wParam,LONG lParam)
  89. {
  90. switch(wParam)
  91. {
  92. case ID_PLAYVCD:
  93. SendMessage(hMainWnd,WM_COMMAND,STHVCD_PLAYVCD,lParam);
  94. break;
  95. case ID_PLAYVCD11:
  96. SendMessage(hMainWnd,WM_COMMAND,STHVCD_PLAYVCD11,lParam);
  97. break;
  98. case ID_PLAYFILE:
  99. SendMessage(hMainWnd,WM_COMMAND,STHVCD_PLAYMULTIFILES,lParam);
  100. break;
  101. case ID_PLAY:
  102. SendMessage(hMainWnd,WM_COMMAND,STHVCD_PLAY,lParam);
  103. break;
  104. case ID_STOP:
  105. SendMessage(hMainWnd,WM_COMMAND,STHVCD_STOP,lParam);
  106. break;
  107. case ID_FORWARD:
  108. SendMessage(hMainWnd,WM_COMMAND,STHVCD_FORWARD,lParam);
  109. break;
  110. case ID_BACKWARD:
  111. SendMessage(hMainWnd,WM_COMMAND,STHVCD_BACKWARD,lParam);
  112. break;
  113. case ID_SEARCH:
  114. SendMessage(hMainWnd,WM_COMMAND,STHVCD_SEARCH,lParam);
  115. break;
  116. case ID_STEP:
  117. SendMessage(hMainWnd,WM_COMMAND,STHVCD_STEP,lParam);
  118. break;
  119. case ID_CLOSE:
  120. SendMessage(hMainWnd,WM_COMMAND,STHVCD_CLOSE,lParam);
  121. break;
  122. case ID_ADVANCE:
  123. PostMessage(hMainWnd,WM_COMMAND,STHVCD_RELEASEDLL,lParam);
  124. break;
  125. case ID_EXIT:
  126. PostMessage(hMainWnd,WM_CLOSE,wParam,lParam);
  127. break;
  128. }
  129. }
  130. #define POINTNUM 28
  131. static POINT Points[POINTNUM]=
  132. {
  133. {0,22},{0,140},{39,140},{51,150},{63,156},{73,159},{87,162},
  134. {321,162},{327,160},{329,157},{329,146},{326,143},{321,140},
  135. {321,23},{323,23},{323,19},{317,15},{308,11},{298,7},{286,4},
  136. {270,2},{239,0},{166,0},{162,2},{159,7},{159,15},{160,18},{162,22},
  137. };
  138. ///////////////////////////////////////////////////////////
  139. BOOL DrawBitmap( HDC hdc, HBITMAP hbm, int x, int y, int cx, int cy) ;
  140. long APIENTRY WndProc(HWND hwnd,UINT message,UINT wParam,LONG lParam)
  141. {
  142. PAINTSTRUCT  ps;
  143. static HBITMAP hbm ;
  144. static int cx, cy ;
  145. switch(message)
  146. {
  147. case WM_CREATE:
  148. {
  149. HRGN hrgn;
  150.   BITMAP bmp ;
  151. hdc = GetDC(hwnd);
  152. // loading the bitmap from the resource file
  153. // hbm = LoadBitmap(hDLLInstance,MAKEINTRESOURCE(IDB_FACEBMP)) ;
  154. hBit = LoadBitmap(hDLLInstance,MAKEINTRESOURCE(IDB_FACEBMP)) ;
  155. // get the object size
  156. GetObject( hBit, sizeof( bmp), &bmp) ;
  157. cx=bmp.bmWidth;
  158. cy=bmp.bmHeight;
  159. // reduce it to a fourth
  160. hrgn = CreatePolygonRgn(Points,POINTNUM,ALTERNATE);
  161. // impose the circular window size
  162. SetWindowRgn( hwnd, hrgn, TRUE) ;
  163. // show the window
  164. SetWindowPos( hwnd, HWND_TOP, 0, 0, cx, cy, SWP_NOMOVE);
  165. // create a virtual window
  166. memdc = CreateCompatibleDC(hdc);
  167. SelectObject(memdc, hBit);
  168. //release resource
  169. DeleteObject(hBit);
  170. ReleaseDC(hwnd, hdc);
  171. SethRgns();
  172. //set a timer
  173. SetTimer(hwnd, 1, 1000, HandleTimer);
  174. }
  175. break ;
  176. case WM_PAINT:
  177. hdc=BeginPaint(hwnd,&ps);
  178. BitBlt(hdc, 0, 0, maxX, maxY, memdc, 0, 0, SRCCOPY);
  179. EndPaint(hwnd,&ps);
  180. return 0;
  181. case WM_LBUTTONDOWN:
  182. Button = OnButton(lParam);
  183. if(Button)
  184. {
  185. SetCapture(hwnd);
  186. SetClassLong(hwnd, GCL_HCURSOR, (long)LoadCursor(hDLLInstance, MAKEINTRESOURCE(IDC_HAND2)));
  187. SetCursor(LoadCursor(hDLLInstance, MAKEINTRESOURCE(IDC_HAND2)));
  188. mdc = CreateCompatibleDC(hdc);
  189. switch (Button)
  190. {
  191. case 1: //Close
  192. hBit = LoadBitmap(hDLLInstance,MAKEINTRESOURCE(IDB_CLOSE));
  193. SelectObject(mdc, hBit);
  194. BitBlt(hdc, 301, 117, 15, 12, mdc, 0, 0, SRCCOPY);
  195. DeleteObject(hBit);
  196. break;
  197. }
  198. DeleteDC(mdc);
  199. }
  200. break;
  201. case WM_LBUTTONUP:
  202. ReleaseCapture();
  203. SetClassLong(hwnd, GCL_HCURSOR, (long)LoadCursor(hDLLInstance, MAKEINTRESOURCE(IDC_HAND1)));
  204. SetCursor(LoadCursor(hDLLInstance, MAKEINTRESOURCE(IDC_HAND1)));
  205. hdc = GetDC(hwnd);
  206. InvalidateRect(hwnd, NULL, FALSE);
  207. switch(OnButton(lParam))
  208. {
  209. case 1: //Close
  210. PostMessage(hMainWnd,WM_COMMAND,STHVCD_EXIT,lParam);
  211. break;
  212. }
  213. break;
  214. case WM_CONTEXTMENU:
  215. //Create Popup menu
  216. TrackPopupMenu( hPopMenu,
  217. TPM_TOPALIGN,
  218. LOWORD( lParam),
  219. HIWORD( lParam),
  220. 0,
  221. hwnd,
  222. NULL) ;
  223. break;
  224. case WM_NCHITTEST:
  225. GetWindowRect(hwnd, &winRect);
  226. lParam-=winRect.left;
  227. lParam-=(winRect.top<<16);
  228. if(OnButton(lParam))
  229. return HTCLIENT;
  230. else 
  231. return HTCAPTION;
  232. case WM_COMMAND:
  233. HandleCommand(wParam,lParam);
  234. break;
  235. case WM_SYSCOMMAND:
  236. if(wParam==SC_SCREENSAVE)
  237. return 1;//Off ScreenSave
  238. if(wParam==SC_MONITORPOWER)
  239. return 1;//Off Screen Power
  240. break;
  241. case WM_CLOSE:
  242. PostMessage(hMainWnd,WM_CLOSE,wParam,lParam);
  243. break;
  244. case WM_DESTROY:
  245. KillTimer(hwnd, 1);
  246. DelhRgns();
  247. break;
  248. }
  249. return DefWindowProc(hwnd,message,wParam,lParam);
  250. }
  251. BOOL DrawBitmap(HDC hdc,HBITMAP hbm,int x,int y,int cx,int cy)
  252. {
  253. HBITMAP hbmpOld ;
  254. BITMAP bm ;
  255. HDC hdcMem ;
  256. // compatibile dc 
  257. hdcMem = CreateCompatibleDC( hdc) ;
  258. GetObject( hbm, sizeof( BITMAP), (LPSTR)&bm) ;
  259. hbmpOld = SelectObject( hdcMem, hbm) ;
  260. BitBlt( hdc, x, y, cx, cy, hdcMem, 0, 0, SRCCOPY) ;
  261. // StretchBlt( hdc, 0, 0, cx, cy, hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY) ; 
  262. SelectObject( hdc, hbmpOld) ;
  263. return DeleteDC( hdcMem) ;
  264. }
  265. int OnButton(LPARAM lParam)
  266. {
  267. int i;
  268. for(i=1; i<=MAX_BUTTON_COUNT; i++)
  269. if(PtInRegion(hRgns[i], LOWORD(lParam), HIWORD(lParam)))
  270. return i;  //on button i
  271. return 0;  //not on any button
  272. }
  273. void SethRgns()
  274. {
  275. hRgns[1]=CreateRectRgn(301, 117, 316, 129);  //button close
  276. }
  277. void DelhRgns()
  278. {
  279. int i;
  280. for(i=1; i<=MAX_BUTTON_COUNT; i++)
  281. if(hRgns[i])
  282. DeleteObject(hRgns[i]);
  283. }
  284. void ShowTime(int hour, int minute, int second, int X, int Y)
  285. {
  286. DrawTime((int)(hour/10), X, Y);
  287. DrawTime(hour%10, X+6, Y);
  288. DrawTime(10, X+12, Y); //show ":"
  289. DrawTime((int)(minute/10), X+18, Y);
  290. DrawTime(minute%10, X+24, Y);
  291. DrawTime(10, X+30, Y);
  292. DrawTime((int)(second/10), X+36, Y);
  293. DrawTime(second%10, X+42, Y);
  294. BitBlt(hdc, X, Y, 48, 9, memdc, X, Y, SRCCOPY); //Refresh Timer
  295. }
  296. void DrawTime(int number, int x, int y)
  297. {
  298. HBITMAP hBmp;
  299. switch (number)
  300. {
  301. case 0:
  302. hBmp = LoadBitmap(hDLLInstance,MAKEINTRESOURCE(IDB_T0));
  303. break;
  304. case 1:
  305. hBmp = LoadBitmap(hDLLInstance,MAKEINTRESOURCE(IDB_T1));
  306. break;
  307. case 2:
  308. hBmp = LoadBitmap(hDLLInstance,MAKEINTRESOURCE(IDB_T2));
  309. break;
  310. case 3:
  311. hBmp = LoadBitmap(hDLLInstance,MAKEINTRESOURCE(IDB_T3));
  312. break;
  313. case 4:
  314. hBmp = LoadBitmap(hDLLInstance,MAKEINTRESOURCE(IDB_T4));
  315. break;
  316. case 5:
  317. hBmp = LoadBitmap(hDLLInstance,MAKEINTRESOURCE(IDB_T5));
  318. break;
  319. case 6:
  320. hBmp = LoadBitmap(hDLLInstance,MAKEINTRESOURCE(IDB_T6));
  321. break;
  322. case 7:
  323. hBmp = LoadBitmap(hDLLInstance,MAKEINTRESOURCE(IDB_T7));
  324. break;
  325. case 8:
  326. hBmp = LoadBitmap(hDLLInstance,MAKEINTRESOURCE(IDB_T8));
  327. break;
  328. case 9:
  329. hBmp = LoadBitmap(hDLLInstance,MAKEINTRESOURCE(IDB_T9));
  330. break;
  331. case 10:
  332. hBmp = LoadBitmap(hDLLInstance,MAKEINTRESOURCE(IDB_T10));
  333. }
  334. mdc = CreateCompatibleDC( hdc) ;
  335. SelectObject(mdc, hBmp);
  336. BitBlt(memdc, x, y, 5, 9, mdc, 0, 0, SRCCOPY);
  337. DeleteDC(mdc);
  338. DeleteObject(hBmp);
  339. }
  340. void CALLBACK HandleTimer( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime )
  341. {
  342. SYSTEMTIME Time;
  343. if( (*GetSthVCDStatus)(STATUS_GETPLAYING, 0, 0) )
  344. {
  345. GetLocalTime(&Time);
  346. ShowTime(Time.wHour, Time.wMinute, Time.wSecond, 240, 55);
  347. }
  348. }