|
Is there a way to split a CString as you can in Perl?
Need to find a way to take a string and split it based on a delemiter.
for example if I have a string that looks like
c:\data\moredata\evenmoredata\datafile.dat
I need to be able to split "datafile" from the string. Since the open file Dialog supports multiple selections I can't use .GetFileTitle();
Any ideas?
|
|
|
|
|
|
Hello there,
Use CString's ReverseFind(..) function to get the position of the first backslash starting the search from the end of the string then use the Right(..) function to extract the datafile.dat name. If you don't want the extenstion you could use the Reverse find funcion again on the initial string and use the Mid(..) function to extract the name between the last backslash and the period.
Alternatively you could have called CString's GetBuffer(..) on the string and tokenize the result it using strtok() or some other low lever function. I would advise the first approach.
Art
|
|
|
|
|
I Looked over MSDN information on both ReverseFind() and strtok() before you posted this information. I did not really understand the ReverseFind() function when I first read the information, and ended up implementing strtok() to do the work, however the code that I am using to do it looks rather nasty.. but it works.. however I will look more into ReverseFind() and see if I can implement this for hopefully cleaner code.
Thank you very much for the information.
|
|
|
|
|
Here you are:
CString sPath(_T("c:\\data\\moredata\\evenmoredata\\datafile.dat"));
int nPos1 = sPath.ReverseFind('\\');
int nPos2 = sPath.ReverseFind('.');
if(nPos1 > -1 && nPos2 > -1)
{
CString sFile = sPath.Mid(nPos1+1, nPos2 - nPos1 -1);
AfxMessageBox(sFile);
}
-----------------
The ReverseFind fn just searches the string starting from the end toward the beginning and stops when it encounters the character it is looking for. The position it reports is referenced from the beginning of the string.
Art
|
|
|
|
|
Hi fellow experts, I got stuck by the following errors:
1, ::GetUserNameEx , this function, as MSDN stated, is declared in Secext.h, but after I included Secext.h I got a whole truck of compiler errors, all of which are located in Secext.h. For example:
d:\ms visual studio\vc98\include\secext.h(22) : error C2146: syntax error : missing ';' before identifier 'UserName'
d:\ms visual studio\vc98\include\secext.h(22) : error C2501: 'SECURITY_STRING' : missing storage-class or type specifiers
d:\ms visual studio\vc98\include\secext.h(22) : error C2501: 'UserName' : missing storage-class or type specifiers
d:\ms visual studio\vc98\include\secext.h(23) : error C2146: syntax error : missing ';' before identifier 'LogonDomainName'
d:\ms visual studio\vc98\include\secext.h(23) : error C2501: 'SECURITY_STRING' : missing storage-class or type specifiers
d:\ms visual studio\vc98\include\secext.h(23) : error C2501: 'LogonDomainName' : missing storage-class or type specifiers
d:\ms visual studio\vc98\include\secext.h(24) : error C2146: syntax error : missing ';' before identifier 'LogonServer'
d:\ms visual studio\vc98\include\secext.h(24) : error C2501: 'SECURITY_STRING' : missing storage-class or type specifiers
d:\ms visual studio\vc98\include\secext.h(24) : error C2501: 'LogonServer' : missing storage-class or type specifiers
d:\ms visual studio\vc98\include\secext.h(33) : error C2146: syntax error : missing ';' before identifier 'GetSecurityUserInfo'
2, ::ListView_SortItemsEx , this function, as MSDN stated, is declared in commctrl.h, but after I included commctrl.h the compiler still says ListView_SortItemsEx is an "undeclared identifier".
How can I solve those? Thanks a lot.
|
|
|
|
|
|
I'm using STL vector to store file names as I retrieve them from FindNextFile() but when I try to access different locations in the vector, they all return the last file added. Am I storing or accessing incorrectly?
<br />
vector<char *> file_names;<br />
<br />
HANDLE Hnd;<br />
WIN32_FIND_DATA WFD;<br />
<br />
Hnd = FindFirstFile( "*.175", &WFD);<br />
file_names.push_back(WFD.cFileName);<br />
int i=0;<br />
while ( FindNextFile( Hnd, &WFD) ) {<br />
file_names.push_back(WFD.cFileName);<br />
cout << file_names[i] < endl;
i++;<br />
}<br />
for(int i=0; i <=file_names.size(); i++) {<br />
cout << file_names[i] << endl;<br />
cout << file_names.at(i) << endl;<br />
}<br />
<br />
vector <char *>::iterator f;<br />
for ( f = file_names.begin(); f != file_names.end(); f++)<br />
cout << *f << endl;<br />
|
|
|
|
|
The vector holds a set of pointers.
One solution is to copy the actual file name to a string container and then store it in the vector.
Kuphryn
|
|
|
|
|
kiken wrote:
file_names.push_back(WFD.cFileName);
Think about what that is doing. It's storing the address of the cFileName array over and over. You need to store copies of each name as they are returned. One way to do that is to use a vector<string>
--Mike--
The Internet is a place where absolutely nothing happens.
-- Strong Bad
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Hi
I have a simple problem regarding toolbars here.
When we create a new SDI project, the codes for the standard toolbar is there. The toolbar will appear and disappear gracefully when we check the function inside the menu. But when i add a new toolbar, how do i make it appear and disappear gracefully ??
I try to use the "ShowWindow(SW_HIDE)" but the ugly gray patch is still there!
Thanx you for ur kind attention !!
bk
|
|
|
|
|
not sure what you are you are describing but the code below seems to work for me.
m_wndMyToolBarName.ShowWindow(SW_HIDE);
RecalcLayout();
|
|
|
|
|
Hi ROK
Really thanx a lot !! Meanwhile i also found another method using
ShowControlBar(&m_WndToolBar, true, false);
bk
|
|
|
|
|
Thanks bk.. Never really had to hide a toolbar in an app before.. so my previous post was the first thing I came up with that worked.. thnks for posting the correct way.
|
|
|
|
|
Let Suppose I have a Frame Window
and this frame is split into to panes
now in each pane is another frame.
How do I get the top level menu to route message commands to the other two frames? I can use classwizard all day long to create message ID's in the other two frames.. but no matter how hard I press that left mouse button.. the message is never delivered.
|
|
|
|
|
Look in the MSDN for OnCmdMsg(). It takes care of command routing. Override it to give your sub-frames a look at the messages before processing them in the normal way.
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed)
NEW: Awasu 1.0[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
From article:
http://www.codeproject.com/dll/plug-in.asp#xx88311xx
Serialize problem only appear with VC7.0,it works fine with vc6.0.
I have been somewhat successful in trying to implement serialization for my test app. I am using a CList template to store objects. Here are a few
details...
Serialization works just fine for documents saved and reloaded during a given session. This includes data stored in dialog resources. This is as long as I serialize the list then walk through the list, serializing each list object.
However, Serialization fails after closing the session and then reopening. In general, I am given only the {DllProxy} class (where I should be getting my dll's runtime class instead) and all other vars are mud.
I AM able to successfully serialize save/load a list of the DLLProxy "pointers" themselves with great fidelity. But the Plug_Object "pointers" that they originally created are lost from session-to-session.
Thanks and Best Regards
|
|
|
|
|
If I am right, you doing a mod of my article. If you can it would be best if you could send a copy of the offending code to me to have a look at. If you do, try and keep it as minimal as possible, so that it just illustraits the problem.
The only other issue is that I work with VC 6 only, so if its dieing in VC7 only, I may not be able to spot/replicate the problem.
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|
Hi all,
i have a problem with this piece of code:
bool CBaseWin::createWin()
{
//Create the application's window
m_hWnd = CreateWindow(m_pAppName,
m_pAppTitle,
WS_OVERLAPPEDWINDOW,
50,
50,
500,
500,
NULL,
NULL,
m_hInstance,
this);
return (m_hWnd != NULL);
}
m_hWnd will always be 0 if i include the "this" pointer as the last parameter, if i substitute NULL for it, it will work and return a value for m_hWnd.
This is from the tutorial located here:
http://www.codeproject.com/useritems/win32windowwrapperclass.asp
Can anyone explain why the inclusion of the "this" pointer causes CreateWindow to fail?
PS. The error code is 1400 - which is invalid window handle.
Regards,
Skute
|
|
|
|
|
You are missing a parameter - either lpClassName or lpWindowName.
|
|
|
|
|
I have been asked to provide a spin control for a tab control which has the standard 'left/right' buttons and also 'first/last' button. Without having to implement a fully owndrawn tab control.
Any suggestions would be gratefully appreciated.
|
|
|
|
|
Hi, In Developer Studio (VC++ ver 4.0),I used to have an "H" button (to switch to the respective header file) above the workspace source file window. It seems to have disappeared recently, and I don't know how to get it back again !!! Anybody got any idea on how I do this ??? (I can't see anythingin "Help" that covers this - most annoying !!!)
Doug
|
|
|
|
|
O.K. -within 2 minutes of posting this message, I solved my own problem !!! (typical !) The .clw file was missing - when I had recreated it, the "H" button reappeared magically !! (Hope this may be of some help to someone in the future !)
Doug
|
|
|
|
|
I have an application based on the CListView class, and I'd like to do the following: when a user resizes the frame of my application, I'd like the columns in the list view to resize themselves appropriately. My problem is that I'm a little confused as to when (and where) I do this.
Currently, I am handling the WM_SIZE method in the view class. Here is the code I'm using (in the OnSize() method):
CListView::OnSize(nType, cx, cy);
if(m_List->GetSafeHwnd() != NULL)
{
CRect rectList;
m_List->GetClientRect(&rectList);
int listwidth = (rectList.Width() - GetSystemMetrics(SM_CXVSCROLL));
int nColInterval = listwidth / 10;
m_List->SetColumnWidth(0, 4 * nColInterval);
m_List->SetColumnWidth(1, listwidth - (4 * nColInterval));
} I have several problems with this code. When the vertical scroll bar actually does appear, the column sizes aren't quite right. I want a space in the header control for the vertical scroll bar's top arrow (hence the GetSystemMetrics() call above). But when the vertical scroll bar shows up, it looks like twice the distance is inserted in the header control.
Another problem is that when I switch from any non-details view to the details view, the size is not updated initially. So, for example, if I'm in "Large Icons" mode and resize the window, then switch to "Details" mode, the columns are sized for the previous window size, not the current size.
Can anyone shed any light on what I should do for this? Any help would be greatly appreciated!
Thanks,
Jonah Bishop
Visit JGB Productions
|
|
|
|
|