Delphi 创建功能区样式的应用程序

Delphi 创建功能区样式的应用程序,delphi,ribbon,Delphi,Ribbon,使用标准的Delphi TRibbon组件,我注意到它们没有那么出色 首先,它们看起来不像微软的那样漂亮,例如TRibbon中的发光效果和颜色看起来不像Windows7中写字板或绘画中使用的那样令人印象深刻 其次,如果您想创建功能区样式的界面,我注意到没有独立于TRibbon的功能区样式菜单或弹出菜单。对于实际功能区,有,但如果出于连续性目的,您希望将功能区样式的弹出菜单指定给TListbox或TListView,则似乎没有 第三,有时禁用Ribbon操作时,即使该操作已禁用,它仍会显示热辉光

使用标准的Delphi TRibbon组件,我注意到它们没有那么出色

  • 首先,它们看起来不像微软的那样漂亮,例如TRibbon中的发光效果和颜色看起来不像Windows7中写字板或绘画中使用的那样令人印象深刻

  • 其次,如果您想创建功能区样式的界面,我注意到没有独立于TRibbon的功能区样式菜单或弹出菜单。对于实际功能区,有,但如果出于连续性目的,您希望将功能区样式的弹出菜单指定给TListbox或TListView,则似乎没有

  • 第三,有时禁用Ribbon操作时,即使该操作已禁用,它仍会显示热辉光效果,就像将鼠标悬停在该操作上一样

  • 最后,我发现在一个组中放置容器组件(如TCombobox)非常麻烦。调整控件和位置等的大小确实很尴尬

我想我的观点是,使用标准的Delphi TRibbon组件在视觉上和使用上似乎都不是最好的方法。我如何才能使一个功能区样式的应用程序看起来和工作起来像微软的一样整洁,就像我之前说的那样,就像Wordpad和Paint在Windows7中所做的那样

请查看此比较屏幕截图,以获得更好的想法:

Delphi功能区似乎不完整,除非我期望太高。我相信Ribbon组件可以为最终用户提供更好的视觉体验和更好的工作空间等

您可以提供哪些建议来增强或使TRibbon工作起来,并使其看起来像Microsoft的TRibbon


我不总是使用Ribbon风格的界面,所以购买第三方组件不是我真正想做的事情。我看过TMS和DevXpress,但就价格而言,它们看起来也没那么好。TMS看起来比标准的Delphi TRibbon更糟糕。

实用的答案是使用另一个组件集。但我使用的是对我来说非常合适的。

要获得本地的外观和感觉,请查看

这是自Windows7(以及安装了一些官方更新后的Vista)以来可用的开源包装。这是Windows 7 Word Pad使用的API

还要注意,您有两种布局:Office2007和Office2010。Delphi VCL功能区实现Office2007样式,而WindowsSeven写字板使用Office2010样式

在一些客户的项目中,我们使用了。代码的大小有点过大(有很多重复项或编写得不好的东西,如组件持久性),但它工作正常,渲染效果良好,支持2007和2010功能区样式。对于我们的客户来说,渲染才是最重要的。对于我们的开源框架,从代码生成:它将使用标准VCL组件进行基本布局,或者使用TMS组件进行完整的Office2007/2010渲染。我们只是定义了一些类,由任意一个库实现。如果您在自己的代码中使用(即
TSynForm、tsyntoolbool、TSynToolButton、tsynpopup菜单、TSynPage、TSynPager、TSynBodyPager
TSynBodyPage
类)和(对于
TSynButton
)中定义的通用组件,USETMSPACK条件将为您发挥所有的魔力

我们还没有使用Delphi 2009中引入的Ribbon组件。它的动作驱动设计不会使我们很容易与用户界面处理的事件驱动设计交互,我们不得不承认,这个组件的声誉相当差(至少在Delphi 2009版本中是如此)

