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

📄 clock.dpr

📁 DELPHI下隐藏进程的方法,并附有源代码,学习很好.
💻 DPR
字号:
{******************************************************************************
*   Program Clock
*   Description:
*       To show a transparent window as a clock on desktop.
*       Support time schedule
*   CopyRight (C) GanHuaXin 2001-1-8
*   Code Tool   :   Delphi 5.0
*   All code is writen by SDK
*   All Rignt Reserved!
*   Date  :
*       New Develop   : 2001-1-8
*       Modify        : 2001-1-9
******************************************************************************}

library Clock;

uses
  Windows,
  Messages,
  untTool in 'untTool.pas',
  untConst in 'untConst.pas',
  untMsgHdl in 'untMsgHdl.pas',
  untHint in 'untHint.pas';

{$R Gan_SDK.RES}

{******************************************************************************
*   Function InitApplication(hInstance)
*   Purpose:
*       Initial Appliaction and Register the window class
*   Parmeters:
*       hInstance     :   Application Instance Handle
*   Return Value:
*       it return the RegisterClass()'s return's Value
******************************************************************************}
function InitApplication(hInstance : THANDLE):bool;
var
  ParentWndClass : TWndClass;
  WndClass : TWndClass;
begin
  ParentWndClass.hInstance := hInstance;
  With ParentWndClass do begin
    style := 0;
    lpfnWndProc := @ParentMainProc;
    cbClsExtra := 0;
    cbWndExtra := 0;
    hCursor := LoadCursor(0,IDC_ARROW);
    lpszMenuName := nil;
    hbrBackground := GetStockObject(BLACK_BRUSH);
    hIcon := LoadIcon(hInstance,'ICON_APP');
    lpszClassName := 'GanParentClock';
  end;

  WndClass.style := 0;
  WndClass.lpfnWndProc := @MainProc;
  WndClass.cbClsExtra := 0;
  WndClass.cbWndExtra := 0;
  WndClass.hInstance := hInstance;
  WndClass.hCursor := LoadCursor(0,IDC_HAND);
  WndClass.lpszMenuName := nil;
  WndClass.hbrBackground := GetStockObject(BLACK_BRUSH);
  WndClass.hIcon := //LoadIcon(0,IDI_APPLICATION	);
            LoadIcon(hInstance,'ICON_APP');
  WndClass.lpszClassName := 'GanClock';
  result := BOOL(RegisterClass(WndClass) and RegisterClass(ParentWndClass));
end;

{******************************************************************************
*   Function InitWindow(hWnd)
*   Purpose:
*       To initial the Window whose handle equal hWnd
*   Date  :
*       New Development   : 2001-01-08
*       Modiefied         :
******************************************************************************}
function InitWindow(hWnd:HWND):BOOL;
var
  WinRect : TRect;
  bOpt    : Boolean;
  dwStyle : integer;
begin
  //
  // to set the window Region
  //
  result := false;
  if hWnd = 0 then exit;
  if not GetWindowRect(hWnd,WinRect) then exit;
  WinRect.Right := WinRect.Right - WinRect.Left;
  WinRect.Bottom := WinRect.Bottom - WinRect.Top;
  WinRect.Top := 0;
  WinRect.Left := 0;

  //
  // Set Special Style
  //
  SetWindowLong(hWnd,GWL_STYLE,378470400 xor WS_THICKFRAME
      xor WS_MAXIMIZEBOX xor WS_BORDER xor WS_MINIMIZEBOX or WS_POPUP);
  //
  // Set whether window all with on top?
  //
  GetRegAllOnTop(bOpt);
  SetWindowAllOnTop(hWnd,bOpt);
  //
  // determine whether Set a icon on tray area
  //
  GetRegShowTray(bOpt);
  if bOpt then
    ShowOnTray(hWnd);
  GetRegShowOnTaskBar(bOpt);
  if bOpt then
    ShowWindow(ParentWnd,SW_SHOW)
  else
    ShowWindow(ParentWnd,SW_HIDE);
  //
  // Set whether transparent ?
  //
  GetRegTransparent(bOpt);
  SetWindowTransparent(hWnd,not bOpt);
  SetWindowTransparent(hWnd,bOpt);

  result := true;
end;


