9
votes

I have upgraded to Delphi XE from 2009 and am experiencing a strange issue.

I create a new project, put down a TRibbon control, compile and run. Keeping the form in its default size I then minimize and restore without issues. I then maximise the form, minimize and restore and the form colour is changed to black.

I have no random code to change it and am using all defaults Delphi XE comes with and it does it each and every time without fail.

I have moved the compiled exe to a friends computer and the problem remains so I know it's not my computer. If I turn off Aero effects the problem goes away, but put Aero back on and the problem returns.

Any ideas at all? I'm having trouble finding any relevant threads regarding this issue across the interwebs.

Thanks, Seb

Edit (as requested, the DFM for the Form that displays this behaviour. Note: This happens on any project I start):

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 555
  ClientWidth = 989
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poScreenCenter
  PrintScale = poNone
  Scaled = False
  PixelsPerInch = 96
  TextHeight = 13
  object Ribbon1: TRibbon
    Left = 0
    Top = 0
    Width = 989
    Height = 143
    Caption = 'Ribbon1'
    ExplicitLeft = 104
    ExplicitTop = 296
    ExplicitWidth = 0
    StyleName = 'Ribbon - Luna'
  end
end

Nothing fanciful at all, it's just a new project with a single form.

2
Do you have GlassFrame.SheetOfGlass = True? Asking because Black is the default keying color for glass, maybe "glass" somehow gets disabled for your app and you end up with the black key color visible.Cosmin Prund
@cosmin-prund - SheetOfGlass is false and the background colour is set to $00FEDABE to match the Luna colour theme. I've tried to intercept when the form is restored from its minimized state and enabling SheetOfGlass then disabling it and even resetting the colour but it didn't fix the problem. Side note: I put in GlassFrame.SheetOfGlass := NOT GlassFrame.SheetOfGlass; into a button, if I click the button twice (Glass := true then Glass := false), it sets the background to the correct colour.Sebastien
I used the following code to check if SheetOfGlass and Colour change at all -> procedure TfmMainForm.WMSysCommand; begin if (Msg.CmdType = SC_RESTORE) or (Msg.CmdType = SC_MAXIMIZE) or (Msg.CmdType = SC_MINIMIZE) then begin ShowMessage('SheetOfGlass = ' + BoolToStr(GlassFrame.SheetOfGlass, True)); ShowMessage('Colour = ' + ColorToString(Color)); end; DefaultHandler(Msg) ; end; <- and nothing changes.Sebastien
@Sebastien, the fact that toggling GlassFrame.SheetOfGlass fixes it is a hint, the black you're seeing is truly related to "glass". Unfortunately I can't test right now. I'd follow several approaches: trace the code when I toggle SheetOfGlass and see what API calls are involved, then figure out if some of those API's are called in the program for other reasons. Then I'll try to figure out if the Black is painted by the VCL or by Windows itself: I'd try overriding the form's WM_ERASEBKGND handler and paint the background red.Cosmin Prund
@cosmin-prund I'll see what I can find on how to override WM_ERASEBKGND (not that knowledgeable with API calls and such :), but what I have found is that inside the Ribbon unit, TCustomRibbon.Paint contains a suspicious piece of code: if GlassFrameSupported then begin canvas.Brush.color := clBlack; canvas.FillRect(LRect); end but changing it doesn't seem to do anything, even if I change clBlack to something else, perhaps I'm doing it wrong? (I change the code and save, not sure if that is correct). Thanks for your assist so far :) - It's suspicious to me, lolSebastien

2 Answers

4
votes

I am able to reproduce the bug, here are some of the issues I discovered. Maybe they'll help someone figure this thing out.

  • If I place a button on the form and call Invalidate from the button's OnClick event, the form gets it's colors back.
  • If I place a place a timer on the form, enable the timer from WndProc on WM_SIZE with wParam = SIZE_MAXIMIZED, then call Invalidate from the timer the form gets it's colors back. This is essentially the same as the first method (calling Invalidate from a button), but the timer makes this automatic and ensures Invalidate is called only when there are no more messages to be processed. I tried the same with a simple PostMessage but didn't work (ie: I was probably Invalidate-ing too soon, and that's probably an other clue)
  • Interesting: If I make Application.MainFormOnTaskbar := False in the project's source, I no longer see the black form.

Workaround

The ribbon takes up the top part of the form. Place a TPanel on the rest of the form, make it Align = alClient and put everything on the Panel. The Black behind the panel is no longer visible!

1
votes

You should enable glass frame when using Ribbon, because the Ribbon control is especially designed to work with aero glass frames on. Secondly you should do a little more work to configure your ribbon, adding an application menu, and some panes, to have it work as designed. I don't believe that "ribbon by itself" without any tab groups, or a system menu, is going to render properly at runtime.

If you want the ribbon to work on systems with Aero glass enabled, you should enable the glass frame property (Form.GlassFrame.Enabled) , and turn on Form.DoubleBuffered property, add some tab pages, add some tab groups, and add a system menu. Lots of steps.

Please try the attached ribbon starter project. (ribbonStarter.zip 88k)

Update If even my ribbonStarter produces the same result on your system, perhaps this should be logged in Quality Central. It is possibly a bug in your video driver, for which some code workaround in the ribbon and form code could be made.