|
Hi everyone,
I have a question, I am curious about the greatness of Cstring, can I used this in non MFC projects? I was trying to use it like this:
#include <Cstring>
#include <iostream>
int main(){
String str("The stars are aligned");
int n = str.Find('e', 5);
cout << n;
}
Code above contains an error "error C2065: 'CString' : undeclared identifier"
Did i miss something? or CString does not work with non MFC projects?
Thanks/Regards
Sidney
|
|
|
|
|
CString will not work in non-MFC projects, it derives from CObject.
If you are going to use STL you may want to consider the basic_string<T> template class.
Or WTL contains a version of CString in the atl_misc.h file.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Ok Thanks for the great help info
Thanks/Regards
Sidney
|
|
|
|
|
BTW, basic_string<T> is typedef'ed to string in VC++
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
CString is part of MFC. You can use the STL string object in non-MFC apps. See this link [new window] for more information.
/ravi
Help put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Ok Thanks for the great help info
Thanks/Regards
Sidney
|
|
|
|
|
If you have VC++ 7, then you can use CString in non-MFC files by including the ATL headers. CString is now shared between ATL and MFC
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Buy it, read it and admire me
|
|
|
|
|
can you show me sample code to do this? i will really appreciate it if you can
Thanks/Regards
Sidney
|
|
|
|
|
Another thing is that I dont have VC++ 7 I'm using VC++ 6 so I guess I cant do this kind of thing right
Thanks/Regards
Sidney
|
|
|
|
|
Correct. There are tons of implimentations of CString type classes if std::string does not do it for you though.
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 use ShowWindow( SW_HIDE ) in my program and it flashes the frame of what would be the window but then it hides. I've tried commenting out a lot of stuff but nothing seems to work. How can I get rid of the flashing?
-Raffi
Why do today what can be put of until tommorrow?
|
|
|
|
|
Try using this instead:
::SetWindowPos(hWnd, NULL, 0,0,0,0, SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE);
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
G'day all!
I have been using CRichEditCtrl class and every 20ms or so, I add things on to the display using this class. So you can imagine there's a whole heap of lines in the display.
I have been trying very hard to make sure that the Vertical Scroll Bar is placed at the latest updated position. Could anyone help me with this one?
Any help will be appreciated!
This above all, to thine own self be TRUE.
William Shakespeare
|
|
|
|
|
I didn't try the following but I believe it should work:
1) Call long GetTextLength() to get number character
2) Call long LineFromChar( long nIndex ) to get line index
3) You may want to call LineLength() to get line length
4) Call LineScroll() by removing the offset of the GetFirstVisibleLine( ) .
CRichEditCtrl ctrl;
int nLine = ctrl.LineFromChar(ctrl.GetTextLength());
ctrl.LineScroll(nLine-ctrl.GetFirsVisibleLine());
Good luck!
One good thing about getting older, you don't lose the ages you've been!
|
|
|
|
|
Thank you Ernest!
It works great, thanks!
Life is like fishing. We are all waiting for a bite
|
|
|
|
|
I'm trying to programmatically size columns of a MSFlexGrid, but I don't understand, and have not been able to find documented, the proper way to do this.
In my case, I have a grid control on a dialog (it happens to be a tabbed dialog, but I don't know that that matters) and it will have 5 columns. I've put the following code in the OnInitDialog() function:
CRect rc;
GetClientRect(rc);
int Width = rc.Width();
Width /= (CellsPerRow + 1);
for ( int i=0; i < CellsPerRow+1; i++ )
{
m_TheGrid.SetColWidth(i, Width );
}
When this code executes, all the columns are tiny, scrunched up on the left side of the control.
The docs for SetColWidth indicate that the argument is in "twips".
I have not been able to figure out what the units of CRect are.
So one question is: How do I convert from the CRect unit to twips. Presumably this is screen resolution dependent.
Another question/problem that I'm sure I'll have to face is: how to I account for the width of the vertical scroll bar on the right of the control. I have the scroll bar enabled, and I'm betting that the GetClientRect probably includes the scroll bar in its area.
Ron
|
|
|
|
|
How do you work with _variant_t variables?
I had a few variables in my ADO code which were declared as VARIANTS.
I changed them to _variant_t, and now the function crashes.
Essentially this is what I used to do:
VARIANT var;
VariantInit(&ar);
var.vt = VT_BSTR;
///set the var.bstrval to some string value
::SysFreeString(&var);
Now, I want to do the same thing with _variant_t, but it doesn't work!
How do you handle this simple scenario using _vairant_t?
|
|
|
|
|
_variant_t is a wrapper. It will free the contents for you, that is what it is for.
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
|
|
|
|
|
You can change the code that you have to this:
variant_t var;
var = ::SysAllocString(L"HelloWorld");
that is it. No initialization, it contains casting operators, and it will clean up the mess.
BTW, If you use variant_t, you will want to use _bstr_t as well for your BSTRs.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Hi,
I have problems converting a bitmap to buffer
and displaying it
I create my hdc,
I use CreateCompatibleBitmap(),
I FillRect() with a color,
I use the function GetDIBits(...)?
GetDIBits(
MemDC,
SaveBitmap,
0,
(WORD) pvi->bmiHeader.biHeight,
pData,
pbi,
DIB_RGB_COLORS);
to put the bit map into my buffer (BYTE pData) and i'm
missing something to display it to screen
I know i can display a red colored background
using :
prgb = (RGBTRIPLE*) pData;
for (iPixel = 0; iPixel < numPixels; iPixel++, prgb++)
{
prgb->rgbtRed = 255;
prgb->rgbtGreen = 0;
prgb->rgbtBlue = 0;
}
but a non uniform bitmap????
Guibz
sguibord@aquadata.com
|
|
|
|
|
Create it as a DIBSECTION and you'll get access to the buffer by default. Chris has written a cool DIBSECTION wrapper here on CP.
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 need to write a screen capture utility that runs as fast as possible. Because I'm dealing with notebook computers with relatively slow graphics hardware, I'd like to capture just the portion of the screen that has changed since the last time I did a capture (blt'ing the whole screen takes too long). Does anyone know how I can accumulate all the update regions on the screen that occur between successive screen captures? Thanks!
|
|
|
|
|
Most likely you will have to resort to a virtual video driver the same way that netmeeting does. There is a function called GetBoundsRect that will accumulate changes to a DC, but I have not been able to get it to work with a WindowsDC only memory DCs. So if you can get that to work more poer to you (and I would also like to know what you did to get it to work).
Besides that I have done quite a bit of work to capture the screen and the fastest that I could get my utility was about 800ms on a 1000Mhz machine. The bottleneck is sending the data from the video card memory to system memory.
Once again, look at how netmeeting accomplishes this, they incorporate a virtual video driver so all new screen updates are written to their buffer as well as the screen buffer.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
You might want to have a look at the VNC source code. It's somewhere at AT&T research IIRC, but Google is your friend.
|
|
|
|