unit style; //{$DEFINE _DEBUG} interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, myLabel, CheckLst, ComCtrls; type TTOOL_WindowStyle = class(TForm) ScrollBox1: TScrollBox; lblStyle: TMyLabel; lstStyle: TCheckListBox; lblExStyle: TMyLabel; lstExStyle: TCheckListBox; pnlButton: TPanel; chkButton: TCheckBox; lstButton: TCheckListBox; pnlEdit: TPanel; chkEdit: TCheckBox; lstEdit: TCheckListBox; pnlStatic: TPanel; chkStatic: TCheckBox; lstStatic: TCheckListBox; pnlComboBox: TPanel; chkComboBox: TCheckBox; lstComboBox: TCheckListBox; pnlListBox: TPanel; chkListBox: TCheckBox; lstListBox: TCheckListBox; pnlControl: TPanel; shpBottom: TShape; btnOk: TButton; btnCancel: TButton; StatusBar1: TStatusBar; lblMove: TLabel; lstMove: TComboBox; pnlScrollBar: TPanel; chkScrollBar: TCheckBox; lstScrollBar: TCheckListBox; RichEdit_Hint: TRichEdit; procedure FormCreate (Sender: TObject); procedure FormClose (Sender: TObject; var Action: TCloseAction); procedure FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); procedure chkButtonClick (Sender: TObject); procedure btnOkClick (Sender: TObject); procedure btnCancelClick (Sender: TObject); procedure lstStyleClick (Sender: TObject); procedure lstStyleClickCheck(Sender: TObject); procedure ComboBox1Select (Sender: TObject); private { Private 宣言 } F_iStyle, F_iExStyle: Longint; procedure F_CheckStyle(iStyle: Longint; AStyleList: TCheckListBox); procedure F_SetStyle(iStyle: Longint); procedure F_SetExStyle(iExStyle: Longint); public { Public 宣言 } property TgtStyle: Longint read F_iStyle write F_SetStyle; property TgtExStyle: Longint read F_iExStyle write F_SetExStyle; end; procedure gpcCreateSetStyleForm; var TOOL_WindowStyle: TTOOL_WindowStyle; implementation uses {$IFDEF _DEBUG} myDebug, {$ENDIF} myMessageDlg, myWindow, main; {$R *.dfm} procedure gpcCreateSetStyleForm; var i: Integer; begin if (TOOL_WindowStyle = nil) then begin TOOL_WindowStyle := TTOOL_WindowStyle.Create(Application); end else begin for i := 0 to Screen.FormCount-1 do begin if (Screen.Forms[i] = TOOL_WindowStyle) then begin Exit; end; end; TOOL_WindowStyle := TTOOL_WindowStyle.Create(Application); end; end; procedure TTOOL_WindowStyle.FormCreate(Sender: TObject); begin Self.Icon := Application.Icon; lstStyle.Height := lstStyle.ItemHeight * lstStyle.Count; lstExStyle.Height := lstExStyle.ItemHeight * lstExStyle.Count; pnlButton.Height := chkButton.Height; pnlEdit.Height := chkEdit.Height; pnlStatic.Height := chkStatic.Height; pnlComboBox.Height := chkComboBox.Height; pnlListBox.Height := chkListBox.Height; pnlScrollBar.Height := chkScrollBar.Height; ScrollBox1.Align := alClient; ScrollBox1.VertScrollBar.Range := lblStyle.Height + lstStyle.Height + lblExStyle.Height + lstExStyle.Height + pnlButton.Height + pnlEdit.Height + pnlStatic.Height + pnlComboBox.Height + pnlListBox.Height + pnlScrollBar.Height ; ScrollBox1.AutoSize := True; end; procedure TTOOL_WindowStyle.FormClose(Sender: TObject; var Action: TCloseAction); begin App_TOOLWindowStyle.Action_Style_Change.Checked := False; end; procedure TTOOL_WindowStyle.chkButtonClick(Sender: TObject); var l_Panel: TPanel; l_CheckBox: TCheckBox; l_CheckListBox: TCheckListBox; begin if not(Sender is TCheckBox) then begin Exit; end; l_CheckBox := TCheckBox(Sender); l_Panel := TPanel(l_CheckBox.Parent); l_CheckListBox := TCheckListBox(FindComponent(Format('lst%s', [Copy(l_CheckBox.Name, 4, MAXINT)]))); if (l_CheckBox.Checked) then begin l_Panel.Height := l_CheckBox.Height + l_CheckListBox.Height; ScrollBox1.VertScrollBar.Range := ScrollBox1.VertScrollBar.Range + l_CheckListBox.Height; end else begin l_Panel.Height := l_CheckBox.Height; ScrollBox1.VertScrollBar.Range := ScrollBox1.VertScrollBar.Range - l_CheckListBox.Height; end; l_CheckListBox.Enabled := l_CheckBox.Checked; end; procedure TTOOL_WindowStyle.btnCancelClick(Sender: TObject); begin Close; end; procedure TTOOL_WindowStyle.F_CheckStyle(iStyle: Longint; AStyleList: TCheckListBox); var li_Comp: Longint; i: Integer; begin for i := 0 to AStyleList.Count-1 do begin li_Comp := App_TOOLWindowStyle.GetStyleValue(AStyleList.Items[i]); if (li_Comp = 0) then begin AStyleList.Checked[i] := ((iStyle and 1) = 0); end else begin AStyleList.Checked[i] := ((iStyle and li_Comp) = li_Comp); end; end; end; procedure TTOOL_WindowStyle.F_SetStyle(iStyle: Longint); begin F_iStyle := iStyle; F_CheckStyle(F_iStyle, lstStyle); F_CheckStyle(F_iStyle, lstButton); F_CheckStyle(F_iStyle, lstEdit); F_CheckStyle(F_iStyle, lstStatic); F_CheckStyle(F_iStyle, lstComboBox); F_CheckStyle(F_iStyle, lstListBox); F_CheckStyle(F_iStyle, lstScrollBar); end; procedure TTOOL_WindowStyle.F_SetExStyle(iExStyle: Longint); begin F_iExStyle := iExStyle; F_CheckStyle(F_iExStyle, lstExStyle); end; procedure TTOOL_WindowStyle.lstStyleClick(Sender: TObject); const lciSTART_STYLENAME = 12; lciSTART_STYLETEXT = 35; var l_CheckListBox: TCheckListBox; ls_Hint : String; li_Pos : Integer; begin if not(Sender is TCheckListBox) then begin Exit; end; l_CheckListBox := TCheckListBox(Sender); l_CHeckListBox.Hint := Format('%s %s', [ Trim(Copy(l_CheckListBox.Items[l_CheckListBox.ItemIndex], lciSTART_STYLENAME, lciSTART_STYLETEXT - lciSTART_STYLENAME)), Copy(l_CheckListBox.Items[l_CheckListBox.ItemIndex], lciSTART_STYLETEXT, MaxInt) ]); //ヒントを下部のヒントメッセージ欄に表示させる li_Pos := Pos('。', l_CheckListBox.Hint); if (li_Pos > 0) then begin ls_Hint := Format('%s'#13'%s', [ Copy(l_CheckListBox.Hint, 1, li_Pos), Copy(l_CheckListBox.Hint, li_Pos, MAXINT) ]); end else begin ls_Hint := l_CHeckListBox.Hint; end; RichEdit_Hint.Text := ls_Hint; // StatusBar1.SimpleText := l_CheckListBox.Items[l_CheckListBox.ItemIndex]; end; procedure TTOOL_WindowStyle.lstStyleClickCheck(Sender: TObject); var l_CheckListBox: TCheckListBox; li_Index: Integer; li_Style: Longint; begin if not(Sender is TCheckListBox) then begin Exit; end; l_CheckListBox := TCheckListBox(Sender); li_Index := l_CheckListBox.ItemIndex; li_Style := App_TOOLWindowStyle.GetStyleValue(l_CheckListBox.Items[li_Index]); if (l_CheckListBox.Checked[li_Index]) then begin //チェックした。 if (Sender = lstExStyle) then begin F_iExStyle := F_iExStyle or li_Style; end else begin F_iStyle := F_iStyle or li_Style; end; end else begin //チェックを外した。 if (Sender = lstExStyle) then begin if ((F_iExStyle and li_Style) = li_Style) then begin Dec(F_iExStyle, li_Style); end; end else begin if ((F_iStyle and li_Style) = li_Style) then begin Dec(F_iStyle, li_Style); end; end; end; if (Sender = lstExStyle) then begin F_SetExStyle(F_iExStyle); end else begin F_SetStyle(F_iStyle); end; end; procedure TTOOL_WindowStyle.btnOkClick(Sender: TObject); var lh_Handle, lh_TopLevel: HWND; lb_Layerd : Boolean; begin lh_Handle := App_TOOLWindowStyle.TgtHandle; lh_TopLevel := GetAncestor(lh_Handle, GA_ROOT); if (IsWindow(lh_Handle)) and (IsWindow(lh_TopLevel)) and (gfniMessageBoxYesNo('選択ウィンドウのスタイルを変更しますか') = ID_YES) then begin lb_Layerd := False; if ((F_iExStyle and WS_EX_LAYERED) = WS_EX_LAYERED) then begin lb_Layerd := ((GetWindowLong(lh_Handle, GWL_EXSTYLE) and WS_EX_LAYERED) = 0); end; SetWindowLong(lh_Handle, GWL_STYLE, F_iStyle); SetWindowLong(lh_Handle, GWL_EXSTYLE, F_iExStyle); //レイヤードウィンドウの処理。 if (lb_Layerd) then begin SetLayeredWindowAttributes(lh_Handle, RGB(0,0,0), 255, LWA_ALPHA); // SetLayeredWindowAttributes(lh_Handle, RGB(0,0,0), 150, LWA_ALPHA); end; if (IsWindowVisible(lh_TopLevel)) then begin ShowWindow(lh_TopLevel, SW_HIDE); ShowWindow(lh_TopLevel, SW_SHOWNOACTIVATE); end; end; end; procedure TTOOL_WindowStyle.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); var li_Scroll: Integer; begin if not(lstMove.Focused) then begin li_Scroll := ScrollBox1.VertScrollBar.Increment; if (WheelDelta > 0) then begin li_Scroll := -(li_Scroll); end; ScrollBox1.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position + li_Scroll; end; end; procedure TTOOL_WindowStyle.ComboBox1Select(Sender: TObject); var ls_Item: String; li_Top: Integer; begin if (lstMove.ItemIndex < 0) then begin Exit; //AIU end; ls_Item := lstMove.Items[lstMove.ItemIndex]; if (ls_Item = 'GWL_EXSTYLE 拡張ウィンドウスタイル') then begin li_Top := lblExStyle.Top; end else if (ls_Item = 'Button ボタン') then begin li_Top := pnlButton.Top; end else if (ls_Item = 'Edit エディット') then begin li_Top := pnlEdit.Top; end else if (ls_Item = 'Static スタティック') then begin li_Top := pnlStatic.Top; end else if (ls_Item = 'ComboBox コンボボックス') then begin li_Top := pnlComboBox.Top; end else if (ls_Item = 'ListBox リストボックス') then begin li_Top := pnlListBox.Top; end else if (ls_Item = 'ScrollBar スクロールバー') then begin li_Top := pnlScrollBar.Top; end else begin //ls_Item = 'GWL_STYLE ウィンドウスタイル' li_Top := lblStyle.Top; end; ScrollBox1.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position + li_Top; end; end.