SetWindowPos() basic question
-
I have a dialog based app, when I want to change window's position form the OnInitDialog() it doesn't work. The same code works fine form OnBnClickedOk()?!? How to setup window's position before it is shown? My test code in OnInitDialog() and OnBnClickedOk(): SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE); Thanks in advance.
-
I have a dialog based app, when I want to change window's position form the OnInitDialog() it doesn't work. The same code works fine form OnBnClickedOk()?!? How to setup window's position before it is shown? My test code in OnInitDialog() and OnBnClickedOk(): SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE); Thanks in advance.
-
I have a dialog based app, when I want to change window's position form the OnInitDialog() it doesn't work. The same code works fine form OnBnClickedOk()?!? How to setup window's position before it is shown? My test code in OnInitDialog() and OnBnClickedOk(): SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE); Thanks in advance.
PatrykDabrowski wrote:
How to setup window's position before it is shown?
You could override PreCreateWindow(). In the override, call the base class PreCreateWindow() then change the x,y,cx,cy members of the passed CREATESTRUCT. Or not for a dialog :) Mark -- modified at 13:51 Sunday 14th January, 2007
-
I have a dialog based app, when I want to change window's position form the OnInitDialog() it doesn't work. The same code works fine form OnBnClickedOk()?!? How to setup window's position before it is shown? My test code in OnInitDialog() and OnBnClickedOk(): SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE); Thanks in advance.
PatrykDabrowski wrote:
SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE);
Actually the above call works fine (as it should do...) inside
OnInitDialog()
on my system (Win2k). I made a test using theCAboutDlg
:)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
In your OnInitDialog() override are you calling the base class' OnInitDialog() first before calling SetWindowPos()?
You may be right
I may be crazy
-- Billy Joel --Within you lies the power for good, use it!!!
Yes, I'm calling SetWindowPos() just before final 'return TRUE;' statement. This dialog window is created form new thread in this way: .... CMyDialog m_lister(CDialog::FromHandle(GetDesktopWindow())); m_pMainWnd=(CWnd *)&m_lister; m_lister.DoModal(); .... Thanks for Your help.
-
PatrykDabrowski wrote:
SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE);
Actually the above call works fine (as it should do...) inside
OnInitDialog()
on my system (Win2k). I made a test using theCAboutDlg
:)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
In my CAboutDlg it is working too, but not in main dialog...(?!?) My CDialog derived class is created on a new thread form CWinThread::InitInstance() using code like this: .... CListerDialog m_lister(CDialog::FromHandle(GetDesktopWindow())); m_pMainWnd=(CWnd *)&m_lister; m_lister.DoModal(); .... hmmm, any idea why simple SetWindowPos() call doesnt work?? Thanks for help.
-
In my CAboutDlg it is working too, but not in main dialog...(?!?) My CDialog derived class is created on a new thread form CWinThread::InitInstance() using code like this: .... CListerDialog m_lister(CDialog::FromHandle(GetDesktopWindow())); m_pMainWnd=(CWnd *)&m_lister; m_lister.DoModal(); .... hmmm, any idea why simple SetWindowPos() call doesnt work?? Thanks for help.
PatrykDabrowski wrote:
CListerDialog m_lister(CDialog::FromHandle(GetDesktopWindow())); m_pMainWnd=(CWnd *)&m_lister; m_lister.DoModal();
Hu....Wy are you doing that....:confused: Anyway, I think you have to use
::GetDesktopWindow()
insted ofGetDesktopWindow()
. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
PatrykDabrowski wrote:
CListerDialog m_lister(CDialog::FromHandle(GetDesktopWindow())); m_pMainWnd=(CWnd *)&m_lister; m_lister.DoModal();
Hu....Wy are you doing that....:confused: Anyway, I think you have to use
::GetDesktopWindow()
insted ofGetDesktopWindow()
. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
"that" - You mean, setting parent window to Desktop?? I set it to have "full thread separated" dialogs. When I pass NULL to the constructor then my 'child' window minimize when I minimize my main dialog window. When I set Desktop window as its parent, I can minimize both windows independently (plus, my 'child' window has its own entry in taskbar;) Isn't that right?
-
I have a dialog based app, when I want to change window's position form the OnInitDialog() it doesn't work. The same code works fine form OnBnClickedOk()?!? How to setup window's position before it is shown? My test code in OnInitDialog() and OnBnClickedOk(): SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE); Thanks in advance.
MFC determines whether it should auto-center a dialog by comparing its RECT before and after your
OnInitDialog()
runs. (See_AfxPreInitDialog()
and_AfxPostInitDialog()
.) If the RECT is the same before and after, then MFC centers it. If the dialog's default position is (0,0) then yourSetWindowPos()
call won't move it, and it will be centered. You can either use another position, or callShowWindow(SW_SHOW)
inOnInitDialog()
so_AfxPostInitDialog()
won't do its auto-centering logic.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ");
-
MFC determines whether it should auto-center a dialog by comparing its RECT before and after your
OnInitDialog()
runs. (See_AfxPreInitDialog()
and_AfxPostInitDialog()
.) If the RECT is the same before and after, then MFC centers it. If the dialog's default position is (0,0) then yourSetWindowPos()
call won't move it, and it will be centered. You can either use another position, or callShowWindow(SW_SHOW)
inOnInitDialog()
so_AfxPostInitDialog()
won't do its auto-centering logic.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ");
WOW, thanks:) Nice trick with this (0,0) window position;) Now it works fine. Thanks again:)
-
I have a dialog based app, when I want to change window's position form the OnInitDialog() it doesn't work. The same code works fine form OnBnClickedOk()?!? How to setup window's position before it is shown? My test code in OnInitDialog() and OnBnClickedOk(): SetWindowPos(&wndTop,0,0,0,0,SWP_NOSIZE); Thanks in advance.
Use
MoveWindow
inOnInitDialog()
."Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001