|
Hello all,
I am using Visual Studio 2008, and I created a new MDI application. In the setup of the application, I chose a file extension to use. In InitInstance of the class derived from CWinApp, I added this code as the first line of the function:
AfxMessageBox("InitInstance");
Also, in the class derived from CWinApp, I added as the first line of the function OnDDECommand:
AfxMessageBox("OnDDECommand");
When I run this program from the IDE, everything appears to be fine. However, when I run this from Windows explorer and double-click on the appropriate file (a file with the extension my program uses), I see the message: "Windows cannot find 'E:\Mikea Documents\mdi41.mdi4'. Make sure you typed the name correctly, and then try again. To search for a file, click the Start button, and then click Search." I also saw the InitInstance message as was expected, but I didn't see any GUI, nor did I see any OnDDECommand message. The application remains open. Now, if I double-click on the file again, I see the OnDDECommand message and the GUI, but I didn't see the InitInstance message. The application now closes.
I have looked at different places on the internet to try to figure out why this is happening, but I haven't gotten anywhere. Does anyone have any ideas?
Regards,
Mike
|
|
|
|
|
My best guess is that of the Messagebox you have put in the InitInstance is behind this behaviour. The first time you double click on your file "mdi41.mdi4", your .exe application gets launched, however it is not getting intitalized correctly, untill you dismiss the MessageBox->"InitInstance" by clicking OK.
Once this happens, even though the document did not get loaded correctly, the Application may still be running (verify this using taskmanager). And next time you double click on the document again, the above mentioned running instance get the notification and loads the document correctly.
-Suhredayan
|
|
|
|
|
Hello,
I checked the Task Manager, and sure enough, the program was still running.
However, I want the program to show the InitInstance message and run the GUI regardless of whether the program is run from the IDE or the program is run after double-clicking the mdi4 file. Furthermore, I don't want to see the "Windows cannot find 'E:\MikeA Documents\mdi41.mdi4'. Make sure you typed the name correctly, and then try again. To search for a file, click the Start button, and then click Search." message.
Regards,
Mike
|
|
|
|
|
Michael Adamus wrote: I want the program to show the InitInstance message
Try to show the message using modelelss dialogbox, or spawn a thread from InitInstance to display the message box.
Michael Adamus wrote: Furthermore, I don't want to see the "Windows cannot find 'E:\MikeA Documents\mdi41.mdi4'. Make sure you typed the name correctly, and then try again. To search for a file, click the Start button, and then click Search." message.
This seems to be a bug within windows, it should have displayed a better error message, like for eg: "The DDE transcation failed", however if the actual issue (blocking InitInstance()) is addressed, then you might not face this one anyways.
-Suhredayan
|
|
|
|
|
Hi all,
I am trying to read a file having read-only property checked. i am not able to read the file and it is showing some exception from the file wincore.cpp stating "Accessing filepath\filename was denied"..
Is it a problem with CFile::moderead??
thanks,
rakesh.
|
|
|
|
|
Can you at least show the relevant code?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Most decidedly, this has nothing to do with CFile itself, but that you're doing something wrong. Can you show us your code?
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Without seeing your code, most likely you're trying to open the file with read/write access, which will fail. If you show your code, perhaps we can be more helpful.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Hi
I used following code to replace my application menu.
CMenu mu;
mu.LoadMenu(nMenuID);
SetMenu(&mu);
DrawMenuBar();
The new menu was loaded. But whenever I tried to get MENU Handle, I will get an assertion error.
CMenu* pMenu = GetMenu();
HMENU hmenu = pMenu->GetSafeHmenu(); --->Assertion error.
How can I solve this?
Thanks,
modified on Wednesday, November 18, 2009 9:04 AM
|
|
|
|
|
I'm not an expert about, but I suppose in not a good idea using a CMenu temporary object.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Do you have any good idea to do this?
What is good way to replace my application menu?
Thanks,
|
|
|
|
|
CPallini wrote: I'm not an expert about, but I suppose in not a good idea using a CMenu temporary object.
Apparently[^], using a local object is the canonical way to set a menu, but CMenu::Detach()[^] nneds to be called before the temp object goes out of scope.
Ah, the beauties of MFC
|
|
|
|
|
Nemanja Trifunovic wrote: Ah, the beauties of MFC
(I would like to know Rajesh's thoughts about...)
Nemanja Trifunovic wrote: Apparently[^], using a local object is the canonical way to set a menu, but CMenu::Detach()[^] nneds to be called before the temp object goes out of scope.
Of course, the canonical way depends on the documentation author of the moment... [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
OK, I just read this post.
Well, I see that MFC is *actually* beautiful. One mistake is that most frequently done by newbies is putting a CFont object on the stack, setting the font of a control with this, and then wondering why it "didn't work". But they'll eventually get things to work and will appreciate the framework.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
transoft wrote: CMenu mu;
mu.LoadMenu(nMenuID);
SetMenu(&mu);
DrawMenuBar();
Is mu local or does it have class scope?
What line of what file is asserting?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
The Debugger did not guide me to there.
Thanks
|
|
|
|
|
Assertions have nothing to do with the debugger. When an assertion fires, you'll see:
Assertion Failed: File %hs, Line %d
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
atlmfc\include\afxwin1.inl: Line 900
Thanks,
|
|
|
|
|
So did you look at line 900 of afxwin1.inl to see what condition is asserting?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
{ ASSERT(this == NULL || m_hMenu == NULL || ::IsMenu(m_hMenu));
I think the menu was destroyed.
|
|
|
|
|
transoft wrote: CMenu* pMenu = GetMenu();
Does not return a CMenu* . You should be calling CWnd::GetMenu() .
|
|
|
|
|
Richard MacCutchan wrote: Does not return a CMenu*.
It does if called in the context of a CWnd -derived class.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: It does if called in the context of a CWnd-derived class.
My (mis-)reading of the documentation implied that you had to call this on a CWnd object reference.
Mr brain thought he was on holiday ...
|
|
|
|
|
Richard MacCutchan wrote: Mr brain thought he was on holiday ...
Ask Rajesh for a new monkey.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
After the call to SetMenu() you need to call mu.Detach() so the destructor does not destroy the handle.
|
|
|
|