主对话框问题中的ShowWindow(SW_HIDE)按钮 [英] ShowWindow(SW_HIDE) button in main dialog problem
问题描述
你好,
我有一个基于对话框的应用.
在主对话框中,我要根据程序中的某些选项设置显示或隐藏一些按钮.
我为我的按钮声明了一个控制值:ctrl_button.
显示或隐藏按钮,我称之为ctrl_button.ShowWindow(SW_HIDE);或SW_SHOW
随后是Invalidate();
但是,这似乎不起作用.
我在子对话框中也是如此,这正常工作.
如果我调用parent-> Invalidate();对孩子来说,主按钮会隐藏!!!
同样,当我最小化最大化对话框时,按钮也会隐藏...
但是当我在主要调用Invalidate()时,什么也没发生.
该按钮仍显示在屏幕上,但不可单击.
我尝试了几种涉及UpdateWindow,RedrawWindow,...的解决方案...
有人有主意吗?
谢谢
PS发生奇怪的事情:
我将按钮默认设置为不可见.
ShowWindow(SW_SHOWS)按钮
但是之后ShowWindow(SW_HIDE)不再隐藏它
Hello,
I have a dialog based app.
In the main dialog I want to show or hide some buttons, according to some option settings in my program.
I declare a control value for my button: ctrl_button.
to show or hide the button I call ctrl_button.ShowWindow(SW_HIDE); or SW_SHOW
followed by Invalidate();
however this does not seem to work.
I do the same in a child dialog and this works properly.
If I call parent->Invalidate(); from the child, the button in the main will hide!!!
Also when I minimize-maximize the dialog the button will hide...
But when I call Invalidate() in the main nothing happens.
The button is still shown on the screen, but is not clickable.
I tried several solutions involving UpdateWindow, RedrawWindow,...
Someone has an idea?
Thanks
PS a strange thing occurs:
I set the button default to invisible.
ShowWindow(SW_SHOWS) the button
but afterwards ShowWindow(SW_HIDE) does not hide it again
推荐答案
让我们说我在对话框中添加了一个名为隐藏我"的按钮,并设置了ID到IDC_BUTTON_HIDE_ME.现在,我需要隐藏它的是双击该按钮并输入:
Let''s say I added some button named `Hide Me` in my dialog and I set the ID to IDC_BUTTON_HIDE_ME. Now, all I need to hide it is to double click on that button and write:
void CMyApplicationDlg::OnBnClickedButtonHideMe()
{
// `IDC_BUTTON_HIDE_ME` is the ID of that button
this->GetDlgItem(IDC_BUTTON_HIDE_ME)->ShowWindow(SW_HIDE);
}
// Or in case you created that button manualy
void CMyApplicationDlg::OnBnClickedAnotherHideMe()
{
// `AnotherHideMeButton` is a CButton class
this->AnotherHideMeButton->ShowWindow(SW_HIDE);
}
在主对话框中,根据程序中的某些选项设置,我想显示或隐藏一些按钮.
In the main dialog I want to show or hide some buttons, according to some option settings in my program.
请注意,如果这些选项是可选的,例如此DropBox对话框中的代理设置:
< img src ="https://community.mcafee.com/servlet/JiveServlet/showImage/2-200568-16528/dropbox1.JPG"/> [
Just a simple note, If these options are optional like the proxy settings in this DropBox dialog:
<img src="https://community.mcafee.com/servlet/JiveServlet/showImage/2-200568-16528/dropbox1.JPG"/>[^]
It''s a good idea to use enable and disable instead of hide and show:
void CMyApplicationDlg::OnBnClickedButtonHideMe()
{
this->GetDlgItem(IDC_BUTTON_HIDE_ME)->EnableWindow(FALSE);
}
void CMyApplicationDlg::OnBnClickedAnotherHideMe()
{
this->AnotherHideMeButton->EnableWindow(FALSE);
}
您好,
找到了,
我重写了OnEraseBkgnd()以避免某些闪烁.
这阻止了按钮的重绘...
Hello,
found it,
I overrided OnEraseBkgnd() to avoid some flickering.
this blocked the redrawing of the buttons...
这篇关于主对话框问题中的ShowWindow(SW_HIDE)按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!