View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0017311 | Patches | LCL | public | 2010-08-31 03:43 | 2011-03-10 01:40 |
Reporter | yang jixian | Assigned To | Paul Ishenin | ||
Priority | normal | Severity | feature | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Platform | windows | OS | windows | ||
Product Version | 0.9.29 (SVN) | ||||
Target Version | 0.99.0 | Fixed in Version | 0.9.31 (SVN) | ||
Summary | 0017311: There is no MainFormOnTaskBar property in Lazarus | ||||
Description | There is no MainFormOnTaskBar property in Lazarus The patch include the feature. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | |||||
LazTarget | 0.99.0 | ||||
Widgetset | Win32/Win64 | ||||
Attached Files |
|
has duplicate | 0015487 | closed | Paul Ishenin | Lazarus | Application.MainFormOnTaskbar does not exist |
related to | 0017965 | closed | Paul Ishenin | Patches | Hide task bar handler for libraries |
related to | 0018499 | acknowledged | Lazarus | Lack of preview of minimized window on Flip3d | |
related to | 0017294 | resolved | Ondrej Pokorny | Lazarus | ShowInTaskBar = stNever does nothing |
related to | 0020864 | closed | yang jixian | Lazarus | ShowInTaskbar = stAlways Bug of MainForm on Windows and TWin32WidgetSet(WidgetSet).AppHandle Bug |
2010-08-31 03:43
|
MainFormOnTaskBar.patch (10,530 bytes)
Index: ide/projectdefs.pas =================================================================== --- ide/projectdefs.pas (revision 27226) +++ ide/projectdefs.pas (working copy) @@ -1359,6 +1359,9 @@ +le +'begin'+le +' Application.Initialize;'+le + +' {$IFDEF MSWINDOWS}'+le + +' Application.MainFormOnTaskBar:=True;'+le + +' {$ENDIF}'+le +' Application.Run;'+le +'end.'+le +le; Index: lcl/forms.pp =================================================================== --- lcl/forms.pp (revision 27235) +++ lcl/forms.pp (working copy) @@ -1167,6 +1167,11 @@ tbSingleButton // hide buttons for Forms with ShowTaskBar = stDefault ); + TMainOnTaskBarForm = class(TForm) + private + public + end; + { TApplication } TApplication = class(TCustomApplication) @@ -1191,6 +1196,7 @@ FHintTimer: TCustomTimer; FHintTimerType: TAppHintTimerType; FHintWindow: THintWindow; + FMainFormOnTaskBar: boolean; FIcon: TIcon; FBigIconHandle: HICON; FModalLevel: Integer; @@ -1205,6 +1211,7 @@ FLastKeyDownKey: Word; FLastKeyDownShift: TShiftState; FMainForm : TForm; + FMainForm2 : TForm; FMouseControl: TControl; FNavigation: TApplicationNavigationOptions; FOldExceptProc: TExceptProc; @@ -1258,6 +1265,7 @@ procedure SetShowHint(const AValue: Boolean); procedure StopHintTimer; function ValidateHelpSystem: Boolean; + procedure SetMainFormOnTaskBar(Value: boolean); procedure WndProc(var AMessage : TLMessage); function DispatchAction(Msg: Longint; Action: TBasicAction): Boolean; procedure AddHandler(HandlerType: TApplicationHandlerType; @@ -1418,6 +1426,8 @@ property Icon: TIcon read FIcon write SetIcon; property Navigation: TApplicationNavigationOptions read FNavigation write SetNavigation; property MainForm: TForm read FMainForm; + property MainForm2: TForm read FMainForm2; + property MainFormOnTaskBar: boolean read FMainFormOnTaskBar write SetMainFormOnTaskBar; property ModalLevel: Integer read FModalLevel; property MouseControl: TControl read FMouseControl; property TaskBarBehavior: TTaskBarBehavior read FTaskBarBehavior write SetTaskBarBehavior; @@ -1658,6 +1668,7 @@ HandlingException: Boolean = False; HaltingProgram: Boolean = False; LastFocusedControl: TWinControl = nil; + MainOnTaskBarForm: TMainOnTaskBarForm; procedure Register; begin Index: lcl/include/application.inc =================================================================== --- lcl/include/application.inc (revision 27235) +++ lcl/include/application.inc (working copy) @@ -124,8 +124,26 @@ ExitProc:=@BeforeFinalization; OnGetApplicationName := @GetApplicationName; + FMainFormOnTaskBar := False; + FMainForm2 := nil; end; +procedure TApplication.SetMainFormOnTaskBar(Value: boolean); +begin + FMainFormOnTaskBar := Value; + {$IFDEF MSWINDOWS} + if Value then + begin + ShowMainForm:=false; + Application.CreateForm(TMainOnTaskBarForm,MainOnTaskBarForm); + MainOnTaskBarForm.Name:='MainOnTaskBarFormEx'; + MainOnTaskBarForm.BorderStyle:=bsNone; + MainOnTaskBarForm.Width:=0; + MainOnTaskBarForm.Height:=0; + end; + {$ENDIF} +end; + {------------------------------------------------------------------------------ TApplication Destructor ------------------------------------------------------------------------------} @@ -926,6 +944,12 @@ function UseAppTaskbarItem(AForm: TCustomForm): Boolean; inline; begin + {$IFDEF MSWINDOWS} + if MainFormOnTaskBar then + Result := (AForm = MainForm2) or (AForm.ShowInTaskBar = stNever) + or ((AForm.ShowInTaskBar = stDefault) and AppUseSingleButton) + else + {$ENDIF} Result := (AForm = MainForm) or (AForm.ShowInTaskBar = stNever) or ((AForm.ShowInTaskBar = stDefault) and AppUseSingleButton); end; @@ -950,6 +974,10 @@ break; end; end; + {$IFDEF MSWINDOWS} + if MainFormOnTaskBar then + Result := false; + {$ENDIF} end; begin @@ -1341,8 +1369,22 @@ TApplication Run MainForm is loaded and control is passed to event processor. ------------------------------------------------------------------------------} + procedure TApplication.Run; begin + {$IFDEF MSWINDOWS} + if MainFormOnTaskBar then + begin + if FFormList.Count>1 then + begin + FMainForm2 := TForm(FFormList[1]); + FMainForm2.Visible:=false; + FMainForm2.ShowInTaskBar:=stAlways; + FMainForm2.Visible:=true; + end; + //ShowMainForm:=False; + end; + {$ENDIF} if (FMainForm <> nil) and FShowMainForm then FMainForm.Show; WidgetSet.AppRun(@RunLoop); end; Index: lcl/include/customform.inc =================================================================== --- lcl/include/customform.inc (revision 27235) +++ lcl/include/customform.inc (working copy) @@ -616,6 +616,48 @@ if Assigned(FOnDeactivate) then FOnDeactivate(Self); end; +procedure AppMinimizeEx; +var + i: Integer; + AForm: TCustomForm; +begin + //debugln('TGtkWidgetSet.AppMinimize A'); + if Screen=nil then exit; + for i:=0 to Screen.CustomFormCount-1 do begin + begin + AForm:=Screen.CustomForms[i]; + //debugln('TGtkWidgetSet.AppMinimize B ',DbgSName(AForm),' AForm.Parent=',DbgSName(AForm.Parent),' AForm.HandleAllocated=',dbgs(AForm.HandleAllocated)); + if (AForm.Parent=nil) and AForm.HandleAllocated + //and (AForm.Name <> Application.MainForm.Name) + and (AForm.Name <> Application.MainForm2.Name) + and AForm.Visible then begin + ShowWindow(AForm.Handle, SW_HIDE); + end; + end; + end; +end; + +procedure AppRestoreEx; +var + i: Integer; + AForm: TCustomForm; +begin + //debugln('TGtkWidgetSet.AppMinimize A'); + if Screen=nil then exit; + for i:=0 to Screen.CustomFormCount-1 do begin + begin + AForm:=Screen.CustomForms[i]; + //debugln('TGtkWidgetSet.AppMinimize B ',DbgSName(AForm),' AForm.Parent=',DbgSName(AForm.Parent),' AForm.HandleAllocated=',dbgs(AForm.HandleAllocated)); + if (AForm.Parent=nil) and AForm.HandleAllocated + //and (AForm.Name <> Application.MainForm.Name) + and (AForm.Name <> Application.MainForm2.Name) + and AForm.Visible then begin + ShowWindow(AForm.Handle, SW_SHOW); + end; + end; + end; +end; + {------------------------------------------------------------------------------ Method: TCustomForm.WMSize Params: Msg: The Size message @@ -625,7 +667,7 @@ ------------------------------------------------------------------------------} procedure TCustomForm.WMSize(var Message: TLMSize); var - OldState: TWindowState; + OldState: TWindowState; i: integer; AForm: TCustomForm; begin {$IFDEF CHECK_POSITION} DebugLn(['[TCustomForm.WMSize] ',DbgSName(Self),' Message.SizeType=',Message.SizeType,' Message.Width=',Message.Width,' Message.Height=',Message.Height,' AutoSizeDelayed=',AutoSizeDelayed]); @@ -657,6 +699,20 @@ if (WidgetSet.GetLCLCapability(lcNeedMininimizeAppWithMainForm) <> LCL_CAPABILITY_NO) and (Application.MainForm = Self) then Application.Minimize; + {$IFDEF MSWINDOWS} + if Application.MainFormOnTaskBar then + if (WidgetSet.GetLCLCapability(lcNeedMininimizeAppWithMainForm) <> LCL_CAPABILITY_NO) + and (Application.MainForm2 = Self) then + begin + {if Application.FFormList.Count>2 then + for i:=2 to Application.FFormList.Count-1 do + begin + if TCustomForm(Application.FFormList[i]).Visible then + ShowWindow(TCustomForm(Application.FFormList[i]).Handle, SW_HIDE); + end; } + AppMinimizeEx; + end; + {$ENDIF} end; SIZEFULLSCREEN: if Showing then @@ -669,6 +725,20 @@ begin Application.Restore; end; + {$IFDEF MSWINDOWS} + if Application.MainFormOnTaskBar then + if (OldState = wsMinimized) and (Application.MainForm2 = Self) + and (WidgetSet.GetLCLCapability(lcNeedMininimizeAppWithMainForm) <> LCL_CAPABILITY_NO) then + begin + {if Application.FFormList.Count>2 then + for i:=2 to Application.FFormList.Count-1 do + begin + if TCustomForm(Application.FFormList[i]).Visible then + ShowWindow(TCustomForm(Application.FFormList[i]).Handle, SW_SHOW); + end; } + AppRestoreEx; + end; + {$ENDIF} if Assigned(OnWindowStateChange) then OnWindowStateChange(Self); end; @@ -2000,7 +2070,7 @@ procedure TCustomForm.Close; var CloseAction: TCloseAction; - IsMainForm: Boolean; + IsMainForm, IsMainForm2: Boolean; begin if fsModal in FFormState then ModalResult := mrCancel @@ -2010,6 +2080,14 @@ begin // IsMainForm flag set if we are closeing MainForm or its parent IsMainForm := (Application.MainForm = Self) or (Self.IsParentOf(Application.MainForm)); + {$IFDEF MSWINDOWS} + if Application.MainFormOnTaskBar then + if Application.MainForm2 <> nil then + IsMainForm2 := (Application.MainForm2 = Self) or (Self.IsParentOf(Application.MainForm2)) + else + IsMainForm2 := false; + {$ENDIF} + // Prepare default close action if FormStyle = fsMDIChild then begin @@ -2022,6 +2100,15 @@ CloseAction := caFree else CloseAction := caHide; + {$IFDEF MSWINDOWS} + if Application.MainFormOnTaskBar then + begin + if IsMainForm2 then + CloseAction := caFree + else + CloseAction := caHide; + end; + {$ENDIF} end; // call event handler and let user modify CloseAction DoClose(CloseAction); @@ -2039,6 +2126,15 @@ Application.Terminate else Release; + {$IFDEF MSWINDOWS} + if Application.MainFormOnTaskBar then + begin + if IsMainForm2 then + Application.Terminate + else + Release; + end; + {$ENDIF} end; end; end; |
|
The patch added MainFormOnTaskBar property for Lazarus. |
|
For reference the Delphi documentation on the subject: http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/Forms_TApplication_MainFormOnTaskBar.html |
|
Hello, thanks for the patch, but it isn't implemented in the correct way. The LCL is not implemented with ifdef's, it is implemented in separate modules for each platforms. Read here for more information: http://wiki.lazarus.freepascal.org/LCL_Internals#How_to_implement_a_new_windowed_component The code in LCL only calls the backend implementation, which in your case will most likely be in TWin32CustomForm or something similar in lcl/interfaces/win32/wsforms.pas or similar. You need to add a new function there as well as in the main widgetset declaration and the LCL implementation only calls the widgetset. Later I can provide more details. About the feature itself I have no opinion, I will ask other developers. |
|
Thanks for the information. |
|
TApplication is a kind of form in Lazarus and delphi. After Delphi 2009 the feature MainFormOnTaskBar added for Windows Vista Aero effects. In delphi, "Application.MainFormOnTaskbar := True; " should be after Application.Initialize and before main form creation. Therefore the patch create a form with width=0 and height=0 to replace the Application.MainForm and set Application.ShowMainForm=false when "Application.MainFormOnTaskbar := True;" and show first form of project in taskbar. For minimize and restore, the patch hide or show forms("Forms.Show" ). |
2010-09-01 09:48
|
MainFormOnTaskBar2.patch (10,807 bytes)
Index: ide/projectdefs.pas =================================================================== --- ide/projectdefs.pas (revision 27242) +++ ide/projectdefs.pas (working copy) @@ -1359,6 +1359,9 @@ +le +'begin'+le +' Application.Initialize;'+le + +' {$IFDEF MSWINDOWS}'+le + +' Application.MainFormOnTaskBar:=True;'+le + +' {$ENDIF}'+le +' Application.Run;'+le +'end.'+le +le; Index: lcl/forms.pp =================================================================== --- lcl/forms.pp (revision 27242) +++ lcl/forms.pp (working copy) @@ -214,7 +214,6 @@ property DockSite; property DragCursor; property DragKind; - property DragMode; property Enabled; property Color nodefault; @@ -1191,6 +1190,7 @@ FHintTimer: TCustomTimer; FHintTimerType: TAppHintTimerType; FHintWindow: THintWindow; + FMainFormOnTaskBar: boolean; FIcon: TIcon; FBigIconHandle: HICON; FModalLevel: Integer; @@ -1205,6 +1205,7 @@ FLastKeyDownKey: Word; FLastKeyDownShift: TShiftState; FMainForm : TForm; + FMainForm2 : TForm; FMouseControl: TControl; FNavigation: TApplicationNavigationOptions; FOldExceptProc: TExceptProc; @@ -1258,6 +1259,7 @@ procedure SetShowHint(const AValue: Boolean); procedure StopHintTimer; function ValidateHelpSystem: Boolean; + procedure SetMainFormOnTaskBar(Value: boolean); procedure WndProc(var AMessage : TLMessage); function DispatchAction(Msg: Longint; Action: TBasicAction): Boolean; procedure AddHandler(HandlerType: TApplicationHandlerType; @@ -1418,6 +1420,8 @@ property Icon: TIcon read FIcon write SetIcon; property Navigation: TApplicationNavigationOptions read FNavigation write SetNavigation; property MainForm: TForm read FMainForm; + property MainForm2: TForm read FMainForm2; + property MainFormOnTaskBar: boolean read FMainFormOnTaskBar write SetMainFormOnTaskBar; property ModalLevel: Integer read FModalLevel; property MouseControl: TControl read FMouseControl; property TaskBarBehavior: TTaskBarBehavior read FTaskBarBehavior write SetTaskBarBehavior; Index: lcl/include/application.inc =================================================================== --- lcl/include/application.inc (revision 27242) +++ lcl/include/application.inc (working copy) @@ -122,6 +122,9 @@ FOldExitProc:=ExitProc; ExitProc:=@BeforeFinalization; + + FMainFormOnTaskBar := False; + FMainForm2 := nil; OnGetApplicationName := @GetApplicationName; end; @@ -432,6 +435,12 @@ end; end; +procedure TApplication.SetMainFormOnTaskBar(Value: boolean); +begin + FMainFormOnTaskBar := Value; + WidgetSet.AppSetMainForm2(Value); +end; + {------------------------------------------------------------------------------ Method: TApplication.UpdateMouseHint Params: None @@ -950,6 +959,8 @@ break; end; end; + if MainFormOnTaskBar then + Result := false; end; begin @@ -1343,6 +1354,17 @@ ------------------------------------------------------------------------------} procedure TApplication.Run; begin + if FMainFormOnTaskBar then + begin + if FFormList.Count>1 then + begin + FMainForm2 := TForm(Application.FFormList[1]); + FMainForm2.Visible:=false; + FMainForm2.ShowInTaskBar:=stAlways; + FMainForm2.Visible:=true; + end; + FShowMainForm:=false; + end; if (FMainForm <> nil) and FShowMainForm then FMainForm.Show; WidgetSet.AppRun(@RunLoop); end; Index: lcl/include/customform.inc =================================================================== --- lcl/include/customform.inc (revision 27242) +++ lcl/include/customform.inc (working copy) @@ -657,6 +657,12 @@ if (WidgetSet.GetLCLCapability(lcNeedMininimizeAppWithMainForm) <> LCL_CAPABILITY_NO) and (Application.MainForm = Self) then Application.Minimize; + if Application.MainFormOnTaskBar then + if (WidgetSet.GetLCLCapability(lcNeedMininimizeAppWithMainForm) <> LCL_CAPABILITY_NO) + and (Application.MainForm2 = Self) then + begin + WidgetSet.AppMinimizeEx; + end; end; SIZEFULLSCREEN: if Showing then @@ -669,6 +675,12 @@ begin Application.Restore; end; + if Application.MainFormOnTaskBar then + if (OldState = wsMinimized) and (Application.MainForm2 = Self) + and (WidgetSet.GetLCLCapability(lcNeedMininimizeAppWithMainForm) <> LCL_CAPABILITY_NO) then + begin + WidgetSet.AppRestoreEx; + end; if Assigned(OnWindowStateChange) then OnWindowStateChange(Self); end; @@ -2000,7 +2012,8 @@ procedure TCustomForm.Close; var CloseAction: TCloseAction; - IsMainForm: Boolean; + //IsMainForm: Boolean; + IsMainForm, IsMainForm2: Boolean; begin if fsModal in FFormState then ModalResult := mrCancel @@ -2010,6 +2023,11 @@ begin // IsMainForm flag set if we are closeing MainForm or its parent IsMainForm := (Application.MainForm = Self) or (Self.IsParentOf(Application.MainForm)); + if Application.MainFormOnTaskBar then + if Application.MainForm2 <> nil then + IsMainForm2 := (Application.MainForm2 = Self) or (Self.IsParentOf(Application.MainForm2)) + else + IsMainForm2 := false; // Prepare default close action if FormStyle = fsMDIChild then begin @@ -2022,6 +2040,13 @@ CloseAction := caFree else CloseAction := caHide; + if Application.MainFormOnTaskBar then + begin + if IsMainForm2 then + CloseAction := caFree + else + CloseAction := caHide; + end; end; // call event handler and let user modify CloseAction DoClose(CloseAction); @@ -2039,6 +2064,13 @@ Application.Terminate else Release; + if Application.MainFormOnTaskBar then + begin + if IsMainForm2 then + WidgetSet.AppTerminateEx(IsMainForm2) + else + Release; + end; end; end; end; Index: lcl/interfacebase.pp =================================================================== --- lcl/interfacebase.pp (revision 27242) +++ lcl/interfacebase.pp (working copy) @@ -98,10 +98,14 @@ procedure BeforeDestruction;override; procedure AppInit(var ScreenInfo: TScreenInfo); virtual; abstract; + procedure AppSetMainForm2(Value: boolean); virtual; abstract; procedure AppRun(const ALoop: TApplicationMainLoop); virtual; procedure AppWaitMessage; virtual; abstract; procedure AppProcessMessages; virtual; abstract; procedure AppTerminate; virtual; abstract; + procedure AppTerminateEx(Value: boolean); virtual; abstract; + procedure AppMinimizeEx; virtual; abstract; + procedure AppRestoreEx; virtual; abstract; procedure AppMinimize; virtual; abstract; procedure AppRestore; virtual; abstract; procedure AppBringToFront; virtual; abstract; Index: lcl/interfaces/win32/win32int.pp =================================================================== --- lcl/interfaces/win32/win32int.pp (revision 27242) +++ lcl/interfaces/win32/win32int.pp (working copy) @@ -117,6 +117,13 @@ { TWin32WidgetSet } + TMainOnTaskBarForm = class(TForm) + private + public + end; + + + TWin32WidgetSet = class(TWidgetSet) private // The parent of all windows, represents the button of the taskbar @@ -167,12 +174,16 @@ { Initialize the API } procedure AppInit(var ScreenInfo: TScreenInfo); override; + procedure AppSetMainForm2(Value: boolean); override; + procedure AppMinimizeEx; override; + procedure AppRestoreEx; override; procedure AppMinimize; override; procedure AppRestore; override; procedure AppBringToFront; override; procedure AppProcessMessages; override; procedure AppWaitMessage; override; procedure AppTerminate; override; + procedure AppTerminateEx(Value: boolean); override; procedure AppSetIcon(const Small, Big: HICON); override; procedure AppSetTitle(const ATitle: string); override; procedure AppSetVisible(const AVisible: Boolean); override; @@ -208,8 +219,8 @@ var Win32WidgetSet: TWin32WidgetSet absolute WidgetSet; + MainOnTaskBarForm: TMainOnTaskBarForm; - const BOOL_RESULT: array[Boolean] of String = ('False', 'True'); ClsName: array[0..6] of char = 'Window'#0; Index: lcl/interfaces/win32/win32object.inc =================================================================== --- lcl/interfaces/win32/win32object.inc (revision 27242) +++ lcl/interfaces/win32/win32object.inc (working copy) @@ -192,6 +192,64 @@ Assert(False, 'Trace:Win32Object.Init - Exit'); end; +procedure TWin32WidgetSet.AppSetMainForm2(Value: boolean); +begin +if Value then + begin + Application.ShowMainForm:=false; + Application.CreateForm(TMainOnTaskBarForm,MainOnTaskBarForm); + MainOnTaskBarForm.Name:='MainOnTaskBarFormEx'; + MainOnTaskBarForm.BorderStyle:=bsNone; + MainOnTaskBarForm.Width:=0; + MainOnTaskBarForm.Height:=0; + end; +end; + +procedure TWin32WidgetSet.AppTerminateEx(Value: boolean); +begin +if Application.MainFormOnTaskBar then + begin + if Value then + Application.Terminate + end; +end; + +procedure TWin32WidgetSet.AppMinimizeEx; +var + i: Integer; + AForm: TCustomForm; +begin + if Screen=nil then exit; + for i:=0 to Screen.CustomFormCount-1 do begin + begin + AForm:=Screen.CustomForms[i]; + if (AForm.Parent=nil) and AForm.HandleAllocated + and (AForm.Name <> Application.MainForm2.Name) + and AForm.Visible then begin + ShowWindow(AForm.Handle, SW_HIDE); + end; + end; + end; +end; + +procedure TWin32WidgetSet.AppRestoreEx; +var + i: Integer; + AForm: TCustomForm; +begin + if Screen=nil then exit; + for i:=0 to Screen.CustomFormCount-1 do begin + begin + AForm:=Screen.CustomForms[i]; + if (AForm.Parent=nil) and AForm.HandleAllocated + and (AForm.Name <> Application.MainForm2.Name) + and AForm.Visible then begin + ShowWindow(AForm.Handle, SW_SHOW); + end; + end; + end; +end; + {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppMinimize Params: None |
|
MainFormOnTaskBar2.patch put the functions into nterfaces/win32/ws...pas |
|
> TApplication is a kind of form in Lazarus and delphi. Only in desktop windows > In delphi, "Application.MainFormOnTaskbar := True; > should be after Application.Initialize and before main form creation. I think that we can skip that and start with this property set to true with TApplication creates. It cannot start with value False because value False is not cross-platform. It cannot be implemented for Mac OS X for example. False would also be incompatible with projects from previous versions which is an unneeded headache. But let's see what other developers think. PS: Ah, and adding ifdefs to newly created apps should almost never happen. And in this case it isn't even necessary because the true value should be the default and is the only value supported in all platforms. |
|
@Felipe: If I understand the function of MainFormOnTaskbar right, it must be False by default on desktop Windows platforms, because those show the bar of the application window instead of the MainForm window. And it should be documented somewhere (wiki? help file?) that this property is only usable one some platforms (only if it get's commited of course ^^). Regards, Sven |
|
I don't see a single reason to implement this property into LCL and such property will flood lcl. According to embarcadero docs this is important only for Vista Aero effects and newest MS operating systems. What should it do under linux or macosx ? eg. there's no "application hidden window" under qt or gtk2. |
2010-09-06 16:34
|
MFormOnTaskBar.patch (5,436 bytes)
Index: interfaces/win32/win32callback.inc =================================================================== --- interfaces/win32/win32callback.inc (revision 27273) +++ interfaces/win32/win32callback.inc (working copy) @@ -799,11 +799,13 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, Application.MainForm.Left, Application.MainForm.Top, Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -1166,14 +1168,7 @@ WM_CLOSE: begin - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and - (Application.MainForm <> nil) then - begin - Windows.SendMessage(Application.MainForm.Handle, WM_CLOSE, 0, 0); - end - else begin - LMessage.Msg := LM_CLOSEQUERY; - end; + LMessage.Msg := LM_CLOSEQUERY; // default is to destroy window, inhibit WinProcess := false; end; @@ -1461,7 +1456,7 @@ begin if WParam <> 0 Then LMessage.Msg := LM_SETEDITABLE; - if Window = TWin32WidgetSet(WidgetSet).FAppHandle then + {if Window = TWin32WidgetSet(WidgetSet).FAppHandle then if WParam = 0 then begin RemoveStayOnTopFlags(Window); @@ -1471,7 +1466,7 @@ begin RestoreStayOnTopFlags(Window); Screen.EnableForms(DisabledForms); - end; + end; } // disable child windows of for example groupboxes, but not of forms if Assigned(lWinControl) and not (lWinControl is TCustomForm) then @@ -2053,7 +2048,7 @@ Status := LParam; end; //DebugLn(GetStackTrace(false)); - if assigned(lWinControl) and ((WParam<>0) or not lWinControl.Visible) + {if assigned(lWinControl) and ((WParam<>0) or not lWinControl.Visible) and ((WParam=0) or lWinControl.Visible) and (Application<>nil) and (lWinControl=Application.MainForm) then begin @@ -2062,7 +2057,7 @@ else Flags := SW_SHOWNOACTIVATE; Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, Flags); - end; + end; } end; WM_SYSCHAR: begin @@ -2287,7 +2282,7 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: interfaces/win32/win32object.inc =================================================================== --- interfaces/win32/win32object.inc (revision 27273) +++ interfaces/win32/win32object.inc (working copy) @@ -83,8 +83,8 @@ if FDotsPatternBitmap <> 0 then DeleteObject(FDotsPatternBitmap); - if FAppHandle <> 0 then - DestroyWindow(FAppHandle); + //if FAppHandle <> 0 then + // DestroyWindow(FAppHandle); if UnicodeEnabledOS then begin @@ -144,7 +144,6 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then @@ -173,10 +172,6 @@ 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); // initialize ScreenInfo Handle := GetDesktopWindow; @@ -189,6 +184,8 @@ // Thread.Synchronize support WakeMainThread := @HandleWakeMainThread; + SetWindowLong(FAppHandle, GWL_EXSTYLE, not WS_EX_APPWINDOW); + Assert(False, 'Trace:Win32Object.Init - Exit'); end; @@ -216,7 +213,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None Index: interfaces/win32/win32wsforms.pp =================================================================== --- interfaces/win32/win32wsforms.pp (revision 27273) +++ interfaces/win32/win32wsforms.pp (working copy) @@ -398,6 +398,11 @@ FlagsEx := FlagsEx or WS_EX_APPWINDOW; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + if (Application.MainForm = lForm) then + begin + Parent := GetDesktopWindow; + FlagsEx := FlagsEx or WS_EX_APPWINDOW; + end; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -616,6 +621,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
Thanks a lot for the reply. There should not be such property as Delphi. No effection on other platform. Lazarus IDE on win32 works fine. |
|
Anyone can review MFormOnTaskBar.patch on win32 ? |
|
Excuse me, I find some bug. 1. PopMenu shows inversely. 2. MainForm actived but the other forms do not be brought to front of other process. |
2010-09-07 17:50
|
MainFormOnTaskBar3.patch (6,037 bytes)
Index: interfaces/win32/win32callback.inc =================================================================== --- interfaces/win32/win32callback.inc (revision 27273) +++ interfaces/win32/win32callback.inc (working copy) @@ -799,11 +799,13 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, Application.MainForm.Left, Application.MainForm.Top, Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -1106,7 +1108,21 @@ LMessage.LParam := LParam; end; end; + if LOWORD(WParam) = WA_ACTIVE then + if Window = Application.MainForm.Handle then + begin + if Application.MainForm.HandleAllocated then + begin + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + Application.MainForm.Left, Application.MainForm.Top, + Application.MainForm.Width, 0, SWP_NOACTIVATE); + Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOACTIVATE or SWP_NOSIZE or SWP_NOMOVE); + end; + end; end; + WM_IME_ENDCOMPOSITION: begin {IME Windows the composition has finished} @@ -1166,14 +1182,7 @@ WM_CLOSE: begin - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and - (Application.MainForm <> nil) then - begin - Windows.SendMessage(Application.MainForm.Handle, WM_CLOSE, 0, 0); - end - else begin - LMessage.Msg := LM_CLOSEQUERY; - end; + LMessage.Msg := LM_CLOSEQUERY; // default is to destroy window, inhibit WinProcess := false; end; @@ -1461,7 +1470,8 @@ begin if WParam <> 0 Then LMessage.Msg := LM_SETEDITABLE; - if Window = TWin32WidgetSet(WidgetSet).FAppHandle then + //if Window = TWin32WidgetSet(WidgetSet).FAppHandle then + if Window = Application.MainForm.Handle then if WParam = 0 then begin RemoveStayOnTopFlags(Window); @@ -2053,7 +2063,7 @@ Status := LParam; end; //DebugLn(GetStackTrace(false)); - if assigned(lWinControl) and ((WParam<>0) or not lWinControl.Visible) + {if assigned(lWinControl) and ((WParam<>0) or not lWinControl.Visible) and ((WParam=0) or lWinControl.Visible) and (Application<>nil) and (lWinControl=Application.MainForm) then begin @@ -2062,7 +2072,7 @@ else Flags := SW_SHOWNOACTIVATE; Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, Flags); - end; + end; } end; WM_SYSCHAR: begin @@ -2287,7 +2297,7 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: interfaces/win32/win32object.inc =================================================================== --- interfaces/win32/win32object.inc (revision 27273) +++ interfaces/win32/win32object.inc (working copy) @@ -83,8 +83,8 @@ if FDotsPatternBitmap <> 0 then DeleteObject(FDotsPatternBitmap); - if FAppHandle <> 0 then - DestroyWindow(FAppHandle); + //if FAppHandle <> 0 then + // DestroyWindow(FAppHandle); if UnicodeEnabledOS then begin @@ -144,7 +144,6 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then @@ -173,10 +172,6 @@ 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); // initialize ScreenInfo Handle := GetDesktopWindow; @@ -189,6 +184,8 @@ // Thread.Synchronize support WakeMainThread := @HandleWakeMainThread; + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + Assert(False, 'Trace:Win32Object.Init - Exit'); end; @@ -216,7 +213,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None Index: interfaces/win32/win32wsforms.pp =================================================================== --- interfaces/win32/win32wsforms.pp (revision 27273) +++ interfaces/win32/win32wsforms.pp (working copy) @@ -398,6 +398,11 @@ FlagsEx := FlagsEx or WS_EX_APPWINDOW; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + if (Application.MainForm = lForm) then + begin + Parent := GetDesktopWindow; + FlagsEx := FlagsEx or WS_EX_APPWINDOW; + end; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -616,6 +621,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
In MainFormOnTaskBar3.patch, the bugs have been fixed. |
|
There is property for TForm.ShowInTaskBar, i think it compensate the Delphi one. |
2010-09-08 03:05
|
MainFormOnTaskBar4.patch (5,038 bytes)
Index: win32/win32callback.inc =================================================================== --- win32/win32callback.inc (revision 27276) +++ win32/win32callback.inc (working copy) @@ -799,11 +799,13 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, Application.MainForm.Left, Application.MainForm.Top, Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -1106,6 +1108,14 @@ LMessage.LParam := LParam; end; end; + if (Application.MainForm <> nil) and (LOWORD(WParam) = WA_ACTIVE) + and (Window = Application.MainForm.Handle) then + begin + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + end; end; WM_IME_ENDCOMPOSITION: begin @@ -1166,14 +1176,7 @@ WM_CLOSE: begin - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and - (Application.MainForm <> nil) then - begin - Windows.SendMessage(Application.MainForm.Handle, WM_CLOSE, 0, 0); - end - else begin - LMessage.Msg := LM_CLOSEQUERY; - end; + LMessage.Msg := LM_CLOSEQUERY; // default is to destroy window, inhibit WinProcess := false; end; @@ -2019,7 +2022,10 @@ if (Window = Win32WidgetSet.AppHandle) then begin if not IsIconic(Window) and IsWindow(WindowLastFocused) then + begin + SendMessage(Win32WidgetSet.FAppHandle, WM_ACTIVATE, 0, 0); SetFocus(WindowLastFocused); + end; Result := 0; Exit; end; @@ -2287,7 +2293,7 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: win32/win32object.inc =================================================================== --- win32/win32object.inc (revision 27276) +++ win32/win32object.inc (working copy) @@ -83,8 +83,8 @@ if FDotsPatternBitmap <> 0 then DeleteObject(FDotsPatternBitmap); - if FAppHandle <> 0 then - DestroyWindow(FAppHandle); + //if FAppHandle <> 0 then + // DestroyWindow(FAppHandle); if UnicodeEnabledOS then begin @@ -144,7 +144,6 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then @@ -173,10 +172,6 @@ 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); // initialize ScreenInfo Handle := GetDesktopWindow; @@ -189,6 +184,8 @@ // Thread.Synchronize support WakeMainThread := @HandleWakeMainThread; + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + Assert(False, 'Trace:Win32Object.Init - Exit'); end; @@ -216,7 +213,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None Index: win32/win32wsforms.pp =================================================================== --- win32/win32wsforms.pp (revision 27276) +++ win32/win32wsforms.pp (working copy) @@ -398,6 +398,11 @@ FlagsEx := FlagsEx or WS_EX_APPWINDOW; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + if (Application.MainForm = lForm) then + begin + Parent := GetDesktopWindow; + FlagsEx := FlagsEx or WS_EX_APPWINDOW; + end; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -616,6 +621,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
2010-09-08 05:06
|
MainFormOnTaskBar5.patch (5,704 bytes)
Index: win32/win32callback.inc =================================================================== --- win32/win32callback.inc (revision 27276) +++ win32/win32callback.inc (working copy) @@ -799,11 +799,13 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, Application.MainForm.Left, Application.MainForm.Top, Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -1106,6 +1108,25 @@ LMessage.LParam := LParam; end; end; + if (Application.MainForm <> nil) and ((LOWORD(WParam) = WA_ACTIVE) or (LOWORD(WParam) = WA_CLICKACTIVE)) + and (Window = Application.MainForm.Handle) then + begin + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + SetFocus(Application.MainForm.Handle); + end; + if (Application.MainForm <> nil) and ((LOWORD(WParam) = WA_ACTIVE) or (LOWORD(WParam) = WA_CLICKACTIVE)) + and (lWinControl is TCustomForm) + and (Window <> Application.MainForm.Handle) then + begin + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + SetFocus(TWin32WidgetSet(WidgetSet).FAppHandle); + end; end; WM_IME_ENDCOMPOSITION: begin @@ -1166,14 +1187,7 @@ WM_CLOSE: begin - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and - (Application.MainForm <> nil) then - begin - Windows.SendMessage(Application.MainForm.Handle, WM_CLOSE, 0, 0); - end - else begin - LMessage.Msg := LM_CLOSEQUERY; - end; + LMessage.Msg := LM_CLOSEQUERY; // default is to destroy window, inhibit WinProcess := false; end; @@ -2019,7 +2033,10 @@ if (Window = Win32WidgetSet.AppHandle) then begin if not IsIconic(Window) and IsWindow(WindowLastFocused) then + begin + SendMessage(Win32WidgetSet.FAppHandle, WM_ACTIVATE, 0, 0); SetFocus(WindowLastFocused); + end; Result := 0; Exit; end; @@ -2287,7 +2304,7 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: win32/win32object.inc =================================================================== --- win32/win32object.inc (revision 27276) +++ win32/win32object.inc (working copy) @@ -83,8 +83,8 @@ if FDotsPatternBitmap <> 0 then DeleteObject(FDotsPatternBitmap); - if FAppHandle <> 0 then - DestroyWindow(FAppHandle); + //if FAppHandle <> 0 then + // DestroyWindow(FAppHandle); if UnicodeEnabledOS then begin @@ -144,7 +144,6 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then @@ -173,10 +172,6 @@ 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); // initialize ScreenInfo Handle := GetDesktopWindow; @@ -189,6 +184,8 @@ // Thread.Synchronize support WakeMainThread := @HandleWakeMainThread; + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + Assert(False, 'Trace:Win32Object.Init - Exit'); end; @@ -216,7 +213,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None Index: win32/win32wsforms.pp =================================================================== --- win32/win32wsforms.pp (revision 27276) +++ win32/win32wsforms.pp (working copy) @@ -398,6 +398,11 @@ FlagsEx := FlagsEx or WS_EX_APPWINDOW; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + if (Application.MainForm = lForm) then + begin + Parent := GetDesktopWindow; + FlagsEx := FlagsEx or WS_EX_APPWINDOW; + end; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -616,6 +621,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
2010-09-08 17:33
|
MainFormOnTaskBar6.patch (6,775 bytes)
Index: win32/win32callback.inc =================================================================== --- win32/win32callback.inc (revision 27284) +++ win32/win32callback.inc (working copy) @@ -799,11 +799,13 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, + {Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); + Application.MainForm.Width, 0, SWP_NOACTIVATE);} if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -1106,6 +1108,25 @@ LMessage.LParam := LParam; end; end; + if (Application.MainForm <> nil) and ((LOWORD(WParam) = WA_ACTIVE) or (LOWORD(WParam) = WA_CLICKACTIVE)) + and (Window = Application.MainForm.Handle) then + begin + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + //SetFocus(Application.MainForm.Handle); + end; + if (Application.MainForm <> nil) and ((LOWORD(WParam) = WA_ACTIVE) or (LOWORD(WParam) = WA_CLICKACTIVE)) + and (lWinControl is TCustomForm) + and (Window <> Application.MainForm.Handle) then + begin + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + //SetFocus(TWin32WidgetSet(WidgetSet).FAppHandle); + end; end; WM_IME_ENDCOMPOSITION: begin @@ -1166,14 +1187,15 @@ WM_CLOSE: begin - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and + {if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and (Application.MainForm <> nil) then begin - Windows.SendMessage(Application.MainForm.Handle, WM_CLOSE, 0, 0); + //Windows.SendMessage(Application.MainForm.Handle, WM_CLOSE, 0, 0); + LMessage.Msg := LM_CLOSEQUERY; end - else begin + else begin } LMessage.Msg := LM_CLOSEQUERY; - end; + //end; // default is to destroy window, inhibit WinProcess := false; end; @@ -2019,7 +2041,10 @@ if (Window = Win32WidgetSet.AppHandle) then begin if not IsIconic(Window) and IsWindow(WindowLastFocused) then + begin + SendMessage(Win32WidgetSet.FAppHandle, WM_ACTIVATE, 0, 0); SetFocus(WindowLastFocused); + end; Result := 0; Exit; end; @@ -2287,7 +2312,7 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: win32/win32object.inc =================================================================== --- win32/win32object.inc (revision 27284) +++ win32/win32object.inc (working copy) @@ -83,8 +83,8 @@ if FDotsPatternBitmap <> 0 then DeleteObject(FDotsPatternBitmap); - if FAppHandle <> 0 then - DestroyWindow(FAppHandle); + //if FAppHandle <> 0 then + // DestroyWindow(FAppHandle); if UnicodeEnabledOS then begin @@ -144,7 +144,6 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then @@ -173,10 +172,6 @@ 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); // initialize ScreenInfo Handle := GetDesktopWindow; @@ -189,6 +184,8 @@ // Thread.Synchronize support WakeMainThread := @HandleWakeMainThread; + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + Assert(False, 'Trace:Win32Object.Init - Exit'); end; @@ -216,7 +213,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -486,22 +482,22 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - {$ifdef WindowsUnicodeSupport} + (*{$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then begin Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))); end else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); {$else} Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} + {$endif} *) end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if AVisible then + {if AVisible then Windows.ShowWindow(FAppHandle, SW_SHOW) else - Windows.ShowWindow(FAppHandle, SW_HIDE); + Windows.ShowWindow(FAppHandle, SW_HIDE); } end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: win32/win32wsforms.pp =================================================================== --- win32/win32wsforms.pp (revision 27284) +++ win32/win32wsforms.pp (working copy) @@ -398,6 +398,11 @@ FlagsEx := FlagsEx or WS_EX_APPWINDOW; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + if (Application.MainForm = lForm) then + begin + Parent := GetDesktopWindow; + FlagsEx := FlagsEx or WS_EX_APPWINDOW; + end; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -616,6 +621,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
Sorry, MainFormOnTaskBar6.patch is the recommended version now |
|
can all previous patches be deleted? |
|
Thanks, of course. At first, I want to create a form to act as MainForm, but now it is clear that the form is not required like the property MainFormOnTaskBar. Then the MainForm' s parent was set to desktop window to minimize to taskbar and the application window which is always hidden manages the other windows(Forms). When MainForm activated, other forms should be brought to front, and vice versa. This is done by windows API SetWindowPos. The last patch fixed the bug "the Application window was shown as soon as closequery happened" by commenting TWin32WidgetSet.AppSetVisible function. |
2010-09-09 03:27
|
MainFormOnTaskBar7.patch (6,894 bytes)
Index: win32/win32callback.inc =================================================================== --- win32/win32callback.inc (revision 27284) +++ win32/win32callback.inc (working copy) @@ -799,11 +799,13 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, + {Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); + Application.MainForm.Width, 0, SWP_NOACTIVATE);} if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -1106,6 +1108,26 @@ LMessage.LParam := LParam; end; end; + //Bring the forms to front of other process + if (Application.MainForm <> nil) and ((LOWORD(WParam) = WA_ACTIVE) or (LOWORD(WParam) = WA_CLICKACTIVE)) + and (Window = Application.MainForm.Handle) then + begin + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + //SetFocus(Application.MainForm.Handle); Do not need SetFocus + end; + if (Application.MainForm <> nil) and ((LOWORD(WParam) = WA_ACTIVE) or (LOWORD(WParam) = WA_CLICKACTIVE)) + and (lWinControl is TCustomForm) + and (Window <> Application.MainForm.Handle) then + begin + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + //SetFocus(TWin32WidgetSet(WidgetSet).FAppHandle); + end; end; WM_IME_ENDCOMPOSITION: begin @@ -1166,14 +1188,15 @@ WM_CLOSE: begin - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and + //Now MainForm' parent is not FAppHandle LM_CLOSEQUERY enough + {if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and (Application.MainForm <> nil) then begin - Windows.SendMessage(Application.MainForm.Handle, WM_CLOSE, 0, 0); + //Windows.SendMessage(Application.MainForm.Handle, WM_CLOSE, 0, 0); end - else begin + else begin } LMessage.Msg := LM_CLOSEQUERY; - end; + //end; // default is to destroy window, inhibit WinProcess := false; end; @@ -2019,7 +2042,10 @@ if (Window = Win32WidgetSet.AppHandle) then begin if not IsIconic(Window) and IsWindow(WindowLastFocused) then + //begin + // SendMessage(Win32WidgetSet.FAppHandle, WM_ACTIVATE, 0, 0); SetFocus(WindowLastFocused); + //end; Result := 0; Exit; end; @@ -2287,7 +2313,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: win32/win32object.inc =================================================================== --- win32/win32object.inc (revision 27284) +++ win32/win32object.inc (working copy) @@ -144,7 +144,6 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then @@ -173,10 +172,13 @@ AIcon := Windows.LoadIcon(MainInstance, 'MAINICON'); AppSetIcon(AIcon, AIcon); // remove useless menuitems from sysmenu + // Do not need these for always hidden window + { 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); + } // initialize ScreenInfo Handle := GetDesktopWindow; @@ -189,6 +191,9 @@ // Thread.Synchronize support WakeMainThread := @HandleWakeMainThread; + //Application window is not shown on taskbar now + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + Assert(False, 'Trace:Win32Object.Init - Exit'); end; @@ -216,7 +221,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -486,22 +490,23 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - {$ifdef WindowsUnicodeSupport} + (*{$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then begin Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))); end else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); {$else} Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} + {$endif} *) end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if AVisible then + //This action show application window on closequery + {if AVisible then Windows.ShowWindow(FAppHandle, SW_SHOW) else - Windows.ShowWindow(FAppHandle, SW_HIDE); + Windows.ShowWindow(FAppHandle, SW_HIDE); } end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: win32/win32wsforms.pp =================================================================== --- win32/win32wsforms.pp (revision 27284) +++ win32/win32wsforms.pp (working copy) @@ -398,6 +398,12 @@ FlagsEx := FlagsEx or WS_EX_APPWINDOW; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm parent to desktop window + if (Application.MainForm = lForm) then + begin + Parent := GetDesktopWindow; + FlagsEx := FlagsEx or WS_EX_APPWINDOW; + end; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -616,6 +622,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
There are comments in last patch now. |
|
To help increase the readability of a patch, don't comment code you want to remove, but just remove it. If you look at line 12 of patch 7 Application.MainForm.Left, Application.MainForm.Top, there is no + or - sign, so it seems that this line remains unchanged after applying the patch, while in fact isn't active anymore, because it is commented. |
2010-09-09 09:42
|
MainFormOnTaskBar8.patch (6,076 bytes)
Index: win32/win32callback.inc =================================================================== --- win32/win32callback.inc (revision 27284) +++ win32/win32callback.inc (working copy) @@ -799,11 +799,10 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -1106,6 +1105,24 @@ LMessage.LParam := LParam; end; end; + //Bring the forms above other processes when actived + if (Application.MainForm <> nil) and ((LOWORD(WParam) = WA_ACTIVE) or (LOWORD(WParam) = WA_CLICKACTIVE)) + and (Window = Application.MainForm.Handle) then + begin + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + end; + if (Application.MainForm <> nil) and ((LOWORD(WParam) = WA_ACTIVE) or (LOWORD(WParam) = WA_CLICKACTIVE)) + and (lWinControl is TCustomForm) + and (Window <> Application.MainForm.Handle) then + begin + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + end; end; WM_IME_ENDCOMPOSITION: begin @@ -1166,14 +1183,9 @@ WM_CLOSE: begin - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and - (Application.MainForm <> nil) then - begin - Windows.SendMessage(Application.MainForm.Handle, WM_CLOSE, 0, 0); - end - else begin - LMessage.Msg := LM_CLOSEQUERY; - end; + //Now MainForm' parent is not FAppHandle, LM_CLOSEQUERY enough + LMessage.Msg := LM_CLOSEQUERY; + // default is to destroy window, inhibit WinProcess := false; end; @@ -2287,7 +2299,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: win32/win32object.inc =================================================================== --- win32/win32object.inc (revision 27284) +++ win32/win32object.inc (working copy) @@ -144,7 +144,6 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then @@ -172,11 +171,7 @@ // set nice main icon 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); + // remove useless menuitems from sysmenu, do not need these for forever hidden window // initialize ScreenInfo Handle := GetDesktopWindow; @@ -189,6 +184,9 @@ // Thread.Synchronize support WakeMainThread := @HandleWakeMainThread; + //TApplication window is no longer shown on taskbar + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + Assert(False, 'Trace:Win32Object.Init - Exit'); end; @@ -216,7 +214,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -486,22 +483,12 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - {$ifdef WindowsUnicodeSupport} - if UnicodeEnabledOS then - begin - Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))); - end else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); - {$else} - Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} + end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if AVisible then - Windows.ShowWindow(FAppHandle, SW_SHOW) - else - Windows.ShowWindow(FAppHandle, SW_HIDE); + //This action show TApplication window on closequery, removed end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: win32/win32wsforms.pp =================================================================== --- win32/win32wsforms.pp (revision 27284) +++ win32/win32wsforms.pp (working copy) @@ -398,6 +398,12 @@ FlagsEx := FlagsEx or WS_EX_APPWINDOW; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm parent to desktop window + if (Application.MainForm = lForm) then + begin + Parent := GetDesktopWindow; + FlagsEx := FlagsEx or WS_EX_APPWINDOW; + end; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -616,6 +622,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
Thanks. I learnt. They are removed in MainFormOnTaskBar8.patch |
2010-09-15 16:12
|
MainFormOnTaskBar9.patch (11,187 bytes)
Index: ide/main.pp =================================================================== --- ide/main.pp (revision 27341) +++ ide/main.pp (working copy) @@ -3350,6 +3350,7 @@ // do not call 'AForm.Show', because it will set Visible to true AForm.BringToFront; LCLIntf.ShowWindow(AForm.Handle,SW_SHOWNORMAL); + AForm.MinVisible := True; end; procedure TMainIDE.DoViewAnchorEditor(Show: boolean); @@ -6186,6 +6187,7 @@ if NewComponent is TControl then TControl(NewComponent).ControlStyle:= TControl(NewComponent).ControlStyle - [csNoDesignVisible]; LCLIntf.ShowWindow(DesignerForm.Handle, ShowCommands[AnUnitInfo.ComponentState]); + DesignerForm.MinVisible := True; FLastFormActivated := DesignerForm; end; Index: lcl/forms.pp =================================================================== --- lcl/forms.pp (revision 27358) +++ lcl/forms.pp (working copy) @@ -569,6 +569,7 @@ function DoUpdateAction(TheAction: TBasicAction): boolean; procedure UpdateActions; virtual; public + MinVisible: boolean; constructor Create(AOwner: TComponent); override; constructor CreateNew(AOwner: TComponent; Num: Integer = 0); virtual; destructor Destroy; override; Index: lcl/include/customform.inc =================================================================== --- lcl/include/customform.inc (revision 27358) +++ lcl/include/customform.inc (working copy) @@ -457,6 +457,7 @@ {$ENDIF} if (fsShowing in FFormState) then exit; Include(FFormState, fsShowing); + MinVisible := True; try // only fire event if reason is not some other window hide/showing etc. if Message.Status = 0 then @@ -495,6 +496,7 @@ begin UpdateShowInTaskBar; end; + MinVisible := True; end; {------------------------------------------------------------------------------ @@ -1942,6 +1944,7 @@ inherited Create(AOwner); Visible := False; + MinVisible := False; fCompStyle:= csForm; FMenu := nil; @@ -2117,6 +2120,7 @@ if (fsModal in FormState) and (ModalResult = 0) then ModalResult := mrCancel; Visible := False; + MinVisible := False; end; {------------------------------------------------------------------------------ @@ -2126,6 +2130,7 @@ begin Visible := True; BringToFront; + MinVisible := True; end; {------------------------------------------------------------------------------ @@ -2134,6 +2139,7 @@ procedure TCustomForm.ShowOnTop; begin Visible := True; + MinVisible := True; if WindowState = wsMinimized then WindowState := wsNormal; BringToFront; Index: lcl/interfaces/win32/win32callback.inc =================================================================== --- lcl/interfaces/win32/win32callback.inc (revision 27358) +++ lcl/interfaces/win32/win32callback.inc (working copy) @@ -758,8 +758,9 @@ procedure HandleSysCommand; var - ParentForm: TCustomForm; + ParentForm, AForm: TCustomForm; prevFocus: HWND; + i: integer; begin // forward keystroke to show window menu, if parent form has no menu // if wparam contains SC_KEYMENU, lparam contains key pressed @@ -788,7 +789,6 @@ SC_MINIMIZE: begin - if (Application <> nil) and (lWinControl <> nil) and (Application.MainForm <> nil) and (Application.MainForm = lWinControl) then @@ -799,13 +799,23 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + begin + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + AForm:=Screen.CustomForms[i]; + if (AForm.Parent=nil) and AForm.HandleAllocated + and (AForm.Handle <> Application.MainForm.Handle) then + begin + if AForm.MinVisible then + Windows.ShowWindow(AForm.Handle, SW_HIDE); + end; + end; + end; + end; end; - PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); WinProcess := False; Application.IntfAppMinimize; @@ -814,8 +824,7 @@ SC_RESTORE: begin - - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and + if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and (Application <> nil) then begin PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -823,7 +832,21 @@ if (Application.MainForm <> nil) and Application.MainForm.HandleAllocated then begin if Application.MainForm.HandleObjectShouldBeVisible then + begin + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + AForm:=Screen.CustomForms[i]; + if (AForm.Parent=nil) and AForm.HandleAllocated + and (AForm.Handle <> Application.MainForm.Handle) then + begin + if AForm.MinVisible then + Windows.ShowWindow(AForm.Handle, SW_SHOWNA) + end; + end; + end; Windows.ShowWindow(Application.MainForm.Handle, SW_SHOWNA); + end; end; Application.IntfAppRestore; end; @@ -2053,16 +2076,6 @@ Status := LParam; end; //DebugLn(GetStackTrace(false)); - if assigned(lWinControl) and ((WParam<>0) or not lWinControl.Visible) - and ((WParam=0) or lWinControl.Visible) - and (Application<>nil) and (lWinControl=Application.MainForm) then - begin - if WParam=0 then - Flags := SW_HIDE - else - Flags := SW_SHOWNOACTIVATE; - Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, Flags); - end; end; WM_SYSCHAR: begin @@ -2287,7 +2300,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: lcl/interfaces/win32/win32object.inc =================================================================== --- lcl/interfaces/win32/win32object.inc (revision 27358) +++ lcl/interfaces/win32/win32object.inc (working copy) @@ -144,25 +144,24 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then FAppHandle := CreateWindowW(@ClsNameW, PWideChar(UTF8ToUTF16(Application.Title)), - WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,} 0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,} 0, 0, HWND(nil), HMENU(nil), HInstance, nil); @@ -172,11 +171,7 @@ // set nice main icon 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); + // remove useless menuitems from sysmenu, do not need these for forever hidden window // initialize ScreenInfo Handle := GetDesktopWindow; @@ -216,7 +211,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -486,22 +480,16 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - {$ifdef WindowsUnicodeSupport} - if UnicodeEnabledOS then - begin - Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))); - end else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); - {$else} - Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} + end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if AVisible then - Windows.ShowWindow(FAppHandle, SW_SHOW) - else - Windows.ShowWindow(FAppHandle, SW_HIDE); + //This action show TApplication window on closequery, removed + SetWindowLong(FAppHandle, GWL_STYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: lcl/interfaces/win32/win32wsforms.pp =================================================================== --- lcl/interfaces/win32/win32wsforms.pp (revision 27358) +++ lcl/interfaces/win32/win32wsforms.pp (working copy) @@ -398,6 +398,9 @@ FlagsEx := FlagsEx or WS_EX_APPWINDOW; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm to taskbar + if (Application.MainForm = lForm) then + FlagsEx := FlagsEx or WS_EX_APPWINDOW; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -616,6 +619,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
The MainFormOnTaskBar9.patch uses the frozen and hidden tapplicaiton window as parent therefore mainform can be between two forms. Can we set MainForm.Handle to Application.Handle? |
|
The MainFormOnTaskBar9.patch bug is hint window shows by restore. |
2010-09-17 09:52
|
MainFormOnTaskBar10.patch (5,965 bytes)
Index: win32callback.inc =================================================================== --- win32callback.inc (revision 27389) +++ win32callback.inc (working copy) @@ -802,11 +802,11 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + begin + Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + end; end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -1109,6 +1109,26 @@ LMessage.LParam := LParam; end; end; + //Bring the forms above other processes when actived + if ((LOWORD(WParam) = WA_ACTIVE) or (LOWORD(WParam) = WA_CLICKACTIVE)) + and (lWinControl is TCustomForm) and (Application.MainForm <> nil) + and (window = TWin32WidgetSet(WidgetSet).AppHandle) then + begin + if (Window = Application.MainForm.Handle) then + begin + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOACTIVATE); + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + end + else + begin + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOACTIVATE); + end; + end; end; WM_IME_ENDCOMPOSITION: begin @@ -1169,14 +1189,8 @@ WM_CLOSE: begin - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and - (Application.MainForm <> nil) then - begin - Windows.SendMessage(Application.MainForm.Handle, WM_CLOSE, 0, 0); - end - else begin - LMessage.Msg := LM_CLOSEQUERY; - end; + //Now MainForm' parent is not FAppHandle, LM_CLOSEQUERY enough + LMessage.Msg := LM_CLOSEQUERY; // default is to destroy window, inhibit WinProcess := false; end; @@ -2290,7 +2304,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: win32object.inc =================================================================== --- win32object.inc (revision 27389) +++ win32object.inc (working copy) @@ -144,7 +144,6 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then @@ -172,11 +171,7 @@ // set nice main icon 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); + // remove useless menuitems from sysmenu, do not need these for forever hidden window // initialize ScreenInfo Handle := GetDesktopWindow; @@ -189,6 +184,9 @@ // Thread.Synchronize support WakeMainThread := @HandleWakeMainThread; + //TApplication window is no longer shown on taskbar + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + Assert(False, 'Trace:Win32Object.Init - Exit'); end; @@ -216,7 +214,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -486,22 +483,12 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - {$ifdef WindowsUnicodeSupport} - if UnicodeEnabledOS then - begin - Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))); - end else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); - {$else} - Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} + end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if AVisible then - Windows.ShowWindow(FAppHandle, SW_SHOW) - else - Windows.ShowWindow(FAppHandle, SW_HIDE); + //This action show TApplication window on closequery, removed end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: win32wsforms.pp =================================================================== --- win32wsforms.pp (revision 27389) +++ win32wsforms.pp (working copy) @@ -398,6 +398,12 @@ FlagsEx := FlagsEx or WS_EX_APPWINDOW; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm parent to desktop window + if (Application.MainForm = lForm) then + begin + Parent := GetDesktopWindow; + FlagsEx := FlagsEx or WS_EX_APPWINDOW; + end; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -616,6 +622,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
The The MainFormOnTaskBar12 disabled TApplication window and minimize by hiding the visible windows. The MainFormOnTaskBar10, 11.patch has a minimize bug. |
2010-09-17 10:17
|
MainFormOnTaskBar11.patch (5,742 bytes)
Index: interfaces/win32/win32callback.inc =================================================================== --- interfaces/win32/win32callback.inc (revision 27389) +++ interfaces/win32/win32callback.inc (working copy) @@ -802,11 +802,13 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + begin + Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + end; end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -1109,6 +1111,26 @@ LMessage.LParam := LParam; end; end; + //Bring the forms above other processes when actived + if ((LOWORD(WParam) = WA_ACTIVE) or (LOWORD(WParam) = WA_CLICKACTIVE)) + and (lWinControl is TCustomForm) and (Application.MainForm <> nil) + and (window = TWin32WidgetSet(WidgetSet).AppHandle) then + begin + if (Window = Application.MainForm.Handle) then + begin + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOACTIVATE); + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + end + else + begin + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOACTIVATE); + end; + end; end; WM_IME_ENDCOMPOSITION: begin @@ -2290,7 +2312,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: interfaces/win32/win32object.inc =================================================================== --- interfaces/win32/win32object.inc (revision 27389) +++ interfaces/win32/win32object.inc (working copy) @@ -144,7 +144,6 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then @@ -172,11 +171,7 @@ // set nice main icon 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); + // remove useless menuitems from sysmenu, do not need these for forever hidden window // initialize ScreenInfo Handle := GetDesktopWindow; @@ -189,6 +184,9 @@ // Thread.Synchronize support WakeMainThread := @HandleWakeMainThread; + //TApplication window is no longer shown on taskbar + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + Assert(False, 'Trace:Win32Object.Init - Exit'); end; @@ -216,7 +214,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -486,22 +483,12 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - {$ifdef WindowsUnicodeSupport} - if UnicodeEnabledOS then - begin - Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))); - end else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); - {$else} - Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} + end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if AVisible then - Windows.ShowWindow(FAppHandle, SW_SHOW) - else - Windows.ShowWindow(FAppHandle, SW_HIDE); + //This action show TApplication window on closequery, removed end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: interfaces/win32/win32wsforms.pp =================================================================== --- interfaces/win32/win32wsforms.pp (revision 27389) +++ interfaces/win32/win32wsforms.pp (working copy) @@ -398,6 +398,12 @@ FlagsEx := FlagsEx or WS_EX_APPWINDOW; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm parent to desktop window + if (Application.MainForm = lForm) then + begin + Parent := GetDesktopWindow; + FlagsEx := FlagsEx or WS_EX_APPWINDOW; + end; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -616,6 +622,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
2010-09-18 05:49
|
MainFormOnTaskBar12.patch (8,733 bytes)
Index: forms.pp =================================================================== --- forms.pp (revision 27401) +++ forms.pp (working copy) @@ -569,6 +569,7 @@ function DoUpdateAction(TheAction: TBasicAction): boolean; procedure UpdateActions; virtual; public + MinVisible: boolean; constructor Create(AOwner: TComponent); override; constructor CreateNew(AOwner: TComponent; Num: Integer = 0); virtual; destructor Destroy; override; Index: interfaces/win32/win32callback.inc =================================================================== --- interfaces/win32/win32callback.inc (revision 27401) +++ interfaces/win32/win32callback.inc (working copy) @@ -763,6 +763,7 @@ var ParentForm: TCustomForm; prevFocus: HWND; + i: integer; begin // forward keystroke to show window menu, if parent form has no menu // if wparam contains SC_KEYMENU, lparam contains key pressed @@ -791,7 +792,6 @@ SC_MINIMIZE: begin - if (Application <> nil) and (lWinControl <> nil) and (Application.MainForm <> nil) and (Application.MainForm = lWinControl) then @@ -802,11 +802,22 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + begin + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + Screen.CustomForms[i].MinVisible:=Screen.CustomForms[i].Showing; + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_HIDE); + end; + end; + end; + end; end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -817,7 +828,6 @@ SC_RESTORE: begin - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and (Application <> nil) then begin @@ -825,6 +835,17 @@ WinProcess := False; if (Application.MainForm <> nil) and Application.MainForm.HandleAllocated then begin + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_SHOWNA); + end; + end; + end; if Application.MainForm.HandleObjectShouldBeVisible then Windows.ShowWindow(Application.MainForm.Handle, SW_SHOWNA); end; @@ -2048,6 +2069,13 @@ end; WM_SHOWWINDOW: begin + if Window = TWin32WidgetSet(WidgetSet).FAppHandle then + begin + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + Exit; + end; Assert(False, 'Trace:WindowProc - Got WM_SHOWWINDOW'); with TLMShowWindow(LMessage) Do begin @@ -2290,7 +2318,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now, otherwise the MainForm will be terrible + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: interfaces/win32/win32object.inc =================================================================== --- interfaces/win32/win32object.inc (revision 27401) +++ interfaces/win32/win32object.inc (working copy) @@ -144,25 +144,24 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then FAppHandle := CreateWindowW(@ClsNameW, PWideChar(UTF8ToUTF16(Application.Title)), - WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,} 0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,} 0, 0, HWND(nil), HMENU(nil), HInstance, nil); @@ -172,11 +171,7 @@ // set nice main icon 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); + // remove useless menuitems from sysmenu, do not need these for forever hidden window // initialize ScreenInfo Handle := GetDesktopWindow; @@ -216,7 +211,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -486,22 +480,16 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - {$ifdef WindowsUnicodeSupport} - if UnicodeEnabledOS then - begin - Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))); - end else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); - {$else} - Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} + end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if AVisible then - Windows.ShowWindow(FAppHandle, SW_SHOW) - else - Windows.ShowWindow(FAppHandle, SW_HIDE); + //This action show TApplication window on closequery, disabled + SetWindowLong(FAppHandle, GWL_STYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: interfaces/win32/win32wsforms.pp =================================================================== --- interfaces/win32/win32wsforms.pp (revision 27401) +++ interfaces/win32/win32wsforms.pp (working copy) @@ -398,6 +398,9 @@ FlagsEx := FlagsEx or WS_EX_APPWINDOW; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm to taskbar + if (Application.MainForm = lForm) then + FlagsEx := FlagsEx or WS_EX_APPWINDOW; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -616,6 +619,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
After delphi 2007, the delphi mainform is all other forms' parent which behind all other forms. One of the patches above have a better solution, mainform is independent, other forms' parent is TApplication. So mainform can be above or under other forms but not be between them. |
|
The MainFormOnTaskBar12.patch has been applied on my computer for a long time. When the application crashed, TApplication window of the IDE will show. |
2010-11-12 02:14
|
MainFormOnTaskBar13.patch (10,281 bytes)
Index: dbctrls.pp =================================================================== --- dbctrls.pp (revision 28184) +++ dbctrls.pp (working copy) @@ -1020,6 +1020,7 @@ property DragCursor; property DragMode; property OnClick; + property OnDblClick; property OnDragDrop; property OnDragOver; property OnEndDrag; Index: forms.pp =================================================================== --- forms.pp (revision 28184) +++ forms.pp (working copy) @@ -570,6 +570,7 @@ function DoUpdateAction(TheAction: TBasicAction): boolean; procedure UpdateActions; virtual; public + MinVisible: boolean; constructor Create(AOwner: TComponent); override; constructor CreateNew(AOwner: TComponent; Num: Integer = 0); virtual; destructor Destroy; override; Index: include/dbimage.inc =================================================================== --- include/dbimage.inc (revision 28184) +++ include/dbimage.inc (working copy) @@ -133,12 +133,7 @@ end; procedure TDBImage.LoadPicture; - var s : Tstream; - GraphExt : string; - gc : TGraphicClass; - AGraphic : TGraphic; - begin if not FPictureLoaded then begin @@ -160,22 +155,11 @@ Picture.Clear; exit; end; - AGraphic := nil; try - GraphExt := s.ReadAnsiString; - - gc := GetGraphicClassForFileExtension(GraphExt); - if assigned(gc) then - begin - AGraphic := gc.Create; - AGraphic.LoadFromStream(s); - - Picture.Assign(AGraphic); - end; + Picture.LoadFromStream(S); finally - if assigned(AGraphic) then AGraphic.Free; s.Free; - end {try} + end end else Index: interfaces/win32/win32callback.inc =================================================================== --- interfaces/win32/win32callback.inc (revision 28184) +++ interfaces/win32/win32callback.inc (working copy) @@ -770,6 +770,7 @@ var ParentForm: TCustomForm; prevFocus: HWND; + i: integer; begin // forward keystroke to show window menu, if parent form has no menu // if wparam contains SC_KEYMENU, lparam contains key pressed @@ -798,7 +799,6 @@ SC_MINIMIZE: begin - if (Application <> nil) and (lWinControl <> nil) and (Application.MainForm <> nil) and (Application.MainForm = lWinControl) then @@ -809,11 +809,22 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + begin + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + Screen.CustomForms[i].MinVisible:=Screen.CustomForms[i].Showing; + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_HIDE); + end; + end; + end; + end; end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -824,7 +835,6 @@ SC_RESTORE: begin - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and (Application <> nil) then begin @@ -832,6 +842,17 @@ WinProcess := False; if (Application.MainForm <> nil) and Application.MainForm.HandleAllocated then begin + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_SHOWNA); + end; + end; + end; if Application.MainForm.HandleObjectShouldBeVisible then Windows.ShowWindow(Application.MainForm.Handle, SW_SHOWNA); end; @@ -2064,6 +2085,13 @@ end; WM_SHOWWINDOW: begin + if Window = TWin32WidgetSet(WidgetSet).FAppHandle then + begin + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + Exit; + end; Assert(False, 'Trace:WindowProc - Got WM_SHOWWINDOW'); with TLMShowWindow(LMessage) Do begin @@ -2306,7 +2334,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now, otherwise the MainForm will be terrible + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: interfaces/win32/win32object.inc =================================================================== --- interfaces/win32/win32object.inc (revision 28184) +++ interfaces/win32/win32object.inc (working copy) @@ -144,25 +144,24 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then FAppHandle := CreateWindowW(@ClsNameW, PWideChar(UTF8ToUTF16(Application.Title)), - WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,} 0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,} 0, 0, HWND(nil), HMENU(nil), HInstance, nil); @@ -172,11 +171,7 @@ // set nice main icon 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); + // remove useless menuitems from sysmenu, do not need these for forever hidden window // initialize ScreenInfo Handle := GetDesktopWindow; @@ -216,7 +211,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -486,22 +480,18 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - {$ifdef WindowsUnicodeSupport} - if UnicodeEnabledOS then - begin - Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))); - end else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); - {$else} - Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} + end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if AVisible then - Windows.ShowWindow(FAppHandle, SW_SHOW) - else - Windows.ShowWindow(FAppHandle, SW_HIDE); + //This action show TApplication window on closequery, disabled + {SetWindowLong(FAppHandle, GWL_STYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); } + SetWindowLong(FAppHandle, GWL_STYLE, GetWindowLong(FAppHandle, GWL_STYLE) or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, GetWindowLong(FAppHandle, GWL_EXSTYLE) or WS_DISABLED); end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: interfaces/win32/win32wsforms.pp =================================================================== --- interfaces/win32/win32wsforms.pp (revision 28184) +++ interfaces/win32/win32wsforms.pp (working copy) @@ -397,6 +397,9 @@ SubClassWndProc := @CustomFormWndProc; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm to taskbar + if (Application.MainForm = lForm) then + FlagsEx := FlagsEx or WS_EX_APPWINDOW; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -615,6 +618,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
MainFormOnTaskBar13.patch is on test. |
2010-11-19 03:47
|
MainFormOnTaskbar14-2.patch (11,735 bytes)
Index: dbctrls.pp =================================================================== --- dbctrls.pp (revision 28334) +++ dbctrls.pp (working copy) @@ -1020,6 +1020,7 @@ property DragCursor; property DragMode; property OnClick; + property OnDblClick; property OnDragDrop; property OnDragOver; property OnEndDrag; Index: forms.pp =================================================================== --- forms.pp (revision 28334) +++ forms.pp (working copy) @@ -570,6 +570,7 @@ function DoUpdateAction(TheAction: TBasicAction): boolean; procedure UpdateActions; virtual; public + MinVisible: boolean; constructor Create(AOwner: TComponent); override; constructor CreateNew(AOwner: TComponent; Num: Integer = 0); virtual; destructor Destroy; override; @@ -1180,6 +1181,7 @@ FCreatingForm: TForm;// currently created form (CreateForm), candidate for MainForm FFindGlobalComponentEnabled: boolean; FFlags: TApplicationFlags; + FHandle: HWND; FHint: string; FHintColor: TColor; FHintControl: TControl; @@ -1408,6 +1410,7 @@ write FFindGlobalComponentEnabled; property Flags: TApplicationFlags read FFlags write SetFlags; //property HelpSystem : IHelpSystem read FHelpSystem; + property Handle: HWND read FHandle write FHandle; property Hint: string read FHint write SetHint; property HintColor: TColor read FHintColor write SetHintColor; property HintHidePause: Integer read FHintHidePause write FHintHidePause; Index: include/application.inc =================================================================== --- include/application.inc (revision 28334) +++ include/application.inc (working copy) @@ -2099,7 +2099,10 @@ AForm := TForm(Instance); UpdateMainForm(AForm); if FMainForm = AForm then + begin AForm.HandleNeeded; + Application.Handle := AForm.Handle; + end; if AForm.FormStyle = fsSplash then begin // show the splash form and handle the paint message Index: include/dbimage.inc =================================================================== --- include/dbimage.inc (revision 28334) +++ include/dbimage.inc (working copy) @@ -133,12 +133,7 @@ end; procedure TDBImage.LoadPicture; - var s : Tstream; - GraphExt : string; - gc : TGraphicClass; - AGraphic : TGraphic; - begin if not FPictureLoaded then begin @@ -160,22 +155,11 @@ Picture.Clear; exit; end; - AGraphic := nil; try - GraphExt := s.ReadAnsiString; - - gc := GetGraphicClassForFileExtension(GraphExt); - if assigned(gc) then - begin - AGraphic := gc.Create; - AGraphic.LoadFromStream(s); - - Picture.Assign(AGraphic); - end; + Picture.LoadFromStream(S); finally - if assigned(AGraphic) then AGraphic.Free; s.Free; - end {try} + end end else Index: interfaces/win32/win32callback.inc =================================================================== --- interfaces/win32/win32callback.inc (revision 28334) +++ interfaces/win32/win32callback.inc (working copy) @@ -770,6 +770,7 @@ var ParentForm: TCustomForm; prevFocus: HWND; + i: integer; begin // forward keystroke to show window menu, if parent form has no menu // if wparam contains SC_KEYMENU, lparam contains key pressed @@ -809,11 +810,24 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + begin + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + Screen.CustomForms[i].MinVisible:=Screen.CustomForms[i].Showing; + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_HIDE); + end; + end; + end; + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_DISABLED); + end; end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -832,6 +846,19 @@ WinProcess := False; if (Application.MainForm <> nil) and Application.MainForm.HandleAllocated then begin + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_SHOWNA); + end; + end; + end; + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_DISABLED); if Application.MainForm.HandleObjectShouldBeVisible then Windows.ShowWindow(Application.MainForm.Handle, SW_SHOWNA); end; @@ -2067,6 +2094,15 @@ end; WM_SHOWWINDOW: begin + if Window = TWin32WidgetSet(WidgetSet).FAppHandle then + begin + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + //SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + // WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_DISABLED); + Exit; + end; Assert(False, 'Trace:WindowProc - Got WM_SHOWWINDOW'); with TLMShowWindow(LMessage) Do begin @@ -2309,7 +2345,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now, otherwise the MainForm will be terrible + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: interfaces/win32/win32object.inc =================================================================== --- interfaces/win32/win32object.inc (revision 28334) +++ interfaces/win32/win32object.inc (working copy) @@ -144,25 +144,24 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then FAppHandle := CreateWindowW(@ClsNameW, PWideChar(UTF8ToUTF16(Application.Title)), - WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,} 0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,} 0, 0, HWND(nil), HMENU(nil), HInstance, nil); @@ -172,11 +171,7 @@ // set nice main icon 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); + // remove useless menuitems from sysmenu, do not need these for forever hidden window // initialize ScreenInfo Handle := GetDesktopWindow; @@ -216,7 +211,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -486,22 +480,18 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - {$ifdef WindowsUnicodeSupport} - if UnicodeEnabledOS then - begin - Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))); - end else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); - {$else} - Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} + end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if AVisible then - Windows.ShowWindow(FAppHandle, SW_SHOW) - else - Windows.ShowWindow(FAppHandle, SW_HIDE); + //This action show TApplication window on closequery, disabled + {SetWindowLong(FAppHandle, GWL_STYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); } + SetWindowLong(FAppHandle, GWL_STYLE, GetWindowLong(FAppHandle, GWL_STYLE) or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, GetWindowLong(FAppHandle, GWL_EXSTYLE) or WS_DISABLED); end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: interfaces/win32/win32wsforms.pp =================================================================== --- interfaces/win32/win32wsforms.pp (revision 28334) +++ interfaces/win32/win32wsforms.pp (working copy) @@ -397,6 +397,9 @@ SubClassWndProc := @CustomFormWndProc; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm to taskbar + if (Application.MainForm = lForm) then + FlagsEx := FlagsEx or WS_EX_APPWINDOW; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -615,6 +618,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
MainFormOnTaskBar14-2.patch is on test. |
|
By the way, your patch is not clear - it has grpahics and dbcrtl changes which are not related to issue. |
|
Besides that why Application.Handle := AForm.Handle ? |
2010-11-19 09:51
|
MainFormOnTaskbar15.patch (12,956 bytes)
Index: dbctrls.pp =================================================================== --- dbctrls.pp (revision 28334) +++ dbctrls.pp (working copy) @@ -1020,6 +1020,7 @@ property DragCursor; property DragMode; property OnClick; + property OnDblClick; property OnDragDrop; property OnDragOver; property OnEndDrag; Index: forms.pp =================================================================== --- forms.pp (revision 28334) +++ forms.pp (working copy) @@ -570,6 +570,7 @@ function DoUpdateAction(TheAction: TBasicAction): boolean; procedure UpdateActions; virtual; public + MinVisible: boolean; constructor Create(AOwner: TComponent); override; constructor CreateNew(AOwner: TComponent; Num: Integer = 0); virtual; destructor Destroy; override; @@ -1180,6 +1181,7 @@ FCreatingForm: TForm;// currently created form (CreateForm), candidate for MainForm FFindGlobalComponentEnabled: boolean; FFlags: TApplicationFlags; + FHandle: HWND; FHint: string; FHintColor: TColor; FHintControl: TControl; @@ -1408,6 +1410,7 @@ write FFindGlobalComponentEnabled; property Flags: TApplicationFlags read FFlags write SetFlags; //property HelpSystem : IHelpSystem read FHelpSystem; + property Handle: HWND read FHandle write FHandle; property Hint: string read FHint write SetHint; property HintColor: TColor read FHintColor write SetHintColor; property HintHidePause: Integer read FHintHidePause write FHintHidePause; Index: include/application.inc =================================================================== --- include/application.inc (revision 28334) +++ include/application.inc (working copy) @@ -2099,7 +2099,10 @@ AForm := TForm(Instance); UpdateMainForm(AForm); if FMainForm = AForm then + begin AForm.HandleNeeded; + Application.Handle := AForm.Handle; + end; if AForm.FormStyle = fsSplash then begin // show the splash form and handle the paint message Index: include/dbimage.inc =================================================================== --- include/dbimage.inc (revision 28334) +++ include/dbimage.inc (working copy) @@ -133,12 +133,7 @@ end; procedure TDBImage.LoadPicture; - var s : Tstream; - GraphExt : string; - gc : TGraphicClass; - AGraphic : TGraphic; - begin if not FPictureLoaded then begin @@ -160,22 +155,11 @@ Picture.Clear; exit; end; - AGraphic := nil; try - GraphExt := s.ReadAnsiString; - - gc := GetGraphicClassForFileExtension(GraphExt); - if assigned(gc) then - begin - AGraphic := gc.Create; - AGraphic.LoadFromStream(s); - - Picture.Assign(AGraphic); - end; + Picture.LoadFromStream(S); finally - if assigned(AGraphic) then AGraphic.Free; s.Free; - end {try} + end end else Index: interfaces/win32/win32callback.inc =================================================================== --- interfaces/win32/win32callback.inc (revision 28334) +++ interfaces/win32/win32callback.inc (working copy) @@ -770,6 +770,7 @@ var ParentForm: TCustomForm; prevFocus: HWND; + i: integer; begin // forward keystroke to show window menu, if parent form has no menu // if wparam contains SC_KEYMENU, lparam contains key pressed @@ -798,7 +799,6 @@ SC_MINIMIZE: begin - if (Application <> nil) and (lWinControl <> nil) and (Application.MainForm <> nil) and (Application.MainForm = lWinControl) then @@ -809,11 +809,24 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + begin + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + Screen.CustomForms[i].MinVisible:=Screen.CustomForms[i].Showing; + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_HIDE); + end; + end; + end; + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_DISABLED); + end; end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -824,14 +837,26 @@ SC_RESTORE: begin - - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and + if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and (Application <> nil) then begin PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); WinProcess := False; if (Application.MainForm <> nil) and Application.MainForm.HandleAllocated then begin + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_SHOWNA); + end; + end; + end; + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_DISABLED); if Application.MainForm.HandleObjectShouldBeVisible then Windows.ShowWindow(Application.MainForm.Handle, SW_SHOWNA); end; @@ -1483,18 +1508,6 @@ begin if WParam <> 0 Then LMessage.Msg := LM_SETEDITABLE; - if Window = TWin32WidgetSet(WidgetSet).FAppHandle then - if WParam = 0 then - begin - RemoveStayOnTopFlags(Window); - DisabledForms := Screen.DisableForms(nil, DisabledForms); - end - else - begin - RestoreStayOnTopFlags(Window); - Screen.EnableForms(DisabledForms); - end; - // disable child windows of for example groupboxes, but not of forms if Assigned(lWinControl) and not (lWinControl is TCustomForm) then EnableChildWindows(lWinControl, WParam<>0); @@ -2067,6 +2080,15 @@ end; WM_SHOWWINDOW: begin + if Window = TWin32WidgetSet(WidgetSet).FAppHandle then + begin + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + //SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + // WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_DISABLED); + Exit; + end; Assert(False, 'Trace:WindowProc - Got WM_SHOWWINDOW'); with TLMShowWindow(LMessage) Do begin @@ -2309,7 +2331,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now, otherwise the MainForm will be terrible + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: interfaces/win32/win32object.inc =================================================================== --- interfaces/win32/win32object.inc (revision 28334) +++ interfaces/win32/win32object.inc (working copy) @@ -144,25 +144,24 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then FAppHandle := CreateWindowW(@ClsNameW, PWideChar(UTF8ToUTF16(Application.Title)), - WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,} 0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,} 0, 0, HWND(nil), HMENU(nil), HInstance, nil); @@ -172,11 +171,7 @@ // set nice main icon 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); + // remove useless menuitems from sysmenu, do not need these for forever hidden window // initialize ScreenInfo Handle := GetDesktopWindow; @@ -216,7 +211,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -486,22 +480,18 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - {$ifdef WindowsUnicodeSupport} - if UnicodeEnabledOS then - begin - Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))); - end else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); - {$else} - Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} + end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if AVisible then - Windows.ShowWindow(FAppHandle, SW_SHOW) - else - Windows.ShowWindow(FAppHandle, SW_HIDE); + //This action show TApplication window on closequery, disabled + {SetWindowLong(FAppHandle, GWL_STYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); } + SetWindowLong(FAppHandle, GWL_STYLE, GetWindowLong(FAppHandle, GWL_STYLE) or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, GetWindowLong(FAppHandle, GWL_EXSTYLE) or WS_DISABLED); end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: interfaces/win32/win32wsforms.pp =================================================================== --- interfaces/win32/win32wsforms.pp (revision 28334) +++ interfaces/win32/win32wsforms.pp (working copy) @@ -397,6 +397,9 @@ SubClassWndProc := @CustomFormWndProc; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm to taskbar + if (Application.MainForm = lForm) then + FlagsEx := FlagsEx or WS_EX_APPWINDOW; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -615,6 +618,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
In MainFormOnTaskbar15.patch, WM_ENABLE for FAppHandle disabled. |
|
MainFormOnTaskbar15.patch includes the TDBImage change. MainFormOnTaskbar15-1.patch is clean version. |
2010-11-19 09:58
|
MainFormOnTaskbar15-1.patch (11,603 bytes)
Index: forms.pp =================================================================== --- forms.pp (revision 28334) +++ forms.pp (working copy) @@ -570,6 +570,7 @@ function DoUpdateAction(TheAction: TBasicAction): boolean; procedure UpdateActions; virtual; public + MinVisible: boolean; constructor Create(AOwner: TComponent); override; constructor CreateNew(AOwner: TComponent; Num: Integer = 0); virtual; destructor Destroy; override; @@ -1180,6 +1181,7 @@ FCreatingForm: TForm;// currently created form (CreateForm), candidate for MainForm FFindGlobalComponentEnabled: boolean; FFlags: TApplicationFlags; + FHandle: HWND; FHint: string; FHintColor: TColor; FHintControl: TControl; @@ -1408,6 +1410,7 @@ write FFindGlobalComponentEnabled; property Flags: TApplicationFlags read FFlags write SetFlags; //property HelpSystem : IHelpSystem read FHelpSystem; + property Handle: HWND read FHandle write FHandle; property Hint: string read FHint write SetHint; property HintColor: TColor read FHintColor write SetHintColor; property HintHidePause: Integer read FHintHidePause write FHintHidePause; Index: include/application.inc =================================================================== --- include/application.inc (revision 28334) +++ include/application.inc (working copy) @@ -2099,7 +2099,10 @@ AForm := TForm(Instance); UpdateMainForm(AForm); if FMainForm = AForm then + begin AForm.HandleNeeded; + Application.Handle := AForm.Handle; + end; if AForm.FormStyle = fsSplash then begin // show the splash form and handle the paint message Index: interfaces/win32/win32callback.inc =================================================================== --- interfaces/win32/win32callback.inc (revision 28334) +++ interfaces/win32/win32callback.inc (working copy) @@ -770,6 +770,7 @@ var ParentForm: TCustomForm; prevFocus: HWND; + i: integer; begin // forward keystroke to show window menu, if parent form has no menu // if wparam contains SC_KEYMENU, lparam contains key pressed @@ -798,7 +799,6 @@ SC_MINIMIZE: begin - if (Application <> nil) and (lWinControl <> nil) and (Application.MainForm <> nil) and (Application.MainForm = lWinControl) then @@ -809,11 +809,24 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + begin + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + Screen.CustomForms[i].MinVisible:=Screen.CustomForms[i].Showing; + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_HIDE); + end; + end; + end; + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_DISABLED); + end; end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -824,14 +837,26 @@ SC_RESTORE: begin - - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and + if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and (Application <> nil) then begin PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); WinProcess := False; if (Application.MainForm <> nil) and Application.MainForm.HandleAllocated then begin + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_SHOWNA); + end; + end; + end; + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_DISABLED); if Application.MainForm.HandleObjectShouldBeVisible then Windows.ShowWindow(Application.MainForm.Handle, SW_SHOWNA); end; @@ -1483,18 +1508,6 @@ begin if WParam <> 0 Then LMessage.Msg := LM_SETEDITABLE; - if Window = TWin32WidgetSet(WidgetSet).FAppHandle then - if WParam = 0 then - begin - RemoveStayOnTopFlags(Window); - DisabledForms := Screen.DisableForms(nil, DisabledForms); - end - else - begin - RestoreStayOnTopFlags(Window); - Screen.EnableForms(DisabledForms); - end; - // disable child windows of for example groupboxes, but not of forms if Assigned(lWinControl) and not (lWinControl is TCustomForm) then EnableChildWindows(lWinControl, WParam<>0); @@ -2067,6 +2080,15 @@ end; WM_SHOWWINDOW: begin + if Window = TWin32WidgetSet(WidgetSet).FAppHandle then + begin + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + //SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + // WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_DISABLED); + Exit; + end; Assert(False, 'Trace:WindowProc - Got WM_SHOWWINDOW'); with TLMShowWindow(LMessage) Do begin @@ -2309,7 +2331,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now, otherwise the MainForm will be terrible + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: interfaces/win32/win32object.inc =================================================================== --- interfaces/win32/win32object.inc (revision 28334) +++ interfaces/win32/win32object.inc (working copy) @@ -144,25 +144,24 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then FAppHandle := CreateWindowW(@ClsNameW, PWideChar(UTF8ToUTF16(Application.Title)), - WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,} 0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,} 0, 0, HWND(nil), HMENU(nil), HInstance, nil); @@ -172,11 +171,7 @@ // set nice main icon 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); + // remove useless menuitems from sysmenu, do not need these for forever hidden window // initialize ScreenInfo Handle := GetDesktopWindow; @@ -216,7 +211,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -486,22 +480,18 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - {$ifdef WindowsUnicodeSupport} - if UnicodeEnabledOS then - begin - Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))); - end else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); - {$else} - Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} + end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if AVisible then - Windows.ShowWindow(FAppHandle, SW_SHOW) - else - Windows.ShowWindow(FAppHandle, SW_HIDE); + //This action show TApplication window on closequery, disabled + {SetWindowLong(FAppHandle, GWL_STYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); } + SetWindowLong(FAppHandle, GWL_STYLE, GetWindowLong(FAppHandle, GWL_STYLE) or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, GetWindowLong(FAppHandle, GWL_EXSTYLE) or WS_DISABLED); end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: interfaces/win32/win32wsforms.pp =================================================================== --- interfaces/win32/win32wsforms.pp (revision 28334) +++ interfaces/win32/win32wsforms.pp (working copy) @@ -397,6 +397,9 @@ SubClassWndProc := @CustomFormWndProc; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm to taskbar + if (Application.MainForm = lForm) then + FlagsEx := FlagsEx or WS_EX_APPWINDOW; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -615,6 +618,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
Application.Handle := AForm.Handle means Application.Handle := Application.MainForm.Handle Sometimes it makes some Delphi source code compiled without change. |
|
Postponed to next release, because this seems a risky patch. Can be tested and applied after the branching of the Lazarus 0.9.30 branch. |
2010-11-30 14:43
|
MainFormOnTaskbar15-2.patch (11,722 bytes)
Index: forms.pp =================================================================== --- forms.pp (revision 28347) +++ forms.pp (working copy) @@ -571,6 +571,7 @@ function DoUpdateAction(TheAction: TBasicAction): boolean; procedure UpdateActions; virtual; public + MinVisible: boolean; constructor Create(AOwner: TComponent); override; constructor CreateNew(AOwner: TComponent; Num: Integer = 0); virtual; destructor Destroy; override; @@ -1181,6 +1182,7 @@ FCreatingForm: TForm;// currently created form (CreateForm), candidate for MainForm FFindGlobalComponentEnabled: boolean; FFlags: TApplicationFlags; + FHandle: HWND; FHint: string; FHintColor: TColor; FHintControl: TControl; @@ -1409,6 +1411,7 @@ write FFindGlobalComponentEnabled; property Flags: TApplicationFlags read FFlags write SetFlags; //property HelpSystem : IHelpSystem read FHelpSystem; + property Handle: HWND read FHandle write FHandle; property Hint: string read FHint write SetHint; property HintColor: TColor read FHintColor write SetHintColor; property HintHidePause: Integer read FHintHidePause write FHintHidePause; Index: include/application.inc =================================================================== --- include/application.inc (revision 28347) +++ include/application.inc (working copy) @@ -2099,7 +2099,10 @@ AForm := TForm(Instance); UpdateMainForm(AForm); if FMainForm = AForm then + begin AForm.HandleNeeded; + Application.Handle := AForm.Handle; + end; if AForm.FormStyle = fsSplash then begin // show the splash form and handle the paint message Index: interfaces/win32/win32callback.inc =================================================================== --- interfaces/win32/win32callback.inc (revision 28347) +++ interfaces/win32/win32callback.inc (working copy) @@ -770,6 +770,7 @@ var ParentForm: TCustomForm; prevFocus: HWND; + i: integer; begin // forward keystroke to show window menu, if parent form has no menu // if wparam contains SC_KEYMENU, lparam contains key pressed @@ -798,7 +799,6 @@ SC_MINIMIZE: begin - if (Application <> nil) and (lWinControl <> nil) and (Application.MainForm <> nil) and (Application.MainForm = lWinControl) then @@ -809,11 +809,24 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + begin + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + Screen.CustomForms[i].MinVisible:=Screen.CustomForms[i].Showing; + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_HIDE); + end; + end; + end; + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_DISABLED); + end; end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -824,16 +837,29 @@ SC_RESTORE: begin - - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and + if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and (Application <> nil) then begin PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); WinProcess := False; if (Application.MainForm <> nil) and Application.MainForm.HandleAllocated then begin + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_SHOWNA); + end; + end; + end; + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_DISABLED); if Application.MainForm.HandleObjectShouldBeVisible then Windows.ShowWindow(Application.MainForm.Handle, SW_SHOWNA); + Windows.SetFocus(Screen.ActiveControl.Handle); end; Application.IntfAppRestore; end; @@ -1483,18 +1509,6 @@ begin if WParam <> 0 Then LMessage.Msg := LM_SETEDITABLE; - if Window = TWin32WidgetSet(WidgetSet).FAppHandle then - if WParam = 0 then - begin - RemoveStayOnTopFlags(Window); - DisabledForms := Screen.DisableForms(nil, DisabledForms); - end - else - begin - RestoreStayOnTopFlags(Window); - Screen.EnableForms(DisabledForms); - end; - // disable child windows of for example groupboxes, but not of forms if Assigned(lWinControl) and not (lWinControl is TCustomForm) then EnableChildWindows(lWinControl, WParam<>0); @@ -2067,6 +2081,15 @@ end; WM_SHOWWINDOW: begin + if Window = TWin32WidgetSet(WidgetSet).FAppHandle then + begin + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + //SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + // WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_DISABLED); + Exit; + end; Assert(False, 'Trace:WindowProc - Got WM_SHOWWINDOW'); with TLMShowWindow(LMessage) Do begin @@ -2309,7 +2332,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now, otherwise the MainForm will be terrible + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: interfaces/win32/win32object.inc =================================================================== --- interfaces/win32/win32object.inc (revision 28347) +++ interfaces/win32/win32object.inc (working copy) @@ -144,25 +144,24 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then FAppHandle := CreateWindowW(@ClsNameW, PWideChar(UTF8ToUTF16(Application.Title)), - WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,} 0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,} 0, 0, HWND(nil), HMENU(nil), HInstance, nil); @@ -172,11 +171,7 @@ // set nice main icon 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); + // remove useless menuitems from sysmenu, do not need these for forever hidden window // initialize ScreenInfo Handle := GetDesktopWindow; @@ -216,7 +211,6 @@ Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -486,22 +480,18 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - {$ifdef WindowsUnicodeSupport} - if UnicodeEnabledOS then - begin - Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))); - end else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); - {$else} - Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} + end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if AVisible then - Windows.ShowWindow(FAppHandle, SW_SHOW) - else - Windows.ShowWindow(FAppHandle, SW_HIDE); + //This action show TApplication window on closequery, disabled + {SetWindowLong(FAppHandle, GWL_STYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); } + SetWindowLong(FAppHandle, GWL_STYLE, GetWindowLong(FAppHandle, GWL_STYLE) or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, GetWindowLong(FAppHandle, GWL_EXSTYLE) or WS_DISABLED); end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: interfaces/win32/win32wsforms.pp =================================================================== --- interfaces/win32/win32wsforms.pp (revision 28347) +++ interfaces/win32/win32wsforms.pp (working copy) @@ -397,6 +397,9 @@ SubClassWndProc := @CustomFormWndProc; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm to taskbar + if (Application.MainForm = lForm) then + FlagsEx := FlagsEx or WS_EX_APPWINDOW; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -615,6 +618,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
2010-12-30 17:24
|
MainFormOnTaskbar1230.patch (12,116 bytes)
Index: forms.pp =================================================================== --- forms.pp (revision 28842) +++ forms.pp (working copy) @@ -571,6 +571,7 @@ function DoUpdateAction(TheAction: TBasicAction): boolean; procedure UpdateActions; virtual; public + MinVisible: boolean; constructor Create(AOwner: TComponent); override; constructor CreateNew(AOwner: TComponent; Num: Integer = 0); virtual; destructor Destroy; override; @@ -1181,6 +1182,7 @@ FCreatingForm: TForm;// currently created form (CreateForm), candidate for MainForm FFindGlobalComponentEnabled: boolean; FFlags: TApplicationFlags; + FHandle: HWND; FHint: string; FHintColor: TColor; FHintControl: TControl; @@ -1409,6 +1411,7 @@ write FFindGlobalComponentEnabled; property Flags: TApplicationFlags read FFlags write SetFlags; //property HelpSystem : IHelpSystem read FHelpSystem; + property Handle: HWND read FHandle write FHandle; property Hint: string read FHint write SetHint; property HintColor: TColor read FHintColor write SetHintColor; property HintHidePause: Integer read FHintHidePause write FHintHidePause; Index: include/application.inc =================================================================== --- include/application.inc (revision 28842) +++ include/application.inc (working copy) @@ -2099,7 +2099,10 @@ AForm := TForm(Instance); UpdateMainForm(AForm); if FMainForm = AForm then + begin AForm.HandleNeeded; + Application.Handle := AForm.Handle; + end; if AForm.FormStyle = fsSplash then begin // show the splash form and handle the paint message Index: interfaces/win32/win32callback.inc =================================================================== --- interfaces/win32/win32callback.inc (revision 28842) +++ interfaces/win32/win32callback.inc (working copy) @@ -770,6 +770,7 @@ var ParentForm: TCustomForm; prevFocus: HWND; + i: integer; begin // forward keystroke to show window menu, if parent form has no menu // if wparam contains SC_KEYMENU, lparam contains key pressed @@ -798,7 +799,19 @@ SC_MINIMIZE: begin - + if Window = Application.MainForm.Handle then + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + Screen.CustomForms[i].MinVisible:=Screen.CustomForms[i].Showing; + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_HIDE); + end; + end; + end; if (Application <> nil) and (lWinControl <> nil) and (Application.MainForm <> nil) and (Application.MainForm = lWinControl) then @@ -809,11 +822,12 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + begin + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + //SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + // GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_DISABLED); + end; end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -824,8 +838,19 @@ SC_RESTORE: begin - - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and + if Window = Application.MainForm.Handle then + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_SHOWNA); + end; + end; + end; + if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and (Application <> nil) then begin PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -834,6 +859,7 @@ begin if Application.MainForm.HandleObjectShouldBeVisible then Windows.ShowWindow(Application.MainForm.Handle, SW_SHOWNA); + Windows.SetFocus(Screen.ActiveControl.Handle); end; Application.IntfAppRestore; end; @@ -1483,18 +1509,6 @@ begin if WParam <> 0 Then LMessage.Msg := LM_SETEDITABLE; - if Window = TWin32WidgetSet(WidgetSet).FAppHandle then - if WParam = 0 then - begin - RemoveStayOnTopFlags(Window); - DisabledForms := Screen.DisableForms(nil, DisabledForms); - end - else - begin - RestoreStayOnTopFlags(Window); - Screen.EnableForms(DisabledForms); - end; - // disable child windows of for example groupboxes, but not of forms if Assigned(lWinControl) and not (lWinControl is TCustomForm) then EnableChildWindows(lWinControl, WParam<>0); @@ -2067,6 +2081,15 @@ end; WM_SHOWWINDOW: begin + if Window = TWin32WidgetSet(WidgetSet).FAppHandle then + begin + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + //SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + // WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_DISABLED); + Exit; + end; Assert(False, 'Trace:WindowProc - Got WM_SHOWWINDOW'); with TLMShowWindow(LMessage) Do begin @@ -2309,7 +2332,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now, otherwise the MainForm will be terrible + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: interfaces/win32/win32object.inc =================================================================== --- interfaces/win32/win32object.inc (revision 28842) +++ interfaces/win32/win32object.inc (working copy) @@ -144,25 +144,24 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then FAppHandle := CreateWindowW(@ClsNameW, PWideChar(UTF8ToUTF16(Application.Title)), - WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 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, + WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, 0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,} 0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,} 0, 0, HWND(nil), HMENU(nil), HInstance, nil); @@ -172,11 +171,7 @@ // set nice main icon 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); + // remove useless menuitems from sysmenu, do not need these for forever hidden window // initialize ScreenInfo Handle := GetDesktopWindow; @@ -201,7 +196,7 @@ ------------------------------------------------------------------------------} procedure TWin32WidgetSet.AppMinimize; begin - Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0); + Windows.SendMessage(Application.MainForm.Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0); end; {------------------------------------------------------------------------------ @@ -213,10 +208,9 @@ ------------------------------------------------------------------------------} procedure TWin32WidgetSet.AppRestore; begin - Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); + Windows.SendMessage(Application.MainForm.Handle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -486,22 +480,18 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - {$ifdef WindowsUnicodeSupport} - if UnicodeEnabledOS then - begin - Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))); - end else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); - {$else} - Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} + end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if AVisible then - Windows.ShowWindow(FAppHandle, SW_SHOW) - else - Windows.ShowWindow(FAppHandle, SW_HIDE); + //This action show TApplication window on closequery, disabled + {SetWindowLong(FAppHandle, GWL_STYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW + and not WS_CAPTION and not WS_MINIMIZEBOX or WS_DISABLED); } + SetWindowLong(FAppHandle, GWL_STYLE, GetWindowLong(FAppHandle, GWL_STYLE) or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, GetWindowLong(FAppHandle, GWL_EXSTYLE) or WS_DISABLED); end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: interfaces/win32/win32wsforms.pp =================================================================== --- interfaces/win32/win32wsforms.pp (revision 28842) +++ interfaces/win32/win32wsforms.pp (working copy) @@ -397,6 +397,9 @@ SubClassWndProc := @CustomFormWndProc; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm to taskbar + if (Application.MainForm = lForm) then + FlagsEx := FlagsEx or WS_EX_APPWINDOW; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -615,6 +618,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
The MainFormOnTaskbar1230.patch fix the bug of Minimize FAppHandle. |
2010-12-31 08:40
|
MainFormOnTaskbar1231.patch (14,442 bytes)
Index: forms.pp =================================================================== --- forms.pp (revision 28833) +++ forms.pp (working copy) @@ -571,6 +571,7 @@ function DoUpdateAction(TheAction: TBasicAction): boolean; procedure UpdateActions; virtual; public + MinVisible: boolean; constructor Create(AOwner: TComponent); override; constructor CreateNew(AOwner: TComponent; Num: Integer = 0); virtual; destructor Destroy; override; @@ -1181,6 +1182,7 @@ FCreatingForm: TForm;// currently created form (CreateForm), candidate for MainForm FFindGlobalComponentEnabled: boolean; FFlags: TApplicationFlags; + FHandle: HWND; FHint: string; FHintColor: TColor; FHintControl: TControl; @@ -1409,6 +1411,7 @@ write FFindGlobalComponentEnabled; property Flags: TApplicationFlags read FFlags write SetFlags; //property HelpSystem : IHelpSystem read FHelpSystem; + property Handle: HWND read FHandle write FHandle; property Hint: string read FHint write SetHint; property HintColor: TColor read FHintColor write SetHintColor; property HintHidePause: Integer read FHintHidePause write FHintHidePause; Index: include/application.inc =================================================================== --- include/application.inc (revision 28833) +++ include/application.inc (working copy) @@ -2099,7 +2099,13 @@ AForm := TForm(Instance); UpdateMainForm(AForm); if FMainForm = AForm then + begin + begin AForm.HandleNeeded; + Application.Handle := AForm.Handle; + end; + Application.Handle := AForm.Handle; + end; if AForm.FormStyle = fsSplash then begin // show the splash form and handle the paint message Index: interfaces/win32/win32callback.inc =================================================================== --- interfaces/win32/win32callback.inc (revision 28842) +++ interfaces/win32/win32callback.inc (working copy) @@ -770,6 +770,7 @@ var ParentForm: TCustomForm; prevFocus: HWND; + i: integer; begin // forward keystroke to show window menu, if parent form has no menu // if wparam contains SC_KEYMENU, lparam contains key pressed @@ -798,7 +799,19 @@ SC_MINIMIZE: begin - + if Window = Application.MainForm.Handle then + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + Screen.CustomForms[i].MinVisible:=Screen.CustomForms[i].Showing; + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_HIDE); + end; + end; + end; if (Application <> nil) and (lWinControl <> nil) and (Application.MainForm <> nil) and (Application.MainForm = lWinControl) then @@ -809,23 +822,36 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + begin + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + end; end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); WinProcess := False; Application.IntfAppMinimize; + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); end; end; SC_RESTORE: begin - - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and + if Window = Application.MainForm.Handle then + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_SHOWNA); + end; + end; + end; + if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and (Application <> nil) then begin PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -834,6 +860,7 @@ begin if Application.MainForm.HandleObjectShouldBeVisible then Windows.ShowWindow(Application.MainForm.Handle, SW_SHOWNA); + Windows.SetFocus(Screen.ActiveControl.Handle); end; Application.IntfAppRestore; end; @@ -1116,6 +1143,24 @@ LMessage.LParam := LParam; end; end; + //Bring the forms to front of other process + if (Application.MainForm <> nil) and ((LOWORD(WParam) = WA_ACTIVE) or (LOWORD(WParam) = WA_CLICKACTIVE)) + and (Window = Application.MainForm.Handle) then + begin + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + end; + if (Application.MainForm <> nil) and ((LOWORD(WParam) = WA_ACTIVE) or (LOWORD(WParam) = WA_CLICKACTIVE)) + and (lWinControl is TCustomForm) + and (Window <> Application.MainForm.Handle) then + begin + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + end; end; WM_IME_ENDCOMPOSITION: begin @@ -1183,6 +1228,9 @@ end else begin LMessage.Msg := LM_CLOSEQUERY; + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); end; // default is to destroy window, inhibit WinProcess := false; @@ -1483,18 +1531,6 @@ begin if WParam <> 0 Then LMessage.Msg := LM_SETEDITABLE; - if Window = TWin32WidgetSet(WidgetSet).FAppHandle then - if WParam = 0 then - begin - RemoveStayOnTopFlags(Window); - DisabledForms := Screen.DisableForms(nil, DisabledForms); - end - else - begin - RestoreStayOnTopFlags(Window); - Screen.EnableForms(DisabledForms); - end; - // disable child windows of for example groupboxes, but not of forms if Assigned(lWinControl) and not (lWinControl is TCustomForm) then EnableChildWindows(lWinControl, WParam<>0); @@ -2067,6 +2103,11 @@ end; WM_SHOWWINDOW: begin + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + if Window = TWin32WidgetSet(WidgetSet).FAppHandle then + Exit; Assert(False, 'Trace:WindowProc - Got WM_SHOWWINDOW'); with TLMShowWindow(LMessage) Do begin @@ -2083,7 +2124,7 @@ Flags := SW_HIDE else Flags := SW_SHOWNOACTIVATE; - Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, Flags); + //Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, Flags); end; end; WM_SYSCHAR: @@ -2309,7 +2350,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now, otherwise the MainForm will be terrible + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: interfaces/win32/win32object.inc =================================================================== --- interfaces/win32/win32object.inc (revision 28842) +++ interfaces/win32/win32object.inc (working copy) @@ -144,25 +144,27 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' {$ifdef WindowsUnicodeSupport} if UnicodeEnabledOS then FAppHandle := CreateWindowW(@ClsNameW, PWideChar(UTF8ToUTF16(Application.Title)), - WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX, + //WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, + WS_DISABLED and not WS_DLGFRAME and not WS_BORDER and not WS_CAPTION, 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, + //WS_POPUP or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, + WS_DISABLED and not WS_DLGFRAME and not WS_BORDER and not WS_CAPTION, 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, + FAppHandle := CreateWindow(@ClsName, PChar(Application.Title), //WS_POPUP or + //WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, + WS_DISABLED and not WS_DLGFRAME and not WS_BORDER and not WS_CAPTION, 0, {Windows.GetSystemMetrics(SM_CXSCREEN) div 2,} 0, {Windows.GetSystemMetrics(SM_CYSCREEN) div 2,} 0, 0, HWND(nil), HMENU(nil), HInstance, nil); @@ -172,11 +174,7 @@ // set nice main icon 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); + // remove useless menuitems from sysmenu, do not need these for forever hidden window // initialize ScreenInfo Handle := GetDesktopWindow; @@ -186,6 +184,8 @@ ScreenInfo.ColorDepth := GetDeviceCaps(DC, BITSPIXEL); Windows.ReleaseDC(Handle, DC); + SetWindowLong(FAppHandle, GWL_EXSTYLE, GetWindowLong(FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); + // Thread.Synchronize support WakeMainThread := @HandleWakeMainThread; @@ -201,7 +201,7 @@ ------------------------------------------------------------------------------} procedure TWin32WidgetSet.AppMinimize; begin - Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0); + Windows.SendMessage(Application.MainForm.Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0); end; {------------------------------------------------------------------------------ @@ -213,10 +213,9 @@ ------------------------------------------------------------------------------} procedure TWin32WidgetSet.AppRestore; begin - Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); + Windows.SendMessage(Application.MainForm.Handle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -486,22 +485,14 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - {$ifdef WindowsUnicodeSupport} - if UnicodeEnabledOS then - begin - Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))); - end else Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); - {$else} - Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} + end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if AVisible then - Windows.ShowWindow(FAppHandle, SW_SHOW) - else - Windows.ShowWindow(FAppHandle, SW_HIDE); + //This action show TApplication window on closequery, disabled + SetWindowLong(FAppHandle, GWL_STYLE, GetWindowLong(FAppHandle, GWL_STYLE) or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, GetWindowLong(FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: interfaces/win32/win32wsforms.pp =================================================================== --- interfaces/win32/win32wsforms.pp (revision 28842) +++ interfaces/win32/win32wsforms.pp (working copy) @@ -397,6 +397,12 @@ SubClassWndProc := @CustomFormWndProc; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm to taskbar + if (Application.MainForm = lForm) then + begin + FlagsEx := FlagsEx or WS_EX_APPWINDOW; + Parent := GetDesktopWindow; + end; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -615,6 +621,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
The MainFormOnTaskbar1231.patch fixed the bug of close query. |
2011-01-28 17:54
|
MainFormOnTaskbar20110128.patch (13,221 bytes)
Index: forms.pp =================================================================== --- forms.pp (revision 29237) +++ forms.pp (working copy) @@ -571,6 +571,7 @@ function DoUpdateAction(TheAction: TBasicAction): boolean; procedure UpdateActions; virtual; public + MinVisible: boolean; constructor Create(AOwner: TComponent); override; constructor CreateNew(AOwner: TComponent; Num: Integer = 0); virtual; destructor Destroy; override; @@ -1181,6 +1182,7 @@ FCreatingForm: TForm;// currently created form (CreateForm), candidate for MainForm FFindGlobalComponentEnabled: boolean; FFlags: TApplicationFlags; + FHandle: HWND; FHint: string; FHintColor: TColor; FHintControl: TControl; @@ -1409,6 +1411,7 @@ write FFindGlobalComponentEnabled; property Flags: TApplicationFlags read FFlags write SetFlags; //property HelpSystem : IHelpSystem read FHelpSystem; + property Handle: HWND read FHandle write FHandle; property Hint: string read FHint write SetHint; property HintColor: TColor read FHintColor write SetHintColor; property HintHidePause: Integer read FHintHidePause write FHintHidePause; Index: include/application.inc =================================================================== --- include/application.inc (revision 29237) +++ include/application.inc (working copy) @@ -2099,7 +2099,13 @@ AForm := TForm(Instance); UpdateMainForm(AForm); if FMainForm = AForm then + begin + begin AForm.HandleNeeded; + Application.Handle := AForm.Handle; + end; + Application.Handle := AForm.Handle; + end; if AForm.FormStyle = fsSplash then begin // show the splash form and handle the paint message Index: include/customform.inc =================================================================== --- include/customform.inc (revision 29237) +++ include/customform.inc (working copy) @@ -827,7 +827,7 @@ var Value: TShowInTaskBar; begin - if (Application.MainForm = Self) or (not HandleAllocated) or + if {(Application.MainForm = Self) or} (not HandleAllocated) or Assigned(Parent) or (FormStyle = fsMDIChild) or not Showing then Exit; Value := GetEffectiveShowInTaskBar; if FRealizedShowInTaskBar <> Value then Index: interfaces/win32/win32callback.inc =================================================================== --- interfaces/win32/win32callback.inc (revision 29237) +++ interfaces/win32/win32callback.inc (working copy) @@ -770,6 +770,7 @@ var ParentForm: TCustomForm; prevFocus: HWND; + i: integer; begin // forward keystroke to show window menu, if parent form has no menu // if wparam contains SC_KEYMENU, lparam contains key pressed @@ -798,7 +799,19 @@ SC_MINIMIZE: begin - + if Window = Application.MainForm.Handle then + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + Screen.CustomForms[i].MinVisible:=Screen.CustomForms[i].Showing; + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_HIDE); + end; + end; + end; if (Application <> nil) and (lWinControl <> nil) and (Application.MainForm <> nil) and (Application.MainForm = lWinControl) then @@ -809,23 +822,36 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + begin + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + end; end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); WinProcess := False; Application.IntfAppMinimize; + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); end; end; SC_RESTORE: begin - - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and + if Window = Application.MainForm.Handle then + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_SHOWNA); + end; + end; + end; + if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and (Application <> nil) then begin PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -834,6 +860,7 @@ begin if Application.MainForm.HandleObjectShouldBeVisible then Windows.ShowWindow(Application.MainForm.Handle, SW_SHOWNA); + Windows.SetFocus(Screen.ActiveControl.Handle); end; Application.IntfAppRestore; end; @@ -1116,6 +1143,24 @@ LMessage.LParam := LParam; end; end; + //Bring the forms to front of other process + if (Application.MainForm <> nil) and ((LOWORD(WParam) = WA_ACTIVE) or (LOWORD(WParam) = WA_CLICKACTIVE)) + and (Window = Application.MainForm.Handle) then + begin + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + end; + if (Application.MainForm <> nil) and ((LOWORD(WParam) = WA_ACTIVE) or (LOWORD(WParam) = WA_CLICKACTIVE)) + and (lWinControl is TCustomForm) + and (Window <> Application.MainForm.Handle) then + begin + Windows.SetWindowPos(Application.MainForm.Handle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + Windows.SetWindowPos(TWin32WidgetSet(WidgetSet).FAppHandle, HWND_TOP, + 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); + end; end; WM_IME_ENDCOMPOSITION: begin @@ -1183,6 +1228,9 @@ end else begin LMessage.Msg := LM_CLOSEQUERY; + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); end; // default is to destroy window, inhibit WinProcess := false; @@ -1483,18 +1531,6 @@ begin if WParam <> 0 Then LMessage.Msg := LM_SETEDITABLE; - if Window = TWin32WidgetSet(WidgetSet).FAppHandle then - if WParam = 0 then - begin - RemoveStayOnTopFlags(Window); - DisabledForms := Screen.DisableForms(nil, DisabledForms); - end - else - begin - RestoreStayOnTopFlags(Window); - Screen.EnableForms(DisabledForms); - end; - // disable child windows of for example groupboxes, but not of forms if Assigned(lWinControl) and not (lWinControl is TCustomForm) then EnableChildWindows(lWinControl, WParam<>0); @@ -2067,6 +2103,11 @@ end; WM_SHOWWINDOW: begin + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + if Window = TWin32WidgetSet(WidgetSet).FAppHandle then + Exit; Assert(False, 'Trace:WindowProc - Got WM_SHOWWINDOW'); with TLMShowWindow(LMessage) Do begin @@ -2083,7 +2124,7 @@ Flags := SW_HIDE else Flags := SW_SHOWNOACTIVATE; - Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, Flags); + //Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, Flags); end; end; WM_SYSCHAR: @@ -2309,7 +2350,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now, otherwise the MainForm will be terrible + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: interfaces/win32/win32object.inc =================================================================== --- interfaces/win32/win32object.inc (revision 29237) +++ interfaces/win32/win32object.inc (working copy) @@ -144,7 +144,6 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' if not IsLibrary then begin @@ -165,12 +164,11 @@ {$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} + 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 AIcon := Windows.LoadIcon(MainInstance, 'MAINICON'); AppSetIcon(AIcon, AIcon); @@ -180,7 +178,6 @@ Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); end; - // initialize ScreenInfo Handle := GetDesktopWindow; DC := Windows.GetDC(Handle); @@ -189,6 +186,8 @@ ScreenInfo.ColorDepth := GetDeviceCaps(DC, BITSPIXEL); Windows.ReleaseDC(Handle, DC); + SetWindowLong(FAppHandle, GWL_EXSTYLE, GetWindowLong(FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); + // Thread.Synchronize support WakeMainThread := @HandleWakeMainThread; @@ -205,7 +204,7 @@ procedure TWin32WidgetSet.AppMinimize; begin if FAppHandle <> 0 then - Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0); + Windows.SendMessage(Application.MainForm.Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0); end; {------------------------------------------------------------------------------ @@ -218,10 +217,9 @@ procedure TWin32WidgetSet.AppRestore; begin if FAppHandle <> 0 then - Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); + Windows.SendMessage(Application.MainForm.Handle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -512,10 +510,9 @@ begin if FAppHandle <> 0 then begin - if AVisible then - Windows.ShowWindow(FAppHandle, SW_SHOW) - else - Windows.ShowWindow(FAppHandle, SW_HIDE); + //This action show TApplication window on closequery, disabled + SetWindowLong(FAppHandle, GWL_STYLE, GetWindowLong(FAppHandle, GWL_STYLE) or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, GetWindowLong(FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); end; end; Index: interfaces/win32/win32wsforms.pp =================================================================== --- interfaces/win32/win32wsforms.pp (revision 29237) +++ interfaces/win32/win32wsforms.pp (working copy) @@ -397,6 +397,12 @@ SubClassWndProc := @CustomFormWndProc; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm to taskbar + if (Application.MainForm = lForm) then + begin + FlagsEx := FlagsEx or WS_EX_APPWINDOW; + Parent := GetDesktopWindow; + end; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -615,6 +621,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
2011-02-01 17:45
|
MainFormOnTaskbar20110202.patch (12,838 bytes)
Index: forms.pp =================================================================== --- forms.pp (revision 29154) +++ forms.pp (working copy) @@ -571,6 +571,7 @@ function DoUpdateAction(TheAction: TBasicAction): boolean; procedure UpdateActions; virtual; public + MinVisible: boolean; constructor Create(AOwner: TComponent); override; constructor CreateNew(AOwner: TComponent; Num: Integer = 0); virtual; destructor Destroy; override; @@ -1181,6 +1182,7 @@ FCreatingForm: TForm;// currently created form (CreateForm), candidate for MainForm FFindGlobalComponentEnabled: boolean; FFlags: TApplicationFlags; + FHandle: HWND; FHint: string; FHintColor: TColor; FHintControl: TControl; @@ -1409,6 +1411,7 @@ write FFindGlobalComponentEnabled; property Flags: TApplicationFlags read FFlags write SetFlags; //property HelpSystem : IHelpSystem read FHelpSystem; + property Handle: HWND read FHandle write FHandle; property Hint: string read FHint write SetHint; property HintColor: TColor read FHintColor write SetHintColor; property HintHidePause: Integer read FHintHidePause write FHintHidePause; Index: include/application.inc =================================================================== --- include/application.inc (revision 29154) +++ include/application.inc (working copy) @@ -2099,7 +2099,13 @@ AForm := TForm(Instance); UpdateMainForm(AForm); if FMainForm = AForm then + begin + begin AForm.HandleNeeded; + Application.Handle := AForm.Handle; + end; + Application.Handle := AForm.Handle; + end; if AForm.FormStyle = fsSplash then begin // show the splash form and handle the paint message Index: interfaces/win32/win32callback.inc =================================================================== --- interfaces/win32/win32callback.inc (revision 29154) +++ interfaces/win32/win32callback.inc (working copy) @@ -770,6 +770,7 @@ var ParentForm: TCustomForm; prevFocus: HWND; + i: integer; begin // forward keystroke to show window menu, if parent form has no menu // if wparam contains SC_KEYMENU, lparam contains key pressed @@ -798,7 +799,19 @@ SC_MINIMIZE: begin - + if Window = Application.MainForm.Handle then + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + Screen.CustomForms[i].MinVisible:=Screen.CustomForms[i].Showing; + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_HIDE); + end; + end; + end; if (Application <> nil) and (lWinControl <> nil) and (Application.MainForm <> nil) and (Application.MainForm = lWinControl) then @@ -809,23 +822,36 @@ begin if (Application.MainForm <> nil) then begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); + begin + Windows.ShowWindow(Application.MainForm.Handle, SW_MINIMIZE); + end; end; PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); WinProcess := False; Application.IntfAppMinimize; + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); end; end; SC_RESTORE: begin - - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and + if Window = Application.MainForm.Handle then + if Screen<>nil then + for i:=0 to Screen.CustomFormCount-1 do begin + begin + if (Screen.CustomForms[i].Parent=nil) and Screen.CustomForms[i].HandleAllocated + and (Screen.CustomForms[i].Handle <> Application.MainForm.Handle) then + begin + if Screen.CustomForms[i].MinVisible then + Windows.ShowWindow(Screen.CustomForms[i].Handle, SW_SHOWNA); + end; + end; + end; + if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and (Application <> nil) then begin PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); @@ -834,6 +860,7 @@ begin if Application.MainForm.HandleObjectShouldBeVisible then Windows.ShowWindow(Application.MainForm.Handle, SW_SHOWNA); + Windows.SetFocus(Screen.ActiveControl.Handle); end; Application.IntfAppRestore; end; @@ -1183,6 +1210,9 @@ end else begin LMessage.Msg := LM_CLOSEQUERY; + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); end; // default is to destroy window, inhibit WinProcess := false; @@ -1483,18 +1513,6 @@ begin if WParam <> 0 Then LMessage.Msg := LM_SETEDITABLE; - if Window = TWin32WidgetSet(WidgetSet).FAppHandle then - if WParam = 0 then - begin - RemoveStayOnTopFlags(Window); - DisabledForms := Screen.DisableForms(nil, DisabledForms); - end - else - begin - RestoreStayOnTopFlags(Window); - Screen.EnableForms(DisabledForms); - end; - // disable child windows of for example groupboxes, but not of forms if Assigned(lWinControl) and not (lWinControl is TCustomForm) then EnableChildWindows(lWinControl, WParam<>0); @@ -2067,6 +2085,11 @@ end; WM_SHOWWINDOW: begin + SetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE, + GetWindowLong(TWin32WidgetSet(WidgetSet).FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); + ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, SW_HIDE); + if Window = TWin32WidgetSet(WidgetSet).FAppHandle then + Exit; Assert(False, 'Trace:WindowProc - Got WM_SHOWWINDOW'); with TLMShowWindow(LMessage) Do begin @@ -2083,7 +2106,7 @@ Flags := SW_HIDE else Flags := SW_SHOWNOACTIVATE; - Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, Flags); + //Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, Flags); end; end; WM_SYSCHAR: @@ -2309,7 +2332,8 @@ Window := Application.MainForm.Handle; end; end; - if IsIconic(Window) then + //MainForm do not need to GetWindowPlacement now, otherwise the MainForm will be terrible + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do Index: interfaces/win32/win32object.inc =================================================================== --- interfaces/win32/win32object.inc (revision 29154) +++ interfaces/win32/win32object.inc (working copy) @@ -144,7 +144,6 @@ InitCommonControlsEx(@ICC); end; end; - // Create parent of all windows, 'button on taskbar' if not IsLibrary then begin @@ -163,24 +162,19 @@ 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, + FAppHandle := CreateWindow(@ClsName, PChar(Application.Title), //WS_POPUP or + //WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_DISABLED, + WS_DISABLED and not WS_DLGFRAME and not WS_BORDER and not WS_CAPTION, 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 - 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); - Windows.DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); - Windows.DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND); + {$endif} + AllocWindowInfo(FAppHandle); end; - + // set nice main icon + AIcon := Windows.LoadIcon(MainInstance, 'MAINICON'); + AppSetIcon(AIcon, AIcon); + // remove useless menuitems from sysmenu, do not need these for forever hidden window // initialize ScreenInfo Handle := GetDesktopWindow; DC := Windows.GetDC(Handle); @@ -189,6 +183,8 @@ ScreenInfo.ColorDepth := GetDeviceCaps(DC, BITSPIXEL); Windows.ReleaseDC(Handle, DC); + SetWindowLong(FAppHandle, GWL_EXSTYLE, GetWindowLong(FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); + // Thread.Synchronize support WakeMainThread := @HandleWakeMainThread; @@ -204,8 +200,8 @@ ------------------------------------------------------------------------------} procedure TWin32WidgetSet.AppMinimize; begin - if FAppHandle <> 0 then - Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0); + if Application.MainForm.Handle <> 0 then + Windows.SendMessage(Application.MainForm.Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0); end; {------------------------------------------------------------------------------ @@ -217,11 +213,10 @@ ------------------------------------------------------------------------------} procedure TWin32WidgetSet.AppRestore; begin - if FAppHandle <> 0 then - Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); + if Application.MainForm.Handle <> 0 then + Windows.SendMessage(Application.MainForm.Handle, WM_SYSCOMMAND, SC_RESTORE, 0); end; - {------------------------------------------------------------------------------ Method: TWin32WidgetSet.AppBringToFront Params: None @@ -495,28 +490,13 @@ procedure TWin32WidgetSet.AppSetTitle(const ATitle: string); begin - if FAppHandle <> 0 then - begin - {$ifdef WindowsUnicodeSupport} - if UnicodeEnabledOS then - Windows.SetWindowTextW(FAppHandle, PWideChar(UTF8ToUTF16(ATitle))) - else - Windows.SetWindowText(FAppHandle, PChar(Utf8ToAnsi(ATitle))); - {$else} - Windows.SetWindowText(FAppHandle, PChar(ATitle)); - {$endif} - end; end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if FAppHandle <> 0 then - begin - if AVisible then - Windows.ShowWindow(FAppHandle, SW_SHOW) - else - Windows.ShowWindow(FAppHandle, SW_HIDE); - end; + //This action show TApplication window on closequery, disabled + SetWindowLong(FAppHandle, GWL_STYLE, GetWindowLong(FAppHandle, GWL_STYLE) or WS_DISABLED); + SetWindowLong(FAppHandle, GWL_EXSTYLE, GetWindowLong(FAppHandle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW); end; function TWin32WidgetSet.AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; Index: interfaces/win32/win32wsforms.pp =================================================================== --- interfaces/win32/win32wsforms.pp (revision 29154) +++ interfaces/win32/win32wsforms.pp (working copy) @@ -397,6 +397,9 @@ SubClassWndProc := @CustomFormWndProc; if not (csDesigning in lForm.ComponentState) and lForm.AlphaBlend then FlagsEx := FlagsEx or WS_EX_LAYERED; + //Set MainForm to taskbar + if (Application.MainForm = lForm) then + FlagsEx := FlagsEx or WS_EX_APPWINDOW; end; SetStdBiDiModeParams(AWinControl, Params); // create window @@ -615,6 +618,7 @@ OldStyle := GetWindowLong(AForm.Handle, GWL_EXSTYLE); NewStyle := OldStyle; + if AValue = stAlways then NewStyle := NewStyle or WS_EX_APPWINDOW else |
|
Please update to recent 0.9.31 version and check whether Application.MainFormOnTaskBar := True; do what you need? I'm not going to replace Application.Handle with MainForm.Handle in the LCL. |
|
Please update to recent 0.9.31 version and check whether Application.MainFormOnTaskBar := True; do what you need? I'm not going to replace Application.Handle with MainForm.Handle in the LCL. |
|
I have try the newest svn and the new property and add set it to true in the IDE. Of course the mainform of the IDE under all of other windows. The problem raised after the minimized IDE restored, the mainform of the IDE changed. So I think the property MainFormOnTaskBar is not certainly required. By the way, the MainFormOnTaskbar20110202.patch have a small bug and I will fix it. |
|
For the patch MainFormOnTaskbar20110202, click one of the IDE form, the taskbar button status is not change. The bug is just in XP and 2003 but in Win7 it is not a problem. |
2011-02-19 15:37
|
mainformontaskbar20110219.patch (513 bytes)
Index: win32callback.inc =================================================================== --- win32callback.inc (revision 29597) +++ win32callback.inc (working copy) @@ -2321,7 +2321,7 @@ Window := Application.MainFormHandle; end; end; - if IsIconic(Window) then + if IsIconic(Window) and (Window <> Application.MainForm.Handle) then begin GetWindowPlacement(Window, @WindowPlacement); with WindowPlacement.rcNormalPosition do |
|
The mainformontaskbar20110219.patch fixed the bug of svn 29597 while MainFormOnTaskbar is true. |
|
Please tell me what bug mainformontaskbar20110219.patch fixes. I need to test it myself to see what is wrong and maybe to find other similar places. |
|
After updated from Lazarus SVN, I set application.MainFormOnTaskbar := True in lazarus.pp. When I minimize IDE and restore it, the MainForm of IDE resized to be larger and a black edge on its right and bottom. |
|
r29756 fixes the window size growing after minimizing/maximizing. Please close the issue if it works ok for you. I suggest to create an independent bug reports if something new will be found regards MainFormOnTaskBar property. |
|
The r29756 works fine now. |
Date Modified | Username | Field | Change |
---|---|---|---|
2010-08-31 03:43 | yang jixian | New Issue | |
2010-08-31 03:43 | yang jixian | File Added: MainFormOnTaskBar.patch | |
2010-08-31 03:43 | yang jixian | Widgetset | => Win32/Win64 |
2010-08-31 03:48 | yang jixian | Note Added: 0040667 | |
2010-08-31 09:37 | Felipe Monteiro de Carvalho | Note Added: 0040670 | |
2010-08-31 09:44 | Felipe Monteiro de Carvalho | Note Added: 0040671 | |
2010-08-31 09:44 | Felipe Monteiro de Carvalho | Status | new => assigned |
2010-08-31 09:44 | Felipe Monteiro de Carvalho | Assigned To | => Felipe Monteiro de Carvalho |
2010-08-31 10:28 | yang jixian | Note Added: 0040673 | |
2010-08-31 10:47 | yang jixian | Note Added: 0040674 | |
2010-09-01 09:48 | yang jixian | File Added: MainFormOnTaskBar2.patch | |
2010-09-01 09:51 | yang jixian | Note Added: 0040698 | |
2010-09-01 13:15 | Felipe Monteiro de Carvalho | Note Added: 0040701 | |
2010-09-01 13:17 | Felipe Monteiro de Carvalho | LazTarget | => 0.9.30 |
2010-09-01 13:37 | Felipe Monteiro de Carvalho | Note Edited: 0040701 | |
2010-09-01 14:24 | Felipe Monteiro de Carvalho | Assigned To | Felipe Monteiro de Carvalho => |
2010-09-01 14:27 | Felipe Monteiro de Carvalho | Note Edited: 0040701 | |
2010-09-01 15:46 | Sven Barth | Note Added: 0040713 | |
2010-09-02 21:14 | Zeljan Rikalo | Note Added: 0040755 | |
2010-09-02 22:00 | Maxim Ganetsky | Status | assigned => new |
2010-09-06 16:34 | yang jixian | File Added: MFormOnTaskBar.patch | |
2010-09-06 16:38 | yang jixian | Note Added: 0040865 | |
2010-09-06 16:51 | Zeljan Rikalo | Note Added: 0040866 | |
2010-09-06 16:51 | Zeljan Rikalo | Status | new => feedback |
2010-09-07 10:35 | yang jixian | Note Added: 0040877 | |
2010-09-07 17:50 | yang jixian | File Added: MainFormOnTaskBar3.patch | |
2010-09-07 17:51 | yang jixian | Note Added: 0040886 | |
2010-09-08 01:54 | Zaher Dirkey | Note Added: 0040889 | |
2010-09-08 03:05 | yang jixian | File Added: MainFormOnTaskBar4.patch | |
2010-09-08 05:06 | yang jixian | File Added: MainFormOnTaskBar5.patch | |
2010-09-08 17:33 | yang jixian | File Added: MainFormOnTaskBar6.patch | |
2010-09-08 17:34 | yang jixian | Note Added: 0040898 | |
2010-09-08 21:10 | Dmitry Boyarintsev | Note Added: 0040901 | |
2010-09-09 03:05 | yang jixian | Note Added: 0040903 | |
2010-09-09 03:27 | yang jixian | File Added: MainFormOnTaskBar7.patch | |
2010-09-09 03:28 | yang jixian | Note Edited: 0040865 | |
2010-09-09 03:30 | yang jixian | Note Added: 0040904 | |
2010-09-09 08:36 | Vincent Snijders | Note Added: 0040909 | |
2010-09-09 09:42 | yang jixian | File Added: MainFormOnTaskBar8.patch | |
2010-09-09 09:43 | yang jixian | Note Added: 0040911 | |
2010-09-15 16:12 | yang jixian | File Added: MainFormOnTaskBar9.patch | |
2010-09-15 16:16 | yang jixian | Note Added: 0041119 | |
2010-09-17 02:58 | yang jixian | Note Added: 0041153 | |
2010-09-17 09:52 | yang jixian | File Added: MainFormOnTaskBar10.patch | |
2010-09-17 09:53 | yang jixian | Note Added: 0041157 | |
2010-09-17 09:54 | yang jixian | Note Edited: 0041157 | |
2010-09-17 10:17 | yang jixian | File Added: MainFormOnTaskBar11.patch | |
2010-09-17 10:17 | yang jixian | Note Edited: 0041157 | |
2010-09-17 10:23 | yang jixian | Note Edited: 0041157 | |
2010-09-18 05:49 | yang jixian | File Added: MainFormOnTaskBar12.patch | |
2010-09-18 05:51 | yang jixian | Note Edited: 0041157 | |
2010-10-28 12:47 | Vincent Snijders | Status | feedback => acknowledged |
2010-11-03 14:55 | yang jixian | Note Added: 0042719 | |
2010-11-11 08:12 | yang jixian | Note Added: 0042957 | |
2010-11-11 08:16 | yang jixian | Note Edited: 0042957 | |
2010-11-12 02:14 | yang jixian | File Added: MainFormOnTaskBar13.patch | |
2010-11-12 02:15 | yang jixian | Note Added: 0042976 | |
2010-11-18 10:10 | Juha Manninen | Relationship added | related to 0017965 |
2010-11-19 03:47 | yang jixian | File Added: MainFormOnTaskbar14-2.patch | |
2010-11-19 03:47 | yang jixian | Note Added: 0043213 | |
2010-11-19 04:02 | Paul Ishenin | Note Added: 0043214 | |
2010-11-19 08:06 | Zeljan Rikalo | Note Added: 0043224 | |
2010-11-19 09:51 | yang jixian | File Added: MainFormOnTaskbar15.patch | |
2010-11-19 09:54 | yang jixian | Note Added: 0043236 | |
2010-11-19 09:57 | yang jixian | Note Added: 0043238 | |
2010-11-19 09:58 | yang jixian | File Added: MainFormOnTaskbar15-1.patch | |
2010-11-19 09:58 | yang jixian | Note Edited: 0043238 | |
2010-11-19 10:01 | yang jixian | Note Added: 0043239 | |
2010-11-24 15:45 | Vincent Snijders | LazTarget | 0.9.30 => 0.99.0 |
2010-11-24 15:45 | Vincent Snijders | Note Added: 0043474 | |
2010-11-24 15:45 | Vincent Snijders | Target Version | => 0.99.0 |
2010-11-30 14:43 | yang jixian | File Added: MainFormOnTaskbar15-2.patch | |
2010-12-30 17:24 | yang jixian | File Added: MainFormOnTaskbar1230.patch | |
2010-12-30 17:26 | yang jixian | Note Added: 0044731 | |
2010-12-30 17:27 | yang jixian | Note Edited: 0044731 | |
2010-12-31 08:40 | yang jixian | File Added: MainFormOnTaskbar1231.patch | |
2010-12-31 08:46 | yang jixian | Note Added: 0044745 | |
2010-12-31 08:47 | yang jixian | Note Edited: 0044745 | |
2011-01-27 09:49 | Vincent Snijders | Relationship added | has duplicate 0018499 |
2011-01-27 09:51 | Vincent Snijders | Relationship replaced | related to 0018499 |
2011-01-28 17:54 | yang jixian | File Added: MainFormOnTaskbar20110128.patch | |
2011-01-29 07:38 | Paul Ishenin | Status | acknowledged => assigned |
2011-01-29 07:38 | Paul Ishenin | Assigned To | => Paul Ishenin |
2011-02-01 17:45 | yang jixian | File Added: MainFormOnTaskbar20110202.patch | |
2011-02-12 10:24 | Paul Ishenin | Note Added: 0045991 | |
2011-02-12 10:24 | Paul Ishenin | Status | assigned => feedback |
2011-02-12 10:24 | Paul Ishenin | Note Added: 0045992 | |
2011-02-15 07:40 | yang jixian | Note Added: 0046062 | |
2011-02-15 07:47 | yang jixian | Note Added: 0046063 | |
2011-02-19 15:37 | yang jixian | File Added: mainformontaskbar20110219.patch | |
2011-02-19 15:38 | yang jixian | Note Added: 0046139 | |
2011-02-22 07:51 | Paul Ishenin | Relationship added | has duplicate 0015487 |
2011-03-02 07:41 | Paul Ishenin | Note Added: 0046336 | |
2011-03-03 14:57 | yang jixian | Note Added: 0046364 | |
2011-03-09 05:09 | Paul Ishenin | Status | feedback => resolved |
2011-03-09 05:09 | Paul Ishenin | Fixed in Version | => 0.9.31 (SVN) |
2011-03-09 05:09 | Paul Ishenin | Resolution | open => fixed |
2011-03-09 05:09 | Paul Ishenin | Note Added: 0046530 | |
2011-03-10 01:40 | yang jixian | Status | resolved => closed |
2011-03-10 01:40 | yang jixian | Note Added: 0046540 | |
2011-10-02 23:01 | Felipe Monteiro de Carvalho | Relationship added | related to 0017294 |
2011-12-13 15:30 | yang jixian | Relationship added | related to 0020864 |