|
mrobeda wrote: So how can i use a generic array that can handle different type of objects?
Personally, I would create a pure abstract base class (Interface) for the object-types I would need to put in the container.
You could then either use RTTI/dynamic_cast or a self-devised mechanism of type-determination.
May I ask if you come from a scripting-language background?
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
hi,
Thanks for your help, i took Cedric Moonen advise (part of it).
btw - the answear to your question is no.
|
|
|
|
|
On my MFC application I read file and do some process on it. Here is the code I used to open and read only.
<br />
CFile srf_ReadFile;<br />
char * srf_FilePath = "ReadFile_001.txt";<br />
if(srf_ReadFile.Open(srf_FilePath, CFile::modeRead))<br />
{<br />
}<br />
So, the file should be always in the same folder which the project/solution contain. If I want to read another file, say ReadFile_002.txt, have to do it manually, go to the code and gives the new file name.
char * srf_FilePath = "ReadFile_002.txt";
It is too boring. So I want to make it more reliable to use. I want to add a browse button(I think that is the correct word, which is used to find the file in Windows) and set it as the file which I want to read.
How can I do it. Can you guys explain.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: I want to add a browse button(I think that is the correct word, which is used to find the file in Windows) and set it as the file which I want to read.
GetOpenFileName[^] will help you.
|
|
|
|
|
Thanks, I read it and little bit confusing. Do you know any place I can see a small worked example.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: I read it
Mmmh, if you had scrolled down the page, there is a link to an exemple here[^].
|
|
|
|
|
Thanks pal, now I have two such examples. I'll be if I got any issue there.
Thanks again.
I appreciate your help all the time...
Eranga
|
|
|
|
|
hai...
in codeproject site itself so many examples are there.....y cant u go and search...any how... refer this <pre<a href="http://www.codeproject.com/buttonctrl/CBrowseCtrl.asp">http://www.codeproject.com/buttonctrl/CBrowseCtrl.asp</a>[<a href="http://www.codeproject.com/buttonctrl/CBrowseCtrl.asp" target="_blank" title="New Window">^</a>]>
Born to win...!
|
|
|
|
|
What about calling CFileDialog ??? Would it help you?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Actually all the worked examples I've found are too complected for me. Is there any easy way. All of the program use a edit box and use it for browsing. I'm not clear what's happened there.
I appreciate your help all the time...
Eranga
|
|
|
|
|
There are not difficult maybe you need to more work for learn them.
|
|
|
|
|
Yes, it's true. Those things are really new for me. That's why I'm stuck on different steps.
I appreciate your help all the time...
Eranga
|
|
|
|
|
I think if you buy a book about mfc is helpful for you.
|
|
|
|
|
donot get confused.
do as nelek has suggested using a CFileDialog. i had been using it since years.
see the example here.
CFileDialog dlg(true,NULL,_T("*.*"),OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,"textfiles(*.*)|*.*|*.*");<br />
dlg.m_ofn.lpstrTitle="select the required file";<br />
if(dlg.DoModal()!=IDCANCEL)<br />
{<br />
CString filename=dlg.GetPathName();<br />
}<br />
else<br />
return;
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
|
|
Thanks pal. I've read it well and do my work well. I have another question regarding MFC control editing. I'll start a new thread.
Thanks again.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Look at your docu and read about CFileDialog
One example with my personal use in my project, it gives something like save as... asking to overwrite if the file already exists:
CFileDialog newFileDlg (TRUE, "*.ext", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Searched File (*.ext) | *.ext|", NULL);
Then you can use functions like newDlg.GetFileName (), GetFilePath ()... and others, that will help you to create the archive with CFile or CArchive
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
I found this and refer, but lots of coding going there. I'm really confusing. Someone can give a brief explanation how to refer it.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Are you reading the answers we give you?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Hello,
I create a "Windows Form Application" project that names p2pport, in Microsoft visual .NET 2005.
I want to use the Message Map. I see it on MSDN. MFC uses it.
So I include the #include <afxwin.h>, and use MFC in a shared DLL.
This is my code.
BEGIN_MESSAGE_MAP(p2pport::Dlg,public System::Windows::Forms::Form)
ON_MESSAGE(WM_UI1, p2pport::Dlg::OnUI1, WPARAM wParam, LPARAM lParam)
ON_MESSAGE(WM_UI2, p2pport::Dlg::OnUI2, WPARAM wParam, LPARAM lParam)
ON_MESSAGE(MM_MIXM_LINE_CHANGE,p2pport::Dlg::onMixerCallBack)
ON_MESSAGE(MM_MIXM_CONTROL_CHANGE,p2pport::Dlg::onMixerCallBack)
END_MESSAGE_MAP()
p2pport is my project name, and Dlg is the name of my form file.
But I get a lots of errors.
error C2039: 'GetMessageMap' : is not a member of 'p2pport::Dlg'
error C2039: 'GetThisMessageMap' : is not a member of 'p2pport::Dlg'
error C2039: 'GetThisMessageMap' : is not a member of 'System::Int32'
error C2270: 'GetMessageMap' : modifiers not allowed on nonmember functions
error C2365: 'GetThisMessageMap' : redefinition; previous definition was 'formerly unknown identifier'
error C2440: 'static_cast' : cannot convert from 'void (__clrcall p2pport::Dlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
error C2440: 'static_cast' : cannot convert from 'void (__clrcall p2pport::Dlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
error C2440: 'static_cast' : cannot convert from 'void (__clrcall p2pport::Dlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
error C2440: 'static_cast' : cannot convert from 'void (__clrcall p2pport::Dlg::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
error C3861: 'GetThisMessageMap': identifier not found
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I google it, but nothing finds.
Can anybody help me to solve it?
Appreciate for ur reply. Thx.
-- modified at 5:03 Tuesday 6th November, 2007
|
|
|
|
|
Own created messages will be handled this way in >>MFC<<:
In header:
class MyView
{
...
LRESULT OnMyMessage(WPARAM w=0,LPARAM l=0);
...
};
in .cpp:
BEGIN_MESSAGEMAP(MyView,CFormView)
ON_MESSAGE(WM_MY_OWN_MESSAGE,OnMyMessage)
END_MESSAGE_MAP()
LRESULT MyView::OnMyMessage(WPARAM w,LPARAM l)
{
// Work
return TRUE;
}
I hope this helps you
|
|
|
|
|
Thx for your reply.
It helps me a lot.
But I still get some errors.
I create a header file that named CMyView and the content is following.
#ifndef CMYVIEW_H<br />
#define CMYVIEW_H<br />
#include <afxwin.h><br />
#include <afxext.h><br />
public class CMyView : public CFormView<br />
{<br />
LRESULT OnUI1(WPARAM wParam, LPARAM lParam);<br />
LRESULT OnUI2(WPARAM wParam, LPARAM lParam);<br />
LRESULT onMixerCallBack(WPARAM wParam, LPARAM lParam);<br />
<br />
};<br />
#endif
And my code is modified as below.
BEGIN_MESSAGE_MAP(CMyView,CFormView)<br />
ON_MESSAGE(WM_UI1, OnUI1)<br />
ON_MESSAGE(WM_UI2, OnUI2)<br />
ON_MESSAGE(MM_MIXM_LINE_CHANGE,onMixerCallBack)<br />
ON_MESSAGE(MM_MIXM_CONTROL_CHANGE,onMixerCallBack)<br />
END_MESSAGE_MAP()
And there's the error.
error C2509: 'GetMessageMap' : member function not declared in 'CMyView'
error C2509: 'GetThisMessageMap' : member function not declared in 'CMyView'
How could I solve this problem?
Appreciate for ur reply.
Thx.
|
|
|
|
|
I got it.
I lose DECLARE_MESSAGE_MAP()in the header file.
The correct code is as below.
#ifndef CMYVIEW_H<br />
#define CMYVIEW_H<br />
<br />
#include <afxwin.h><br />
#include <afxext.h><br />
<br />
public class CMyView : public CFormView<br />
{<br />
<br />
public:<br />
afx_msg LRESULT OnUI1(WPARAM wParam, LPARAM lParam);<br />
LRESULT OnUI2(WPARAM wParam, LPARAM lParam);<br />
LRESULT onMixerCallBack(WPARAM wParam, LPARAM lParam);<br />
protected:<br />
DECLARE_MESSAGE_MAP();<br />
<br />
};<br />
<br />
#endif
|
|
|
|
|
Outstanding
Great that it works for you
|
|
|
|