|
You have to use the SystemParametersInfo function
with the SPI_GETNONCLIENTMETRICS option.
|
|
|
|
|
Use <pre> tags.
CString szTitle = szText;
TRY{
CWindowDC dc(this);
CRect r;
GetWindowRect(&r);
int nWindWidth = r.Width();
int nSpace = nWindWidth;
szTitle += szReg;
int nActualWidth = dc.GetTextExtent(szTitle).cx;
BOOL bStop = FALSE;
CString szSep;
int nCount = 0;
while (!bStop){
if (nActualWidth < nSpace){
szSep += " ";
szTitle = szText + szSep + szReg;
nActualWidth = dc.GetTextExtent(szTitle).cx;
}
else
bStop = TRUE;
nCount++;
if (nCount > 1000){
bStop = TRUE;
SetWindowText(szText + " " + szReg);
}
}
SetWindowText(szTitle);
}
CATCH(CResourceException,e){
SetWindowText(szText + " " + szReg);
}
END_CATCH
Jason Henderson quasi-homepage articles "Like it or not, I'm right!"
|
|
|
|
|
I have a window that contains an ActiveMovie4 control. I set the control window to be 500 x 500 originally, then the video resizes itself to suit the file opened. How can I get this new rect?
I tried GetWindowRect(), but this only gave me the rect that I initially set as 500 x 500. I also tried GetClientRect(), but this did the same thing and moved the dialog box outside of the main window. Please Help!!!
|
|
|
|
|
I return a variant of this type from an ATL server's interface to an ASP script's object obj . len(obj) returns 0, although in a VB test application i can see a correct returned value.
Is this combination a good one? What else could i return, except BSTR?
rechi
|
|
|
|
|
Bogdan Rechi wrote:
len(obj) returns 0,
You are supposed to use LenB instaed of Len for binary data.
|
|
|
|
|
Hi...
I want to insert text between 2 others lines in a text file.
Do I have to recreate this file or not???
Thanks in advance...
Hello World!!!
from Raphaël
|
|
|
|
|
The only way (to the best of my knowledge) is to create a new temporary file with the updated contents and then replacing the old file with this. Writing to a preexisting file works in an overwriting manner, rather than inserting extra space.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I tried the following:
void CMainFrame::OnChecking()
{
CMenu* mmenu = GetMenu();
mmenu->ModifyMenu(ID_CHECKING, MF_BYCOMMAND,ID_CHECKING, " Selection");
Invalidate();
This does change the title to "selection" but only after the second click. The old caption is still visible beneath the new one which looks like its on a button of its own placed over the old button. Please advise.
Thanks,
ns
|
|
|
|
|
Call function DrawMenuBar.
|
|
|
|
|
That was superb! I didnt know it existed! I really appreciate your help. MAny thanks!
ns
|
|
|
|
|
I have developed MFC based MDI application using VC++ 6.0. The application can open multiple documents using the File->Open menu option. Once there are many documents open, it is quite time consuming to close each of the documents one by one. For this reason I would be interested in providing a menu option under Windows popup menu i.e. Windows->CloseAll, that will help the application to close all the child windows at one shot. As an example the VC++ IDE can be referred, that provides this option. Can someone help me find a solution for doing this.
Thanks/Regards,
|
|
|
|
|
This thread discusses a similar problem, namely that of minimizing all child windows. I guess you can use the technique described there to your purposes.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
There is another easy way of doing this by writing the message handler in the CMainFrame class. The code is as follows...
void CMainFrame::OnWindowCloseall()
{
CMDIChildWnd* child = NULL;
while((child = MDIGetActive())!=NULL)
{
if (child)
child->MDIDestroy();
}
}
This will be completely MFC based.
Thanks/Regards,
|
|
|
|
|
I'm working on an application which has a CWnd descended window called CAnimateWnd.
CAnimateWnd uses SetWindowRgn(hClipRgn, TRUE) to change the shape of the window frequently. It then uses SetWindowPos() to change the location of the window.
Calling SetWindowRgn() with the second param (bRedraw) TRUE causes the window to be redrawn. Changing the position of the window with SetWindowPos() or MoveWindow() causes the window to be redrawn. However, since the new shape of the window may look wrong until the window is in its new position, I want the window to be redrawn only once.
If I call SetWindowRgn() with bRedraw as FALSE, the area beneath the window is filled back under the assumption of the new region shape rather than the old, leaving bits of the previous view behind.
Is there a way to set the window region and change the position in the same instant?
|
|
|
|
|
Hide the window before setting the new region and show it back after repositioning it.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
That works but it also makes the window flicker. Is there any other way to do it?
|
|
|
|
|
Well, I haven't tried this, but it might help reduce the flickering. Before repositioning the window, save its original surrounding rectangle with GetWindowRect . After repositiong, invalidate the desktop window with InvalidateRect using the rectangle previously saved.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
That'sa good idea. I tried it but it didn't seem to have any effect at all. Maybe I'm doing it wrong. Do you see any obvious problems with this code?
<br />
void CAnimateWnd::ChangeAppearanceAndPosition(HRGN hNewRgn, int iPosX, int iPosY)<br />
{<br />
CRect oldRect;<br />
GetWindowRect(&oldRect);<br />
<br />
SetWindowRgn(hNewRgn, FALSE);
SetWindowPos(&wndTopMost, iPosX, iPosY, 100, 100, SWP_NOACTIVATE);<br />
<br />
::InvalidateRect( GetDesktopWindow()->GetSafeHwnd(), &oldRect, TRUE);<br />
}<br />
|
|
|
|
|
The code seems OK to me There are a couple of things you might want to try:- Do a
ScreenToClient of the rectangle for the desktop window prior to using it in InvalidateRect .
- Force the repainting of the desktop window with
UpdateWindow after invalidating. Other than these, I cannot come out with any other possible reason for this failing.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I tried each of those but there was no change. My guess is that, since I did not repaint during my SetWindowRgn() call, the desktop thinks it is intended to leave the bits of previous regions behind.
If I have to I can live with the flicker but I'd much rather have a perfectly smooth animation display.
|
|
|
|
|
What about this?
void CAnimateWnd::ChangeAppearanceAndPosition(HRGN hNewRgn, int iPosX, int iPosY)
{
CRgn oldRgn;
oldRgn.CreateRectRgn(0,0,0,0);
GetWindowRgn(oldRgn);
SetWindowRgn(hNewRgn, FALSE);
GetDesktopWindow()->InvalidateRect(&oldRgn);
SetWindowPos(&wndTopMost, iPosX, iPosY, 100, 100, SWP_NOACTIVATE);
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Ah, you mean InvalidateRgn(), right? Hrmm... still no visible effect. I wonder if we're misinterpreting the expected behavior for the Desktop Window. Maybe it doesn't know how to update but, rather, is simply storing an image of the desktop in its current state, in which case that current state would include the broken bits of previous animation frames.
|
|
|
|
|
Ummm. One more try:
void CAnimateWnd::ChangeAppearanceAndPosition(HRGN hNewRgn, int iPosX, int iPosY)
{
CRgn oldRgn;
oldRgn.CreateRectRgn(0,0,0,0);
GetWindowRgn(oldRgn);
SetWindowRgn(hNewRgn, FALSE);
InvalidateRect(&oldRgn);
SetWindowPos(&wndTopMost, iPosX, iPosY, 100, 100, SWP_NOACTIVATE);
} Would you care to tell me the result now?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Same as before. No visible change.
|
|
|
|
|
I found a solution. For the curious, I will post it here:
The main problem is that the window needs to change its HRGN shape and its position at the same time. Since the new shape will not be correct until the window is in the new position, I needed the window to redrawn only when both the new HRGN and the new position have been set but I still needed to restore the background in areas of the old shape which were not part of the new shape.
<br />
void CAnimateWnd::UpdateRgnAndPos(HRGN hNewRgn, int iPosX, int iPosY)<br />
{<br />
HRGN hOldRgn = CreateRectRgn(0, 0, 0, 0);
GetWindowRgn(hOldRgn);<br />
<br />
HRGN hOffRgn = CreateRectRgn(0, 0, 0, 0);
CombineRgn(hOffRgn, hNewRgn, NULL, RGN_COPY);
OffsetRgn(hOffRgn, iPosX - m_iOldPosX, iPosY - m_iOldPosY);
<br />
HRGN hCombinedRgn = CreateRectRgn(0, 0, 0, 0);
CombineRgn(hCombineRgn, hOffRgn, hOldRgn, RGN_OR);
<br />
SetWindowRgn(hCombinedRgn, FALSE);
<br />
SetWindowPos(iPosX, iPosY, 100, 100, SWP_NOACTIVATE);
<br />
SetWindowRgn(hNewRgn, TRUE);
<br />
Invalidate(TRUE);
<br />
m_iOldPosX = iPosX;
m_iOldPosY = iPosY;<br />
}<br />
|
|
|
|
|