|
Thanks much
it works with this call
i m really stupid
|
|
|
|
|
In my Visual Studi 2003 C++ project I've got a weird bug. I have a 'normal' for loop:
int i = 0 ;
for ( i = 0 ; i < m_NumberOfObjects ; i++ ) ;
{
m_ListObjects[i]->DoStuff ( ) ;
}
where m_NumberOfObjects is a static int (member variable) within the class.
The problem is the for loop seems o ignore the entry criteria so if i = 0 and m_NumberOfObjects = 0 is still goes in (even with i = 1 and m_NumberOfObjects replaced with a 0)
Has anyone came across this? or know what is going wrong?
TIA,
Andy
|
|
|
|
|
doesn't matter I'm an idiot, stray semi-colon
|
|
|
|
|
mcsherry wrote: stray semi-colon
Don't let 'em get away from you. They're feisty little buggers
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Mark Salsbery wrote: Don't let 'em get away from you. They're feisty little buggers
|
|
|
|
|
You should not put the ";" after the for loop Dear...
and you don't normally come across such issues if you know how does a for loop work:->
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
The bug is the semicolon ; following the for statement: an empty statement is controlled by the for expression while the code block inside the curly braces {} is always executed.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
I suspect you're suffering from a change in the syntax between VC6 and Visual Studio 2003 C++ combined with a stray semi colon. The scope of counters in for loops (i in your case ) has changed so that if they're declared in the loop they can't escape from the loop. You possibly have 2 i's happening here in different scopes which is to say the least. I now use this syntax to try and be both 'correct' and compatible
<br />
int i = 0;<br />
for( ; i < m_NumberOfObjects; i++ )
{<br />
m_ListObjects[i]->DoStuff();<br />
}<br />
<br />
for( int i; i < m_NumberOfObjects; i++ )
{<br />
m_ListObjects[i]->DoStuff();<br />
}<br />
The extra ; has caused the intended loop code to happen only once and declaring the i outside has let you get away with it Perhaps that's why they changed it.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
thanks all for your replies, obviously just the stray semi-colon (couldn't spot it after looking at the code for ages, post the question on here and spot it straightaway always the same!)
Andy,
|
|
|
|
|
I know the feeling.
Therefor I sometimes use one of my colleagues to wine about some extreme strange bug.
They are willing to help. Once I show them the piece of code and start explaining what it suppose to do. I start swearing at my own stupidity. Time on time i have found the bug before they do.
codito ergo sum
|
|
|
|
|
mcsherry wrote:
int i = 0 ;
for ( i = 0 ; i < m_NumberOfObjects ; i++ ) ;
{
m_ListObjects[i]->DoStuff ( ) ;
}
there you are. The semi colon in the second line is causing problems to you.
sorry, i didn't see that you figured it out by yourself.
Regards,
Vijay.
God may not give us what we 'want', but he surely gives us what we 'need'.
|
|
|
|
|
The compiler should have given you a warning about that semicolon. If not, turn warnings back on.
|
|
|
|
|
I don't think so Mike. That looks like completely valid C code with the semi-colon in there.
That one would drive me nuts if I didn't see it right away in my code LOL
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi All
i want to detect at run time what kind of device is connected to USB port(like if Digital camera is connected then it shows Digital camera etc.)like how our windows is showing(if you cannect scanner to USB port then in My computer you can view in "Type" Image scanner.
i got something "SystemParametersInfo" but i dont know how will i use it and wheter it is useful or not
Thanks in advance
R e h a n
|
|
|
|
|
Basically the symbolic link for the device should have the GUID which should be unique per type .
Look into plug and play notifications on Windows
Engineering is the effort !
|
|
|
|
|
I want to change the color of static control to white.As well as in the static controls the text also should be visible.
CStatic temp = new CStatic();
temp->Create(text ,style |SS_LEFT ,pos ,this ,m_iAutoControlID);
bhw
|
|
|
|
|
See WM_CTLCOLORSTATIC and on the this message use of SetTextColor() for text color and SetBKColor() for background color.
|
|
|
|
|
This is a dynamically created control.is there any style or method to do that.
bhw
|
|
|
|
|
I dont understand what you said can you more explain.
|
|
|
|
|
WhiteSky wrote: I dont understand what you said can you more explain.
The control is created at runtime rather than design time.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
No I want to know his question was about control or color.
|
|
|
|
|
Hello
Use WinProc or PreTranslateMessage to catch the message WM_CTLCOLORSTATIC
and compare the control id with the id that you give to your static.
And then is just the same as if you use the designer.
Something like this:
BOOL CYourDialog::PreTranslateMessage(MSG* pMsg) <br />
{<br />
if(pMsg->message == WM_KEYDOWN && pMsg->wParam==VK_RETURN)<br />
{<br />
if(IsWindow(m_YourStatic.m_hWnd))<br />
{<br />
if(pMsg->hwnd==m_YourStatic.m_hWnd)<br />
{<br />
DoSomething();<br />
}<br />
}<br />
}<br />
}
|
|
|
|
|
I am new to window programming and I need to do a task which is to know whether all the child dialogs have been exited before closing the main dialog. Can you please direct me, how can i do it?
Further explanation is the main dialog should not exit of ESC key unless all the child dialogs are properly closed.
Thanks in advance.
S.S
-- modified at 8:53 Tuesday 12th June, 2007
|
|
|
|
|
Are the child dialogs modal or modeless?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: Are the child dialogs modal
I hope not
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|