|
I have OnCtlColor for coloring controls. It works with all but the buttons. Additionally I have OnDrawItem; even if it does not do anything, the coloring made in OnCtlControl appears.
Can one explain it to me, why the coloring suddenly appears - only by virtue of declaring OnDrawItem?
But the more important issue is: text does not appear on the button - neither the originally defined text (via the button declaration), nor the text passed in OnDrawItem via DrawText.
DrawText returns the font size, i.e. apparently it runs properly - only, that the text does not appear.
|
|
|
|
|
To anyone interested:
the rectangle in the DrawText function has to be taken from DRAWITEMSTRUCT, because the position is relative to the button, i.e. the top left position is (0,0). First I passed the button position in the dialog window.
|
|
|
|
|
I ran into the same thing (kinda) a couple days ago.
If we think of there being 3 coordinate systems : screen, window, client then we see that most drawing functions are in client with the remainder in screen.
But both ExtTextOut() and DrawText() seem to use window coordinates (and of course the MS docs don't mention this).
A general solution is to get the client coord then adjust for any border. I whipped up a small function to get the border :
bool GetBorderRect( HWND H, RECT &R )
{
if( !H || !::IsWindow(H) ) return(false);
CkRECT rw(1000,1000,1000,1000);
::AdjustWindowRectEx(&rw,
::GetWindowLongPtrW(H, GWL_STYLE),
FALSE,
::GetWindowLongPtrW(H, GWL_EXSTYLE)
);
R.left = 1000 - rw.left;
R.top = 1000 - rw.top;
R.right = rw.right - 1000;
R.bottom = rw.bottom - 1000;
return(true);
}
I can then do something like (for custom static painting) :
CkRECT rc; ::GetClientRect(wndHnd, rc);
CkRECT rb; ::GetBorderRect(wndHnd, rb);
rc.MoveBy(rb.left, rb.top);
::ExtTextOutW(DC, rc.left,rc.top, ETO_OPAQUE, &rc, NULL, 0, NULL);
...
::DrawTextW(DC, s, -1, &rc, TxtStyle);
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Thanks. Somewhere I calculated the recangle the same way you suggest; however in OnDrawItem it is not necessary, because the rectangle is part of the parameter.
The reason I'm writing this is another issue. You mentioned the different coordinate systems (it's a real joy, isn't it).
If you are working on products, which have to run on all 32-bit Windows, you may find following information useful.
I just wrote a program, which stretches respectively shrinks a dialog window (every control, fonts, etc.) on special user key actions, in order to adjust it to monitor resolution and magnification.
Anyway, I needed the size of the desktop to maximize the window size.
deskwnd = GetDesktopWindow();
(*deskwnd).GetWindowPlacement(&desktop);
Now, this works well on XP and Win98 (I have not tested it on Win2000), but on Win95 it returns a negative number for the width of the desktop (but the height is ok .
I tested it with different resolutions: the returned value is always the correct value - 5428.
I thought you might use this info.
|
|
|
|
|
Vancouver wrote:
however in OnDrawItem it is not necessary, because the rectangle is part of the parameter.
I don't use MFC anymore, i've got my own Win32 class framework. It is in my static window control, that does custom painting, where i needed this.
Vancouver wrote:
I just wrote a program, which stretches respectively shrinks a dialog window (every control, fonts, etc.) on special user key actions, in order to adjust it to monitor resolution and magnification.
Ouch, and i thought i was a sadist. Cool, but it must have been a pain to write.
Vancouver wrote:
Anyway, I needed the size of the desktop to maximize the window size.
Have you looked at :
GetSystemMetrics() with SM_CXSCREEN, SM_CYSCREEN, or GetDeviceCaps() with HORZRES, VERTRES (one calls the other) ?
... also when reading the doc's for GetSystemMetrics() check out SM_CXFULLSCREEN.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
I have a movie clip playing with directshow in a picture control (created with the resource editor) inside a dialog. Although it plays well and functions fine, there is one problem I can't seem to get around. When the video clip is paused and I minimize the program, everything gets repainted except for the picture control showing the paused scene (this happens 9/10 times; the other 10% it gets repainted). Is there a workaround for this or should I scrap the picture control and create my own child window with WS_CLIPCHILDREN to correct this, amd will this even correct the problem?
I mention WS_CLIPCHILDREN because the sample PlayWnd that comes w/ DirectX states the they window needs WS_CLIPCHILDREN style.
|
|
|
|
|
Hi all
im being a bit thick at the moment and my if statement does not seem
to be working as it should.
i have a CString variable called str_Status
this holds the valued "Cancelled by User"
when i step through my program and come to the below if statement
if ((str_Status != "Sent") || (str_Status != "Cancelled by User"))
i expect it not to go into the if, but it does and i dont know why
can any see whats wrong here, it seems to be with the "or", but i just cant
get it to work
thanks in advance
si
|
|
|
|
|
Hi,
As far as I can see in your example any string will go into the if code.
ie
"Cancelled by User" != "Sent" .... therefore it goes into if (the first test)
"Sent" != "Cancelled by User" .... therefore it goes into if (the second test)
"Anything else" != "Sent" ........ therefore it goes into if (the first test)
I think you may need to brush up on your or and ands, then try again!
Happy coding,
Ali
|
|
|
|
|
thanks for that, but that makes no sense at all.
|
|
|
|
|
It might be better to treat it as a truth table - Alison is right.
treat a as your first string check, eg:
bool a = (str != "Whatever");
treat b as your second one:
bool b = (str != "Something else");
then you have (effectively):
if(a || b)<br />
{<br />
}
So if str is "Whatever", then a == false, but b == true, so (a || b) == true as well, and so it goes into the if
If str is "Something else", then a == true, b == false, so (a || b) == true again, so it goes into the if
If str is any other string, then a == true, b == true, so (a || b) == true, and so it goes into the if.
What you probably want is:
if( (str != "Whatever) && (str != "Something else") )<br />
{<br />
// do stuff.<br />
}
--
Ian Darling
"The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
|
|
|
|
|
The statement:
if((str_Status != "Sent" || (...))
is always true because you said you set str_Status to "Cancelled by User".
Art
|
|
|
|
|
If I understand it correctly, you don't want it to run the block of code if status = "sent" or "cancelled by user". Try doing the following if statement:
if (!((str_Status == "Sent") || (str_Status == "Cancelled by User")))
If it's equal to "Sent", then it returns false
If it's equal to "Cancelled by User", then it returns false
If it's equal to "Anything else", then it returns true.
Hope this helps,
Tim
|
|
|
|
|
Step through the != operator code (F11 in the debugger) to see the logic flow. First it tests str_status != "Sent" . Since str_status is, in fact, not equal to "Sent" , the left side of the || is true. Since || short-circuits in C, the || evaluation immediately stops and returns true . Since the if test is true , the block of code following the if runs.
What you want is
if ( str_Status != "Sent" <font color=red>&&</font> str_Status != "Cancelled by User") && not ||
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Kosh reminded me of some of the prima-donna programmers I've worked with. Knew everything but when you asked them a question; never gave you a straight answer.
-- Michael P. Butler in the Lounge
|
|
|
|
|
In an or test || if the first condition is true the second conditon is not even tested for, thus in your
if ((str_Status != "Sent") || (str_Status != "Cancelled by User"))
(str_Status != "Sent") is true so the if statement is executed. Just use (str_Status != "Cancelled by User") as the sole condition.
|
|
|
|
|
Hi,
Could anyone tell me how could I implement opening a folder as seen on some of the CD setup, such as Browse CD (MFC).
.
Thank you,
Mariusz
|
|
|
|
|
Do you mean, how to make a window automatically pop up when inserting a CD disk into the CD-drive, then
1.Add a file in your CD's root folder named: autorun.inf
2.Set it's content to
[AutoRun]
open=folderonyourCD/yourexetoberun.exe
icon=folderonyourCD/yourexetoberun.exe,3
Peter Molnar
|
|
|
|
|
In case that some of the buttons' captions (or other resources)of a dialog application have been changed - is it possible at runtime to set all the resources to their original names/values? I tried with AfxSetResourceHandle(), but nothing happened. Any suggestions how to do this? Thanks.
|
|
|
|
|
I assume you used a dialog template to create your dialog ?
Now, mostly all (if not all) controls you place on this template are NOT resources, but control windows. The button is not a resource; it is a window with "Button" class and a title it displays on it as it's caption. If you use an icon or a bitmapped button, then those resources are bound to the button: a window with a bound resource that is drawn to it.
So, once more: the dialog template is a resource, but the controls placed there are not. The template just specifies what controls are placed and where. The Framework will worry about creating these controls and placing them. Consider the template like a drawing plan.
If the captions of buttons have changed, it is possible to change them back by using GetDlgItem and specifying the ID as parameter. If you convert the return value to CButton* , you can use the 'SetWindowText' method of the class to set the button's caption.
Hope this helps. If it doesn't, I suggest you dig up the infamous 'Programming Windows' book by Charles Petzold. This should help you get started by first introducing you to the concept of resources: what and where they are and how they are used in a Windows environment.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
OK, thanks! But I was trying to avoid using GetDlgItem and SetWindowText functions. What I was asking was is it possible to load the default values (caption, size and so on)as they are defined in the *.rc file? Let's say the captions of some button or static controls have been changed (using 'SetWindowText'). Is it possible at runtime to restore the original values as they are defined in the *.rc-file? I mean to load them directly from this file? I can't get Petzold's book and that's why I'm asking here. By the way, is it available somewhere on the net as eBook?
Greetings -J.
|
|
|
|
|
How to get CMenu* for the menu loaded with the document (IDR_xxxTYPE resource) in a MDI app?
|
|
|
|
|
Call AfxGetMainWnd()->GetMenu();
|
|
|
|
|
Rejeesh.T.S wrote:
Call AfxGetMainWnd()->GetMenu();
thanks for your answer, but:
with this you get the default menu. This menu is shown when no document is open. (IDR_MAINFRAME)
I want to get the shared menu loaded by the framework if a document is loaded (IDR_xxxTYPE)
|
|
|
|
|
You need to access it through the relevant CDocTemplate object registered in InitInstance.
If your doing this in a document object, you can use GetDocTemplate()->m_hMenuShared. If you need to access it from elsewhere, you need to use the undocument class CDocManager through the CWinApp:m_pDocMan(ager) pointer. Use the GetFirstDcoTemplatePosition() and GetNExtDocTemplate() iterator functions.
Roger Allen - Sonork 100.10016
If your dead and reading this, then you have no life!
|
|
|
|
|
Hello,
I'm curious about what date type is a HANDLE? Is it an int pointer? Thanks.
|
|
|
|
|
Not exactly a pointer,it just a handle,you can take some operation on it or with it
I am seeking...
For what?
Why did you ask me for what? I don't know!
|
|
|
|
|