From 9dc2198062e245fd8825543db3738caa0d652b92 Mon Sep 17 00:00:00 2001 From: paul Date: Tue, 21 Oct 2008 03:38:09 +0000 Subject: [PATCH] lcl, win32: fix form.icon handling (#0012395) git-svn-id: trunk@17077 - --- lcl/include/customform.inc | 2 +- lcl/include/promptdialog.inc | 8 ++++---- lcl/interfaces/win32/win32object.inc | 21 ++++++--------------- lcl/interfaces/win32/win32wsforms.pp | 10 ++++++++-- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/lcl/include/customform.inc b/lcl/include/customform.inc index 4551e36d36..b4a517f528 100644 --- a/lcl/include/customform.inc +++ b/lcl/include/customform.inc @@ -1265,7 +1265,7 @@ begin if HandleAllocated then begin TWSCustomFormClass(WidgetSetClass).SetFormBorderStyle(Self, NewStyle); - TWSCustomFormClass(WidgetSetClass).SetIcon(Self, 0, 0); + Perform(CM_ICONCHANGED, 0, 0); end; end; diff --git a/lcl/include/promptdialog.inc b/lcl/include/promptdialog.inc index 97ac40d064..8e3eb84829 100644 --- a/lcl/include/promptdialog.inc +++ b/lcl/include/promptdialog.inc @@ -260,7 +260,7 @@ begin NumButtons := ButtonCount; Buttons := TheButtons; - If (DefaultIndex >= ButtonCount) or + if (DefaultIndex >= ButtonCount) or (DefaultIndex < 0) then TheDefaultIndex := 0 @@ -268,12 +268,12 @@ begin theDefaultIndex := DefaultIndex; // Assures a minimum text size - If MSG = '' then MSG := ' '; + if MSG = '' then MSG := ' '; // Initialize TextStyle FillChar(TextStyle, SizeOf(TTextStyle), 0); - With TextStyle do + with TextStyle do begin Clipping := True; Wordbreak := True; @@ -534,7 +534,7 @@ begin Top := Y; end; theModalResult := ShowModal; - Case theModalResult of + case theModalResult of -1 : Result := EscapeResult else Result := DialogResult[theModalResult]; diff --git a/lcl/interfaces/win32/win32object.inc b/lcl/interfaces/win32/win32object.inc index 01a3d7fa95..6e8672b39d 100644 --- a/lcl/interfaces/win32/win32object.inc +++ b/lcl/interfaces/win32/win32object.inc @@ -98,6 +98,7 @@ var SysMenu: HMENU; Handle: HWND; DC: HDC; + AIcon: HICON; begin Assert(False, 'Trace:Win32Object.Init - Start'); if not WinRegister then @@ -147,8 +148,8 @@ begin AllocWindowInfo(FAppHandle); // set nice main icon - Windows.SendMessage(FAppHandle, WM_SETICON, ICON_BIG, - LParam(Windows.LoadIcon(MainInstance, 'MAINICON'))); + AIcon := Windows.LoadIcon(MainInstance, 'MAINICON'); + AppSetIcon(AIcon, AIcon); // remove useless menuitems from sysmenu SysMenu := Windows.GetSystemMenu(FAppHandle, False); Windows.DeleteMenu(SysMenu, SC_MAXIMIZE, MF_BYCOMMAND); @@ -414,7 +415,10 @@ end; procedure TWin32WidgetSet.AppSetIcon(const Small, Big: HICON); begin Windows.SendMessage(Win32Widgetset.AppHandle, WM_SETICON, ICON_SMALL, LPARAM(Small)); + SetClassLong(Win32Widgetset.AppHandle, GCL_HICONSM, LONG(Small)); + Windows.SendMessage(Win32Widgetset.AppHandle, WM_SETICON, ICON_BIG, LPARAM(Big)); + SetClassLong(Win32Widgetset.AppHandle, GCL_HICON, LONG(Big)); end; procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); @@ -639,19 +643,6 @@ begin if Flags = SW_SHOWMAXIMIZED then Windows.SendMessage(Handle, WM_SHOWWINDOW, 1, 0); end; - if (Sender is TCustomForm) then - begin - if TCustomForm(Sender).BorderStyle <> bsDialog then - begin - SetClassLong(Handle, GCL_HICONSM, LONG(TCustomForm(Sender).SmallIconHandle)); - SetClassLong(Handle, GCL_HICON, LONG(TCustomForm(Sender).BigIconHandle)); - end - else - begin - SetClassLong(Handle, GCL_HICONSM, 0); - SetClassLong(Handle, GCL_HICON, 0); - end; - end; end else begin diff --git a/lcl/interfaces/win32/win32wsforms.pp b/lcl/interfaces/win32/win32wsforms.pp index 447b472ff5..4fbe69eb92 100644 --- a/lcl/interfaces/win32/win32wsforms.pp +++ b/lcl/interfaces/win32/win32wsforms.pp @@ -414,11 +414,17 @@ begin end; class procedure TWin32WSCustomForm.SetIcon(const AForm: TCustomForm; const Small, Big: HICON); +var + Wnd: HWND; begin if not WSCheckHandleAllocated(AForm, 'SetIcon') then Exit; - SendMessage(AForm.Handle, WM_SETICON, ICON_SMALL, LPARAM(Small)); - SendMessage(AForm.Handle, WM_SETICON, ICON_BIG, LPARAM(Big)); + Wnd := AForm.Handle; + SendMessage(Wnd, WM_SETICON, ICON_SMALL, LPARAM(Small)); + SetClassLong(Wnd, GCL_HICONSM, LONG(Small)); + + SendMessage(Wnd, WM_SETICON, ICON_BIG, LPARAM(Big)); + SetClassLong(Wnd, GCL_HICON, LONG(Big)); end; class procedure TWin32WSCustomForm.SetShowInTaskbar(const AForm: TCustomForm;