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

📄 unavclutils.pas

📁 Voice Commnucation Components for Delphi
💻 PAS
字号:

(*
	----------------------------------------------

	  unaVCLUtils.pas
	  VCL utility functions and classes

	----------------------------------------------
	  This source code cannot be used without
	  proper license granted to you as a private
	  person or an entity by the Lake of Soft, Ltd

	  Visit http://lakeofsoft.com/ for more information.

	  Copyright (c) 2001, 2003 Lake of Soft, Ltd
		     All rights reserved
	----------------------------------------------

	  created by:
		Lake, 29 Apr 2002

	  modified by:
		Lake, Apr-Dec 2002
		Lake, Jan-Oct 2003

	----------------------------------------------
*)

{$I unaDef.inc}

unit
  unaVCLUtils;

interface

uses
  Windows, unaTypes, unaClasses, Classes, Controls, ComCtrls;

function loadControlPosition(control: tControl; ini: unaIniAbstractStorage; const section: string = 'settings'; allowFormOptions: bool = true; allowSizeChange: bool = true): bool;
function saveControlPosition(control: tControl; ini: unaIniAbstractStorage; const section: string = 'settings'; allowFormOptions: bool = true): bool;

function loadStringList(list: tStrings; ini: unaIniAbstractStorage; const section: string = 'settings'; noEmpty: bool = false): integer;
function saveStringList(list: tStrings; ini: unaIniAbstractStorage; const section: string = 'settings'; noEmpty: bool = false): integer;

function dummyWinpos(handle: tHandle; width, height: int): int;

function getREWideText(re: hWnd): wideString;
function setREWideText(re: hWnd; const text: wideString): LRESULT;


implementation


uses
  unaUtils, Messages, RichEdit, Forms;

// --  --
function loadControlPosition(control: tControl; ini: unaIniAbstractStorage; const section: string; allowFormOptions: bool; allowSizeChange: bool): bool;
var
  isForm: bool;
  ws: TWindowState;
begin
  if (ini.enter(section)) then
    try
      if (nil <> control) then begin
	//
	isForm := (control is tCustomForm);
	//
	with control, ini do begin
	  //
	  left    := get(Name + '.left', left);
	  top     := get(Name + '.top', top);
	  //
	  if (allowSizeChange) then begin
	    //
	    width   := get(Name + '.width', width);
	    height  := get(Name + '.height', height);
	  end;
	  //
	  enabled := get(Name + '.enabled', enabled);
	  //
	  if (not isForm) then
	    visible := get(Name + '.visible', visible);
	  //
	  dockOrientation := tDockOrientation(get(Name + '.dockOrnt', ord(dockOrientation)));
	end;
	//
	if (isForm and allowFormOptions) then begin
	  //
	  with (control as tCustomForm) do begin
	    //
	    ws := tWindowState(ini.get(Name + '.windowState', ord(wsNormal)));
	    //
	    if (windowState <> ws) then
	      windowState := ws;
	  end;
	end;
	//
      end;
      //
      result := true;
    finally
      ini.leave();
    end
  else
    result := false;
end;

// --  --
function saveControlPosition(control: tControl; ini: unaIniAbstractStorage; const section: string; allowFormOptions: bool): bool;
var
  isForm: bool;
begin
  if (ini.enter(section)) then
    try
      if (nil <> control) then begin
	//
	isForm := (control is tCustomForm);
	//
	with (control) do begin
	  //
	  if (isForm and allowFormOptions) then begin
	    //
	    with (control as tCustomForm) do begin
	      //
	      ini.setValue(Name + '.windowState', ord(windowState));
	      windowState := wsNormal;
	    end;
	  end;
	  //
	  with (ini) do begin
	    //
	    setValue(Name + '.left', Left);
	    setValue(Name + '.top', Top);
	    setValue(Name + '.width', Width);
	    setValue(Name + '.height', Height);
	    setValue(Name + '.enabled', Enabled);
	    setValue(name + '.docked', HostDockSite <> nil);
	    setValue(name + '.dockOrnt', ord(dockOrientation));
	    //
	    if (not isForm) then
	      setValue(Name + '.visible', Visible);
	  end;
	end;
      end;
      //
      result := true;
    finally
      ini.leave();
    end
  else
    result := false;
