⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datelock.cpp

📁 时间锁源代码.zip
💻 CPP
字号:
#include <windows.h>
#include "resource.h"
int  Delay;
char szAppName[]="时间锁";
char inifile[MAX_PATH];

LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
SYSTEMTIME systime,oldtime;
char  oldfilepath[MAX_PATH],oldfilename[MAX_PATH];
char  filepath[MAX_PATH],filename[MAX_PATH];
HINSTANCE hInst;
int GetOldpath(void)
{
char ctemp[MAX_PATH],*p;
 lstrcpy(ctemp,GetCommandLine());
 p=strlen(ctemp)-1+ctemp;
 while(p!=ctemp)
  {
   if(*p=='\"')
   *p=0;
   else 
	if(*p=='\\')
	{*p=0;
	 lstrcpy(oldfilepath,ctemp+1);
	 lstrcpy(oldfilename,p+1);
	 return 0;
	}
   p--;
 }
return 1;
}

int RunFile(HWND hwnd,LPSTR lpCmdLine,int iShow)
{
char ctemp[MAX_PATH];

memcpy(&oldtime,&systime,sizeof SYSTEMTIME);
GetOldpath();
wsprintf(inifile,"%s\\DateLock.ini\0",oldfilepath);
systime.wYear=GetPrivateProfileInt(szAppName,"Year",0,inifile);
systime.wMonth=GetPrivateProfileInt(szAppName,"Month",0,inifile);
systime.wDay=GetPrivateProfileInt(szAppName,"Day",0,inifile);
Delay=GetPrivateProfileInt(szAppName,"Delay",0,inifile);
GetPrivateProfileString(szAppName,"FilePath","NULL",filepath,MAX_PATH,inifile);
GetPrivateProfileString(szAppName,"FileName","NULL",filename,MAX_PATH,inifile);

if(systime.wYear<1980||systime.wMonth==0||systime.wDay==0
   ||systime.wMonth>12||systime.wDay>31||stricmp("NULL",filepath)==0
   ||stricmp("NULL",filename)==0)
{MessageBoxEx(hwnd,"读取 DateLock.ini 文件错误\n请先用参数 /SetupDateLock 设置选项!",NULL,MB_OK|MB_ICONSTOP,0x804);
 return 1;
}
SetCurrentDirectory(filepath);
int i=SetLocalTime(&systime);
wsprintf(ctemp,"\"%s\\%s\" %s",filepath,filename,lpCmdLine);
SetTimer(hwnd,1,Delay*100,NULL);
static STARTUPINFO StartInfo;
static PROCESS_INFORMATION ProcInfo;
StartInfo.cb=sizeof(STARTUPINFO); 
CreateProcess(NULL,ctemp,NULL,NULL,FALSE,
		0,NULL,NULL,&StartInfo,&ProcInfo);
return 0;
}

