Home > Back-end >  Display button in the title bar, to minimize the time it will display in the current operation windo
Display button in the title bar, to minimize the time it will display in the current operation windo

Time:09-22

Button in the title bar display an instance of the source program, which is like some player software, to minimize the time it will be in the current window's title bar top right operation shows its common play button, to facilitate control of it, having a little BUG in Windows 7, Windows xp is normal, beg god for help?

Download address:
http://download.csdn.net/detail/znhyz1/9597998


CodePudding user response:

Hook ActiveHook. DLL
 
The library ActiveHook;

USES the
SysUtils,
Classes,
Windows,
UActiveHook in 'uActiveHook. Pas';

{$R *. Res}

Exports
GetDLLData,
EnableHook,
RemoveHook;

The begin
DllProc:=@ DLLEntryPoint;
DLLEntryPoint (DLL_PROCESS_ATTACH);
End.


 
The unit uActiveHook;

Interface

USES the
Windows, Messages, SysUtils;

Const
MSG_FINDWIN=WM_USER + 2416;
MSG_REPOSITION=WM_USER + 2335;
MSG_CLOSE=WM_USER + 2248;
MAPFILE_GNAME: PChar='WIN_ACTIVE_INFO';

Type
PReceiveStruct=^ TReceiveStruct;
TReceiveStruct=record
RecHandle: THandle;
CurHandle: THandle;
end;

Procedure DLLEntryPoint (dwReason: DWord);
Procedure GetDLLData (var aReceiveStruct: PReceiveStruct); Stdcall; Export;
The function EnableHook (aRecHandle: THandle) : Boolean; Export;
The function RemoveHook: Boolean; Export;
The function Hook (iCode: Integer; WParam: wParam; CWPRet: PCWPRetStruct) : LRESULT; Stdcall; Export;

Implementation

Var
CurHookProc: HHOOK;
MapFileHandle: THandle;
ReceiveStruct: PReceiveStruct;

Procedure GetDLLData (var aReceiveStruct: PReceiveStruct); Stdcall;
The begin
AReceiveStruct:=ReceiveStruct;
end;

The function EnableHook (aRecHandle: THandle) : Boolean; Export;
The begin
ReceiveStruct. RecHandle:=aRecHandle;
If CurHookProc=0 then
The begin
CurHookProc:=SetWindowsHookEx (WH_CALLWNDPROCRET, @ Hook, HInstance, 0).
end;
Result:=(CurHookProc & lt;> 0);
end;

The function Hook (iCode: Integer; WParam: wParam; CWPRet: PCWPRetStruct) : LRESULT; Stdcall; Export;
The begin
//in the outside need to judge whether the window of the change with their CWPRet. The HWND=MostRecentWindow
If iCode=HC_ACTION then
The begin
ReceiveStruct. CurHandle:=CWPRet. HWND;
Case CWPRet. Message of
WM_ACTIVATE://send MSG to notify the window change pos. Change pos only cur window=the active window
The begin
If CWPRet. LResult=WA_INACTIVE then//
The begin
SendMessage (ReceiveStruct RecHandle MSG_FINDWIN, 0, 0).
//Abandon ();//?? Don't understand the
//Reposition ();
end;
end;
WM_WINDOWPOSCHANGED WM_SETTEXT:
The begin
SendMessage (ReceiveStruct RecHandle MSG_FINDWIN, 0, 0).//MSG_REPOSITION
//Reposition ();
end;
WM_CLOSE:
The begin
SendMessage (ReceiveStruct RecHandle MSG_CLOSE, 0, 0).
//Reposition ();
end;
end;
end;
Result:=CallNextHookEx (CurHookProc, iCode wParam, Integer (CWPRet));
end;

The function RemoveHook: Boolean; Export;
The begin
If CurHookProc & lt;> 0 then
The begin
UnhookWindowshookEx (CurHookProc);
CurHookProc:=0;
end;
Result:=(CurHookProc=0);
end;

Procedure OpenSharedData;
Var
Size: Integer;
The begin
Size:=SizeOf (TReceiveStruct);

MapFileHandle:=CreateFileMapping (DWord (1), nil, PAGE_READWRITE, 0, the Size, MAPFILE_GNAME);

If MapFileHandle=0 then
RaiseLastWin32Error;

ReceiveStruct:=MapViewOfFile (MapFileHandle FILE_MAP_ALL_ACCESS, 0, 0, Size);

If ReceiveStruct=nil then
The begin
The CloseHandle (MapFileHandle);
RaiseLastWin32Error;
end;
end;

Procedure CloseSharedData;
The begin
UnmapViewOfFile (ReceiveStruct);
The CloseHandle (MapFileHandle);
end;

Procedure DLLEntryPoint (dwReason: DWord);
The begin
Case dwReason of
DLL_PROCESS_ATTACH:
OpenSharedData;
DLL_PROCESS_DETACH:
CloseSharedData;
end;
end;

End.

CodePudding user response:

The Demo program:

 
The program DemoHookActive;

USES the
Forms,
UDemoMain in 'uDemoMain. Pas' {FrmMain},
UDemoBar in 'uDemoBar. Pas' {frmBar},
UDemoUtils in 'uDemoUtils. Pas';

{$R *. Res}

The begin
Application. The Initialize;
Application CreateForm (TFrmMain FrmMain);
FrmBar:=TfrmBar. Create (nil);
Application. The Run;
End.


 
The unit uDemoMain;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, uDemoUtils,
Dialogs, ExtCtrls StdCtrls, ActnList JvComponentBase, JvTrayIcon,
JvExControls JvStaticText;

Type
TFrmMain=class (TForm)
P1: TPanel;
BtnEnable: TButton;
BtnDisable: TButton;
Act: TActionList;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related