{******************************************************************************
*   Fuction InitInstance(hInstance:THandle,nCmdShow:INT,hWnd:THANDLE)
*   Purpose:
*       To create the registered windows and show it as nCmdShow
*   Parmeters:
*       hInstance     :   Application Instance
*       nCmdShow      :   The Window Show Method
*       hWnd          :   The created Window Handle
*   Return Value:
*       if success create the window return the window's handle
*       else return 0
******************************************************************************}
function InitInstance(
    hInstance:THANDLE;
    nCmdShow:integer;
    var hWnd:THandle):bool;
var
  RegWindowPos : TMyWindowPos;
  SysMenu : HMENU;
  //ParentWnd : THandle;
begin
  // at first , creat a UnVisible parent window
  ParentWnd := CreateWindow(
              'GanParentClock',
              'Huiyu Clock',
              WS_CLIPSIBLINGS or WS_SYSMENU,
              -20,-20,0,0,
              0,0,hInstance,nil);
  if ParentWnd = 0 then begin
    result := false;
    exit;
  end;
  // to modify the System Menu ! Cool!
  SysMenu := GetSystemMenu(ParentWnd,False);
  DeleteMenu(SysMenu,SC_MOVE,MF_BYCOMMAND);
  DeleteMenu(SysMenu,SC_MAXIMIZE,MF_BYCOMMAND);
  DeleteMenu(SysMenu,SC_MINIMIZE,MF_BYCOMMAND);
  DeleteMenu(SysMenu,SC_SIZE,MF_BYCOMMAND);
  DeleteMenu(SysMenu,SC_RESTORE,MF_BYCOMMAND);
  DeleteMenu(SysMenu,0,MF_BYPOSITION);
  InsertMenu(SysMenu,1,MF_STRING or MF_BYPOSITION,IDM_ABOUT,'About');
  InsertMenu(SysMenu,1,MF_STRING or MF_BYPOSITION,IDM_OPTION,'Option');
  InsertMenu(SysMenu,1,MF_SEPARATOR or MF_BYPOSITION,0,'');

  // then create my self clock window
  GetPlacePos(RegWindowPos);
  hWnd := CreateWindow(
              'GanClock',
              'Hello World!This is a test for sdk program!',
              WS_POPUP or WS_OVERLAPPED or WS_CLIPSIBLINGS,
              RegWindowPos.Left,
              RegWindowPos.Top,
              RegWindowPos.Width,
              RegWindowPos.Width,
              ParentWnd,//}0,
              0,
              hInstance,
              nil
  );
  if (hWnd<>0) then
  begin
    ClockWnd := hWnd;
    InitWindow(hWnd);
    ShowWindow(hWnd,nCmdShow);
    SetClockWalk(hWnd);
    result := BOOL(True);
  end else
    result := BOOL(false);
end;

//
// Main procedure entry point
//
var
  hWnd  : LongWord;
  Msg   : TMsg;

procedure ThreadProc(p : pointer); stdcall;
begin
  //hInstance is the golbal var defined in sysinit.pas
  if not InitApplication(hInstance) then halt;
  if not InitInstance(hInstance,SW_SHOW,hWnd) then halt;
  //RegisterServiceProcess(GetCurrentProcessID, 1);
  while GetMessage(Msg,0,0,0) do
  begin
    TranslateMessage(Msg);
    DispatchMessage(Msg);
    // sleep(20);
  end;
end;

var
  hThreadHandle : THandle;
  
procedure DllMain(dwReason : DWORD);
var
  dwThreadID : DWORD;
begin
  case dwReason of
    DLL_PROCESS_ATTACH :
      begin
			  hThreadHandle := CreateThread(nil, 0, @ThreadProc, nil, 0, dwThreadID);
      end;
    DLL_PROCESS_DETACH :
      begin
        SendMessage(hWnd, WM_THREADEXIT, 0, 0);
        if (hThreadHandle <> 0) then begin
          TerminateThread(hThreadHandle, 0);
        end;
      end;
    DLL_THREAD_ATTACH :
      begin
      end;
    DLL_THREAD_DETACH :
      begin
      end;
  end;
end;

begin
  DLLProc := @DLLMain;
  DLLMain(DLL_PROCESS_ATTACH);
end.

⌨️ 快捷键说明

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