|
The usual way is to do a bitwise "OR" of just the bit you want to set, which is 0x0200:
short result = 0x00F0 | 0x0200;
Notice that in this case "or"ing the values is equivalent to adding them together:
Binary Hex Dec
---------------------------------------
0000 0000 1111 0000 0x00F0 240
+ 0000 0010 0000 0000 0x0200 512
= 0000 0010 1111 0000 0x02F0 752
Then to check if the bit is set, you do a bitwise "AND":
bool bitIsSet = (result & 0x0200) != 0;
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
thanks all! I figured it must be easy to do...
I don't get to deal with it all that often, and I usually find myself doing it by hand!
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Hi
Quick question - am I comparing like for like if I do the following in a CEdit derived class? I am trying to determine whether or not the text will be completely visible when placed in the edit control. This code indicates that the text will not be completely visible, even though it quite clearly is!
void CMyEdit::DoSomething(const CString & strText)<br />
{<br />
CRect rectText;<br />
GetClientRect(rectText);<br />
<br />
CDC * pDC = GetDC();<br />
<br />
CSize sizeExtent = pDC->GetTextExtent(strText);<br />
<br />
if (sizeExtent.cx > rectText.Width())
{<br />
}<br />
<br />
ReleaseDC(pDC);<br />
}
Thanks in advance!
|
|
|
|
|
I just did a quick lookup on the GetTextExtent function and noticed that there's another one called GetOutputTextExtent, which may be the one you need.
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
When you call GetDC() you get a DC with a default font in it. This will (most probably) not be the font being used by the edit control. You need to use that font when measuring your text. Check the result of a call to CEdit::GetFont().
Roger Allen
Sonork 100.10016
WHats brown and sticky?
A stick or some smelly stuff!
|
|
|
|
|
Thanks for that - calling CEdit::GetFont() and passing the result to CDC::SelectObject() before doing the comparison worked a treat!
|
|
|
|
|
I am a rookie in the MFC game , and am having some awful problems in creating a Popup window. From the parent windows OnCreate i try to create the popupwindow with createEx(...). Have tried all combinations (also excluding WS_CHILD) but nothing seems to work. I receive an assert error upon launch. If I keep the window simple (WS_CHILD), no problemo. I cannot seem to find any documentation on the subject. Can anyone HELP ME.
Thanks
|
|
|
|
|
Can you say what is your assertion failor? which source file and line?
A. Riazi
|
|
|
|
|
we need to migrate a huge project overseas - or to other OS.
the project works fine on pure english OS, but crashes on other OS which use different languages, i.e. Italian and Chinese windows.
we don't need to modify the project at all because people there know english - but it crashes there.
it is too hard to find why in the moment.
any experience, hint or comment to fix the problem is useful, thx in advance.
includeh10
|
|
|
|
|
Well, is it just not starting, or do you need to do something special, like entering a special character etc?
All of my programs, developed with english OS wrk great on german windows. they even tolerate the umlauts.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
Is your project use OS resources (any strings, bitmaps, icons, ...)?
A. Riazi
|
|
|
|
|
yes, many.
bitmap, menu (which uses string), icon ...
is this possible reason?
includeh10
|
|
|
|
|
If program wants to load string (or any other resources) from resource but not found it, program will be crashed.
A. Riazi
|
|
|
|
|
If I were to press the "Print Screen" key on my keyboard, and capture whatever screen image my monitor might be showing, does window assign a filename to that screen image for later use?
Normally, that image would go to the clipboard from which you can 'Paste' it on to another screen to get the image. However, not all applications have the 'Paste' icon available (or the means for it to be used).
What I need to do, is capture a screen image, compress it, and send it as an attachment in an email message.
Thanks for any help. I appreciate it.
William
|
|
|
|
|
*print screen*
-->Open MS Paint
*paste*
*crop* (if necessary) [aside] You can use alt + print screen to capture the current window. [/aside]
File-->save as:
Select jpg format if you don't have a compression utility like win zip. Or you can choose bmp and zip it afterwards.
*attach file to e-mail*
*send*
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Also you can press Alt+Print Screen to capture "Active Window".
use paint to paste bitmap!
A. Riazi
|
|
|
|
|
A. Riazi wrote:
Also you can press Alt+Print Screen to capture "Active Window".
He said that!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Here's my suggestion: read the data directly from the clipboard. The format of the data in the clipboard is Device Independant Bitmap (CF_DIB).
There's a MFC sample that retrieve a DIB from the clipboard. Search for DIBLOOK in MSDN.
Once you have the DIB you can save it in an other format. We used Stringray SECJpeg class a few years ago but you can surely find great code for that on the net (if not on this site...).
Good luck.
|
|
|
|
|
I have a class derived from CListCtrl, and I want it send a customized message to its parent window(which is derived from CDialog) when in need. So I defined a message ID, say, "#define WM_SOMETHING WM_APP + 100" in my project and handle this message by the following way:
void CMyListCtrl::OnSomething
{
CWnd* pParent = GetParent();
if (pParent != NULL)
pParent->PostMessage(WM_SOMETHING, 0, 0);
}
afx_msg void OnSomethingHappened();
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
ON_MESSAGE(WM_SOMETHING, OnSomethingHappened)
END_MESSAGE_MAP()
void CMyDlg::OnSomethingHappened()
{
}
Now, in debug mode it works great, but in release mode it crashes. If I remove the "PostMessage..." code from implementation of CMyListCtrl, it will not crash so the problem must be there... What am I doing wrong? Thank you.
|
|
|
|
|
Your message handler function has to have the form
LRESULT CMyWnd::OnMyMessage(WPARAM WParam, LPARAM LParam)<br />
{<br />
return (LRESULT)0;<br />
}
If your app crashes in release mode the cause should be your wrong function declaration.
|
|
|
|
|
|
As a note, take a look at RegisterWindowMessage() as any WM_SOMETHING message defined using
#define WM_SOMETHING WM_USER + x
can be problematic as the message number may be in use my one of the new common controls. WHich can give possible unpredictable behaviour to your app at a later time (especially when their implementation changes)
Roger Allen
Sonork 100.10016
WHats brown and sticky?
A stick or some smelly stuff!
|
|
|
|
|
I think it doesn't matter as long as your messages are only to be used in your application, not system-wide. As MSDN says:
WM_APP through 0xBFFF: Messages available for use by applications.
Beside that fact I think in our case RegisterWindowMessage() has not been used, as in that case we'd to take on_registered_message instead of on_message.
|
|
|
|
|
did you try ::SendMessage?
A. Riazi
|
|
|
|
|
How can I get the text to a CString from a list box
with out select anything?
\Larsson
|
|
|
|