main.cpp
上传用户:mushi823
上传日期:2013-03-02
资源大小:21k
文件大小:5k
源码类别:

屏幕保护

开发平台:

Visual C++

  1. #include<windows.h>
  2. #include<mmsystem.h>
  3. #include<DIGITALV.H>
  4. #include<mciavi.h>
  5. #include<scrnsave.h> 
  6. #include"Resource.h"
  7. extern HINSTANCE hMainInstance;
  8. extern char FileName[1000];
  9. extern DWORD FullScreen;
  10. extern int ReadReg(char *,DWORD*,DWORD *);
  11. extern int WriteReg(char *,DWORD*,DWORD *);
  12. extern int TestReg();
  13. int Play=0;
  14. int IsReg=0;
  15. BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
  16. {
  17. switch(message)
  18. {
  19. case WM_INITDIALOG:
  20. IsReg=TestReg();
  21. if(IsReg==0)
  22. {
  23. EnableWindow(GetDlgItem(hDlg,IDC_CHECK1),FALSE);
  24. FullScreen=0;
  25. }
  26. else
  27. {
  28. EnableWindow(GetDlgItem(hDlg,IDC_EDIT2),FALSE);
  29. EnableWindow(GetDlgItem(hDlg,IDC_BUTTON2),FALSE);
  30. }
  31. SetDlgItemText(hDlg,IDC_EDIT1,FileName);
  32. CheckDlgButton(hDlg,IDC_CHECK1,FullScreen);
  33. return TRUE;
  34. case WM_COMMAND:
  35. switch(LOWORD(wParam))
  36. {
  37. case IDC_BUTTON1:
  38. OPENFILENAME fname;
  39. char filename[1000];
  40. memset(&fname,0,sizeof(fname));
  41. fname.lStructSize=sizeof(fname);
  42. fname.hwndOwner=hDlg;
  43. strcpy(filename,"");
  44. fname.lpstrFile=filename;
  45. fname.nMaxFile=900;
  46. fname.lpstrFilter="多媒体文件*.*";
  47. if(GetOpenFileName(&fname))
  48. {
  49. SetDlgItemText(hDlg,IDC_EDIT1,filename);
  50. }
  51. return TRUE;
  52. case IDC_BUTTON2:
  53. DWORD regnum;
  54. regnum=GetDlgItemInt(hDlg,IDC_EDIT2,NULL,TRUE);
  55. WriteReg(NULL,&regnum,NULL);
  56. if(TestReg()==0)
  57. {
  58. MessageBox(hDlg,"注册号不对!","错误",MB_OK|MB_ICONSTOP);
  59. }
  60. return TRUE;
  61. case IDOK:
  62. GetDlgItemText(hDlg,IDC_EDIT1,FileName,1000);
  63. FullScreen=IsDlgButtonChecked(hDlg,IDC_CHECK1);
  64. WriteReg(FileName,NULL,&FullScreen);
  65. case IDCANCEL:
  66. EndDialog(hDlg,TRUE);
  67. return TRUE;
  68. }
  69. return TRUE;
  70. }
  71. return FALSE;
  72. }
  73. BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
  74. {
  75. return TRUE;
  76. }
  77. LONG WINAPI ScreenSaverProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
  78. {
  79. static char s[100];
  80. static int ret;
  81. static UINT id;
  82. static repeat=0;
  83. static HDC hdc;
  84. RECT rect;
  85. // int x,y;
  86. switch(message)
  87. {
  88. case WM_CREATE:
  89. IsReg=TestReg();
  90. if(IsReg==0)
  91. {
  92. SetTimer(hwnd,100,600000,NULL);
  93. repeat=0;
  94. }
  95. MCI_OVLY_OPEN_PARMS openparm;
  96. MCI_PLAY_PARMS pp;
  97. openparm.lpstrElementName=FileName;
  98. openparm.dwStyle=WS_CHILD|WS_BORDER;
  99. openparm.hWndParent=hwnd;
  100. openparm.dwCallback=NULL;
  101. ret=mciSendCommand(NULL,MCI_OPEN,MCI_OPEN_ELEMENT|MCI_OVLY_OPEN_WS|MCI_OVLY_OPEN_PARENT ,(unsigned)&openparm);
  102. if(ret==0)
  103. {
  104. id=openparm.wDeviceID;
  105. MCI_OVLY_RECT_PARMS rectparm;
  106. ret=mciSendCommand(id,MCI_WHERE,MCI_DGV_WHERE_DESTINATION,(unsigned)&rectparm);
  107. GetClientRect(hwnd,&rect);
  108. // x=GetSystemMetrics(SM_CXSCREEN);
  109. // y=GetSystemMetrics(SM_CYSCREEN);
  110. // if(x==rect.right&&y==rect.bottom)SetCapture(hwnd);
  111. if(FullScreen)GetClientRect(hwnd,&rectparm.rc);
  112. else
  113. {
  114. int l,h;
  115. l=(rect.right-rectparm.rc.right)/2;
  116. h=(rect.bottom-rectparm.rc.bottom)/2;
  117. rectparm.rc.left+=l;
  118. rectparm.rc.top+=h;
  119. }
  120. ret=mciSendCommand(id,MCI_PUT,MCI_DGV_PUT_CLIENT|MCI_DGV_PUT_WINDOW|MCI_DGV_RECT,(unsigned)&rectparm);
  121. ret=mciSendCommand(id,MCI_PLAY,MCI_NOTIFY|MCI_DGV_PLAY_REPEAT,(unsigned)&pp);
  122. Play=1;
  123. }
  124. else Play=0;
  125. break;
  126. case WM_ERASEBKGND:
  127. if(Play==1)break;
  128. hdc=GetDC(hwnd);
  129. GetClientRect(hwnd,&rect);
  130. FillRect(hdc,&rect,GetStockObject(BLACK_BRUSH));
  131. DWORD color,bkcolor;
  132. color=SetTextColor(hdc,RGB(255,255,255));
  133. bkcolor=SetBkColor(hdc,RGB(0,0,0));
  134. TextOut(hdc,0,0,"没有指定合法的多媒体文件,",26);
  135. TextOut(hdc,0,30,"请在设置对话框中选择一个合适的多媒体文件",40);
  136. TextOut(hdc,0,60,"如*.AVI、*.DAT等,以及您的WINDOWS中已定义的任何可播放的文件。",61);
  137. SetTextColor(hdc,color);
  138. SetBkColor(hdc,bkcolor);
  139. ReleaseDC(hwnd,hdc);
  140. return 0;
  141. case WM_TIMER:
  142. if(repeat==1||Play==0)break;
  143. else
  144. {
  145. repeat=1;
  146. MessageBox(hwnd,"本屏保程序尚未注册,nn请抓紧在设置对话框中进行注册!nn请将您的WINDOWS所在目录下的SAVERREG.DAT文件通过电邮传给我(请放心仅4字节,不含任何安全信息)nn我将通过电邮寄给您注册号。我的信箱为:nnCRSCDTF@PUBLIC.BTA.NET.CNnn内部用户请使用612CL@CRSCD.COM.CN",
  147. "请注册",MB_ICONWARNING|MB_OK);
  148. repeat=0;
  149. }
  150. break;
  151. case WM_DESTROY:
  152. if(Play==1)
  153. {
  154. MCI_GENERIC_PARMS stopparm;
  155. ret=mciSendCommand(id,MCI_STOP,MCI_WAIT,(unsigned)&stopparm);
  156. // mciGetErrorString(ret,s,100);
  157. MCI_CLOSE_PARMS cp;
  158. ret=mciSendCommand(id,MCI_CLOSE,MCI_WAIT,(unsigned)&cp);
  159. // mciGetErrorString(ret,s,100);
  160. }
  161. KillTimer(hwnd,100);
  162. // ReleaseCapture();
  163. PostQuitMessage(0);
  164. break;
  165. default:
  166. break;
  167. }
  168. return DefScreenSaverProc(hwnd,message,wParam,lParam);
  169. }