int CALLBACK DlgProc(HWND hDlg,UINT iMsg,WPARAM wParam,LPARAM lParam)
{
char ctemp[MAX_PATH],ctemp1[MAX_PATH],*p;
UINT i;
switch(iMsg)
{ case WM_INITDIALOG:
       SetDlgItemInt(hDlg,IDC_EDIT1,systime.wYear,TRUE);
	   SetDlgItemInt(hDlg,IDC_EDIT2,systime.wMonth,TRUE);
	   SetDlgItemInt(hDlg,IDC_EDIT3,systime.wDay,TRUE);
	   SetDlgItemInt(hDlg,IDC_EDIT4,40,TRUE);
       CheckDlgButton(hDlg,IDC_CHECK1,BST_CHECKED);
       break; 
  case WM_COMMAND:
    switch(wParam) 
	{case IDOK:
      systime.wYear=GetDlgItemInt(hDlg,IDC_EDIT1,NULL,FALSE);
      systime.wMonth=GetDlgItemInt(hDlg,IDC_EDIT2,NULL,FALSE);
	  systime.wDay=GetDlgItemInt(hDlg,IDC_EDIT3,NULL,FALSE);
	  
      if(systime.wMonth==0||systime.wDay==0
		  ||systime.wYear<1900||systime.wMonth>12||systime.wDay>31||systime.wDay==0)
	  {
	   MessageBoxEx(hDlg,"日期输入错误!",NULL,MB_OK|MB_ICONSTOP,0x804);
	   break;
	  }
	  i=1;
	  GetDlgItemText(hDlg,IDC_EDIT5,ctemp,MAX_PATH);
      if(ctemp[0]!=0)
	  {
        p=ctemp+lstrlen(ctemp)-1;
		while(p!=ctemp)
		{
		 if(*p=='\\')
		 {*p=0;
		  lstrcpy(filepath,ctemp);
          lstrcpy(filename,p+1);
		  i=0;
		  break;
		 }
		 p--;
		}
	  }
	  if(!i)
	    i=GetOldpath();
	  if(i)
	  {
       MessageBoxEx(hDlg,"路径输入错误!",NULL,MB_OK|MB_ICONSTOP,0x804);
	   break;
	  }
	  Delay=GetDlgItemInt(hDlg,IDC_EDIT4,NULL,FALSE);
	   if(IsDlgButtonChecked(hDlg,IDC_CHECK1))
	   {
	    wsprintf(ctemp,"%s\\%s",filepath,filename);
	    wsprintf(ctemp1,"%s\\DateLock_%s",filepath,filename);
	    if(MoveFile(ctemp,ctemp1)==0)
		{
	     MessageBoxEx(hDlg,"文件更名错误!请退出目标程序!",NULL,MB_OK|MB_ICONSTOP,0X804);
	     break;
		}
	    wsprintf(ctemp1,"%s\\%s",oldfilepath,oldfilename);
	    if(CopyFile(ctemp1,ctemp,TRUE)==0)
		{
	 	 MessageBoxEx(hDlg,"复制文件错误!",NULL,MB_OK|MB_ICONSTOP,0X804);
	     break;
		}
	    wsprintf(inifile,"%s\\DateLock.INI",filepath);
	    wsprintf(ctemp1,"原程序被更名为DateLock_%s!\r\n你可自由使用了!",filename);
	    i=1;
	   }
	   else 
	   {
	    wsprintf(inifile,"%s\\datelock.ini",oldfilepath);
	    wsprintf(ctemp1,"现在运行本程序就行了!");
	    i=0;
	   }
	   wsprintf(ctemp,"%d",systime.wYear);
       WritePrivateProfileString(szAppName,"Year",ctemp,inifile);
	   wsprintf(ctemp,"%d",systime.wMonth);
       WritePrivateProfileString(szAppName,"Month",ctemp,inifile);
	   wsprintf(ctemp,"%d",systime.wDay);
       WritePrivateProfileString(szAppName,"Day",ctemp,inifile);
       wsprintf(ctemp,"%d",Delay);
       WritePrivateProfileString(szAppName,"Delay",ctemp,inifile); 
       WritePrivateProfileString(szAppName,"FilePath",filepath,inifile);
	   if(IsDlgButtonChecked(hDlg,IDC_CHECK1))
	     wsprintf(ctemp,"DateLock_%s",filename);
	   else wsprintf(ctemp,"%s",filename);
	   WritePrivateProfileString(szAppName,"FileName",ctemp,inifile);
	   MessageBoxEx(hDlg,ctemp1,"成功",MB_OK|MB_ICONINFORMATION,0X804);
     case IDCANCEL:
       EndDialog(hDlg,0);
	   break;
     case IDC_BUTTON1:
       OPENFILENAME ofn;
	   memset(&ofn,0,sizeof ofn);
	   wsprintf(ctemp,"*.EXE");
       ofn.lStructSize=sizeof OPENFILENAME;
	   ofn.hInstance=hInst;
	   ofn.lpstrFilter="可执行文件(*.EXE)";
	   ofn.lpstrFile=ctemp;
	   ofn.nMaxFile=MAX_PATH;
	   ofn.lpstrTitle="选择运行的程序";
	   ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY
		   |OFN_PATHMUSTEXIST|OFN_READONLY;
	   i=GetOpenFileName(&ofn);
	   if(i)SetDlgItemText(hDlg,IDC_EDIT5,ctemp);
       break;
	 case IDBUTTON2:
       MessageBoxEx(hDlg,
		   "这是一个令你的软件不再过期的软件\n\n"
		   "1.程序运行日期是指运行程序时的日期\n\n"
		   "2.延时指运行程序后等待多长时间恢复\n"
		   "原来的日期。(10=1秒)\n\n"
		   "3.程序路径指欲运行程序所在的位置。\n\n"
		   "4.当选择更名并替代原程序时, 原程序\n"
		   "将被更名为'DateLock_'+原程序名。本\n"
		   "程序将复制一分代替原程序。"
		   ,
		   "帮助",
           MB_OK,0x804);
	   break;
	}
  return TRUE;
}
return FALSE;
}

WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR lpCmdLine,int iShow)
{   
 WNDCLASSEX wndclass;
 HWND hwnd;
 MSG msg;
 HBITMAP hBitmap=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP1));
 HBRUSH hBrush=CreatePatternBrush(hBitmap);
 wndclass.cbSize        = sizeof (wndclass) ;
     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance     = hInst;
     wndclass.hIcon         = LoadIcon (hInst,MAKEINTRESOURCE(IDI_ICON1));
     wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW) ;
     wndclass.hbrBackground = hBrush;//(HBRUSH) GetStockObject (LTGRAY_BRUSH) ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName;
     wndclass.hIconSm       = LoadIcon (hInst,MAKEINTRESOURCE(IDI_ICON1)) ;
     RegisterClassEx (&wndclass) ;
	 GetLocalTime(&systime);
	 hwnd = CreateWindow (szAppName,szAppName,   
                    WS_POPUPWINDOW|WS_VISIBLE|DS_CENTER,
                    300,200,247,113,           
                    NULL,NULL,hInst,NULL) ;		           
	 ::hInst=hInst;
     if(stricmp(lpCmdLine,"/SetupDateLock")==0)
	 {
      DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1),NULL,DlgProc);
      return 0;
	 }
     else
     if(RunFile(hwnd,lpCmdLine,iShow))return 0;
     while (GetMessage (&msg, NULL, 0, 0))
	 {
       TranslateMessage (&msg) ;
       DispatchMessage (&msg) ;
	 }
    return 0;
}


LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{

	switch(iMsg)
	{
	 case WM_TIMER:
     case WM_DESTROY:
      SetLocalTime(&oldtime);
	  PostQuitMessage(0);
	  break;
	}
return DefWindowProc(hwnd,iMsg,wParam,lParam);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -