在 Windows 中隐藏控件

发布于 2024-11-14 10:02:03 字数 1618 浏览 3 评论 0原文

我不知道如何隐藏子窗口(控件),更具体地说是 GroupBox 和 PushButton。我认为使用 SW_HIDE 作为第二个参数的 ShowWindow() 可以完成这项工作,但它根本不起作用。然而SW_SHOW工作得很好。我有两个控件的正确窗口句柄,所以这不是问题。

我用谷歌搜索,我能找到的只是人们询问如何隐藏对话框,而不是控件。或者是基于 MFC 的应用程序,但此处不适用。 我使用纯 Windows API,没有 MFC

我错了什么?

编辑:更多信息:我正在为 WinApi 控件编写一些简单的类包装器。 WindowsControl 类具有以下用于显示和隐藏 Control 的方法以及其他方法:

void Show() {
    ShowWindow(this->_hWnd,SW_SHOWNOACTIVATE);
}

void Hide() {
    ShowWindow(this->_hWnd,SW_HIDE);
}

每个控件都继承自 WindowsControl。

该图像具有窗口布局,因此您可以准确理解我在做什么: https://i.sstatic.net /PHQnH.png

当用户单击“Chipset”静态控件内部时,它将加载给定 Tile 的信息(存储在数组中,但这无关紧要)。根据设置,它将隐藏左侧的“编辑位墙”按钮并显示其后面的空 GroupBox,反之亦然。 需要明确的是,这不是我的 Windows api 包装器的问题,我得到了正确的 HWND。尽管 ShowWindow 可能无法从不是父级的窗口过程中调用(这很奇怪)。

EDIT2:在 Visual Studio 2008 中使用 C++,没有 MFC、没有 WTL、没有 CLR、没有 .NET

EDIT3:我将发布更多代码,以便更容易

在静态内部窗口过程,我像这样处理 WN_LBUTTONDOWN:

case WM_LBUTTONDOWN: {
  ...
  update_tiledata(c, l)


void update_tiledata(GroupBox * c, ListView* l ) {
    ...

   if (chp_copy.Tiles[selectedTile].Pass() == PT_BITWALL) {
          c->Controls(CTL_BTNEDITBIT)->Show();
          c->Controls(CTL_FRPHOLD)->Hide();
   } else {

          c->Controls(CTL_FRPHOLD)->Show();
          c->Controls(CTL_BTNEDITBIT)->Hide();
   }
   update_edits();
}

省略的代码不会影响类,正如我之前所说,使用正确的 HWND 调用 ShowWindow 和 SW_HIDE,但是什么也没发生。

I can't figure out how to hide a child window (a control), more specifically a GroupBox and a PushButton. I thought ShowWindow() with SW_HIDE as the second parameter would do the job, but it simply doesn't work. Yet SW_SHOW works just fine. I have the correct window handle for both controls, so that's not the issue.

I googled and all I could find was people asking how to hide dialogs, not controls. Either that or MFC-based applications, which doesn't apply here.
I'm using pure Windows API, no MFC.

What am I getting wrong?

EDIT: More info: I'm writing some simple class wrappers for WinApi controls. The WindowsControl class has, along other methods, the following methods for showing and hiding the Control:

void Show() {
    ShowWindow(this->_hWnd,SW_SHOWNOACTIVATE);
}

void Hide() {
    ShowWindow(this->_hWnd,SW_HIDE);
}

Every control inherits from WindowsControl.

This image has the window layout so you understand exactly what I'm doing: https://i.sstatic.net/PHQnH.png

When the user clicks inside the "Chipset" Static control, it'll load information for a given Tile (which is stored in an array, but that's irrelevant). Depending on the setting, it'll hide the "Edit bitwall" button on the left and show the empty GroupBox behind it or viceversa.
Just to be clear this isn't something wrong with my windows api wrappers, I am getting the correct HWND. Though ShowWindow might not be able to be called from a Window Procedure that isn't the parent's (that'd be weird).

EDIT2: Using C++ with Visual Studio 2008, no MFC, no WTL, no CLR, no .NET

EDIT3: I'll post even more code so it's easier

Inside the static's window procedure, I handle WN_LBUTTONDOWN like this:

case WM_LBUTTONDOWN: {
  ...
  update_tiledata(c, l)


void update_tiledata(GroupBox * c, ListView* l ) {
    ...

   if (chp_copy.Tiles[selectedTile].Pass() == PT_BITWALL) {
          c->Controls(CTL_BTNEDITBIT)->Show();
          c->Controls(CTL_FRPHOLD)->Hide();
   } else {

          c->Controls(CTL_FRPHOLD)->Show();
          c->Controls(CTL_BTNEDITBIT)->Hide();
   }
   update_edits();
}

The ommited code does nothing to affect the classes, as I said before, ShowWindow with SW_HIDE IS getting called, with the correct HWND, but nothing is happening.

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

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

发布评论

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

评论(2

恋你朝朝暮暮 2024-11-21 10:02:03

窗口或对话框中的控件可以使用隐藏

ShowWindow(hControlWin, SW_HIDE);

在对话框中,您可以通过调用来检索控件窗口句柄

GetDlgItem(hDlg,);

通常你会写这样的内容:

ShowWindow(GetDlgItem(hDlg, 2), SW_HIDE);

如果您提供更多信息和一些代码,将会很有帮助:您是如何创建控件的?你使用什么语言、编译和框架?

A control in a Window or dialog can be hidden using

ShowWindow(hControlWin, SW_HIDE);

In a dialog you can retrive the controls window handle by calling

GetDlgItem(hDlg, < CtrlID >);

Typically you write something like:

ShowWindow(GetDlgItem(hDlg, 2), SW_HIDE);

It would be helpful if you give more information and some code: How did you create the controls? What language, compile and framework did you use?

隐诗 2024-11-21 10:02:03

我认为您想要的函数调用是 EnableWindow我以前曾使用过它来禁用表单上的按钮。不过,您需要首先获取窗口(对象)的句柄,因此您可能需要使用 EnumChildWindows 遍历所有控件以找到您想要的控件。

I think the function call you want is EnableWindow I have used this before to disable a button on a form. You will need to get an handle to the Window (object) first though so you might want to use EnumChildWindows to iterate through all the controls to find the one you want.

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