使用 SetWindowLong 命令更改树视图方向时,右键单击(弹出菜单)不起作用

发布于 2024-11-17 06:01:35 字数 463 浏览 4 评论 0原文

当我使用 SetWindowLong 命令更改树视图的方向时,其节点上的弹出菜单不显示。完整代码在这里:

Procedure SetWinControlBiDi(Control: TTreeView);
 var
  ExStyle: Longint;
 begin

  ExStyle := GetWindowLong(Control.Handle, GWL_EXSTYLE);

  SetWindowLong(Control.Handle, GWL_EXSTYLE, ExStyle or WS_EX_RTLREADING or WS_EX_RIGHT or WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT );

 end;


procedure TMainForm.FormShow(Sender: TObject);
 begin

  SetWinControlBiDi(TreeView1);

 end;

When I use SetWindowLong command to change direction of treeview, popupmenu on its node dose not show. Full Code is here :

Procedure SetWinControlBiDi(Control: TTreeView);
 var
  ExStyle: Longint;
 begin

  ExStyle := GetWindowLong(Control.Handle, GWL_EXSTYLE);

  SetWindowLong(Control.Handle, GWL_EXSTYLE, ExStyle or WS_EX_RTLREADING or WS_EX_RIGHT or WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT );

 end;


procedure TMainForm.FormShow(Sender: TObject);
 begin

  SetWinControlBiDi(TreeView1);

 end;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

马蹄踏│碎落叶 2024-11-24 06:01:35

执行此操作的标准方法是使用 Delphi BiDiMode 属性。最好这样做,以便 VCL 知道您想要从右到左。您还需要更改弹出菜单上的 BiDiMode 属性。

现在,正确的方法是不要更改各个组件的属性。这样做既费力又容易出错。在应用程序初始化的某个位置设置 Application.BiDiMode ,更改将传播到所有组件。

例如,您可以在应用程序的 .dpr 文件中进行更改:

Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.BiDiMode := bdRightToLeft;
Application.CreateForm(TMainForm, MainForm);
Application.Run;

您需要确保未在任何 .dfm 文件中修改任何组件的 BiDiModeParentBiDiMode。如果您只是从 .dfm 文件中删除这些行,那么将允许单个应用程序范围的 Application.BiDiMode 设置来控制一切。


您设置 GWL_EXSTYLE 的方法有问题。 VCL 控制该设置,如果您确实需要更改它,在 TForm.OnShow 中执行此操作将导致奇怪的错误。有时需要重新创建窗口,当发生这种情况时,设置 GWL_EXSTYLE 的代码将不会运行,并且树视图将恢复为从左到右。如果您确实需要修改窗口样式,那么您需要重写组件的TWinControl.CreateParams。然而,在这种情况下,VCL 直接支持 BiDi,这是最好的解决方案。

The standard way to do this is to use the Delphi BiDiMode property. It's best to do it this way so that the VCL is aware that you want right-to-left. You need to change the BiDiMode property on the popup menu too.

Now, the correct way to do this is not to change the properties on the individual components. Doing it that way is laborious and very error prone. Set Application.BiDiMode somewhere in your application's initialization and the change will propagate through to all your components.

For example you can make the change in your application's .dpr file:

Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.BiDiMode := bdRightToLeft;
Application.CreateForm(TMainForm, MainForm);
Application.Run;

You need to make sure that you have not modified any component's BiDiMode or ParentBiDiMode in any .dfm file. If you have simply remove those lines from your .dfm file and that will allow the single application wide Application.BiDiMode setting to control everything.


Your approach of setting GWL_EXSTYLE is problematic. The VCL is in control of that setting and if you do need to change it, doing so in TForm.OnShow will lead to strange bugs. Sometimes windows need to be re-created and when this happens your code to set GWL_EXSTYLE will not run and your tree view will revert to left-to-right. If you do need to modify the window styles then you need to override TWinControl.CreateParams for the component. However, in this case the VCL has direct support for BiDi and that is the best solution.

沉默的熊 2024-11-24 06:01:35

这是显示 TPopupMenu 的替代解决方案 在本例中

1- 使用 OnMouseDown 事件

2- 编写此代码以在单击鼠标右键时显示​​ TPopupMenu

 var
  pt : TPoint;

  begin
  pt := Mouse.CursorPos;

   if Button = mbRight then
        APopupMenu.Popup(pt.X, pt.Y);

祝你好运!

This is an alternative solution to show TPopupMenu In this case

1- Use OnMouseDown Event

2- Write this code to show a TPopupMenu when you click the right mouse button

 var
  pt : TPoint;

  begin
  pt := Mouse.CursorPos;

   if Button = mbRight then
        APopupMenu.Popup(pt.X, pt.Y);

Good luck !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文