Delphi的优秀Windows Ribbon框架无法满足我们对通过代码动态生成Ribbon的需求。它的设计来自微软的实现本身,是从一个XML资源创建UI,在编译时链接。。。因此,它不适合我们的需要,但可能适合您的需要,用于更“静态”的应用程序UI设计


如果在应用程序中使用类似Office的功能区,请注意。

我使用Windows功能区框架—Windows(7)附带的本机组件

下面是一个关于Delphi的Windows Ribbon框架的超短入门;复制粘贴代码的重要部分,无需太多解释:

procedure TfrmTicketDetail.ShowScenicRibbon;
begin
    try
        Fframework := UIRibbon.CoUIRibbonFramework.Create;
        Fframework.Initialize(Self.Handle, Self); //Give the ribbon the hwnd, and our implementation of uiapplication for callbacks
        OleCheck(Fframework.LoadUI(hInstance, 'APPLICATION_RIBBON'));
    except
        on e:Exception do
        begin
            if DebugHook > 0 then
                raise;
            Exit;
        end;
    end;
end;
但它开始变得毛茸茸的,因为你必须遵循微软的API

{IUIApplication}
function  OnViewChanged(viewId: SYSUINT; typeID: UI_VIEWTYPE; const view: IUnknown;
      verb: UI_VIEWVERB; uReasonCode: SYSINT): HResult; stdcall;
function  OnCreateUICommand(commandId: SYSUINT; typeID: UI_COMMANDTYPE;
      out commandHandler: IUICommandHandler): HResult; stdcall;
function  OnDestroyUICommand(commandId: SYSUINT; typeID: UI_COMMANDTYPE;
      const commandHandler: IUICommandHandler): HResult; stdcall;
然后你必须实现它们:

function TfrmTicketDetail.OnViewChanged(viewId: SYSUINT;
     typeID: UI_VIEWTYPE; const view: IUnknown; verb: UI_VIEWVERB;
     uReasonCode: SYSINT): HResult;
var
    cy: integer;
begin
    Result := S_OK;

    //viewID: The ID for the view. Only a value of zero is valid.
    if viewID <> 0 then
       Exit;

    //typeID: The only declared typeID is UI_VIEWTYPE_RIBBON
    if typeID <> UI_VIEWTYPE_RIBBON then
       Exit;

    case verb of //there are only 4 verbs: create, destroy, size, error
    UI_VIEWVERB_CREATE:
        begin
            {   The view was resized.
                In the case of the Ribbon view, the application should call
                GetHeight() to determine the height of the Ribbon.}
            (view as IUIRibbon).GetHeight(cy);
            bvTopSpacer.Height := cy;
        end;
    UI_VIEWVERB_SIZE:
        begin
            {   The view was resized.
                In the case of the Ribbon view, the application should call
                GetHeight() to determine the height of the Ribbon.}
            (view as IUIRibbon).GetHeight(cy);
            bvTopSpacer.Height := cy;
        end;
    UI_VIEWVERB_DESTROY: {nop};
    UI_VIEWVERB_ERROR: {nop};
    end;

    Result := S_OK;
end;

function TfrmTicketDetail.OnCreateUICommand(commandId: SYSUINT;
  typeID: UI_COMMANDTYPE; out commandHandler: IUICommandHandler): HResult;
begin
    commandHandler := Self; //this form will handle all commands on the ribbon;
    Result := S_OK;
end;

function TfrmTicketDetail.OnDestroyUICommand(commandId: SYSUINT; typeID: UI_COMMANDTYPE;
      const commandHandler: IUICommandHandler): HResult;
begin
   Result := E_NOTIMPL;
end;