end;

// --  --
function loadStringList(list: tStrings; ini: unaIniAbstractStorage; const section: string; noEmpty: bool): integer;
var
  i: integer;
  max: integer;
  s: string;
begin
  result := 0;
  //
  if (ini.enter(section)) then
    try
      if (nil <> list) then begin
	//
	list.clear();
	max := ini.get('list.count', integer(0));
	i := 0;
	//
	while (i < max) do begin
	  //
	  s := ini.get('list.item' + int2Str(i), '');
	  if (noEmpty and ('' = trim(s))) then
	    // skip empty entrie
	  else begin
	    list.add(strUnescape(s));
	    inc(result);
	  end;
	  //
	  inc(i);
	end;
      end;
    finally
      ini.leave();
    end;
end;

// --  --
function saveStringList(list: tStrings; ini: unaIniAbstractStorage; const section: string; noEmpty: bool): integer;
var
  i: integer;
  s: string;
begin
  result := 0;
  //
  if (ini.enter(section)) then
    try
      if (nil <> list) then begin
	//
	i := 0;
	while (i < list.count) do begin
	  s := list[i];
	  if (noEmpty and ('' = trim(s))) then
	    // do not save empty entries
	  else begin
	    ini.setValue('list.item' + int2Str(result), strEscape(s));
	    inc(result); 
	  end;
	  //
	  inc(i);  
	end;
	//
	ini.setValue('list.count', result);
      end;
    finally
      ini.leave();
    end
end;

// --  --
function dummyWinpos(handle: tHandle; width, height: int): int;
var
  pos: WINDOWPOS;
begin
  pos.hwnd := handle;
  pos.cx := width;
  pos.cy := height;
  pos.flags := SWP_NOACTIVATE or SWP_NOCOPYBITS or SWP_NOOWNERZORDER or SWP_NOREDRAW or SWP_NOSENDCHANGING or SWP_NOZORDER or SWP_NOMOVE;
  result := SendMessage(handle, WM_WINDOWPOSCHANGED, 0, int(@pos));
end;

{$IFDEF __BEFORE_D5__ }
type
  GETTEXTEX = tGETTEXTEX;
{$ENDIF }

// --  --
function getREwideText(re: hWnd): wideString;
var
  gte: GETTEXTEX;
  len: int;
begin
  if (g_wideApiSupported) then begin
    //
    setLength(result, 65535);
    //
    fillChar(gte, sizeof(gte), #0);
    gte.cb := 65534 * 2;
    gte.flags := GT_DEFAULT;
    gte.codepage := 1200;
    //
    len := sendMessage(re, EM_GETTEXTEX, wParam(@gte), lParam(@result[1]));
    if (0 < len) then
      setLength(result, len)
    else
      result := '';
  end
  else begin
    //
    len := GetWindowTextLength(re);
    if (0 < len) then begin
      //
      setLength(result, len);
      //
      if (0 < len) then begin
	//
	GetWindowText(re, @result[1], len + 1);
      end;
    end
    else
      result := '';
  end;
end;



const
//* Flags for the SETEXTEX data structure */
  ST_DEFAULT	= 0;
  ST_KEEPUNDO	= 1;
  ST_SELECTION	= 2;


  EM_SETTEXTEX	= WM_USER + 97;

type
  SETTEXTEX = packed record
    flags: DWORD;
    codepage: UINT;
  end;


// --  --
function setREwideText(re: hWnd; const text: wideString): LRESULT;
var
  ste: SETTEXTEX;
  buf: array[0..0] of wideChar;
begin
  if (g_wideApiSupported) then begin
    //
    ste.flags := ST_DEFAULT;
    ste.codepage := 1200;
    if ('' = text) then begin
      buf[0] := #0;
      result := LRESULT(SendMessage(re, EM_SETTEXTEX, WPARAM(@ste), LPARAM(@buf[0])))
    end
    else
      result := LRESULT(SendMessage(re, EM_SETTEXTEX, WPARAM(@ste), LPARAM(@text[1])))
  end
  else begin
    //
    SetWindowText(re, pChar(string(text)));
    result := length(text);
  end;
end;


end.

⌨️ 快捷键说明

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