请问有办法动态转换对话框的WS_CHILD和WS_POPUP属性吗

wxhazso 2011-08-25 01:14:31
如题,需要在窗口创建完成后改变,需要的时候又能改回来,请问该怎么做?
...全文
489 22 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
吹雪 2011-11-26
  • 打赏
  • 举报
回复
BOOL CChildDialog::Create( UINT nIDTemplate,CWnd* pParentWnd )
{
HINSTANCE hInst = AfxFindResourceHandle( MAKEINTRESOURCE( nIDTemplate ), RT_DIALOG);
HRSRC hResource = ::FindResource(hInst,MAKEINTRESOURCE( nIDTemplate ), RT_DIALOG);
HGLOBAL hTemplate = LoadResource(hInst, hResource);
ASSERT( hTemplate );
LPCDLGTEMPLATE lpDialogTemplate = ( LPCDLGTEMPLATE )LockResource( hTemplate );
ASSERT( lpDialogTemplate );
DWORD *ptrStyle = ( DWORD* )&lpDialogTemplate->style;
*ptrStyle &= ~( WS_OVERLAPPEDWINDOW|WS_POPUPWINDOW );
*ptrStyle |= WS_CHILDWINDOW;
UnlockResource( hTemplate );
BOOL bResult = CreateIndirect(hTemplate, pParentWnd, hInst);
FreeResource(hTemplate);

return bResult;
}
wxhazso 2011-08-25
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 visualeleven 的回复:]

引用 19 楼 wxhazso 的回复:
引用 16 楼 visualeleven 的回复:

C/C++ code
void CXXXDlg::OnOK()
{
// TODO: Add extra validation here

CAboutDlg* pDlg = new CAboutDlg;
pDlg->Create(IDD_ABOUTBOX);

pDlg->Sh……
[/Quote]
嗯 刚写了个小程序 确实可以
问题还不知道怎么解决 不过感谢各位
Eleven 2011-08-25
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 wxhazso 的回复:]
引用 16 楼 visualeleven 的回复:

C/C++ code
void CXXXDlg::OnOK()
{
// TODO: Add extra validation here

CAboutDlg* pDlg = new CAboutDlg;
pDlg->Create(IDD_ABOUTBOX);

pDlg->ShowWindow(SW_SHOW);
}
……
[/Quote]
你自己建个Demo程序试试,不用皮肤~
wxhazso 2011-08-25
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 visualeleven 的回复:]

C/C++ code
void CXXXDlg::OnOK()
{
// TODO: Add extra validation here

CAboutDlg* pDlg = new CAboutDlg;
pDlg->Create(IDD_ABOUTBOX);

pDlg->ShowWindow(SW_SHOW);
}

void CA……
[/Quote]
这里不用SetParent(NULL)也有效,而且父窗口也没变,但是我的程序里这样做移动画面会花 请问可能会是什么?是不是用了皮肤的关系?
gibsonboy 2011-08-25
  • 打赏
  • 举报
回复
用到函数多查查MSDN吧
Remarks
Certain window data is cached, so changes you make using SetWindowLong will not take effect until you call the SetWindowPos function. Specifically, if you change any of the frame styles, you must call SetWindowPos with the SWP_FRAMECHANGED flag for the cache to be updated properly.
gibsonboy 2011-08-25
  • 打赏
  • 举报
回复
WS_POPUPWINDOW 用这个试试,
The window is a pop-up window. The WS_CAPTION and WS_POPUPWINDOW styles must be combined to make the window menu visible.
Eleven 2011-08-25
  • 打赏
  • 举报
回复
void CXXXDlg::OnOK() 
{
// TODO: Add extra validation here

CAboutDlg* pDlg = new CAboutDlg;
pDlg->Create(IDD_ABOUTBOX);

pDlg->ShowWindow(SW_SHOW);
}

void CAboutDlg::OnOK()
{
// TODO: Add extra validation here
CRect rect;
GetWindowRect(&rect);
ModifyStyle(WS_CHILD,WS_POPUP);
MoveWindow(&rect);
SetParent(NULL);
}
Eleven 2011-08-25
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 wxhazso 的回复:]
引用 11 楼 visualeleven 的回复:

SetParent不行吗?

是说设置成WS_POPUP然后用SetParent把父对话框设置成父窗口?这样无效
用ModifyStyle(WS_CHILD,WS_POPUP)或SetWindowLong()后调用SetParent(NULL),可以从WS_CHILD换成WS_POPUP,但是这样任务栏会出现新程序图标,而且关闭时会有……
[/Quote]
以About对话框为例子,对话框模板设置的child属性,即初始时候是child风格的,程序没有DestoryWindow和delete
void CXXXDlg::OnOK() 
{
// TODO: Add extra validation here

CAboutDlg* pDlg = new CAboutDlg;
pDlg->Create(IDD_ABOUTBOX);

pDlg->ShowWindow(SW_SHOW);
}

void CAboutDlg::OnOK()
{
// TODO: Add extra validation here
CRect rect;
GetWindowRect(&rect);
ModifyStyle(WS_CHILD,WS_POPUP);
SetParent(NULL);
MoveWindow(&rect);
}
ndy_w 2011-08-25
  • 打赏
  • 举报
回复
楼主的需求有意思...
任务栏图标是因为SetParent(NULL),你设个TOOLWINDOW属性,去掉appwindow就不会出现了。
wxhazso 2011-08-25
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 visualeleven 的回复:]

