|
sorry but the static_cast keyword is part of the C++ language... portable so.
for the portability of bool , i agree. We should prefer BOOL instead...
TOXCCT >>> GEII power
|
|
|
|
|
toxcct wrote:
sorry but the static_cast keyword is part of the C++ language... portable so.
Maybe on the newer compilers, but not on the ones I started with. It's also not available in C. The point was that !! will work across the board whereas static_cast and bool will not.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
ok if you want to port code from C++ to C... but you'll probably encounter many other problems...
TOXCCT >>> GEII power
|
|
|
|
|
but BOOL would in turn go into the whole idea of a boolean (only true/false)
if I'm not mistaken takes a bool less memory then a BOOL (in Java it is so I think), but then again maybe not.
but that would take us too far...
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
why BOOL would take more memory than a bool ??
one byte doesn't it ?
TOXCCT >>> GEII power
|
|
|
|
|
Is a BOOL 1 Byte? I thought it was of size equal to an integer (cause 1,2,3,4,5,6,... = TRUE) bool doesn't know 0,1,2,3,4,...
bool is for certain 1 byte,
don't know about BOOL
Not really important when working with enough memory
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix
|
|
|
|
|
BOOL is an "int" and can have the same values as an int.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
BOOL is 4 bytes on 32-bit systems.
bool, on the other hand, is 1 byte.
Bikram Singh
|
|
|
|
|
oh... why not.
and can we have an evidence of what you are telling us ?
TOXCCT >>> GEII power
|
|
|
|
|
Fire up Visual C++ and run this code.
<br />
#include "stdafx.h"<br />
#include <conio.h><br />
#include <windows.h><br />
<br />
int main(int argc, char* argv[])<br />
{<br />
printf("\nbool = %u",sizeof(bool));<br />
printf("\nBOOL = %u",sizeof(BOOL));<br />
getch();<br />
return 0;<br />
}<br />
Bikram Singh
|
|
|
|
|
i have many more interesting things to do instead...
perhaps also you wanted to write <stdio.h> and <conio.h> ??
but, ok, that's an evidence
TOXCCT >>> GEII power
|
|
|
|
|
yup, i did. first time i've posted a #include statement.
<conio.h>
Bikram Singh
|
|
|
|
|
toxcct wrote:
perhaps also you wanted to write <stdio.h> and <conio.h> ??
They're there. Look closely!
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
DavidCrow wrote:
They're there
hem, maybe they are too big and i'm too close...
TOXCCT >>> GEII power
|
|
|
|
|
What David means is, look at the page's source code...
"look closely", "read between the lines" etc... get it ?
Bikram Singh
|
|
|
|
|
toxcct wrote:
for the portability of bool, i agree. We should prefer BOOL instead...
no, BOOL is MS-specific, bool is ANSI C++. Also, you should always compare via similar types, so a correct form of the original (according to my profiler) would be:
bool bAllowUnvalidateTextResult = (siteFlags.GetNbrValue(ALLOW_UNVALIDATE_TEXTRESULT) == 1) ? true : false;
that is, if GetNbrValue returns an int .
~Nitron.
ññòòïðïðB A start
|
|
|
|
|
Nitron wrote:
bool is ANSI C++
yes. int too. and to prevent any change between architectures, the types ares redefined to be similar on every systems. that's called portability
Nitron wrote:
Also, you should always compare via similar types
but the implicit casts also exist ! i only said that my code line was working. i never said it was the best !
TOXCCT >>> GEII power
|
|
|
|
|
toxcct wrote:
i only said that my code line was working. i never said it was the best !
I know, and I do it too, what I was saying was that my Parasoft C++ Test profiler says it's bad practice, but hey, what do profilers know
~Nitron.
ññòòïðïðB A start
|
|
|
|
|
What if GetNbrValue() returns 2? Do all non-zero values indicate true?
How about:
bool bAllowUnvalidateTextResult = (siteFlags.GetNbrValue(ALLOW_UNVALIDATE_TEXTRESULT) == 0) ? false : true;
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
atenshun to detale!
i like, i like!
Bikram Singh
|
|
|
|
|
bool a = b != 0;
That works just fine and IMHO is much clearer.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I've a got a problem using a MsFlexGrid control in a CDialogBar window.
I've developed a new class derived from CDialogBar in order to manage the DialogBar window.
My project is a MDI and the instance of my class (derived from CDialogBar) belongs to CMainFrame class.
My problem is the following:
- the MsFlexGrid control doesn't receive any user interface event (scroll up, scroll down, onbutton, and so on....). When the main window is shown, and the DialogBar is shown within it, the user can't manage the MsFlexGrid control: in example, clicking on scroll bar buttons doesn't have any effect.
I think I need to write some code in CMainFrame class in order to let it map all MsFlexGrid control windows messages, but I don't know how to do it !
I'm able to do it for other controls like buttons, listboxes and so on... but I think is not the same for MsFlexGrid. For that kind of controls I use the following code in CMainFrame:
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)<br />
ON_BN_CLICKED(IDC_BTN_MY_BUTTON, CDlgbarMyDialogBar::OnBtnMyButton)<br />
END_MESSAGE_MAP()
But I'm almost sure it is not the same for the MSFlexgrid. By the way I don't need to write any code to let a listbox work in a CDialogBar...
so, can someone help me ?
Thank you very much !
|
|
|
|
|
If it is possible I would like to know how could I get the (x,y) coordinate just by flying over the chart by the mouse, that is how do I translate the screen coords catched by the mouse to the x,y coords of the MSChart.
Thanks in advance to any reply
|
|
|
|
|
Hi, I am a newbie using MFC. Most program scripts were copied from either books and examples.
I encounter a difficulty when I wanna to scroll view and print preview.
//======================
void CSLReaderView::OnDraw(CDC* pDC)
{
CSLReaderDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//change the mapping mode
pDC->SetMapMode(MM_LOENGLISH);
//plot a rectanglar first, height 400 pixels, not shown in the script
// display data here
pDC->TextOut(100, -500, "RECORDING REPORT");
for (i=0; i<n; i++)
="" {
="" sprintf(s,="" "%3d",="" pdoc-="">m_SLDA[i].LAi);
pDC->TextOut(100, -540-i*20, s);
}
CSize docSize(100, 400+(N+10)*20); //doc size
CRect rect; //cal page size
GetClientRect(&rect);
CSize pageSize(rect.right, rect.bottom);
CSize lineSize(0, 20); //line size
SetScrollSizes(MM_LOENGLISH, docSize, pageSize, lineSize);
}
void CSLReaderView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
void CSLReaderView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
CSLReaderDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int pageHeight = pDC->GetDeviceCaps(VERTRES); //page height (dots)
int logPixelsY = pDC->GetDeviceCaps(LOGPIXELSY); //dots/inch for pt int plotHeight = (int) (4.0*logPixelsY); //rectan->pixels for pt
int lineHeight = (int) (0.2*logPixelsY); //line hight->pixels for pt int numPages = (pDoc->m_SLDA.GetSize()*lineHeight + plotHeight) / pageHeight + 1;
pInfo ->SetMaxPage(numPages);
}
void CSLReaderView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
if (pDC->IsPrinting())
{
int pageHeight = pDC->GetDeviceCaps(VERTRES);
int OriginY = pageHeight * (pInfo->m_nCurPage-1);
pDC->SetViewportOrg(0, -OriginY);
}
//CScrollView::OnPrepareDC(pDC, pInfo); //CONFLICT 1: if so, print preview can not show the 2nd page
//CView::OnPrepareDC(pDC, pInfo); //CONFLICT 2: if so, view can not scroll
}
The conflict comes from the last two commands OnPrepareDC(), if use only the first, print preview can not show the 2nd page, i.e. all pages are the same. if use only the second, the view can not be scrolled properly in view.
Thanks for your time. The code is long but I have no other ways to describe it better.
Regards,
Nelson![Confused | :confused:](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_confused.gif)
|
|
|
|
|
Hai all,
I am uncleared with the logic used in the OnprepareDC() and OnDraw() functions in the the view class of the DRAWCLI sample application from microsoft msdn samples.
Can any one explain me.
Thanks,
Arun Chakaravarthy
|
|
|
|