Mega Code Archive

 
Categories / Delphi / Forms
 

Changing TForm BorderIcons

Title: Changing TForm BorderIcons Question: Has you know you can enable or disable a form bordericons (system menu, minimize, maximize and help) just by including or excluding the value you want from the bordericons set. Answer: Anyway, this method has (at least) one disadvantage. To the change to this property have efect, VCL internal structure need's to call a function (TWinControl.RecreateWnd). As you can see this method causes the activation of at least one event (OnShow), and the flick of the form. So, one option to avoid this is by using the following function that can enable/disable bordericons by bypassing TWinControl.RecreateWnd procedure SetBorderIcons(Value: TBorderIcons); var FStyle, FAppStyle: LongWord; FExStyle, FAppExStyle: LongWord; begin // Get old style's FStyle := GetWindowLong(Handle, GWL_STYLE); FExStyle := GetWindowLong(Handle, GWL_EXSTYLE); FAppStyle := GetWindowLong(Application.Handle, GWL_STYLE); FAppExStyle := GetWindowLong(Application.Handle, GWL_EXSTYLE); // Process styles, according to the parameters if BorderStyle in [bsSingle, bsSizeable, bsNone] then if (FormStyle fsMDIChild) or (biSystemMenu in Value) then begin if biMinimize in Value then begin FStyle := FStyle or WS_MINIMIZEBOX; FAppStyle := FAppStyle or WS_MINIMIZEBOX; end else begin FStyle := FStyle and not WS_MINIMIZEBOX; FAppStyle := FAppStyle and not WS_MINIMIZEBOX; end; if biMaximize in Value then begin FStyle := FStyle or WS_MAXIMIZEBOX; FAppStyle := FAppStyle or WS_MAXIMIZEBOX; end else begin FStyle := FStyle and not WS_MAXIMIZEBOX; FAppStyle := FAppStyle and not WS_MAXIMIZEBOX; end; end; if biSystemMenu in Value then begin FStyle := FStyle or WS_SYSMENU; FAppStyle := FAppStyle or WS_SYSMENU; end else begin FStyle := FStyle and not WS_SYSMENU; FAppStyle := FAppStyle and not WS_SYSMENU; end; if (biHelp in Value) then FExStyle := FExStyle or WS_EX_CONTEXTHELP else FExStyle := FExStyle and not WS_EX_CONTEXTHELP; // Update new style's SetWindowLong(Handle, GWL_STYLE, FStyle); SetWindowLong(Handle, GWL_EXSTYLE, FExStyle); SetWindowLong(Application.Handle, GWL_STYLE, FAppStyle); SetWindowLong(Application.Handle, GWL_EXSTYLE, FAppExStyle); // Force repaint the Non Client (NC) area, for updating form SetWindowPos(Handle, 0, 0, 0, 0, 0, SWP_NOZORDER or SWP_NOSIZE or SWP_NOMOVE or SWP_DRAWFRAME or SWP_SHOWWINDOW); end; The only problem with this routine (and I hope someone could help) is that it doesn't update form's BorderIcons. I tried to access FBorderIcons private variable in TCustomForm, but because it is private...