BSOne.SFC/Tocsg.Module/SunkAssister/EXE_SunkAssister/WindowPage/FWindowPage.pas

265 lines
8.5 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

unit FWindowPage;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls,
ManageWindowPage, Vcl.StdCtrls;
type
TFrame = TWndFrame;
TFrmWindowPage = class(TFrame)
tInit: TTimer;
pnMain: TPanel;
pnTop: TPanel;
chFormAutoSize: TCheckBox;
pnBottom: TPanel;
mmStyle: TMemo;
SP1: TSplitter;
cbBoderStyle: TComboBox;
Label1: TLabel;
procedure tInitTimer(Sender: TObject);
procedure pnMainResize(Sender: TObject);
procedure chFormAutoSizeClick(Sender: TObject);
procedure cbBoderStyleChange(Sender: TObject);
private
{ Private declarations }
WndInfo_: TWndInfo;
OrzWndRect_: TRect;
OrzBorderStyle_,
OrzBorderExStyle_: NativeInt;
OldWndProc_: Pointer;
NewWndProc_: Pointer;
procedure SubClassWndProc(var msg: TMessage);
{$IFDEF DEBUG}
procedure PrintBorderStyle;
{$ENDIF}
procedure SetStretchForm(bVal: Boolean);
public
{ Public declarations }
Constructor Create(aOwner: TComponent); override;
Destructor Destroy; override;
end;
implementation
uses
Tocsg.Trace, Tocsg.Process, Tocsg.WndUtil;
{$R *.dfm}
Constructor TFrmWindowPage.Create(aOwner: TComponent);
begin
Inherited Create(aOwner);
WndInfo_ := OwnerTabSheet_.WndInfo;
{$IFNDEF DEBUG}
SP1.Enabled := false;
SP1.Visible := false;
pnBottom.Enabled := false;
pnBottom.Visible := false;
{$ENDIF}
OldWndProc_ := nil;
NewWndProc_ := nil;
tInit.Enabled := true;
end;
Destructor TFrmWindowPage.Destroy;
begin
if OldWndProc_ <> nil then
begin
SetWindowLong(WndInfo_.WndHandle, GWL_WNDPROC, NativeInt(OldWndProc_));
OldWndProc_ := nil;
end;
// if GetProcessNameFromPID(WndInfo_.ProcID) <> '' then
// Winapi.Windows.SetParent(WndInfo_.WndHandle, GetDesktopWindow);
Inherited;
end;
procedure TFrmWindowPage.SubClassWndProc(var msg: TMessage);
begin
with msg do
begin
Result := CallWindowProc(OldWndProc_, WndInfo_.WndHandle, msg, WParam, LParam);
end;
Case msg.Msg of
WM_SIZE :
begin
TTgTrace.T( '%d, %d', [ LOWORD(msg.LParam), HiWord(msg.LParam)] );
end;
end;
end;
{$IFDEF DEBUG}
procedure TFrmWindowPage.PrintBorderStyle;
var
niResult: NativeInt;
begin
mmStyle.Lines.Add(GetWindowStyleStr(WndInfo_.WndHandle));
mmStyle.Lines.Add('');
mmStyle.Lines.Add('');
mmStyle.Lines.Add(GetWindowExStyleStr(WndInfo_.WndHandle));
end;
{$ENDIF}
procedure TFrmWindowPage.cbBoderStyleChange(Sender: TObject);
var
niBorderStyle,
niBorderExStyle: NativeInt;
WndPlacement: TWindowPlacement;
begin
case cbBoderStyle.ItemIndex of
0 : // Original
begin
niBorderStyle := OrzBorderStyle_;
niBorderExStyle := OrzBorderExStyle_;
end;
1 : // None
begin
niBorderStyle := WS_OVERLAPPED or WS_POPUP or WS_VISIBLE or WS_CLIPSIBLINGS or WS_CLIPCHILDREN;
niBorderExStyle := WS_EX_LEFT or WS_EX_LTRREADING or WS_EX_RIGHTSCROLLBAR or
WS_EX_CONTROLPARENT or WS_EX_APPWINDOW;
end;
2 : // Single
begin
niBorderStyle := WS_OVERLAPPED or WS_VISIBLE or WS_CLIPSIBLINGS or WS_CLIPCHILDREN or
WS_CAPTION or WS_BORDER or WS_DLGFRAME or WS_SYSMENU or WS_GROUP or
WS_TABSTOP or WS_MINIMIZEBOX or WS_MAXIMIZEBOX;
niBorderExStyle := WS_EX_WINDOWEDGE or WS_EX_LEFT or WS_EX_LTRREADING or
WS_EX_RIGHTSCROLLBAR or WS_EX_CONTROLPARENT or WS_EX_APPWINDOW;
end;
3 : // Sizeable
begin
niBorderStyle := WS_OVERLAPPED or WS_VISIBLE or WS_CLIPSIBLINGS or WS_CLIPCHILDREN or
WS_CAPTION or WS_BORDER or WS_DLGFRAME or WS_SYSMENU or
WS_THICKFRAME or WS_GROUP or WS_TABSTOP or WS_MINIMIZEBOX or WS_MAXIMIZEBOX;
niBorderExStyle := WS_EX_WINDOWEDGE or WS_EX_LEFT or WS_EX_LTRREADING or
WS_EX_RIGHTSCROLLBAR or WS_EX_CONTROLPARENT or WS_EX_APPWINDOW;
end;
4 : // Dialog
begin
niBorderStyle := WS_OVERLAPPED or WS_POPUP or WS_VISIBLE or WS_CLIPSIBLINGS or
WS_CLIPCHILDREN or WS_CAPTION or WS_BORDER or WS_DLGFRAME or WS_SYSMENU;
niBorderExStyle := WS_EX_DLGMODALFRAME or WS_EX_WINDOWEDGE or WS_EX_LEFT or
WS_EX_LTRREADING or WS_EX_RIGHTSCROLLBAR or WS_EX_CONTROLPARENT or WS_EX_APPWINDOW;
end;
5 : // ToolWindow
begin
niBorderStyle := WS_OVERLAPPED or WS_VISIBLE or WS_CLIPSIBLINGS or WS_CLIPCHILDREN or
WS_CAPTION or WS_BORDER or WS_DLGFRAME or WS_SYSMENU;
niBorderExStyle := WS_EX_TOOLWINDOW or WS_EX_WINDOWEDGE or WS_EX_LEFT or
WS_EX_LTRREADING or WS_EX_RIGHTSCROLLBAR or WS_EX_CONTROLPARENT or WS_EX_APPWINDOW;
end;
6 : // SizeToolWin
begin
niBorderStyle := WS_OVERLAPPED or WS_VISIBLE or WS_CLIPSIBLINGS or WS_CLIPCHILDREN or
WS_CAPTION or WS_BORDER or WS_DLGFRAME or WS_SYSMENU or WS_THICKFRAME;
niBorderExStyle := WS_EX_TOOLWINDOW or WS_EX_WINDOWEDGE or WS_EX_LEFT or WS_EX_LTRREADING or
WS_EX_RIGHTSCROLLBAR or WS_EX_CONTROLPARENT or WS_EX_APPWINDOW;
end;
else exit;
end;
SetWindowLong(WndInfo_.WndHandle, GWL_STYLE, niBorderStyle);
SetWindowLong(WndInfo_.WndHandle, GWL_EXSTYLE, niBorderExStyle);
// InvalidateRect(WndInfo_.WndHandle, nil, true);
// UpdateWindow(WndInfo_.WndHandle);
// OwnerTabSheet_.Repaint;
// OwnerTabSheet_.PageControl.Repaint;
ShowWindow(WndInfo_.WndHandle, SW_HIDE);
ShowWindow(WndInfo_.WndHandle, SW_SHOWNORMAL);
// if GetWindowPlacement(WndInfo_.WndHandle, WndPlacement) then
// begin
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20>̷<EFBFBD><CCB7><EFBFBD> <20><><EFBFBD>ش<EFBFBD>.. 16_1601 00:01:53 sunk
// MoveWindow(WndInfo_.WndHandle,
// WndPlacement.rcNormalPosition.Left,
// WndPlacement.rcNormalPosition.Top,
// WndPlacement.rcNormalPosition.Width,
// WndPlacement.rcNormalPosition.Height,
// true);
// end;
{$IFDEF DEBUG}
PrintBorderStyle;
{$ENDIF}
end;
procedure TFrmWindowPage.chFormAutoSizeClick(Sender: TObject);
begin
SetStretchForm(chFormAutoSize.Checked);
end;
procedure TFrmWindowPage.SetStretchForm(bVal: Boolean);
var
WndPlacement: TWindowPlacement;
begin
if bVal then
begin
if GetWindowPlacement(WndInfo_.WndHandle, WndPlacement) then
begin
OrzWndRect_ := WndPlacement.rcNormalPosition;
MoveWindow(WndInfo_.WndHandle, 0, 0, pnMain.Width, pnMain.Height, true);
end;
end else begin
MoveWindow(WndInfo_.WndHandle, OrzWndRect_.Left, OrzWndRect_.Top, OrzWndRect_.Width, OrzWndRect_.Height, true);
end;
end;
procedure TFrmWindowPage.pnMainResize(Sender: TObject);
begin
if chFormAutoSize.Checked and (WndInfo_.WndHandle <> 0) then
MoveWindow(WndInfo_.WndHandle, 0, 0, pnMain.Width, pnMain.Height, true);
end;
procedure TFrmWindowPage.tInitTimer(Sender: TObject);
var
h, hPreParent: HWND;
WndPlacement: TWindowPlacement;
begin
tInit.Enabled := false;
try
// hPreParent := GetWindowLong(WndInfo_.WndHandle, GWL_HWNDPARENT);
h := Winapi.Windows.SetParent(WndInfo_.WndHandle, pnMain.Handle);
// SetWindowLong(WndInfo_.WndHandle, GWL_HWNDPARENT, pnMain.Handle); // SetParent <20><> <20><><EFBFBD><EFBFBD> ȿ<><C8BF>..
if h = 0 then
begin
TTgTrace.T('fail .. SetParent(), Error=%d', [GetLastError]);
WndInfo_.WndHandle := 0;
exit;
end;
if GetWindowPlacement(WndInfo_.WndHandle, WndPlacement) then
begin
OrzWndRect_ := WndPlacement.rcNormalPosition;
MoveWindow(WndInfo_.WndHandle, 0, 0, OrzWndRect_.Width, OrzWndRect_.Height, true);
end;
OrzBorderStyle_ := GetWindowStyle(WndInfo_.WndHandle);
OrzBorderExStyle_ := GetWindowExStyle(WndInfo_.WndHandle);
//
// if hPreParent <> 0 then
// SetWindowLong(WndInfo_.WndHandle, GWL_HWNDPARENT, hPreParent);
// SetWindowLong(WndInfo_.WndHandle, GWL_USERDATA, NativeInt(Self));
// OldWndProc_ := Pointer(GetWindowLong(WndInfo_.WndHandle, GWL_WNDPROC)); // <20>ڽ<EFBFBD> <20><><EFBFBD>μ<EFBFBD><CEBC><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ƴϸ<C6B4> GWL_WNDPROC <20>̰<EFBFBD> <20>̿<EFBFBD><CCBF><EFBFBD> <20><> <20><><EFBFBD>ܴ<EFBFBD>..16_0114 01:10:33 sunk
// if OldWndProc_ <> nil then
// begin
// NewWndProc_ := MakeObjectInstance(SubClassWndProc);
// SetWindowLong(WndInfo_.WndHandle, GWL_WNDPROC, NativeInt(NewWndProc_));
// end;
// todo : <20>ƹ<EFBFBD><C6B9><EFBFBD> <20>ص<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ȿ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>α׷<CEB1><D7B7><EFBFBD> ĸ<><C4B8> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Ҽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>... <20>׳<EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ŷ<EFBFBD><C5B7><EFBFBD><EFBFBD> ó<><C3B3><EFBFBD>ϴ°ɷ<C2B0> <20><><EFBFBD><EFBFBD> 16_0114 01:12:16 sunk
chFormAutoSize.Checked := true;
{$IFDEF DEBUG}
PrintBorderStyle;
{$ENDIF}
finally
ShowWindow(WndInfo_.WndHandle, SW_SHOWNORMAL);
end;
end;
end.