main.cpp
资源名称:ScrSaver.zip [点击查看]
上传用户:mushi823
上传日期:2013-03-02
资源大小:21k
文件大小:5k
源码类别:
屏幕保护
开发平台:
Visual C++
- #include<windows.h>
- #include<mmsystem.h>
- #include<DIGITALV.H>
- #include<mciavi.h>
- #include<scrnsave.h>
- #include"Resource.h"
- extern HINSTANCE hMainInstance;
- extern char FileName[1000];
- extern DWORD FullScreen;
- extern int ReadReg(char *,DWORD*,DWORD *);
- extern int WriteReg(char *,DWORD*,DWORD *);
- extern int TestReg();
- int Play=0;
- int IsReg=0;
- BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
- {
- switch(message)
- {
- case WM_INITDIALOG:
- IsReg=TestReg();
- if(IsReg==0)
- {
- EnableWindow(GetDlgItem(hDlg,IDC_CHECK1),FALSE);
- FullScreen=0;
- }
- else
- {
- EnableWindow(GetDlgItem(hDlg,IDC_EDIT2),FALSE);
- EnableWindow(GetDlgItem(hDlg,IDC_BUTTON2),FALSE);
- }
- SetDlgItemText(hDlg,IDC_EDIT1,FileName);
- CheckDlgButton(hDlg,IDC_CHECK1,FullScreen);
- return TRUE;
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDC_BUTTON1:
- OPENFILENAME fname;
- char filename[1000];
- memset(&fname,0,sizeof(fname));
- fname.lStructSize=sizeof(fname);
- fname.hwndOwner=hDlg;
- strcpy(filename,"");
- fname.lpstrFile=filename;
- fname.nMaxFile=900;
- fname.lpstrFilter="多媒体文件 *.* ";
- if(GetOpenFileName(&fname))
- {
- SetDlgItemText(hDlg,IDC_EDIT1,filename);
- }
- return TRUE;
- case IDC_BUTTON2:
- DWORD regnum;
- regnum=GetDlgItemInt(hDlg,IDC_EDIT2,NULL,TRUE);
- WriteReg(NULL,®num,NULL);
- if(TestReg()==0)
- {
- MessageBox(hDlg,"注册号不对!","错误",MB_OK|MB_ICONSTOP);
- }
- return TRUE;
- case IDOK:
- GetDlgItemText(hDlg,IDC_EDIT1,FileName,1000);
- FullScreen=IsDlgButtonChecked(hDlg,IDC_CHECK1);
- WriteReg(FileName,NULL,&FullScreen);
- case IDCANCEL:
- EndDialog(hDlg,TRUE);
- return TRUE;
- }
- return TRUE;
- }
- return FALSE;
- }
- BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
- {
- return TRUE;
- }
- LONG WINAPI ScreenSaverProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
- {
- static char s[100];
- static int ret;
- static UINT id;
- static repeat=0;
- static HDC hdc;
- RECT rect;
- // int x,y;
- switch(message)
- {
- case WM_CREATE:
- IsReg=TestReg();
- if(IsReg==0)
- {
- SetTimer(hwnd,100,600000,NULL);
- repeat=0;
- }
- MCI_OVLY_OPEN_PARMS openparm;
- MCI_PLAY_PARMS pp;
- openparm.lpstrElementName=FileName;
- openparm.dwStyle=WS_CHILD|WS_BORDER;
- openparm.hWndParent=hwnd;
- openparm.dwCallback=NULL;
- ret=mciSendCommand(NULL,MCI_OPEN,MCI_OPEN_ELEMENT|MCI_OVLY_OPEN_WS|MCI_OVLY_OPEN_PARENT ,(unsigned)&openparm);
- if(ret==0)
- {
- id=openparm.wDeviceID;
- MCI_OVLY_RECT_PARMS rectparm;
- ret=mciSendCommand(id,MCI_WHERE,MCI_DGV_WHERE_DESTINATION,(unsigned)&rectparm);
- GetClientRect(hwnd,&rect);
- // x=GetSystemMetrics(SM_CXSCREEN);
- // y=GetSystemMetrics(SM_CYSCREEN);
- // if(x==rect.right&&y==rect.bottom)SetCapture(hwnd);
- if(FullScreen)GetClientRect(hwnd,&rectparm.rc);
- else
- {
- int l,h;
- l=(rect.right-rectparm.rc.right)/2;
- h=(rect.bottom-rectparm.rc.bottom)/2;
- rectparm.rc.left+=l;
- rectparm.rc.top+=h;
- }
- ret=mciSendCommand(id,MCI_PUT,MCI_DGV_PUT_CLIENT|MCI_DGV_PUT_WINDOW|MCI_DGV_RECT,(unsigned)&rectparm);
- ret=mciSendCommand(id,MCI_PLAY,MCI_NOTIFY|MCI_DGV_PLAY_REPEAT,(unsigned)&pp);
- Play=1;
- }
- else Play=0;
- break;
- case WM_ERASEBKGND:
- if(Play==1)break;
- hdc=GetDC(hwnd);
- GetClientRect(hwnd,&rect);
- FillRect(hdc,&rect,GetStockObject(BLACK_BRUSH));
- DWORD color,bkcolor;
- color=SetTextColor(hdc,RGB(255,255,255));
- bkcolor=SetBkColor(hdc,RGB(0,0,0));
- TextOut(hdc,0,0,"没有指定合法的多媒体文件,",26);
- TextOut(hdc,0,30,"请在设置对话框中选择一个合适的多媒体文件",40);
- TextOut(hdc,0,60,"如*.AVI、*.DAT等,以及您的WINDOWS中已定义的任何可播放的文件。",61);
- SetTextColor(hdc,color);
- SetBkColor(hdc,bkcolor);
- ReleaseDC(hwnd,hdc);
- return 0;
- case WM_TIMER:
- if(repeat==1||Play==0)break;
- else
- {
- repeat=1;
- MessageBox(hwnd,"本屏保程序尚未注册,nn请抓紧在设置对话框中进行注册!nn请将您的WINDOWS所在目录下的SAVERREG.DAT文件通过电邮传给我(请放心仅4字节,不含任何安全信息)nn我将通过电邮寄给您注册号。我的信箱为:nnCRSCDTF@PUBLIC.BTA.NET.CNnn内部用户请使用612CL@CRSCD.COM.CN",
- "请注册",MB_ICONWARNING|MB_OK);
- repeat=0;
- }
- break;
- case WM_DESTROY:
- if(Play==1)
- {
- MCI_GENERIC_PARMS stopparm;
- ret=mciSendCommand(id,MCI_STOP,MCI_WAIT,(unsigned)&stopparm);
- // mciGetErrorString(ret,s,100);
- MCI_CLOSE_PARMS cp;
- ret=mciSendCommand(id,MCI_CLOSE,MCI_WAIT,(unsigned)&cp);
- // mciGetErrorString(ret,s,100);
- }
- KillTimer(hwnd,100);
- // ReleaseCapture();
- PostQuitMessage(0);
- break;
- default:
- break;
- }
- return DefScreenSaverProc(hwnd,message,wParam,lParam);
- }