|
thanks!, exactly what i needed.
Fred
|
|
|
|
|
Hello,
What is the difference between 'TRUE' and 'true'
BOOL IsYes;
IsYes = TRUE;
IsYes = true;
Does TRUE and true give different results?
Thanks.
Fortitudine Vincimus!
|
|
|
|
|
BOOL is defined as typedef LONG in Visual C++ libraries
TRUE is defined as #define 1
bool is built-in data type supported in C/C++ and true. This value has 1 byte in length while BOOL has 4 bytes in a 32 bit system
-Sarath.
The more you can dream the more you can do - Michael Korda"
|
|
|
|
|
Tara14 wrote: Does TRUE and true give different results?
no. they will both set IsYes to 1
|
|
|
|
|
TRUE is a #define that Microsoft's header files defines to 1. true is a built-in value for a bool that is equal to 1 (or rather, !false ).
It makes a little more sense when you look at the differences in the datatypes. BOOL is a typedef (or #define depending on the version of the header files) for an unsigned int (that is, it is 4 bytes in size). bool is a C++ standard type that is 1 byte in size (but easily can be represented by 1 bit).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
TRUE is actually an int , because defined like this :
typedef enum {
FALSE = 0,
TRUE
} BOOL;
on the other side, bool is from the native language...
|
|
|
|
|
The important difference is between BOOL and bool . With BOOL , any non-zero value (not just TRUE ) is "true". This is the reason for the rule about never comparing a BOOL for equality with TRUE .
bool only has two possible values (true and false ).
|
|
|
|
|
If I understand correctly, if I declare a variable as
BOOL IsYes; then I can write a statement
if (IsYes == TRUE){....}
otherwise:
bool IsYes; if (IsYes == true) {...}
The confusion arose when I declare the variable as
BOOL IsYes; then, I wrote
if (ISYes == true) {..}
On compiling, I got the following warning:
warning C4805: '==' : unsafe mix of type 'int' and type 'const bool' in operation
Fortitudine Vincimus!
|
|
|
|
|
Tara14 wrote: if (IsYes == TRUE){....}
It's safer to do this :-
if(IsYes != FALSE){...}
|
|
|
|
|
Tara14 wrote: BOOL IsYes;
if (IsYes == TRUE){....}
Well, you can write that, but that's exactly what you should not do. As I just explained, TRUE is not the only value for a BOOL that means "true". The clearest (and correct) way to test a boolean for truth is simply:
if (IsYes) { ... }
|
|
|
|
|
Tara14 wrote: if (IsYes == TRUE){....}
You could write it that way, but it is much safer to write it like:
if (FALSE != IsYes)
The constant is first to avoid typographical errors (tracking down bugs when you type if (IsYes = FALSE) is a royal pain when you have large projects).
And testing against FALSE for BOOL variables is safer than testing against TRUE since TRUE is equal to 1, but a boolean expression is simply !FALSE (that is, anything other than 0).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I understand. With BOOL, any non-zero value is true...
Thank you.
Fortitudine Vincimus!
|
|
|
|
|
I have a subclass of a CEdit. I want to be able to resize the visible edit control until it reaches a preset bound and then to keep scrolling horizontaly and vertically. I wrote the following code
To create the control
<br />
dwStyle = ES_LEFT | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL;<br />
<br />
if( multiline ) {<br />
m_pEdit->setMultilineOn();<br />
dwStyle = dwStyle | ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN;<br />
}<br />
m_pEdit->set_bounds(maxWidth, maxHeight);<br />
<br />
m_pEdit->Create(dwStyle, rect, this, ID_inline_edit);<br />
<br />
m_pEdit->SetWindowText(text.data());<br />
The message mapping of my CEdit is
<br />
BEGIN_MESSAGE_MAP(U_W_Edit, CEdit)<br />
ON_WM_CTLCOLOR_REFLECT()<br />
ON_CONTROL_REFLECT(EN_UPDATE, OnEditUpdate)<br />
ON_NOTIFY_REFLECT(EN_UPDATE, OnEditUpdate)<br />
ON_WM_KEYUP()<br />
ON_WM_SIZE()<br />
ON_WM_CHAR()<br />
END_MESSAGE_MAP()<br />
My resize code is simple
<br />
afx_msg void<br />
U_W_Edit::OnEditUpdate()<br />
{<br />
<br />
if( !::IsWindow(this->m_hWnd) )<br />
return;<br />
<br />
if( m_bMaxSizeReached )<br />
return;<br />
<br />
int length = this->GetWindowTextLength() + 1;<br />
<br />
AB_TextBuffer text(length);<br />
<br />
GetWindowText(text.data(), length);<br />
<br />
AB_Integer width;<br />
AB_Integer height;<br />
<br />
this->get_text_extend((AB_Text) text, width, height);<br />
<br />
BOOL resize = FALSE;<br />
<br />
if( width.to_long() > m_width && width <= m_maxWidth ) {<br />
resize = TRUE;<br />
m_width = width.to_long();<br />
}<br />
<br />
if( height.to_long() > m_height && height <= m_maxHeight ) {<br />
resize = TRUE;<br />
m_height = height.to_long();<br />
}<br />
<br />
if( resize )<br />
this->SetWindowPos( NULL, 0, 0, m_width, m_height,<br />
SWP_NOMOVE | SWP_NOREPOSITION | SWP_NOZORDER );<br />
}<br />
However, any time that I type a new character it scrolls it horizontally or vertically. It never resizes the control until it reaches the maximum sizes.
I used Spy++ and realised that the EN_UPDATE message never reaches my CEdit subclass. I wonder how can I know that the stored text has changed. I tried doing it within the OnChar but it is a nightmare to filter out all characters like arrow keys etc and add in the existing text the new key. Is any simple way to track that the stored text has changed?
Making things simple is an art...
|
|
|
|
|
Have you tried catching the EN_CHANGE message instead of EN_UPDATE?
Kelly Ryan
|
|
|
|
|
Just tried that, makes no difference. I think the parent (a CScrollView subclass) does not reflect the EN_UPDATE/EN_CHANGE message properly to the child CEdit for some reason.
|
|
|
|
|
Hi there,
using Visual studio 2005, VC++ static library project, MFC in shared dll.
I am allocating large chunks of memory (close to 5 gb) of data, after 3 gb of allocation i get "out of memory" exception, machine has a physical memory of size 6 gb and also lot of paged memory, so i know that it is not about memory size.
if i use the same code in a vc++ MFC application with /largeaddressware turned on in Linker/System options it runs fine and allocates all the structures, i cannot find the same option for my VC++ static library project.
can some help me how do i make my static library project LARGEADDRESSAWARE or there is any workaround. I tried adding this option in additional options it did'nt work.
Thank you
Imad Khan
|
|
|
|
|
I need to disable WINDOWS XP service.
I need to disable WIA driver (it is service under Windows XP).
Can you tell me how do it? I know do it, but only by means control panel (Start), but I need to disable it in source code (Visual C++).
Please, help me.. Thanks
|
|
|
|
|
Use Service Conrol Manager or SCM. Check this out.
Best,
Jun
|
|
|
|
|
I created several new dialogs for an existing executable that runs on separate PCs. The executables are not exactly the same, so I need to carry over all the files associated with new dialogs. Where is the data for the dialog resources located so that I can assure that the IDD items are included in the other PC?
Thanks for your assistance.
John
John P.
|
|
|
|
|
I have a CDialog that displays a CTreeCtrl with checkboxes. How do i handle changing the check state?
I tried TVN_SELCHANGED and NM_CLICK but it seems that i'm too dumb to figure out how to get what i need
Thanks
|
|
|
|
|
|
Hi All,
I was looking at CMenuXP, which draw the entire menu. but the problem was it doesn't draw the arrow of the popup subitems. it lets windows to draw it by itself.
is there a way to bypass it? i need to draw the arrow with my own color (for enable and disable states)
thanks in advanced
Yaron
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
I usually mixed them and come into a mess.
|
|
|
|
|
geez.
HWND : handle to a HWD, or to a Window.
HDC : handle to a DC, or to a Device Context.
|
|
|
|
|
yes, I can understand the window, but what is exactly the Device Context? what's this include? Dose it include the window, the button, the listbox....etc?
|
|
|
|