|
I suspect because it has to load a dll (shell32.dll I think). This would not really expand your memory footprint since the memory of the dll is typically shared between all programs. If your using the task manager to view the memory footprint, you have to take what it says with a grain of salt.
Joel Lucsy (jjlucsy@ameritech.net)
|
|
|
|
|
Hi, All,
How can I select item in a ListCtrl programmatically? the ListCtrl is in
Report View mode.
Thanks in advance
|
|
|
|
|
Use this...
SetItemState(index, LVIS_SELECTED, LVIS_SELECTED);
... or even this:
SetItemState(index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
|
SetItemState (idx, LVIS_SELECTED, LVIS_SELECTED);
For men use, if they have an evil turn, to write it in marble:
and whoso doth us a good turn we write it in dust.
-- Sir Thomas More
|
|
|
|
|
|
hi all..
I have win32 console application w/o MFC support..
then I " include <afx.h> " in my header file for CString..
and I declare " CString msg; " in my cpp file. Then I run and got following link errors even without setting any value to "msg" yet.
Compiling...<br />
test.cpp<br />
Linking...<br />
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex<br />
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex<br />
Debug/test.exe : fatal error LNK1120: 2 unresolved externals<br />
Error executing link.exe.<br />
<br />
test.exe - 3 error(s), 0 warning(s)<br />
the reason why i want to use CString my cpp file is to format long, and double variable as a string..
<br />
long letter_count,legal_count,tabloid_count,sqft_count;<br />
.<br />
.<br />
.<br />
msg.Format("\nLetter Size:%d\nLegal Size:%d\nTabloid Size:%d\nOverSize:%f\n",letter_count,legal_count,tabloid_count,sqft_count);<br />
<br />
|
|
|
|
|
Switch to multithreaded C runtime in project settings.
Win wrote:
the reason why i want to use CString my cpp file is to format long, and double variable as a string..
sprintf doesn't work?
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
(This does not collide with Thomas' wise advice about the run-time ibrary version you sohuld be using.)
Using CString in an app without MFC is IMHO a bad idea, even if you succeed in your endeavor. For the purposes of formatting, sprintf works pretty much the same as CString::Format (only caveat is you've got to preallocate a buffer large enough to accomodate the result).
If you need a powerful string class with similar functionalities as CString , you can use std::string s.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
You do not have to use CString just for formatiing. You can use just sprintf. That way you will not have to include any MFC related files at all.
Prashant
|
|
|
|
|
just use sprintf on a character array.
char buf[100];
snprintf(buf, 100, "\nLetter Size:%d\nLegal Size:%d\nTabloid Size:%d\nOverSize:%f\n",letter_count,legal_count,tabloid_count,sqft_count);
-c
For men use, if they have an evil turn, to write it in marble:
and whoso doth us a good turn we write it in dust.
-- Sir Thomas More
|
|
|
|
|
Well, why don't you use WTL? It supports CString .. this is much easier than trying to use MFC's CString
(a.k.a. Wal2k) www.wal2k.com
|
|
|
|
|
thank you very much.. why didn't know C that much and I only know printf to format.. thanks again for a word "sprintf".
thanks all . you all helped me...
|
|
|
|
|
I'm trying to define an array of pointers to strings, as follows:
char* pArray[5];
pArray = "text1";
(pArray+1) = "text1";
(pArray+2) = "text1";
(pArray+3) = "text1";
(pArray+4) = "text1";
Or even like this:
char* pArray[5];
char* pVar1 = "text1";
char* pVar2 = "text1";
char* pVar3 = "text1";
char* pVar4 = "text1";
char* pVar5 = "text1";
(pArray) = pVar1;
(pArray+1) = pVar2;
(pArray+2) = pVar3;
(pArray+3) = pVar4;
(pArray+4) = pVar5;
But there is something wrong in my code (I know that there is something wrong but I've never done this before), could you please show me the correct way to do it? I to do this without using the new operator because I want to allocate the memory from the stack not from the heap.
P.S. I'm not so good at using pointers in C++ or C, so please excuse my bad coding.
Thanks
(a.k.a. Wal2k) www.wal2k.com
|
|
|
|
|
try this:
const char* pArray[5] = {"text1", "text1", "text1", "text1", "text1"};
-c
For men use, if they have an evil turn, to write it in marble:
and whoso doth us a good turn we write it in dust.
-- Sir Thomas More
|
|
|
|
|
Excellent .. just one more question .. do the strings have to be the same length?
Thanx
(a.k.a. Wal2k) www.wal2k.com
|
|
|
|
|
no, they can be any length you want.
-c
For men use, if they have an evil turn, to write it in marble:
and whoso doth us a good turn we write it in dust.
-- Sir Thomas More
|
|
|
|
|
Here's another cool trick that will help prevent bugs
const char* pArray[] =
{
"text1",
"text1",
"text1",
"text1",
"text1"
};
const int numArray = sizeof(pArray) / sizeof(char*);
for (int i=0; i<numArray; i++)
{
}
That way if you change the number of items in the array you don't have to remember to update your loop condition.
Todd Smith
|
|
|
|
|
Waleed wrote:
I'm trying to define an array of pointers to strings
Can I ask why your trying to do this???
Regards,
Brian Dela
|
|
|
|
|
O.K., I'll explain what I want to do. I want to write a functon that is passed a pointer to a string then it checks whether the string starts with specific string constants (prefixes) or not.
e.g.
// PROTOTYPES
BOOL MyFunc(char* pStr);
void main()
{
char *pStr = "some text";
if(MyFunc(pStr))
printf("Correct prefix");
else
printf("wrong prefix");
}
BOOL MyFunc(char* pStr)
{
// my function compares the string to some constants to check that
// it starts with some of them, if the string doesn't it returns FALSE
// the function checks that the string start with one of the following
// strings: John, Michael, George, Donald
// here I want to define all the constant and point to them using the
// array of pointers in order to use a for loop to make the comparison
// e.g. let's imagine that I have the array and points to the right
// string constant ( the name of the array of pointers is
// pArrayOfPointerToStrings , now let's use the for loop
for(int i=0;i<4;++i)
{
// use pArrayOfPointerToStrings[i] and compare it
// to the passed string pStr
}
}
Of course that can be done in many other ways without using the array of pointers, - e.g. using char str[4][10] - but the whole point is that I want to know - learn - how to do this (define an array of pointer to strings and make it actually point to the strings)
(a.k.a. Wal2k) www.wal2k.com
|
|
|
|
|
You have ot allocate memory to each of the element os the array before you initialize it with anything.
Try this:
char* pArray[5];
pArray[0] = (char*)calloc(strlen("text1")+1,sizeof(char));
pArray[1] = (char*)calloc(strlen("text2")+1,sizeof(char));
pArray[2] = (char*)calloc(strlen("text3")+1,sizeof(char));
pArray[3] = (char*)calloc(strlen("text4")+1,sizeof(char));
pArray[4] = (char*)calloc(strlen("text5")+1,sizeof(char));
pArray[0] = "text1"
pArray[1] = "text2"
pArray[2] = "text3"
pArray[3] = "text4"
pArray[4] = "text5"
Prashant Panigrahi.
|
|
|
|
|
Hey this is no good! If you first allocate and then assign a const char * , the previously allocated memory gets lost and you'll have leaks. It should be:
pArray[0] = (char*)calloc(strlen("text1")+1,sizeof(char));
...
strcpy(pArray[0],"text1"); The memory should also be freed when no longer needed. If the guy just needs a const char * array, then no memory allocation is needed and Chris' proposal (a couple of posts above) is the way to go.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
or
*(pArray) = pVar1;
*(pArray+1) = pVar2;
*(pArray+2) = pVar3;
*(pArray+3) = pVar4;
*(pArray+4) = pVar5;
|
|
|
|
|
Waleed wrote:
pArray = "text1";
(pArray+1) = "text1";
You're not dereferencing the array correctly. The first element of pArray is pArray[0] , the second is pArray[1] , etc. pArray by itself is the entire array, and pArray+1 points past the end of the array.
--Mike--
Just released - RightClick-Encrypt v1.4 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
I've got an edit control with the ES_AUTO*SCROLL styles off, so no more text can be typed past the end of the control. I was trying to detect when this happens programmatically, and I saw that I get a WM_CHAR message indicating a backspace with a repeat count of zero when this happens. Is this documented anywhere, or do you think it's reliable? ... Or is there another way? Thanks.
|
|
|
|