|
I have been trying all day to get a file open dialog box that would not give me any errors. I have tried the CFileDialog Box which looked like this:
CFileDialog *fileDlg = new CFileDialog(TRUE, "*.exe", NULL, OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, "Executable files (*.exe)|*.exe||", GetActiveWindow());
// Initializes m_ofn structure
fileDlg->m_ofn.lpstrTitle = "Half-Life Executable Path";
// Call DoModal
if ( fileDlg->DoModal() == IDOK)
{
m_PATH.SetWindowText(fileDlg->GetPathName());
}
delete fileDlg;
I have also tried the windows api way (non mfc) (this is for a dll, i think i have to change the return type too):
char *Open_File(HWND m_hwnd)
{
OPENFILENAME ofn;
char szFileName[MAX_PATH];
ZeroMemory(&ofn, sizeof(ofn));
szFileName[0] = 0;
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = m_hwnd; //handle to your window
ofn.lpstrFilter = "Half-Life Executable (*.exe)\0*.exe\0\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "exe";
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if(GetOpenFileName(&ofn))
return ofn.lpstrFile;
else
return "";
}
If I open the file dialog box and then click ok after selecting a file it will do this fine in the window:
m_PATH.SetWindowText(fileDlg->GetPathName());
I have a main window and an options screen. The options screen is in a modal state when I call the file dialog and the parent of the file dialog is the options screen. Now up to this stage it is all dandy because I can close the options screen then open the options screen again and it will display the previously selected file because I save it and load it into the text control. But when I close the program I get this:
he thread 0xF14 has exited with code 133 (0x85).
The thread 0xB88 has exited with code 133 (0x85).
The thread 0x4CC has exited with code 133 (0x85).
The thread 0x5B8 has exited with code 133 (0x85).
The program 'C:\Console Connector++\HLCC 0.5a\Debug\HLCC.exe' has exited with code 133 (0x85).
I ended up playing with it all and found out I only get this when I call GetOpenFileName. After using the file dialog I can no longer do file output. By the way im using VC++ 6.0 SP5.
Argghhhh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! It is very urgent cause Im doing an update for my program that people use!!!
Thanks.
|
|
|
|
|
I'm not sure what your problem is. Are you concerned about all those spurious threads? If so, do not worry about them, they're internally launched by the system when you call GetOpenFileName , it's nothing to care about.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
Are you concerned about all those spurious threads? If so, do not worry about them
I agree. I have several multithreaded programs that I have written and I see this kind of thing all the time during the execution of the program. These threads are internal to windows and there is no reason to worry about them.
John
|
|
|
|
|
But the thing is after using the file dialog it will NOT let me save any data through file ouput.
|
|
|
|
|
So if you've found that CFileDialog works and GetOpenFileName() doesn't, why are you still trying to use GetOpenFileName()?
While the multiple threads that are being spawned is normal, a non-zero return value is suspect.
Just to rule out a scope problem, change your code to:
OPENFILENAME ofn;
char szFileName[MAX_PATH];
char *Open_File(HWND m_hwnd)
{
ZeroMemory(&ofn, sizeof(ofn));
...
}
I have a hard time using code where functions return auto variables. That whole going-out-of-scope thing can cause hours of grief.
|
|
|
|
|
CFileDialog has the same results as GetOpenFileName.
|
|
|
|
|
Did you read the documentation for GetActiveWindow()? It states:
The pointer may be temporary and should not be stored for later use.
Try removing that last parameter to the constructor.
|
|
|
|
|
Hi,
Still new to programming....kinda confused right now.
I created a MFC app to create a standard text editor.(My base class is Ceditview) I wanted to know how i could have the editor have a set string of text on it as soon as it starts.
Basically I want to make it look like a List Control window. Having strings of text passes into the editor window as a display listing. But I also want to allow for regular paragraphs to be passed in? Can this be done or is there a better solution?
Thanks in advance.
|
|
|
|
|
Use SetWindowText in OnCreate.
Hard to suggest a better solution as I dont know what you want the user to do with the pre defined text. But one is to have a list control and an edit control.
Magnus
|
|
|
|
|
I would like to use the predefined text as a column heading. The only thing is that I will have a mixed form of the things that i want to put in the editor.
For example:
Heading 1 Heading 2 Heading 3 Heading 4 Heading 5
1 345 456 567 678 789
2 987 876 765 654 543
This is a line of code that will be inserted in the middle of my so called "table" of information. There is no defined length. This is all entered from another dialog box.
3 123 234 345 456 567
4 678 789 910 566 556
I hope this makes it a little easier for me to understand. I originally wanted to use a ListControl, but since i need to add that paragraph, i couldn't. Unless i can expand it across the columns.
Thanks again in advance.
|
|
|
|
|
Then you have only the editbox, or Richedit if you want more formation options, as an option, unless you make it a little more advanced and use a grid that has support for text over several columns.
There is a really good grid on Codeproject, but I dont know if it supports text over several columns.
Magnus
|
|
|
|
|
Magnus,
Thanks for your help. Can you tell me how I can do this though? I can't the predefined string to the editbox upon startup of the app. Can you or anyone tell me how to do that? How would I format this text? (something like setw() in a cout statement?)
Thanks again.
|
|
|
|
|
Jay Hova wrote:
How would I format this text? (something like setw() in a cout statement?)
Not unless you are working on a console application. Since you've mentioned the use of an edit control and a list control, you are obviously not working on a console application, but rather a GUI application.
Send formatted text to either using a CString object. It has a nice Format() method.
Here's a very simple example:
void CMyEditView::OnInitialUpdate()
{
CEditView::OnInitialUpdate();
CEdit &Edit = GetEditCtrl();
Edit.SetWindowText("Hello World");
CString str;
str.Format("2 * 2 = %d", 2 * 2);
Edit.SetWindowText(str);
}
|
|
|
|
|
I know that I can use SetupIterateCabinet from Setup API to uncompress .cab-files.
Will this function uncompress zip-files? Is there another ways to work with zip archives in
C/C++?
|
|
|
|
|
|
I have 4 DLLs as following:
CFiles.dll
CExceptions.dll
CXML.Dll
CDataFormat.dll
CExceptions contains an Object factory that follows the Loki Object Factory model as following:
It has a map containing function pointers with enteries such as following:
void CExceptionFactory::InitializeMap()
{
AddToMethodMap(CExceptionFactory::DATABASE_EXCEPTIONS, CreateDatabaseExceptions);
AddToMethodMap(CExceptionFactory::NULL_POINTER_EXCEPTIONS, CreateNullPointerExceptions);
AddToMethodMap(CExceptionFactory::READER_EXCEPTIONS, CreateReadExceptions);
}
Now, within the DataFormat DLL, depending on the type of formatting, I load different DLLs. For instance, if the type is XML, I load the XML dll as following:
case ID_XML:
{
//m_pDataFormat = new XML();
HMODULE hLibrary = 0;
DataFormatProc pfnDataFormat = 0;
GEA pfnGEA = 0;
hLibrary = ::LoadLibrary("CXML.dll");
if(hLibrary != 0)
{
DWORD dw = 0;
pfnDataFormat = (DataFormatProc) GetProcAddress (hLibrary, "CreateXMLSingletonInstance");
dw = GetLastError();
if(pfnDataFormat != 0)
m_pDataFormat = pfnDataFormat();
m_pDataFormat->LoadFile(L"Stocks.xml");
::FreeLibrary(hLibrary);
}
Now if the method LoadFile above fails, it throws an exception by calling CExcpetionFactory class above and CExceptionFactory will try to look inside its Loki map and retrieve the required method as shown below:
CExceptionFactory::CExceptionFactory(int nTypeID, const string & strMessage)
{
InitializeMap();
CreateObject(nTypeID);
if(m_pException != 0)
{
m_pException->Log(strMessage);
delete m_pException;
}
else
{
throw CExceptionFactory(CExceptionFactory::NULL_POINTER_EXCEPTIONS,"Unknown Exception.");
}
}
void CExceptionFactory::CreateObject(int nTypeID)
{
CallbackMap::const_iterator i = m_Callbacks.find(nTypeID);
if( i != m_Callbacks.end())
{
m_pException = (i->second)();
}
else
m_pException = 0;
}
Now, as soon as the code hits (i->second)(); , it leaves the exception dll all together and goes back to the beginning of that case statement above.
I am quite puzzled with this behaviour.
I am guessing I have a function pointer to begin with the loaded DLL and then I am getting a second function pointer and the compiler gets confused, but why should it?
Your help would be highly appreciated.
thanks
|
|
|
|
|
Well it sounds like you have corrupted your stack. Then you can end up any where in your code when calling function.
Magnus
|
|
|
|
|
how do i get WM_KEYDOWN for controls like a CEdit or a CComboBox (not for the window..)? In VC++ i can only use some events like a OnChange() and others.. but can i intercept other messages too?
Thanks,
Bye
|
|
|
|
|
Yes, but you need to subclass the control you're interested in. Derive your own class from CEdit (or other class as appropriate). If you're creating the control yourself using the Create() member function, use your class in place of CEdit.
If you're interested in a control that's on, for example, a dialog (or another control that's created by some piece of code you can't modify), create an object of your class with a lifetime at least as long as the control, then call SubclassWindow() on the object, passing the window handle of the control you're interested in.
Typically, if the control is on a dialog, you'll create the object that manages the control as a member variable of the dialog's class.
Alternatively using DDX_Control() in a DoDataExchange() function works well.
The change event (EN_CHANGE, a WM_COMMAND message) is actually sent by the edit control during its processing of the message that caused the control's contents to change.
--
Mike Dimmick
|
|
|
|
|
and how do i add a event handler? or do i have to write a different class for every edit control?
|
|
|
|
|
Derive your control from CEdit into CMyEdit. Replace occurences of CEdit in the Message Mapping for CMyEdit. Then, all "usual" CEdit event handlers will be available, plus the "usual" window message handler.
~RaGE();
|
|
|
|
|
To decouple things a bit, you could have your subclassed edit control send a message back to its parent window, perhaps something in the WM_APP range (e.g. WM_APP + 1).
In the parent window class, you would then handle your WM_APP message using an ON_MESSAGE() entry in the message map. See MFC Technical Note 6[^] for more information about ON_MESSAGE .
To handle a custom message, your function should be prototyped as LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam) .
As an alternative, you could do what the edit control normally does and send a WM_COMMAND message with a code you define (that doesn't clash with the normal edit control notification codes), the ID of your control (which you can get with GetDlgCtrlID ) and the window handle of the control (m_hWnd ). This does run the risk of potentially clashing with a Windows-defined message code in a future version of Windows. The existing codes are defined in WINUSER.H . If you go this way, handle the message with ON_CONTROL() .
--
Mike Dimmick
|
|
|
|
|
thank you very much!
I'll try and see what i can do.
|
|
|
|
|
if i have file name, is there any function that can give me the path or diretory where the file is saved?
for example, filename = notepad.exe
then path = c:\window
thank you
|
|
|
|
|
One solution is FindFirstFile() and FindNextFile().
Kuphryn
|
|
|
|