|
In the app class header file, after the app class definition, add the folowing line:
extern CMyApp theApp;
Add these declarations to your app class:
private:
CMainFrame* m_pMainFrame;
public:
CMainFrame* GetMainFramePtr() { return m_pMainFrame);
In the OnInitInstance function of your app class, do this AFTER the main window is created:
m_pMainFrame = pMainFrame;
In the CMainFrame class, put a function that accepts a CComboBox* like so:
int CMainFrame::FillComboBox(CComboBox* pCombo)
{
return pCombo->GetCount();
}
From within the OnInitDialog() function in the dialog box class, call your function like so:
theApp.GetMainFrame()->FillComboBox(&m_ctrlComboBox);
I'm assuming that your dialog box class already has #include "MyApp.h" in it.
|
|
|
|
|
hi there,
following problem:
char g_szOutputFile[_MAX_PATH];
CString pathname;
now i want to copy pathname into g_szOutputFile and i call
strcpy(g_szOutputFile,pathname);
but this doesn't look like it is working, are there any other functions i can call to convert a CString into a char?
thank's in advance,
patrick
|
|
|
|
|
Strange, it's alwayse working perfectly (and doing so now!)
But try to use LPTSTR GetBuffer( int nMinBufLength );
char *c;
CString S;
c = S.Getbuffer(10)
|
|
|
|
|
I'm pretty new to C++, but it seems to me that you can just cast
the CString. I believe you need an LPTCSTR type for the strcpy function,
so I think you can do a simple cast from CString to the LPTCSTR type:
...(LPTCSTR)pathname...
You may need to cast it again such as:
...(LPTSTR)(LPTCSTR)pathname...
David.
|
|
|
|
|
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.
|
|
|
|