您是否考虑过MS提供的COM版本?我认为使用它们会非常困难,但我确信最终结果会是高质量的。据我所知,Delphi ribbon组件是DevXPress“ExpressBars”的“轻”版本。您可以尝试TMS组件()。他们有自己的本地Delphi Ribbon组件,它们的组件在视觉上非常吸引人。此外,如果您将主窗体从它们提供的特定窗体降下来,则可以使用应用程序按钮效果(应用程序按钮上升到标题上方)。有关详细信息,请参阅演示文稿。@Andreas:不,它们不是DevExpress控件的轻型版本。DevXPress ExpressBars具有完全不同的代码和组件界面。@Andreas:我将确认ExpressBars中的功能区未获得Embarcadero许可。Delphi ribbon组件绝对不是DevXPress ribbon的“轻”版本。源代码使用Delphi 2010中引入的一些功能,例如新的RTTI引擎。因此,您需要Delphi 2010或更高版本才能使用此库该死。@A.Bouchez我只是在仔细阅读代码,看看我能挽救多少——自从我使用的Delphi版本以来,Object Pascal中添加了很多构造。@你的Delphi版本发布时Ian不是克林顿总统?!看起来很有趣,我肯定会更仔细地看这个答案。我以前从未听说过这个。谢谢你的独家报道。我想,我的问题是,我仍然有很多Windows XP用户,所以除非我放弃他们,或者直到
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://schemas.microsoft.com/windows/2009/Ribbon">

    <!-- Commands are like actions, with a name, a numeric ID, caption (LabelTitle), Large and Small images, etc -->
    <Application.Commands>
        <Command Name="cmdNew" Id="0xE100" Symbol="ID_CMD_NEW" LabelTitle="New document" />
        <Command Name="cmdSaveAs" Id="0xE102" Symbol="ID_CMD_SAVEAS" LabelTitle="Save as" />
        <Command Name="cmdOpen" Id="0xE103" Symbol="ID_CMD_OPEN" LabelTitle="Open" />
        <Command Name="cmdExit" Id="0xE104" Symbol="ID_CMD_EXIT" LabelTitle="Exit" />
        <Command Name="cmdUndo" Id="0xE105" Symbol="ID_CMD_UNDO" LabelTitle="Undo" />

        <Command Name="cmdCut" Id="0xE110" Symbol="ID_CMD_CUT" LabelTitle="Cut" />
        <Command Name="cmdCopy" Id="0xE111" Symbol="ID_CMD_COPY" LabelTitle="Copy" />
        <Command Name="cmdPaste" Id="0xE112" Symbol="ID_CMD_PASTE" LabelTitle="Paste" />
        <Command Name="cmdDelete" Id="0xE113" Symbol="ID_CMD_DELETE" LabelTitle="Delete" />
        <Command Name="cmdZoom" Id="0xE114" Symbol="ID_CMD_ZOOM" LabelTitle="Zoom" />

        <Command Name="tabHome" LabelTitle="Home" />

            <Command Name="grpActions" LabelTitle="Actions" />
                <Command Name="cmdSaveAndClose" Id="1101" Symbol="ID_ACTION_SAVEANDCLOSE" LabelTitle="Save and Close">
                    <Command.TooltipTitle>Save and Close (Alt+S)</Command.TooltipTitle>
                    <Command.TooltipDescription>Saves the current ticket and closes the detail screen.</Command.TooltipDescription>
                    <Command.LargeImages>
                        <Image Source="SaveAndClose.bmp" />
                    </Command.LargeImages>
                </Command>
                <Command Name="cmdBack" Id="1102" LabelTitle="Back" />
                <Command Name="cmdControlPanel" Id="1103" LabelTitle="Control Panel" />
                <Command Name="cmdSave" Id="1104" LabelTitle="Save" />

            <Command Name="grpShow" Id="1201" LabelTitle="Show" />
                <Command Name="cmdShowTicket" Id="1202" LabelTitle="Ticket" ></Command>
                <Command Name="cmdShowDiaryEntries" Id="1203" LabelTitle="Diary Entries" >
                    <Command.LargeImages>
                        <Image Source="PencilLog_32x32.bmp" />
                    </Command.LargeImages>
                </Command>
                <Command Name="cmdShowAttachments" Id="1204" LabelTitle="Attachments" />
                <Command Name="cmdShowAuditLog" Id="1205" LabelTitle="Audit Log" />
                <Command Name="cmdShowAdditional" Id="1206" LabelTitle="Additional" />

            <Command Name="grpActivity" LabelTitle="Activity" />
                <Command Name="cmdStartWorking" Id="1301" LabelTitle="Start Working"></Command>
                <Command Name="cmdStopWorking" Id="1302" LabelTitle="Stop Working"></Command>
                <Command Name="cmdPrint" Id="1303" LabelTitle="Print" >
                    <Command.LargeImages>
                        <Image Source="Printer - 256x256.bmp" />
                    </Command.LargeImages>
                    <Command.SmallImages>
                        <Image Source="Printer_16x16.bmp" />
                    </Command.SmallImages>
                </Command>
                <Command Name="cmdDuplicateTicket" Id="1304" LabelTitle="Duplicate Ticket" >
                    <Command.SmallImages>
                        <Image Source="DuplicateTicket16.bmp" />
                    </Command.SmallImages>
                </Command>

            <Command Name="grpTicketStatus" LabelTitle="Ticket Status" />
                <Command Name="cmdCloseTicket" Id="1402" LabelTitle="Close Ticket" />
                <Command Name="cmdOnHold" Id="1403" LabelTitle="On Hold" />
                <Command Name="cmdReadyForInstall" Id="1404" LabelTitle="Ready for install" />
                <Command Name="cmdReopenTicket" Id="1405" LabelTitle="Reopen Ticket" />

    </Application.Commands>

    <!-- Above is all the commands (i.e. Actions). Now we get to the tool on screen (i.e. a DFM) -->
    <Application.Views>
        <Ribbon>

            <!-- Items that appear under the "round button" menu -->
            <Ribbon.ApplicationMenu>
                <ApplicationMenu CommandName="cmdFileMenu">
                    <MenuGroup>
                        <Button CommandName="cmdNew" />
                        <Button CommandName="cmdOpen" />
                        <Button CommandName="cmdSave" />
                        <Button CommandName="cmdSaveAs" />
                    </MenuGroup>
                    <MenuGroup>
                        <Button CommandName="cmdExit" />
                    </MenuGroup>
                </ApplicationMenu>
            </Ribbon.ApplicationMenu>

            <!--What commands to add to the quick access toolbar
                    Right now only Save and Undo, just for fun-->
            <Ribbon.QuickAccessToolbar>
                <QuickAccessToolbar>
                    <QuickAccessToolbar.ApplicationDefaults>
                        <Button CommandName="cmdSave" />
                        <Button CommandName="cmdUndo" />
                    </QuickAccessToolbar.ApplicationDefaults>
                </QuickAccessToolbar>
            </Ribbon.QuickAccessToolbar>

            <!-- And now finally the actual tabs -->
            <Ribbon.Tabs>
                <!--Our one and only tab is "Home" -->
                <Tab CommandName="tabHome">
                    <Tab.ScalingPolicy>
                        <ScalingPolicy>
                            <ScalingPolicy.IdealSizes>
                                <Scale Group="grpActions" Size="Medium"/>
                                <Scale Group="grpShow" Size="Medium"/>
                                <Scale Group="grpActivity" Size="Medium"/>
                                <Scale Group="grpTicketStatus" Size="Medium"/>
                            </ScalingPolicy.IdealSizes>
                            <Scale Group="grpActions" Size="Small"/>
                            <Scale Group="grpShow" Size="Small"/>
                            <Scale Group="grpActivity" Size="Small"/>
                            <Scale Group="grpTicketStatus" Size="Small"/>
                        </ScalingPolicy>
                    </Tab.ScalingPolicy>

                    <!-- Home\Actions -->
                    <Group CommandName="grpActions" SizeDefinition="FourButtons">
                        <Button CommandName="cmdSaveAndClose" />
                        <Button CommandName="cmdBack" />
                        <Button CommandName="cmdControlPanel" />
                        <Button CommandName="cmdSave" />
                    </Group>

                    <!-- Home\Show group -->
                    <Group CommandName="grpShow" SizeDefinition="FiveButtons">
                        <ToggleButton CommandName="cmdShowTicket" />
                        <ToggleButton CommandName="cmdShowDiaryEntries" />
                        <ToggleButton CommandName="cmdShowAttachments" />
                        <ToggleButton CommandName="cmdShowAuditLog" />
                        <ToggleButton CommandName="cmdShowAdditional" />
                    </Group>

                    <!-- Home\Activity group, with a custom sizing definition 
                            so i get my "FourButtons-TwoBigTwoSmall" look -->
                    <Group CommandName="grpActivity" >
                        <SizeDefinition>
                            <ControlNameMap>
                                <ControlNameDefinition Name="button1"/>
                                <ControlNameDefinition Name="button2"/>
                                <ControlNameDefinition Name="button3"/>
                                <ControlNameDefinition Name="button4"/>
                            </ControlNameMap>
                            <GroupSizeDefinition Size="Large">
                                <ControlSizeDefinition ControlName="button1" ImageSize="Large" IsLabelVisible="true" />
                                <ControlSizeDefinition ControlName="button2" ImageSize="Large" IsLabelVisible="true" />
                                <ColumnBreak ShowSeparator="true"/>
                                <ControlSizeDefinition ControlName="button3" ImageSize="Large" IsLabelVisible="true" />
                                <ControlSizeDefinition ControlName="button4" ImageSize="Large" IsLabelVisible="true" />
                            </GroupSizeDefinition>
                            <GroupSizeDefinition Size="Medium">
                                <ControlSizeDefinition ControlName="button1" ImageSize="Large" IsLabelVisible="true" />
                                <ControlSizeDefinition ControlName="button2" ImageSize="Large" IsLabelVisible="true" />
                                <ColumnBreak ShowSeparator="true"/>
                                <Row>
                                    <ControlSizeDefinition ControlName="button3" ImageSize="Small" IsLabelVisible="true" />
                                </Row>
                                <Row>
                                    <ControlSizeDefinition ControlName="button4" ImageSize="Small" IsLabelVisible="true" />
                                </Row>
                            </GroupSizeDefinition>
                            <GroupSizeDefinition Size="Small">
                                <Row>
                                    <ControlSizeDefinition ControlName="button1" ImageSize="Small" IsLabelVisible="true" />
                                    <ControlSizeDefinition ControlName="button3" ImageSize="Small" IsLabelVisible="false" />
                                </Row>
                                <Row>
                                    <ControlSizeDefinition ControlName="button2" ImageSize="Small" IsLabelVisible="true" />
                                    <ControlSizeDefinition ControlName="button4" ImageSize="Small" IsLabelVisible="false" />
                                </Row>
                            </GroupSizeDefinition>
                        </SizeDefinition>

                        <Button CommandName="cmdStartWorking" />
                        <Button CommandName="cmdStopWorking" />
                        <Button CommandName="cmdPrint" />
                        <Button CommandName="cmdDuplicateTicket" />
                    </Group>

                    <!-- Home\Ticket Status group -->
                    <Group CommandName="grpTicketStatus" SizeDefinition="FourButtons">
                        <Button CommandName="cmdCloseTicket" />
                        <Button CommandName="cmdOnHold" />
                        <Button CommandName="cmdReadyForInstall" />
                        <Button CommandName="cmdReopenTicket" />
                    </Group>
                </Tab>
            </Ribbon.Tabs>
            <!-- End of the actual tabs -->

        </Ribbon>
    </Application.Views>
</Application>