|
You can try it as such:
char szFileName[MAX_LENGTH];
CString pathname = "c:\temp";
strcpy(szFileName, (const char*)pathname);
|
|
|
|
|
thank's a lot guys, you helped me a lot
patrick
|
|
|
|
|
I Think strncpy should be used for "safer" strcpy
#define STRCPY(d,s)
strncpy( (d), (s), sizeof( (s) ) - 1 );\
(d)[ sizeof((d)) - 1 ] = NULL;\
STRCPY( g_szOutputFile, pathname );
|
|
|
|
|
you can use one of these:
strcpy(g_szOutputFile, (const char*)pathname);
strcpy(g_szOutputFile, (LPCTSTR)pathname);
strcpy(g_szOutputFile, (LPSTR)pathname);
strcpy(g_szOutputFile, pathname.GetBuffer(pathname..GetLength())); pathname.ReleaseBuffer();
|
|
|
|
|
I want to add the capability to my dialog based application so when I start it, it looks to see if any other instances of the application are running. If there is one already running, that instance will be killed and the new instance will be started. How can I do this, I know I have seen it on here before but cannot find the solution. Any help?
Roger Printy
Software Engineer
TeraNex
Orlando, FL
|
|
|
|
|
So what's exactly is the problem? Determining if another instance is running, or terminating it cleanly?
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Both really. Like I said, I have done it before just cannot find the source code I used.
Roger Printy
Software Engineer
TeraNex
Orlando, FL
|
|
|
|
|
The following article by PJ Naughter deals with "single-instancing":
http://www.codeproject.com/cpp/csingleinst.asp
However, the code you'll find there closes the second instance (not the original one). To close the original instance, you can send a message to its main window. WM_CLOSE could work here, depending on the actions your program performs on closing. If any msgboxes are displayed (prompt for save, etc.), you can choose to use some private application message.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Works like a dream, it really did not matter which one was closed, probably better to have the new instance stopped rather than the last instance. Thanks!
Roger Printy
Software Engineer
TeraNex
Orlando, FL
|
|
|
|
|
Hi there,
i have got a mfc multithreaded app. which works with avi-files. i use the CFileDialog class to be able to open any avi-file.
now, the problem is, that i need to work with the path name of the avi file. in the CFileDialog class, the path name only comes with one backslash(example: C:\mydir\sample.avi) but i need to convert the pathname to two backslashes to go on in the program (C:\\mydir\\samle.avi) because the functions that work with the avi-file only accept strings.
can anyone help me?
thank's in advance,
patrick
|
|
|
|
|
One of the method of CString class does exactly what you want:
int Replace( LPCTSTR lpszOld, LPCTSTR lpszNew );
Pass single backlash as lpszOld and two backlashes as lpszNew.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Hi Tomasz,
thank's for your quick reply but can you show me how exactly you do that when you have the CString variable C:\myfile\sample.avi and convert it to C:\\myfile\\sample.avi?
thank's again,
patrick
|
|
|
|
|
CFileDialog dlg(...);
if (IDOK == dlg.DoModal())
{
CString strFile = dlg.GetPathName();
strFile.Replace("\\", "\\\\");
AfxMessageBox(strFile);
}
Note that "\\" is in fact one backslash, "\\\\" - two backslashes.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
thank's a lot, it works perfect now
regards,
patrick
|
|
|
|
|
I'm pretty new to C++, but this seems weird.
I have written a program just to practice working with CListCtrl. All it does is load the list with a few lines
of stuff (in 3 columns). Then I set some extended styles (select whole line and track select). Then when
the column header is clicked, it sorts the list on that column and puts a little bitmap in the header
to show which column is sorted and whether ascending or descending.
The weird part is this: in one version of the program, it works perfectly in the Release version, but in
the Debug version everytime it gets to the .GetItem line for the CHeaderCtrl it gives me an
"Unhandled exception... Access violation..." error. I couldn't figure out how to fix that, so I started
from scratch on a new project and made the same program (cut and paste some code that seems OK).
In that version of the program the Debug compile works perfectly, but the Release version does not. In the
Release version of the second try, when I click on the column header, the headers actually disappear,
the column widths are screwed up (very wide) and the line items are all jumbled and some parts missing.
The "sort" seems to work OK in all versions, so I don't think that is the snag. It seems to be in the
"getting" and "setting" of the CHeaderCtrl items.
I know this is pretty vague, but any ideas? What the heck is going on? More to the point, what can
I do to figure it out and fix it?
Thanks for any suggestions. David.
|
|
|
|
|
Check that your zero-initializing your structures (LVITEM, etc.).
--Mike--
http://home.inreach.com/mdunn/
The Signature, back by popular demand: Buffy. Pajamas.
|
|
|
|
|
Ahhh, ha ha haaaa! I feel like an idiot.
Actually, it turns out that what makes it work correctly is to set the .mask, .fmt, and .iImage members
before calling GetItem.
I completely forgot that the .mask tells the function which parameters to get. It just seems to me that
the GetItem should get all of the parameters, but that is just me. It still seems odd that I have to
set the .fmt and .iImage parameters as well BEFORE calling GetItem. If I don't, then both of those
parameters get set to weird and useless values by GetItem.
I do still have a problem though. Even if I set the .mask to include the HDI_TEXT flag, the pszText
parameter still does not contain a string after the GetItem call (I set a watch in debug to monitor
that). I have yet to see a valid string in the pszText after the GetItem call. So how do I find out
what the text is in that item of the CHeaderCtrl? Let's say for sake of argument that I wanted to
change the text of the header when the user clicks, but I want different headers to have different
text based on existing text (for example, so say "ascending" or "descending" for the sort order).
I would have to be able to read the existing text to know what I want to changed to. I can't seem
to get at the existing text (without storing in a separate variable which just seems stupid to me).
Thank you SO MUCH for your answer. It put me on the right track.
David.
|
|
|
|
|
It just seems to me that the GetItem should get all of the parameters, but that is just me.
The reason there's a mask is so that the control doesn't return info that you don't want or care about.
Even if I set the .mask to include the HDI_TEXT flag, the pszText parameter still does not contain a string after the GetItem call.
Are you setting the cchTextMax member too? You need to set this to tell the control how big of a buffer you have.
--Mike--
http://home.inreach.com/mdunn/
The Signature, back by popular demand: Buffy. Pajamas.
|
|
|
|
|
Aaarghh! I don't think I'm an idiot, but I'll reserve judgement on that.
First off, thank you very much for you input. I appreciate it.
However, it still isn't working out for me. Therefore, I will include the code and you can tell me where I
am going wrong. Here's the code:
void CLVTest3Dlg::OnColumnclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
////Try to retrieve the Text in the column header
//Need pointer to the CHeaderCtrl.
CHeaderCtrl* pHeader = m_LV.GetHeaderCtrl();
//Find out which column header was clicked
int nDx = pNMListView->iSubItem;
//Set up the HDITEM struc
HDITEM hdi; //passes info to/from HeaderCtrl
hdi.pszText = " ";
hdi.cchTextMax = 255;
hdi.mask |= HDI_TEXT;
hdi.fmt |= HDF_STRING;
//Get info from the Header
pHeader->GetItem(nDx, &hdi);
*pResult = 0;
}
It's a Dialog-based MFC program. I have included OLE Automation (because I thought I read somewhere
that if you are going to use the CListCtrl::SetBkImage function it had to enabled (yes? no?)).
Anyway, I've tried just about every permutation of hdi settings I can think of. I keep getting an
unhandled access violation. What is the trick I'm missing here?
Many thanks in advance. David.
|
|
|
|
|
hdi.pszText = " ";
You're passing in a 2-character buffer here. You need to declare a char array and pass that.
char szText[255];
hdi.pszText = szText;
--Mike--
http://home.inreach.com/mdunn/
Tables, ladders, chairs, OH MY!
|
|
|
|
|
AAH!
Obviously, it never occurred to me. Thanks a bunch.
BTW, I personally really appreciate that there are guys who clearly know what they are doing
out there willing to answer assinine questions like this, and without even being insulting
or condescending. That's really excellent. So thank you (and that goes for several other
of the names I see so often on these boards).
Thanks. David.
|
|
|
|
|
|
How make CBitmap from CLongBinary?
|
|
|
|
|
I use ActiveX componet microsoft winsock ver 6
Mycode is
Server:
VARIANT NewMemberPackage;
NewMemberPackage.vt = VT_BSTR;
NewMemberPackage.bstrVal = MyPacked.AllocSysString();
m_winsockmember.SendData(NewMemberPackage);
----------------------------------------------------------------
Client:
VARIANT mPackage;
VARIANT menumType;
VARIANT mmaxLength;
mPackage.vt = VT_BYREF|VT_BSTR;
menumType.vt = VT_UI1;
menumType.bVal = VT_BSTR;
mmaxLength.vt = VT_I4;
mmaxLength.iVal = 512;
m_WinsockConnect.GetData(&mPackage, menumType, mmaxLength);
---------------------------------------------------------------------
In client is wrong but I can't found information about this Component in my country. How I Programming VC++ Code In Client. Helpme Please
|
|
|
|
|
Hi. I am trying to finish this code for an address book using a struct. Can someone please correct my code. If anyone wishes to help please run the program and you will see what my problem is.
After the user makes an entry (with choice 1), it should be able to display (with choice 2). My display function is not working. I am not doing something right. I need help with that, please, anyone ! Also, if the user enters more than one entry, the display function should display these entries one at a time. The user will hit enter to display the next entry. And so forth. Here is my code:
const char FILENAME[80] = "C:\\MS Visual C++\\Programs\\AddressBooktest.dat";
struct addresstype
{
char lastname[21];
char firstname[21];
char line1[31], line2[31], line3[31], line4[31];
char phone[14];
};
int menu();
void add_to_address_book(struct addresstype &);
void output_info(struct addresstype &, ofstream &);
void input_info(struct addresstype &);
void display_address_book(struct addresstype);
void main()
{
struct addresstype addin;
int choice=0;
ofstream outfile;
outfile.open(FILENAME, ios::out);
if(outfile.fail())
{
cout<<endl;
cout<<filename<<"="" could="" not="" be="" opened="" for="" output."<<endl;=""
cout<<"the="" file="" might="" corrupted."<<endl;=""
exit(1);=""
}=""
else=""
{=""
while(choice!="3)"
choice="menu();"
if(choice=""> 3)
{
system("cls");
cout<<"\t\t" << "INVALID ENTRY"<<endl<<endl<<endl;
}=""
else=""
{=""
switch(choice)=""
case="" 1:="" add_to_address_book(addin);=""
output_info(addin,="" outfile);=""
break;=""
case="" 2:=""
input_info(addin);=""
display_address_book(addin);=""
outfile.close();=""
int="" menu()=""
int="" choice="0;"
cout<<endl<<endl;=""
cout<<"\t\t"="" <<="" "what="" do="" you="" want="" to="" do?"<<endl<<endl;="" "1.="" add="" an="" entry"<<endl;="" "2.="" display="" entries"<<endl;="" "3.="" exit"<<endl;=""
cout<<endl<<endl<<endl;="" "enter="" your="" (1,="" 2="" or="" 3):="" ";=""
cin="">>choice;
return choice;
}
void add_to_address_book(addresstype& addin)
{
system("cls");
cout<<endl<<endl;
cin.ignore(100,="" '\n');=""
cout<<"\t\t"="" <<="" "last="" name:="" ";=""
cin.get(addin.lastname,="" 21,=""
cin.ignore(100,="" "first=""
cin.get(addin.firstname,="" "address="" line="" 1:=""
cin.get(addin.line1,="" 31,="" 2:=""
cin.get(addin.line2,="" 3:=""
cin.get(addin.line3,="" 4:=""
cin.get(addin.line4,="" "telephone="" number:=""
cin.get(addin.phone,="" 14,=""
system("cls");=""
}=""
void="" output_info(addresstype&="" addin,="" ofstream&="" outfile)=""
{=""
outfile<<addin.lastname="" "#"=""
<<addin.firstname=""
<<addin.line1=""
<<addin.line2=""
<<addin.line3=""
<<addin.line4=""
<<addin.phone="" endl;="" input_info(addresstype="" &addin)=""
ifstream="" infile;=""
infile.open(filename,="" ios::in);=""
if(infile.fail())=""
cout<<endl;=""
cout<<filename<<"="" could="" not="" be="" opened="" for="" writing="" into."<<endl;=""
cout<<"the="" file="" might="" corrupted."<<endl;=""
exit(1);=""
infile.get(addin.lastname,="" '#');=""
infile.ignore(1);=""
infile.get(addin.firstname,=""
infile="">> addin.line1;
infile.ignore(1);
infile >> addin.line2;
infile.ignore(1);
infile >> addin.line3;
infile.ignore(1);
infile >> addin.line3;
infile.ignore(1);
infile >> addin.phone;
infile.ignore(100, '\n');
}
void display_address_book(addresstype addin)
{
system("cls");
cout<<"All the entries are:"<
|
|
|
|
|