|
why a ruler? Is not enough with a line?
If you make something with "big dimensions" where is going to be the interception point? At the top? at the middle? at the bottom?
Anyways, If you want it to be similar to the Slider Control, why don't derive a class from it and modify it in your own way?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
You are right. It's enough with a line.
|
|
|
|
|
Is it possible to either lock an executable file that is running so that it cannot be copied or, better still, to delete the disk copy of the executable file whilst it is running? The executable would not need to self delete, rather it would be deleted by a parent program that ran it using, say, CreateProcess(). This would need to work on W2K, XP and Vista.
Thanks
|
|
|
|
|
You would be better off using a licensing or dongle mechanism to keep people from pirating your software.
|
|
|
|
|
led mike wrote: You would be better off using a licensing or dongle mechanism to keep people from pirating your software.
Thanks. Of course you are right but I am not free to use that approach in this instance.
|
|
|
|
|
I want to add Fancy Looking, Buttons to my existing Windows form. The new Buttons should be Re-incarnation of original Windows Style buttons except they should have completely new look. There functionality should be the same as original buttons.
Please tell me the full procedure to accomplish the goal.
Thanks
Kunal Bajpai
|
|
|
|
|
hi...
how can i convert CString to TCHAR & CHAR to CString
paulraj
|
|
|
|
|
For Converting CString to TCHAR Use Following:
CString str;<br />
str = "Manish";<br />
TCHAR *tch = new TCHAR[10];<br />
tch = str.GetBuffer();
Now tch will contain Manish.
And for CHAR to CString Use Following:
char *ch;<br />
<br />
ch = new char[10];<br />
<br />
ch = "Manish";<br />
CString str(ch);
It will Work for you.
Manish Patel.
|
|
|
|
|
thank you. it is working now.
paulraj
|
|
|
|
|
Manish_mnp wrote: tch = str.GetBuffer();
NO !!!!!
GetBuffer() is not designed to cast a CString to a C-Style String but to access its internal buffer directly. very badly used then.
Moreover, when you use it, you have to call ReleaseBuffer() then, which you don't do here.
if you only need to cast the Cstring, use the cast operators it provides : (LPCTSTR) for instance...
there are other design issues in your code:
Manish_mnp wrote: CString str;
str = "Manish";
you should prefer declare with using the _T() macro, because if the UNICODE macro is defined, you force the CString to be initialized with an ANSI string, not multi byte.
Manish_mnp wrote: new TCHAR[10];
never new something without releasing its memory with delete !! you're leading to memory lacks, which is simply not acceptable.
Manish_mnp wrote: char ch = "Manish";
CString str(ch);
here too, you have a problem because you're assuming the state of the UNICODE macro.
you'd better have to write :
TCHAR ch = _T("Manish");
CString str(ch);
|
|
|
|
|
If I dont use new then how can i initialize char array of any size at run time.
I want to do something like this:
char *str = new char[n];
Here n can be vary at runtime.
So tell me how can i do this without new
Manish Patel
|
|
|
|
|
you seem to be a bit confused. Let me explain you some things then.
When you need a string which size may vary, of course, you have no other way than dynamically allocate the buffer (through malloc() in C, or new /new[] in C++). if your need is purely for a string, then i'd suggest you to use std::string at first by the way.
anyway, let's assume here that we must use new explicitely.
here is how to allocate the buffer, and then how we set a string in it :
TCHAR* str = new TCHAR[n];
::_tcsncpy_s(str, n, _T("Hello World"), n);
as you can see, i allocate the memory before using it.
Here is what you did. check the codes below :
Your Code :
CString str;
str = "Manish";
TCHAR *tch = new TCHAR[10];
tch = str.GetBuffer();
How you should have done it:
CString str = _T("Manish");
TCHAR* tch = new TCHAR[10];
::_tcsncpy_s(tch, 10, (LPCTSTR)str, 10);
See the differences step by step:
1- you first allocate a 10 TCHAR buffer on the stack (with the new TCHAR[10] statement).
2- the address of that memory freshly allocated is stored into the tch variable
3- you then get the address of the internal buffer of the CString object (str ) with GetBuffer()
4- you store the address of that internal buffer into the tch variable. by doing this, you overwrite the address allocate in the step 1- .
this leads into 2 falls. not only you loose the memory allocate with new, but you will never be able to release the memory that allocated.
and worst, if you make a delete[] tch , you're not going to free the memory allocated in step 1-, but you're going to delete the CString's internal buffer !!!
so, to fix this, you have to know and remember that we never assign a C-Style string using the = operator. you must use the strcpy() derived functions.
But of course, if you can use std::string class instead of char* strings, it's even better...
do you understand better now ?
|
|
|
|
|
|
Altough I had nothing to do with this question... nice explanation, thanks
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Manish_mnp wrote: CString str;
str = "Manish";
TCHAR *tch = new TCHAR[10];
tch = str.GetBuffer();
It is not a good idea to get a pointer to the CString internal buffer (have a look a t documentation). You'll better copy the buffer content to the TCHAR array.
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.
|
|
|
|
|
Your code will 'work' but is plainly wrong:
TCHAR *tch = new TCHAR[10];<br />
tch = str.GetBuffer();
You create a new buffer of 10 characters and then you make it point to another array, so you will loose ownership of your pointer resulting in a memory leak. Moreover, you point to something that is used internally by the CString class which can reallocate it and then you'll be in BIG troubles. And, you MUST call ReleaseBuffer once you called GetBuffer. You should really look at the documentation of that function before using it that way
ch = new char[10];<br />
<br />
ch = "Manish";
Once again, you allocate an array of 10 characters then you make the pointer point to another location resulting in a memory leak.
Here[^] is a nice link about those conversions
|
|
|
|
|
Manish_mnp wrote: Now tch will contain Manish.
No, it just points to str 's internal buffer. It also introduces a memory leak as tch no longer points to the address returned by the new operator.
Manish_mnp wrote: ch = "Manish";
You've made the same mistake...again. The pointer ch no longer points to the address returned by the new operator, but to a string literal instead.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
for casting from CString to TCHAR, you have the (LPCTSTR) cast operator in the CString class :
TCHAR pStr[50] = {0};
CString str = _T("Hello World");
::tcscpy(pStr, (LPCTSTR)str);
for casting from a TCHAR string to CString, you can simply use the CString constructor :
TCHAR pStr[50] = _T("Hello World");
CString str1 = pStr;
CString str2 = CString(pStr);
never use GetBuffer() method if you don't modify the CString's internal buffer. moreover, when you use GetBuffer() you have to release the buffer with a subsequent call to ReleaseBuffer() .
-- modified at 9:12 Tuesday 6th November, 2007
|
|
|
|
|
toxcct wrote: TCHAR pStr[50] = {0};
CString str = _T("Hello World");
pStr = (LPCTSTR)str;
You might want to rethink this.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: You might want to rethink this
:->
is it better now ?
|
|
|
|
|
i have a listView control has over 1000 no of items displayed, and a text box on which user types to filter the items in listview.
my problem is how to filter the items in ListView contorl. is it possible to hide contents in ListView? or any other idea to do so ?
Thanks & Regards
|
|
|
|
|
nitin3 wrote: is it possible to hide contents in ListView?
No, you have to change the ListView content.
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 would make it, saving the original data in a place, and then according on the filter, take the relevant data, erasing all datas in the list ctrl and filling it another time.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
You could make two controls, and one will always be visible and enabled and the other one will always be hidden and disabled. That way the main (unfiltered) control does not need to be recreated each time, which makes things easier for you, Windows and the user.
I need to do the same type of thing that you are describing and that is how I intend to do it.
There are many other possibilities, depending on what you need or want to do for the user.
|
|
|
|
|
Hi all,
I have made a dialog based application. In that application from the main dialog box i am opening a second dialog box, on that dialog box i have made a button control and on clicking the button a context menu appears. Now my problem is i have to write functions on items of that context menu. i derive them from the class on which button is made that is second dialog box class.
Function is being made in the second dialog box class but when i write code for displaying the message box....Nothing happens on the click event.
Can anybody please solve my problem.
Thanks in advance
|
|
|
|