|
Let me just post my code...
here the questions.
1)what IsAnyItemChecked will return by just looking at the code??
2)why running under 2000 return true and false under XP?
3) does the function need to change?if it has to change, where would it be?
oh... let me explaine what this two functions do
I have file tree control. so my tree contains folders and files name.
There are checkbox for each folder and file name. the following IsAnyItemChecked () call recursive function IsAnyItemChecked(...) to go through the whole tree and see any item (file in this case) is checked. if checked item found, check it's parent.
then return true for checked item found. if not the function will return false. that's it...
<br />
BOOL CSMPprojectDlg::IsAnyItemChecked()<br />
{<br />
HTREEITEM hItem = m_TreeCtrl.GetRootItem();<br />
<br />
int result = IsAnyItemChecked(hItem,hItem);<br />
return result;<br />
}<br />
<br />
BOOL CSMPprojectDlg::IsAnyItemChecked(HTREEITEM hItem, HTREEITEM &ParentItem)<br />
{ <br />
<br />
BOOL CheckItemFound = FALSE;
while(hItem!=NULL)<br />
{ <br />
FileInfo *fileinfo = (FileInfo*)m_TreeCtrl.GetItemData(hItem);<br />
<br />
if(m_TreeCtrl.ItemHasChildren(hItem) || fileinfo->status == FOLDER)<br />
{<br />
IsAnyItemChecked(m_TreeCtrl.GetChildItem(hItem),hItem); <br />
}<br />
if(m_TreeCtrl.GetCheck(hItem))<br />
{<br />
CheckItemFound = TRUE ;
<br />
} <br />
hItem=m_TreeCtrl.GetNextSiblingItem(hItem);<br />
<br />
}
<br />
if(CheckItemFound == TRUE && m_TreeCtrl.ItemHasChildren(hItem))<br />
{<br />
m_TreeCtrl.SetCheck(ParentItem,TRUE); <br />
}<br />
<br />
return CheckItemFound; <br />
}<br />
|
|
|
|
|
int result = IsAnyItemChecked(hItem,hItem); prolly has nothing to do with the problem, but you are setting an int to a bool result
return result; then your returning the int as a bool..
thats the only obvious thing i see.
-dz
|
|
|
|
|
hmmm.. not really .. that's ok now.. i recode my function for xp and it is running under 2000 without error. but i'm still curious why.
|
|
|
|
|
No? Try to use one.
soptest
|
|
|
|
|
What's debugger? Can I use it with Visual Basic?
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Are you from Moon or Mars?
soptest
|
|
|
|
|
soptest wrote:
Are you from Moon or Mars?
I'm from Mercury. And you?
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
i debug it. that's how i found out the function need to recode for xp.
after changing my code, it return true for both xp and 2000.
but i just don't understand why on 2000, the function return true but false on xp
|
|
|
|
|
Hi everyone,
can anybody here help me on how to solve my problem? I'm new to c++, how can I extact a string on a string? Example:
char *str1;
str1 = "The Quick Brown Fox Jumps Over The Lazy Dog";
How can I extract the "Brown" string from str1??? and assign it into a new variable like str2 perhaps. In VB you'll just use the MID(sting,start,len) function... is there a MID like function in C or C++??
I will really appreciate any idea that you may give.
Thanks/Regards
Sidney
Thanks/Regards
Sidney
|
|
|
|
|
Are you using MFC?
If so, you can use CString function Mid, for instance:
<br />
CString str1;<br />
str1 = "The Quick Brown Fox Jumps Over The Lazy Dog";<br />
<br />
CString str2 = str1.Mid(10,5);
I love CString. If you are using stl, there are similar functions there I think, but I don't know stl well enough. Now if you are not using MFC or stl, you can do it in a loop.
<br />
char str2[6];
for(int i = 0; i < 5; i++)<br />
str2[i] = str1[10 + i];<br />
<br />
str2[5] = '\0';
I'm sure there are other ways, too.
No generalization is 100% true.
Not even this one.
|
|
|
|
|
There is a standard C/C++ function called strstr(...) that will work for char strings. Also see the MSDN article String Manipulation for a complete list of functions.
Keep Hacking...
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
Yes, but strstr will search for a substring within a string. I think what was needed was to grab a specific chunk (e.g., start at the 5th char, and get 4 more chars), which is a little different.
No generalization is 100% true.
Not even this one.
|
|
|
|
|
Yes strstr is fine... but I need to extract with offsets, I need to especify the starting point and the length. like MID in VB. But again I cant use CString co'z I'm doing my progrtam in STL, is it possible to use CString in STL programs??
Thanks/Regards
Sidney
|
|
|
|
|
No-one does anything 'in' STL. The standard template library is part of standard C++ and is available to ALL C++ programs. The std::string class exposes iterators and is therefore considered by some to be a part of STL. I guess it is a specialisation - a container that holds characters.
CString is part of MFC, and can be used in MFC programs. Many classes exist online that emulate CString's functionality for non-MFC programs.
std::string has a substr method which takes and returns exactly what you want
std::string s("Gargle Mouse");
MessageBox(0, s.substr(5, 5).c_str(), "", 0);
should ( I am doing this untested ) bring up a dialog that said 'le Mo'.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
I have an edit box that I want to display a number in. I have a member variable (m_var1) assigned to that edit box of type int. So to display a number in that edit box, it only requres a simple assignment:
m_var1 = 36;
But I want the display to be in hex ( e.g. "0x%04x" ).
Obviously I can instead use a member variable of type CString and format the numeric value the way I want.
BUT: is there a _better_ way?
Ron
|
|
|
|
|
BlackDogEngineering wrote:
BUT: is there a _better_ way?
I think you have no choice but to format the number as a string and display that. Why not link a CString to the edit control?
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
The only improvement is to use "%#04x" to automagically add the 0x prefix.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
|
|
|
|
|
Can anybody tell me why I am getting this error for the following line:
graphics = new Graphics(hdcPrint);
For your information, this is my function:
// this function is for OTCDialog: OK button
// It uses GDI to send image to a printer
void OTRDialog::OnPrintFrom()
{
DWORD size;
HDC hdcPrint;
DOCINFO docInfo;
ZeroMemory(&docInfo, sizeof(DOCINFO));
docInfo.cbSize = sizeof(DOCINFO);
docInfo.lpszDocName = "GdiplusPrint";
// Create a PRINTDLG structure, and initialize the appropriate fields.
PRINTDLG printDlg;
ZeroMemory(&printDlg, sizeof(PRINTDLG));
printDlg.lStructSize = sizeof(PRINTDLG);
printDlg.Flags = PD_RETURNDC;
// Display a print dialog box.
if(!PrintDlg(&printDlg))
{
printf("Failure\n");
}
else
{
// Now that PrintDlg has returned, a device context handle
// for the chosen printer is in printDlg->hDC.
StartDoc(hdcPrint, &docInfo);
Graphics* graphics;
StartPage(hdcPrint);
graphics = new Graphics(hdcPrint);
Image image(L"My_report.bmp");
graphics.DrawImage(&image, 5, 0, 360, 410);
// Create a string.
WCHAR string[256];
wcscpy(string, L"Sample Text");
// Initialize arguments.
Font myFont(L"Arial", 6);
PointF origin(20.0f, 5.0f);
SolidBrush blackBrush(Color(255, 0, 0, 0));
// Draw string.
graphics.DrawString(string, wcslen(string), &myFont, origin, &blackBrush);
delete graphics;
EndPage(hdcPrint);
EndDoc(hdcPrint);
DeleteDC(hdcPrint);
}
if(printDlg.hDevMode)
GlobalFree(printDlg.hDevMode);
if(printDlg.hDevNames)
GlobalFree(printDlg.hDevNames);
if(printDlg.hDC)
DeleteDC(printDlg.hDC);
}
|
|
|
|
|
How many parameters does the constructor for Graphics take? Sounds like your giving it less than the number required.
|
|
|
|
|
It takes exactly what she is giving it - a HDC.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
DEBUG_NEW defines a new operator that takes three parameters to catch memory leaks when _DEBUG is also defined. Redefine it to use the non-debug new.
Or, use the scope resolution operator ( :: ) before new to use the default C++ version.
|
|
|
|
|
1. Why does graphics have to be a pointer ? I seem to recall GDI+ does not like having new called on things in C++ ( new in C# is a totally different beast ), because it forces you to use it's .Clone methods instead.
2. Once you fix this, you'll get errors because you're using the . instead of the -> for the graphics object ( as it's a pointer ).
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
Try this:
graphics = ::new Graphics(hdcPrint);
The problem is that an MFC generated define, DEBUG_NEW, defines a "new" operator that takes three parameters. It only applies for a debug build; if you do a release build your program should work. You can undefine DEBUG_NEW so that debug builds also work.
Or, as shown in the example code above, you can use the scope resolution operator ( :: ) before new to use the default C++ version.
|
|
|
|
|
It like that there is no the splash screen compoent in
VC++.Net.How can I add a splash screen to my VC++.net porject???
|
|
|
|
|
hi, is there any equivalent structure defined in C++ as that of timespec in Unix? the timespec definition is:
struct timespec {
long tv_sec; /* number of seconds */
long tv_nsec; /* number of nanoseconds */
};
I tried to search it in MSDN to no avail.
|
|
|
|