win32: minor refactoring

git-svn-id: trunk@29243 -
This commit is contained in:
paul 2011-01-29 08:56:22 +00:00
parent 2b5f589e66
commit 50f08451fd
2 changed files with 36 additions and 29 deletions

View File

@ -151,6 +151,8 @@ type
procedure CheckPipeEvents; procedure CheckPipeEvents;
function WinRegister: Boolean; function WinRegister: Boolean;
procedure CreateAppHandle;
protected protected
function CreateThemeServices: TThemeServices; override; function CreateThemeServices: TThemeServices; override;
public public

View File

@ -116,7 +116,6 @@ const
ICC_PAGESCROLLER_CLASS); ICC_PAGESCROLLER_CLASS);
var var
ICC: TINITCOMMONCONTROLSEX; ICC: TINITCOMMONCONTROLSEX;
SysMenu: HMENU;
Handle: HWND; Handle: HWND;
DC: HDC; DC: HDC;
AIcon: HICON; AIcon: HICON;
@ -148,37 +147,10 @@ begin
// Create parent of all windows, 'button on taskbar' // Create parent of all windows, 'button on taskbar'
if not IsLibrary then if not IsLibrary then
begin begin
{$ifdef WindowsUnicodeSupport} CreateAppHandle;
if UnicodeEnabledOS then
FAppHandle := CreateWindowW(@ClsNameW,
PWideChar(UTF8ToUTF16(Application.Title)),
WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX,
0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,}
0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,}
0, 0, HWND(nil), HMENU(nil), HInstance, nil)
else
FAppHandle := CreateWindow(@ClsName, PChar(Utf8ToAnsi(Application.Title)),
WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX,
0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,}
0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,}
0, 0, HWND(nil), HMENU(nil), HInstance, nil);
{$else}
FAppHandle := CreateWindow(@ClsName, PChar(Application.Title), WS_POPUP or
WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX,
0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,}
0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,}
0, 0, HWND(nil), HMENU(nil), HInstance, nil);
{$endif}
AllocWindowInfo(FAppHandle);
// set nice main icon // set nice main icon
AIcon := Windows.LoadIcon(MainInstance, 'MAINICON'); AIcon := Windows.LoadIcon(MainInstance, 'MAINICON');
AppSetIcon(AIcon, AIcon); AppSetIcon(AIcon, AIcon);
// remove useless menuitems from sysmenu
SysMenu := Windows.GetSystemMenu(FAppHandle, False);
Windows.DeleteMenu(SysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND);
Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND);
end; end;
// initialize ScreenInfo // initialize ScreenInfo
@ -694,6 +666,39 @@ begin
Assert(False, 'Trace:WinRegister - Exit'); Assert(False, 'Trace:WinRegister - Exit');
end; end;
procedure TWin32WidgetSet.CreateAppHandle;
var
SysMenu: HMENU;
begin
{$ifdef WindowsUnicodeSupport}
if UnicodeEnabledOS then
FAppHandle := CreateWindowW(@ClsNameW,
PWideChar(UTF8ToUTF16(Application.Title)),
WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX,
0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,}
0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,}
0, 0, HWND(nil), HMENU(nil), HInstance, nil)
else
FAppHandle := CreateWindow(@ClsName, PChar(Utf8ToAnsi(Application.Title)),
WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX,
0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,}
0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,}
0, 0, HWND(nil), HMENU(nil), HInstance, nil);
{$else}
FAppHandle := CreateWindow(@ClsName, PChar(Application.Title), WS_POPUP or
WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX,
0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,}
0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,}
0, 0, HWND(nil), HMENU(nil), HInstance, nil);
{$endif}
AllocWindowInfo(FAppHandle);
// remove useless menuitems from sysmenu
SysMenu := Windows.GetSystemMenu(FAppHandle, False);
Windows.DeleteMenu(SysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND);
Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND);
end;
function TWin32WidgetSet.CreateThemeServices: TThemeServices; function TWin32WidgetSet.CreateThemeServices: TThemeServices;
begin begin
Result := TWin32ThemeServices.Create; Result := TWin32ThemeServices.Create;