|
I have a simple menu written out, it has 5 options on the main menu bar, and under the 4th menu, I have 3 menu items. I'm trying to check or uncheck the last item under the 4th menu option, it is identified as ID_ACTION_FIT.
Here is the code I have so far to check the item:
CMenu * MainMenu = GetMenu();<br />
CMenu * ActionMenu = MainMenu->GetSubMenu(3);<br />
ActionMenu->CheckMenuItem (ID_ACTION_FIT, MF_BYCOMMAND);
That code is inside the event handler for the item I'm trying to check.
I have done this before once with no problems but it's not working now. When it reaches the second line quoted and attempts to get the submenu, it fails a debug assertion. I don't have the code for GetSubMenu so I don't know what is actually being tested. The MainMenu pointer is valid. I don't know what's wrong but I think I have an error that's too obvious to see. Does anyone have an idea of what is the problem?
|
|
|
|
|
Hello,
What does the assertion dialog say? You do have the source code for CMenu::GetSubMenu() since it's MFC. You didn't delete the implementation files did you?
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
All it says is:
Debug assertion failed!
Program: C:\...path\to\program.exe
File: f:\vs70builds\9955\vc\MFCATL\ship\atlmfc\include\afxwin1.inl
Line: 875
For information on assertions...
(Press Retry to debug the application
[Abort] [Retry] [Ignore]
If I press Retry, it tells me Unhandled exception at some address. If I press Break, and go to the call stack and double click the CMenu::GetSubMenu() item on top of the stack, I get a box that says "There is no source code available for the current location." and I can see the disassembly if I want. I never deleted any implementation files but if I do have the source code for that function, VS .NET cannot find it and I don't know how to tell it where it is.
|
|
|
|
|
I added a "MainMenu->AssertValid();" after I get the main menu pointer but before I get the submenu. I get another assertion but this time I got the source code for that function. The assertion line is "ASSERT(m_hMenu == NULL || ::IsMenu(m_hNull);". m_hNull looks valid, on this particular run of the program, it is 0x0000e900 which is not NULL. I don't see how this assertion is triggered, nothing about the menu data looks suspicious.
|
|
|
|
|
The assertion in CMenu::GetSubMenu is ASSERT(::IsMenu(m_hMenu)); , so the main menu handle seems to be invalid. Where (in which class and function) do you call this code?
Regards,
BB
http://spin.bartoszbien.com
|
|
|
|
|
I'm calling it in my CChildView class, in the event handler for the menu item I'm trying to toggle. When you said that, I realized that the CChildView only corresponds to the view itself, not the entire app, at least as far high as the menu exists. I changed the code to get the menu like this:
CWnd * pParent = ::AfxGetMainWnd();<br />
CMenu * MainMenu = pParent->GetMenu();<br />
CMenu * ActionMenu = MainMenu->GetSubMenu(3);
Which looks like it's picking up the right things when debugging, I won't be sure it's right until I write more code, but thanks for helping me point that out.
|
|
|
|
|
According to CMenu's documentation, "[t]he return value is undefined if CWnd is a child window". Try changing the first line to:
CMenu* MainMenu = AfxGetMainWnd()->GetMenu();
[UPDATE]: After posting this I noticed you had already found the problem. Sorry.
--
jlr
http://jlamas.blogspot.com/[^]
-- modified at 0:36 Thursday 6th October, 2005
|
|
|
|
|
Hello,
I am working on a project that requires file-change-notification to a CDialog. Currently, I am trying to use the CFileChangeEventClass[^] by Fanky Braem. However, when I get notified of a change, and I try to call UpdateData(), the program crashes.
I believe that Franky explains what the problem is:
"A thread can access only MFC objects that it created. This is because temporary and permanent Windows handle maps are kept in thread local storage to ensure protection from simultaneous access from multiple threads."
and provides a solution for a doc/view scenerio. Can anyone help me in figuring out how to solve this for the CDialog case?
Thanks a lot,
-----------------
Genaro
|
|
|
|
|
Do the file change notificaiton/waiting in a secodnary thread. Post messages to your main thread. Process those messages in the main thread. Don't try ot directly update controls from the secodnary thread which processed the file notification. You can look into ON_REGISTERED_MESSAGE.
// example for ON_REGISTERED_MESSAGE
const UINT wm_Find = RegisterWindowMessage( FINDMSGSTRING );
BEGIN_MESSAGE_MAP( CMyWnd, CMyParentWndClass )
ON_REGISTERED_MESSAGE( wm_Find, OnFind )
// ... Possibly more entries to handle additional messages
END_MESSAGE_MAP( )
Post the registered message fromt he notiifcaiton thread. When the main dialog receives it, then call the updatedata.
This should work fine for you.
|
|
|
|
|
Good afternoon
I got this message for the app after finished debug:
The thread 0x6B8 has exited with code 2 (0x2).
The program 'C:\DEV\C++\Billing\Report\Debug\Report.exe' has exited with code 2 (0x2).
the 0x6B8 thread is CDialog::OnCancel, the part of code that calling OnCancel is from here:
LRESULT CReportDlg::OnComplete( WPARAM, LPARAM )
{
m_thrReport.Wait( INFINITE );
PostMessage( WM_CLOSE );
return S_OK;
}
Is it because of infinite waiting causing exited with code 2? what is code 2 mean? thank you!
|
|
|
|
|
When the dialog-based MFC program exits, it usually returns the ID of the button that caused the closing, or else 2 meaning CANCEL or CLOSE and 0 meaning OK.
If you want custom exit codes, override ExitInstance at application and set your own exit code.
|
|
|
|
|
That's the answer I was looking for hours ago! Thank you kind Sir!
After looking into the ressource.h-File I can confirm that it's because of the ID of the Control which lead to the end of the thread.
For example: I was kinda terrified of the unknown thread-exit code 32780. Cannot look up what's this about because usually the exit codes are not as far specified.
After launching my exit procedere mindlessly with my overloaded OnCancel with ID 32780 the weird exit messages kept coming. But I never thought that far.
Hopefully someone will spare some time with this information.
best regards
|
|
|
|
|
I need to perform continous job in RPC Server and then execute callback from a parallel thread to inform client about job completion. Server call should submit new job and exit immediately. In order to do such thing, i think i have to acquire call context, and then restore it in later time.
The bad thing that i still haven't found functions in RPC API for polling client contexts and entering into certain context.
Maybe the functions for context polling is RpcMgmtEpEltInqBegin()/RpcMgmtEpEltInqNext()/RpcMgmtEpEltInqDone(), but i am unsure. I still haven't any ideas how i can activate context.
|
|
|
|
|
Hi, is there a way to compute usage of the stack size of a thread. More precisely, I'd like to know the maximum size that was used during the thread's life. Someone proposed to me that I fill the memory with a pattern before launching the thread, then looking at the end how much was overwritten, but I do not know how to get the thread stack pointer.
You guys have any ideas ?
"Invent a idiot-proof system and a new improved idiot will be invented"
|
|
|
|
|
Last i checked, it was still in the esp register (while the thread is executing, of course).
|
|
|
|
|
That won't get you the maximum size, only perhaps the current size.
|
|
|
|
|
Right. He was going to check for a pattern within the stack, see what changed during execution.
|
|
|
|
|
The trick is to fill the stack with a pattern before the thread is launched. Then, when the thread exits, dump the memory content and compare with an empty stack to compute the size. But I don't want to do this in a debugger, I want to write code that will compute that. So, I need to create a suspended thread, find it's stack pointer, fill it's memory with a pattern, then start the thread. And my problem is, how do I get the stack pointer of another thread ?
|
|
|
|
|
Zykalus wrote:
Then, when the thread exits, dump the memory content and compare with an empty stack to compute the size.
I see... You might want to have a look at GetThreadContext() then. Haven't used it myself, but it looks like just what you're looking for.
|
|
|
|
|
You might want to look at VirtualQuery.
The region size will be approximately how much memoryhas been commtted for stack size. I am pretty sure it never shrinks. Of course, the value is in the granularity of the syste's smallest allocation unit, which I think is 8K. But anyway, it gives you an idea if it used 64K versus 1 MB or such.
You need to pass the value of ESP register in as the lpAddress to the VirtualQuery call.
Use a little bit of inline assembler to get to it.
|
|
|
|
|
Thanks, I'll look into it. What I want to do is add debugging code in my app,. Currently, all threads are using the default size. But since I have a lot of threads, I just want to add in my thread code that will tell me how much was use during the thread life time.
"Invent a idiot-proof system and a new improved idiot will be invented"
|
|
|
|
|
Windows will expand the stack as needed.
Software Zen: delete this;
|
|
|
|
|
Hi all,
I was trying to trigger a button click event programmatically by doing
m_MyButton.SendMessage(BN_CLICKED);
but the event handler was not getting invoked. What did I do wrong and what's the correct way to do it?
Thank you for the help.
|
|
|
|
|
BN_CLICKED is not a message. It's a notification code to be used in the context of a WM_COMMAND message.
You need to send the WM_COMMAND message to the button's parent window, with the following parameters
wParam: MAKEWPARAM(id, BN_CLICKED)
lParam: m_MyButton.m_hWnd
where id is the numeric identifier of the button.
Example:
void CMyWindow::SomeMethod
{
SendMessage(WM_COMMAND, MAKEWPARAM(IDC_MY_BUTTON, BN_CLICKED), (LPARAM) m_MyButton.m_hWnd);
}
--
jlr
http://jlamas.blogspot.com/[^]
-- modified at 15:49 Wednesday 5th October, 2005
|
|
|
|
|
Ok, understand now.
Thank you very much!
|
|
|
|