|
What you need then is a copy constructor in your BUFFER class. Have the copy c'tor make a copy of the string. The default copy c'tor just copies the pointer.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
but how would i know if the object was created locally by the function because it was passed as a parameter, or a user created it for his own use?
i want that if a user creates an instance of this class - the string will be set to "NULL" in the constructor, but if it is passed as a parameter - all its content will be replicated and not point to the original information.
|
|
|
|
|
do this in your class definition :
<font color=#0000FF>class</font> CBuffer {
<font color=#0000FF>char</font>* m_pcString;
<font color=#0000FF>int</font> m_iSize;
<font color=#0000FF>public</font>:
CBuffer() {
<font color=#008000>
m_pcString = 0x00000000;
m_iSize = 0;
}
CBuffer(<font color=#0000FF>const</font> CBuffer& refBuf) {
<font color=#008000>
m_pcString = <font color=#0000FF>new</font> <font color=#0000FF>char</font>[refBuf.m_iSize];
<font color=#0000FF>if</font> (m_pcString != NULL) {
<font color=#0000FF>this</font>->m_iSize = refBuf.m_iSize;
}
}
~CBuffer() {
<font color=#008000>
<font color=#0000FF>delete</font>[m_iSize] m_pcString;
m_iSize = 0;
}
}; then, when you call your function with a CBuffer as parameter, this one is copied by the copy constructor in local when the function is called, and destroyed when the function exits. in any case the global object is affected by the construction/destuction of the local object.
TOXCCT >>> GEII power [VisualCalc]
|
|
|
|
|
I know I can use GetDeviceCaps(desktopDC,BITSPIXEL) to get the bit depth, but what if the desktop is 16 bpp. How do I find out if its RGB555 or RGB565?
Thanks in advance.
|
|
|
|
|
I was wondering how to make my program (.exe) have an icon... I would rather do command line compilation (Vc++ is too big without the optiimiser) so could someone help me out?
|
|
|
|
|
Hi All,
Does anyone knows the algorithm to convert from long to byte?
Thanks...
|
|
|
|
|
There's no algo - long have 4 bytes and it is signed, byte is 1 byte and it's unsigned (I think).
If you do just:
<code>BYTE</code> bRes = (<code>BYTE</code>)lSomeLong;
you strip off the 3bytes including the sign. Thus it will work until you'll keep the numbers inside the long to the size of the BYTE - if it will be higher, then the information will be lost - you'll get the compiler warning.
|
|
|
|
|
Hi geo_m,
I actually need to convert from long to BYTE array of 4 (BYTE[4]) since long is 32bit (32bit = 4 bytes).
That's okay... I have found the solution.
Cheers...
Samin Thomas
|
|
|
|
|
hello all
what code do i need to write in MFC in order to check if the user has clicked alt key on the key board and how can i implement Alt+F4 fuction when the user clickes alt button on the key board and button(with caption F4) which is on my dialog box which is created in an SDI application
my alt and F4 button on the dialogbox has the following code in the fuction
void MyDialog::OnButtonalt1()
{
flag=1;
if( ( (WM_KEYDOWN||WM_SYSKEYDOWN) && (0x8000 ==(0x8000 & GetKeyState(18)) ) ) )
{
MessageBox("in Alt");
}
/*if( (WM_KEYDOWN && !GetKeyState(18)) && caps)
{
Invalidate();
}
BYTE keyState[256];
GetKeyboardState((LPBYTE)&keyState);
if( (TRUE && !(keyState[115] & 1))||(!FALSE && (keyState[115] & 1)) )
{
// Simulate a key press
keybd_event( 38,0x45,KEYEVENTF_EXTENDEDKEY|0,0);
// Simulate a key release
keybd_event(38,0x45,KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP,0);
}
*/
}
void MyDialog::OnButtonF4()
{
int i = GetKeyState(115);
if(i)
{
MessageBox("In F4");
}
}
Request to all to continue this
|
|
|
|
|
Dear u have done it, but you can't call WM_KEYDOWN ||WM_SYSKEYDOWN from inside a command, i do believe that you have to overload it as a seperate function inside that dialog, try it and it will work... Enjoy. Rabih
|
|
|
|
|
override virtual BOOL PreTranslateMessage( MSG* pMsg )
BOOL CMyDialog::PreTranslateMessage( MSG* pMsg )
{
if(pMsg->message == WM_SYSKEYDOWN)
{
//Check for F4 && Do Something
}
return CDialog:: PreTranslateMessage(pMsg);
}
|
|
|
|
|
hi,
how to find the execution time(time taken to execute) of any program in vc++
please help me out.
|
|
|
|
|
Hi
Call GetTickCount when your application starts. Refer MSDN for GetTickCount. Call GetTickCount again when your application stops. Now substract the both to get the execution time.
This will work fine if your application dont continuously execute for more than 49 days. If so you will have to do some extra work.
Regards
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
thanks a lot for your suggestion.
but i want find the time exactly, so i need to find number exection cycle of the program. with this execution cycle i can find the time taken by the code.
so please can you help me out in find execution cycle any code.
Regards and Thanking you
sham
|
|
|
|
|
does anyone know how to create a polygon for a graphics program on visual studio, i'm having problem figuring out the algorith, i know that i'm suppose to use vectors but i'm kind of lost. plus i have to ask the user to input the points of the polygon, any ideas
glowskull
|
|
|
|
|
I work with a subclassed CListCtrl. Tooltips will be displayed on the individual subitems; it works as expected.
I want to display tooltips on the header items as well. OnToolHitTest receives control, it sets the parameters, but OnToolTipText does not receive the control at all.
OnToolTipText will be mapped by
ON_NOTIFY(TTN_NEEDTEXTA, 0, On_ToolTipTextA)
ON_NOTIFY(TTN_NEEDTEXTW, 0, On_ToolTipTextW)
This should work for the CHeaderCtrl as well, should not it?
Btw, if I set the text pointer in OnToolHitTest directly in TOOLINFO.lpszText, instead of setting LPSTR_TEXTCALLBACK, it won't be displayed either (though it won't be ignored either: if I set the address of a constant string, I get an error, when it will be tried to release).
I did read about TTF_IDISHWND, etc. and tried all possible combinations, to no awail.
What else do I have to consider?
|
|
|
|
|
How do I make dialog to behave in a way that, no matter where I am clicking on the screen, I am always clicking the dialog (which is invisiable)? My program is to draw directly on the screen.
|
|
|
|
|
It depends on how it needs to act. There is away to set the transparency of a window on 2000? and XP. That is you could create a dialog that is invisable yet lets you see the screen behind it and draw on that. Or you can override the WM_PAINT and WM_NCPAINT, then only draw where you want, instead of drawing the the background and all that.
(best to do full screen window then).
The dialog needs to be the active window no matter how you do it.
There is one other possibiliy: Read up on the TRACKMOUSEEVENT, since SetCapture will not do the trick. I've used it
You may need to use a normal window instead of a dialog, if I remember correctly, dialogs do not give you much control of how there background is drawn.
Well out of ideas! I hope they were not to bad.
Good Luck!
INTP
|
|
|
|
|
Use a regular window (not a dialog), and give it the WS_EX_TOPMOST and WS_EX_TRANSPARENT extended styles.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
im using visual studio 2003.net and am trying to convert integer numbers from 1-255 into its equivalent ascii character then display it in a textbox, i tried to immediately display a character but the ascii code is the one that gets displayed. right now, im doing it the hard way by comparing each integer value and then placing into a variable its corresponding ascii character. is there a simpler way to do this? please help...
my original program flow:
char dataBuffer[512];
- data goes inside dataBuffer
- i get parts of it by using the index
- i use ToString() method to convert it to string
- display them in a textbox
the problem with this is that let's say,
dataBuffer[0] = 'A';
textBox->Text = dataBuffer[0].ToString();
OUTPUT: "65";
- i'd like it to be "A" instead of "65"
right now, i made a function which converts whatever is inside dataBuffer[x] by comparing it with ascii codes and placing in another variable the equivalent character, then that's what i display in the textbox.
i'm looking for a way to make it shorter 'coz the code to convert it is already about 510 lines.
please, please, please...
|
|
|
|
|
I don't do .NET, but have you tried:
textBox->Text = dataBuffer[0];
According MSDN online the ToString() method is doing exactly what is suposed to be doing.
INTP
|
|
|
|
|
yep, i tried that but the damn textbox keep on complaining that it cant convert char to string thingy or something like that...
|
|
|
|
|
Well if you where using regular C++ and the operator= accepted a regular C string ('\0' terminated) you could do the following.
char szTemp[2];
szTemp[0] = dataBuffer[0];
szTemp[1] = '\0';
text = szTemp;
or possibly
text = String(szTemp);
I do not know if that helped, but there is a .NET forum at CP, where I assume the experts hangout. There are also .NET articles, may be one of them will show you a code example.
Well I am done guessing!
Simple things keep getting harder to do (blast it anyway)!
INTP
|
|
|
|
|
I don't have .NET install on my machine, so I just can guess this.
dataBuffer[0] = 'A';
textBox->Text = String(dataBuffer[0]);
If it still doesn't work, try this:
dataBuffer[0] = 'A';
textBox->Text = (char)dataBuffer[0];
I hope this help.
Cheers...
Samin Thomas
|
|
|
|
|
i just did what "john" suggested and just appended a '\0' at the end of the character array. it seems to work fine...thanx again...
|
|
|
|