|
Maybe you could provide some more info on how you are catching this error? What version of VC are you using? Are you catching this in the debugger? Is this a release or debug build (I am presuming a debug build from your comment about the assert)? _CrtIsValidHeapPointer probably indicates you have overwritten some memory somewhere or are trying to free memory that's already been freed, or perhaps access memory that's already been freed.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
|
Uhhh, is that a "Thank you - it helped" or a "Thank you, and drop dead" ?
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
Hi all,
I'm trying to create a CMDIChildWnd-derived window with a menu, but I'm having problems.
Here's the relevent code from my CMDIChildWnd-derived class's constructor:
<-------------------------SNIP-----------------------------
...
...
Create( NULL, strTitle, WS_CHILD | WS_OVERLAPPEDWINDOW, rectLocation, ((CMDIFrameWnd*)AfxGetMainWnd()), 0 );
VERIFY( m_menu.LoadMenu( IDR_MY_MENU ) );
if( !SetMenu( &m_menu ) )
{
DWORD dwErrorCode = GetLastError(); //returns 1436
ASSERT( FALSE );
}
DrawMenuBar();
...
...
<-------------------------SNIP-----------------------------
The SetMenu(...) call always fails, with GetLastError() returning 1436. According to MSDN this error code is ERROR_CHILD_WINDOW_MENU - "Child windows cannot have menus.".
Does this mean that it's impossible to add a menu to an CMDIChildWnd that's a child of the main window frame?
If so, what are my options to get around this? The two things I can think of are:
A) Draw my own menu window. No Thanks!
B) convert my CMDIChildWnd class to use the MFC Doc/View pattern - AFAIK the frame window of a CView can have menus.
Any other suggestions or advice?
Cheers,
Pete
|
|
|
|
|
Assuming a few things:
You're not using MFC Doc/View
You DO have a properly configured String table entry, accelerator table entry(ies), ICO entry, and MENU entry in your resource .rc file.
The code below uses a class MyMDIChildWnd declared as
class MyMDIChildWnd : public CMDIChildWnd
You can create a new MDI child in you main CWinApp class like so:
MainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
pFrame->CreateNewChild(
RUNTIME_CLASS(MyMDIChildWnd), IDR_MYMDIWNDTYPE, m_hMDIMenu, m_hMDIAccel);
Where:
IDR_MYMDIWNDTYPE is the resource name for the mdi child wnd in the string table, accelerator table, menu entry, and ICO file
m_hMDIMenu is a member in your CWinApp class of type HMENU
m_hMDIAccel is a member in your CWinApp class of type HACCEL
You should initialize m_hMDIMenu and m_hMDIAccel in your InitInstance app function like so:
HINSTANCE hInst = AfxGetResourceHandle();
m_hMDIMenu = ::LoadMenu(hInst, MAKEINTRESOURCE(IDR_MYMDIWNDTYPE));
m_hMDIAccel = ::LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_MYMDIWNDTYPE));
If you create a new MDI app from the MFC App Wizard it will do all of this for you if you DON'T choose Doc/View support.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
Hi Jim,
First of all, thanks for the help!
OK, so I've followed your advice and am now creating my window like so:
<---------------------------------------SNIP---------------------------->
CMDIFrameWnd* pMainFrame = (CMDIFrameWnd *)AfxGetMainWnd();
C2DTrajMainWnd *pWnd = (C2DTrajMainWnd *)pMainFrame->CreateNewChild(
RUNTIME_CLASS(C2DTrajMainWnd), IDR_2D_TRAJ,
hMDIMenu, hMDIAccel );
<---------------------------------------SNIP---------------------------->
However, the IDR_2D_TRAJ menu is still not being displayed.
During the CreateNewChild call, in CMDIChildWnd::LoadFrame(...) MFC TRACE()'s "Warning: no shared menu/acceltable for MDI Child window." Stepping through the execution, it seems that CMDIChildWnd::LoadFrame(...) is being called with a non-NULL CDocTemplate. I don't understand why. My App does have Doc/View support, but I thought that CDocTemplate's were only used when specifically creating Doc/View instances. Am I missing something here?
Thanks again for the help,
Pete
|
|
|
|
|
I think that my solution only work if you are NOT using MFC's Doc/View. If you are then you have to create the child window another way (which I don't recall how at the moment).
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
I'm sorry, I just stepped through the code again and realized some of what I said in my earlier reply was wrong.
When CMDIChildWnd::LoadFrame(...) is called it cannot get a valid CMultiDocTemplate instance from the CreateContext that it's passed, so it says it cannot create the menu/acceltable.
Sorry for the confusion!
|
|
|
|
|
I guess the subject above says it all. I'm trying to find out which message to handle for my CMainFrame being minimized. I had the application where it goes to the system tray when closed if the user has that option checked. But I've recently been informed that it would be better if it only went to the system tray when minimized. Thanks in advance!!
Who are all these people and what are they doing in my house?...Me in 30 years, inside a grocery store
My articles[^]
bdiamond
|
|
|
|
|
Maybe look at WM_SYSCOMMAND and see if the SC_MINIMIZE is set? Another option is to look at WM_SHOWWINDOW or possibly WM_WINDOWPOSCHANGED. Check MSDN docs to be sure (or there's always the tried and true test app to hack around with to test it).
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
I got it. I tried the WM_SYSCOMMAND and check if nSize == SIZE_MINIMIZED. thanks!
Who are all these people and what are they doing in my house?...Me in 30 years, inside a grocery store
My articles[^]
bdiamond
|
|
|
|
|
Here is what I am doing. I have an application which calls DLL_1 and DLL_1 calls DLL_2.
appl --> DLL_1 --> DLL_2
In the appl, I successfully talk to DLL_1 using LoadLibrary() and GetProcAddress() when DLL_2 is not linked to DLL_1.
Then, I linked DLL_2 to DLL_1 by used extern "C" _declspec(dllimport) and add DLL_2.lib to the DLL_1 project settings. I run my application, and LoadLibrary() does not return a valid HINSTANCE.
Seems like linked DLL_2 to DLL_1 causes my application not able to load DLL_1. Can anyone please let me know what I did wrong?
Thank you!
|
|
|
|
|
Possibly the call (from your app) to dynamically load DLL1 fails because DLL1 depends on loading DLL2. DLL1 starts loading, and then, since you linked in DLL2, DLL1 attempts to automatically load in DLL2. But, if DLL2 is not found in the directory of your app, or in then system path, then it craps out since DLL1 can't find DLL2, fails, and in turns causes the ultimate failure of DLL1 loading. Don't know if this is really your case, but it's a guess.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
Hi Jim,
Thank you for your help. I finally found out what happens. I put DLL_2 into my DLL_1 project directory. For whatever reason, DLL_1 cannot find DLL_2. I have to put DLL_2 into the system directory. Then, my program works perfectly.
|
|
|
|
|
I have to put DLL_2 into the system directory
Noooooo!!!
Agh, I hate when people have to do this. I can sympathize with your problem though, and it is an easy solution, but it ultimately will cause problems, either because this will force your users to have admin rights to install your software, or you may find dependency issues, or accidentally overwrite an older version of your dll with a newer one, etc.
You might consider trying to add the directory that holds your DLL2 to the users' path variable.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
I'm just learning programming(C++ is the language being taught), but I just want to make sure I'm reclaiming the memory correctly here. If I created an Employee object, and then in 'main' create an array of Employee pointers, do I reclaim the memory at the end of main by first deleting the pointers and setting them to 0 - followed by the deletion of the array? I'm just wondering the best way to go about this as the book never has the EXACT example I'm looking for. Thanks!
|
|
|
|
|
more or less what you wrote ...
the technicality depends on what kind of array you are using, either MFC, STL, or basic C type array.
remember that for each new there should be a delete and for each new [] there should be a delete []
what book are you refering to ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Well, the book I'm referring to is 'How to Program C++' by Deitel and Deitel. And while there is a page that has NEARLY similar code, the pointer to the object is just a single instance, not an array of them. So, there is no delete [] employeeContainer . By the way, when I first learned arrays, I never saw a delete [] at the end of main - why is that? Now, in the example I'm seeing in the book, I see that the class Employee it created, they user character arrays for the firstName etc. So, why in the destructor must you delete that array explicitly and not have to when you delcare an array in main? Thanks!
|
|
|
|
|
By the way, when I first learned arrays, I never saw a delete [] at the end of main - why is that?
There's nothing special about main --as Maximilien said, everything you allocate with new [] you must deallocate with delete [] .
If you saw otherwise, most likely the code you were studying was simply incorrect.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
LynnJ wrote:
By the way, when I first learned arrays, I never saw a delete [] at the end of main - why is that?
Technically it's not necessary, but it is highly frowned upon to not clean up your mess(es). Once main() is done, Windows will free up any resources, including memory, that your program was using. This is not a license to write sloppy code, however.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi,
In my program I have a main window with lots of buttons inside it. All I have are the handles to the buttons, in HWND form, and I create them using CreateButton. So for instance I have something like:
HWND new_button = null;
new_button = CreateWindow(blah blah etc);
The problem is, when I set the cursor of the main application to what I want, the cursor always returns to the default when I move it over the buttons. Is there a way I can set the cursor of those buttons to be the same as the one I use for the main application window?
I'm not using any class for the buttons so I can't for instance call SetCursor from inside the buttons, all I have are HWND variables.
Thanks
Kelly Ryan
|
|
|
|
|
To reliably set the cursor of window without cursor flicker, you need to have a NULL cursor specified for the window style. Then you need to handle WM_MOUSEMOVE messages and then properly set the cursor using SetCursor() (see this API call in MSDN).
If you really need to do this you can always subclass the BUTTON window class and then add you own behaviour to it. If you are using MFC then you can derive a new class from CButton (or whatever it's called), and add a mouse move handler and override the CWnd::PreCreateWindow() function.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
A little correction - WM_SETCURSOR is the right message to handle, because it takes into account mouse capture.
--
I'm Michael Dunn and I approve this post.
Vote Trogdor in oh-four!
|
|
|
|
|
"I'm Michael Dunn and I approve this post."
That's hilarious! LOL
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
It's a special election-themed sig
--
I'm Michael Dunn and I approve this post.
Vote Trogdor in oh-four!
|
|
|
|
|