|
|
Just call CWnd::CenterWindow() .
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Find the screen dimensions using GetSystemMetrics() (documentation here) with SM_CYSCREEN and SM_CXSCREEN , then use SetWindowPos() to position the window accordingly
Hope this helps,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
In response to WM_INITDIALOG (or in an OnInitDialog() override
in MFC) you could do something like this:
CRect WindowRect;
GetWindowRect(WindowRect);
SetWindowPos(0, (::GetSystemMetrics(SM_CXSCREEN) - WindowRect.Width()) / 2, (::GetSystemMetrics(SM_CYSCREEN) - WindowRect.Height()) / 2, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: In response to WM_INITDIALOG (or in an OnInitDialog() override
in MFC) you could do something like this:
But after OnInitDialog MFC does center the dialog, so IMO we don't need to do it again. In the function _AfxPostInitDialog , a check is done to make sure that the dialog does have the center style enabled, if so a call to CenterWindow is done. But above calls will only take place if the user has not by himself repositioned the dialog.
Code looks like this...
if (!pWnd->CheckAutoCenter())
return;
pWnd->CenterWindow();
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
modified on Wednesday, August 20, 2008 12:16 AM
|
|
|
|
|
Thanks Nibu.
I thought the OP wanted to know a way to actually code it.
The OP also didn't mention MFC as far as I know - that's just the
first code I found to copy/paste, and the method names matched
the equivalent APIs.
I appreciate you pointing that out to me though
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
How does Windows Live Messenger hide its frame like that? You press Alt and it shows. Does it SetWindowRgn around itself?
Thank you.
|
|
|
|
|
I assume that the border and caption around the window is simply removed using SetWindowLong() with GWL_STYLE
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Yeah but hopefully they followed their own advice and used SetWindowLongPtr
led mike
|
|
|
|
|
Is that like the programming version of being politically correct or something?
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Perspx wrote: Is that like the programming version of being politically correct or something?
No, it's more like the programming version of RTFM.
You walked right into that one.
led mike
|
|
|
|
|
I just tried that, which does work, I would just need to resize the window each time so the contents stay in same location.
What I am seeing with the Windows Live Messenger is that the caption and thickframe is just hidden.
View 1 shows that when the window is captured via ALT-Printscreen, that it is actually the full dimensions of the caption and frame. View 2 shows it with the frame in place. I was just curious how they accomplished this.
Thanks.
modified on Wednesday, August 20, 2008 7:20 AM
|
|
|
|
|
Hi all,
in my mfc dialog box application i am not handling the maximize option for the dialog box ( removed) but when I run the exe from the task manager I can maximize the dialog box....
How can I handle this so that I can give a message to the user saying this feature is not supported instead of maximizing the dialog box..
The problem if maximized is all my controls gets to one corner of the window and I want to avoid this...
please help me out in solving this bug....
Thanks in advance....
|
|
|
|
|
Interesting - I can't get my MFC dialog app to maximize
or minimize from the task manager
Have you tried adding a WM_SYSCOMMAND handler, something like this?
void CMyDialog::OnSysCommand(UINT nID, LPARAM lParam)
{
if((nID & 0xFFF0) == SC_MAXIMIZE)
return;
CDialog::OnSysCommand(nID, lParam);
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The code which u have suggested works fine if we want to handle the maximize button placed for a dialog box...
But in my application i am placing only the minimize button so no way user has a chance to maximize the dialog box......but there is one way through wichi a user can maximize the dialog box...that is using the task manager...when u run the application....go to the task manager then right click the exe running in the task manager u have the options of Minimize and Maximize along with someother options.....
I want to handle that maximize.....
|
|
|
|
|
So what you're telling me is you tried it and it didn't work?
I'd like to test it, but like I stated, I can't minimize my MFC
dialog (main window) from the task manager.
What about WM_GETMINMAXINFO?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: What about WM_GETMINMAXINFO?
Mark,
I swear, I saw your reply after posting mine.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Hey this sounds good...
I tried with this ON_WM_GETMINMAXINFO() and I can handle the call from the taskmanager now...
Thanks yaar...
modified on Tuesday, August 19, 2008 2:31 PM
|
|
|
|
|
You can do this by handling WM_GETMINMAXINFO message. Well, have a look at the code snippet. Its copy/paste from my RabbitDlg .
BEGIN_MESSAGE_MAP(CRabbitDlg, CDialog)
...
ON_WM_GETMINMAXINFO()
END_MESSAGE_MAP()
and in cpp implement function - OnGetMinMaxInfo()
void CRabbitDlg::OnGetMinMaxInfo( MINMAXINFO FAR* pMinMaxInfo )
{
RECT rect = { 0 };
GetWindowRect( &rect );
CRect WindowRect( &rect );
pMinMaxInfo->ptMaxSize.x = WindowRect.Width();
pMinMaxInfo->ptMaxSize.y = WindowRect.Height();
pMinMaxInfo->ptMaxPosition.x = rect.left;
pMinMaxInfo->ptMaxPosition.y = rect.top;
}
NB: There is one small known issue - if we maximize via taskmgr, the window remains same, but the title bar will be painted like maximized. I just suggested you one method. May be someone else will suggest you more efficient one.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Hi,
I have made an OpenGL view embedded into a scrollview. I am trying to use SetScrollSizes function to set a proper Window size, but I dont understand how the values are found, I have many rows of rectangles shown in OpenGL, and I want to adjust the length of the scrollbar to accomodate the number of rows.
I have used the following code
SetScrollSizes( MM_TEXT, CSize( 100, totalNumOfRow*60 ) );
where 60 is the length of one rectangle showing on the screen.
Any help would be greatly appreciated.
|
|
|
|
|
godspeed123 wrote: I am trying to use SetScrollSizes function to set a proper Window size, but I dont understand how the values are found
Paul DiLascia's DIBView Article[^] should help you
led mike
|
|
|
|
|
Hi,
Its about the SetScrollSize property that I dont understand, not the images.
Sorry for the confusion.
|
|
|
|
|
He uses CScrollView to display the images so the code will show you how to manage the scrolling aspects, but whatever you say, I'm sure you are correct.
led mike
|
|
|
|
|
I have a multithreaded application with common data to be protected among threads.
For example I have lots of calls to the following functions from many threads :
CString getName()
{
return myName;
}
and :
void setName(CString myName)
{
this->myName=myName;
}
In deed the call to setName is very rare, and also when there is a conflit (the two functions execute at the same time, or two copies of setName are executed by two threads) even if it results in data corruption, then it is Ok, ie it is not very dangerous.
The problem is that I noted that the application crashes at that point (release and debug).
Now what is the solution ?
From the one hand I am furious that the application crash, I can't play with probabilty becuase it is a server application supposed to running 24/24.
But from the other, if I add data protection, ie like CriticalSections, then I fear for the degradation of performance.
If the addition of data protection or thread synchronization is to cause the necessary blocking of threads untill other exit the protected code blocks or data, then it is OK for me, but I want tolerate any unnecessary delay,etc. For I have at least 700 call to getName for example per thread per 3 seconds.
Our Philosophy, Mohammed Baqir Al Sadr
|
|
|
|
|
You have to use thread synchronization, a critical section is preferred.
A critical section is also known as a "fast mutex", which means that it's not a kernel object and cannot be shared among processes. The benefit is that it executes faster since a context switch to the kernel is not necessary.
2100 calls from three different threads in three seconds sounds like a design issue.
Is the name that time critical?
If the name doesn't change frequently in the background, you could cache the name in each thread and update it every e.g. five second, or at whatever frequency you desire.
What happens if a thread uses an old name? Is it possible to use the fact that an operation failed due to an erroneous name as a trigger that says "it's time to update the name"?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|