|
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.
|
|
|
|
|
Check FILETIME struct. It's not the exact equivalent, but uses 100-nanosecond intervals.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
wow, this is fast. I fooled around in lounge for a while and when I was back, you have posted the answer. Salute!
|
|
|
|
|
If you look closely at the time displayed next to the subject, you'll see that I've actually answered your question before you've asked
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
wow, you are always one or two minutes ahead of me. Do you know how to read mind remotely?
|
|
|
|
|
OK, this seems like it should be very simple but I am stumped.
How can you tell an MFC menu to display itself?
I have the CMenu object but there doesn't appear to be a function for this.
SendMessage to the CDialog might be the way to go but I'm not sure what the message would be.
Michael Kramer
-=[mkramer@hamsoft.com]=-
|
|
|
|
|
If you are trying to create a Context Menu, then you should be able to use CMenu::TrackPopupMenu(...) .
Peace!
-=- James.
"Some People Know How To Drive, Others Just Know How To Operate A Car."
(Try Check Favorites Sometime!)
|
|
|
|
|
Hello everyone.
I have a question concerning how to drag
dialog boxes.
I currently have a dialog box that is completely
filled with a CWebBrowser2 ActiveX control. I
would like to be able drag the entire dialog box
when a user does a "mousedown and drag" within
the browser control.
Can anyone please help me out with this?
Thanks.
|
|
|
|
|
pseudo-code:
1-trap mouse-down message, and save current mouse position
2-trap mouse-move message, and if mouse is down, compute new window position based on current position and original position
3- move the window.
Max.
|
|
|
|
|
Nononono.
Kids, kids, haven't had to learn Windows programming the hard way...
You trap the WM_NCHITTEST message, and if it's in the area you want to act as the caption (which is where you usually click to drag the window) you respond HT_CAPTION, else you call DefWindowProc (or equivalent).
|
|
|
|
|
I need some help with Ini files as I am going to parse them in my application .
I have the following questions:
1. THis file is not going to be placed in the Windows directory . How should i Access it using the GetProfileString method ?
2. This File is a bit different . tags [] are going to be placed as
[main]
detail1=0
detail2=1
detail3=1
[detail1]
param_a=val1
param_b=val2
param_c=val3
[detail3]
.
.
Which is the best method to extract these details ?
|
|
|
|
|
Use GetPrivateProfile...() instead of GetProfile...() . You should have no problems with the format.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|