SetParent不行吗?
[/Quote]
是说设置成WS_POPUP然后用SetParent把父对话框设置成父窗口?这样无效
用ModifyStyle(WS_CHILD,WS_POPUP)或SetWindowLong()后调用SetParent(NULL),可以从WS_CHILD换成WS_POPUP,但是这样任务栏会出现新程序图标,而且关闭时会有警告响声,但是没弹出什么错误或断言,真搞不懂哪里出错了 如果用SetParent把父对话框设置成父窗口,好像是变成WS_POPUP了,也能拖动,但是一拖就对话框画面就花了
柚子毛驴 2011-08-25
  • 打赏
  • 举报
回复
virtual BOOL ModifyStyle(
DWORD dwRemove,
DWORD dwAdd,
UINT nFlags
);

virtual BOOL ModifyStyleEx(
DWORD dwRemove,
DWORD dwAdd,
UINT nFlags
);
Eleven 2011-08-25
  • 打赏
  • 举报
回复
SetParent不行吗?
wxhazso 2011-08-25
  • 打赏
  • 举报
回复
如果一直都是WS_POPUP属性 跟随父对话框移动效果很差
wxhazso 2011-08-25
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 visualeleven 的回复:]

引用 7 楼 wxhazso 的回复:
引用 6 楼 visualeleven 的回复:

WS_POPUP和WS_CHILD不能一起用
WS_POPUP
Creates a pop-up window. This style cannot be used with the WS_CHILD style.

嗯 所以是在这两个之间转换

说说你为什么要再这两个属性直接转换呢?
……
[/Quote]
我需要一个子对话框 刚开始是嵌在一个父对话框里面的 所以设置成SW_CHILD属性 主要是跟随父窗口移动效果比较好 然后点击了子对话框里的一个按钮后 这个子对话框要放大同时可拖动 所以这时需要换成SW_POPUP 之后点击按钮又能换回WS_CHILD属性
Eleven 2011-08-25
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 wxhazso 的回复:]
引用 6 楼 visualeleven 的回复:

WS_POPUP和WS_CHILD不能一起用
WS_POPUP
Creates a pop-up window. This style cannot be used with the WS_CHILD style.

嗯 所以是在这两个之间转换
[/Quote]
说说你为什么要再这两个属性直接转换呢?
wxhazso 2011-08-25
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 visualeleven 的回复:]

WS_POPUP和WS_CHILD不能一起用
WS_POPUP
Creates a pop-up window. This style cannot be used with the WS_CHILD style.
[/Quote]
嗯 所以是在这两个之间转换
Eleven 2011-08-25
  • 打赏
  • 举报
回复
WS_POPUP和WS_CHILD不能一起用
WS_POPUP
Creates a pop-up window. This style cannot be used with the WS_CHILD style.
wxhazso 2011-08-25
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 gibsonboy 的回复:]

Style=Style&(!WS_CHILD);
Style |= WS_POPUP;
反之亦然。
[/Quote]
不行 至少WS_CHILD换为WS_POPUP不行
我用ModifyStyle(0,WS_POPUP,也一样,加上SetParent(NULL)后可以 可是不是我想要的效果 因为这样任务栏会出现新的窗口图标 SetParnt设置成原来的父窗口就不行了
gibsonboy 2011-08-25
  • 打赏
  • 举报
回复
Style=Style&(!WS_CHILD);
Style |= WS_POPUP;
反之亦然。
wxhazso 2011-08-25
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 gibsonboy 的回复:]

long Style;
Style=GetWindowLong(GWL_STYLE); //得到窗口风格
Style=Style|WS_CHILD|WS_POPUP;
SetWindowLong(GWL_STYLE,Style); //为窗口设置新的风格

假如你想SetWindowLong(GWL_STYLE,WS_CHILD|WS_POPUP),这样可能影响到其它的风格。
……
[/Quote]
我想做的不是加上这两个属性 而是在这两个属性间转换 比如刚开始是WS_CHILD 我需要动态转换成WS_POPUP 而且只设置SetWindowLong()好像不行
加载更多回复(2)
MFC开发过程序所需的ModifyStyle(needDelStyle,needAddStyle,SWP_FRAMECHANGED); Sytel: WS_BORDER Creates a window that has a border. WS_CAPTION Creates a window that has a title bar (implies the WS_BORDER style). Cannot be used with the WS_DLGFRAME style. WS_CHILD Creates a child window. Cannot be used with the WS_POPUP style. WS_CHILDWINDOW Same as the WS_CHILD style. WS_CLIPCHILDREN Excludes the area occupied by child windows when you draw within the parent window. Used when you create the parent window. WS_CLIPSIBLINGS Clips child windows relative to each other; that is, when a particular child window receives a paint message, the WS_CLIPSIBLINGS style clips all other overlapped child windows out of the region of the child window to be updated. (If WS_CLIPSIBLINGS is not given and child windows overlap, when you draw within the client area of a child window, it is possible to draw within the client area of a neighboring child window.) For use with the WS_CHILD style only. WS_DISABLED Creates a window that is initially disabled. WS_DLGFRAME Creates a window with a double border but no title. WS_GROUP Specifies the first control of a group of controls in which the user can move from one control to the next with the arrow keys. All controls defined with the WS_GROUP style FALSE after the first control belong to the same group. The next control with the WS_GROUP style starts the next group (that is, one group ends where the next begins). WS_HSCROLL Creates a window that has a horizontal scroll bar. WS_ICONIC Creates a window that is initially minimized. Same as the WS_MINIMIZE style. WS_MAXIMIZE Creates a window of maximum size. WS_MAXIMIZEBOX Creates a window that has a Maximize button. WS_MINIMIZE Creates a window that is initially minimized. For use with the WS_OVERLAPPED style only. WS_MINIMIZEBOX Creates a window that has a Minimize button. WS_OVERLAPPED Creates an overlapped window. An overlapped window usually has a caption a

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