I have big,old MFC source code. It is very difficult to debug the code. I am using Spy++ to examine one of the dialog. Following is snapshot of Spy++ of the dialog of MFC application.
Is there any way to find name of class of Dialog, or dialog ID?
Secondly, is there any tool in Visual Studio (using 2008) which can map button callback with correct method of source code.
I know second question sounds greedy, but just trying to see if this type of tool exists?
Launch the Debugger.
Run the application.
Hit Break All
Look into the call stack
You should find the code location that calls DoModal. And there you find the appropriate class that is used.
Related
I am facing a very consistent and persistent problem with Visual Studio 2022 Community Edition.
In an MFC project I open the Resource File and add a new Dialog. Then I place some standard controls and rename the dialog resource from its default name to a new ID.
Then I save and try to assign a Class to the dialog by right-clicking on the dialog and choosing 'Add Class'. Then the 'Add MFC Class' window appears, I enter the Class Name and click [OK].
It appears it creates the class on the File System and then VS2022 crashes completely!
I have disabled all addins in case an addin could be causing the problem but it happens every (almost) every time even without plugins. The only time I manage to get it to work is if I save, close all code editors, exit VS2022, restart it and immediately try to add the class. Another piece of information is that I have changed the MFC dialog template with a different one but it does not seem to bother it when I get it to work. Also intelliSense is completely disabled.
How can I debug this and identify the root cause of this crash?
There's a fair chance that you can't do anything in an effective fashion. VS2022 isn't an open source project, where you can easily pinpoint a crash to a specific line of code and fix it yourself.
But the good thing is that you don't need to. Just use the feedback channel VS2022 provides:
Usually a Microsoft employee will reply within a few days and maybe a fix will be included in the next preview version. Only now and then it can take some month to get a bug resolved.
I have to create a Win32 app for a college class.
I created the "Windows Desktop Application" in the create project section of the Visual Studio Community 2019 and it comes already with a standard dialog that can be tested on the go. Problem is: I cannot edit the main dialog. I can create another dialog and edit it but the main one is not accessible in the resource editor. What can I do? I can't find anything on google. Please help.
The main window of the default application created by the "Windows Desktop Application" project template in Visual Studio is not created with a dialog resource. It is created by registering a window class associated with a window procedure, as is standard when creating a desktop application.
You "edit" that window by changing the source code not with a visual editor.
>>I cannot edit the main dialog. I can create another dialog and edit it but the main one is not accessible in the resource editor.
Yes you can create it, but it has no class and can't be an object.You can try to create a Win32 desktop application, and then create a dialog. When you right-click the dialog box, you will find that you cannot add class.
If you want to use this dialog, you can only use this function DialogBoxW(hInstance, lpTemplate, hWndParent, lpDialogFunc) to create and show the dialog in your program. The third parameter is the Handle of parent window and it can be NULL. The forth parameter is the callback function.
So we test to call DialogBoxW in WinMain. You can check the picture below. We abandoned the traditional Win32 framework and made the custom window our main window. It work.
However, it should be noted that windows created in this form are modal, which is not applicable in many scenarios. What you say and what you want to do may be better done with MFC. Win32 does not encapsulate many interfaces like MFC for you to call.
I use Visual Studio 2013 Enterprise, but the procedures will be the same:
1 - On the Solution Explorer, click on the .RC file
2 - In the new window (Resource View), click in Dialog
3 - Double-click the dialog you want to edit...
That´s it...
Can ListControl be used in a dialog in a Non-MFC project? I am using visual c++ 2010.
The examples I have seen so far uses MFC, so it seems to me that ListControl is part of MFC. The code I am working on is not MFC based, however, Visual Studio still allows adding a ListControl to the dialog in the resource view, and generates rc code for the List Control. So my guess is that I should be able to use it. However, I could not use the standard method found online to add variable to the ListControl and use it.
How can I use the ListControl in this case? e.g. adding a column or write something to a cell? Some code example will certainly help.
The CListCtrl class is an MFC class. It can only be used from within an MFC project.
However, CListCtrl is simply a wrapper around the ListView common control, and a ListView control can be used in any Windows application—no MFC required.
The Resource Editor included with Visual C++ (confusingly) refers to a ListView control as a "List Control". You can insert one on your dialog, and all it will do is insert a ListView control.
If you're using MFC, you can choose to create a member variable corresponding to that control. The type of that member variable will be CListCtrl, because it is encapsulating access to a ListView control on your dialog.
If you are not using MFC, you can still use the ListView control, you'll just have to use the standard SDK mechanisms for accessing and manipulating it. For example, to insert an item into the ListView control on your dialog, you would obtain the control's window handle (GetDlgCtrlID) and send it a LVM_INSERTITEM message. The SDK documentation contains sample code listings, but they are a rather poor way to learn. The best resource for good old Windows SDK programming is still Charles Petzold's Programming Windows.
I am trying to create a new frame window with toolbars inside a dll.
I was able to create the frame and the toolbars but however the messages do not work properly in the CToolbar. Particularly the ON_UPDATE_COMMAND_UI messages are never called in the DLL.
After some research I came to know that this is because
PreTranslateMessage(MSG* pMsg)
and
OnIdle(LONG lCount)
need to be called.
But my calling application is Delphi based and this cannot be done.
After research I came to know that this is best possible from an Extension dll.
Since MFC extension dlls can only be called from an MFC application. I thought of the following solution.
Delphi calls an regular MFC dll
The MFC dll calls the Extension dll.
But I have run into problems because of asserts in in MFC AfxGetResourceHandle() and AfxGetInstanceHandle().
But I am also aware that AFX_MANAGE_STATE(AfxGetStaticModuleState()); cannot be called from an extension dll.
Does anybody have a solution for this problem?
The ON_UPDATE_COMMAND_UI messages are created by the MFC message loop. You don't have one. You will have to build your own ON_UPDATE_COMMAND_UI translator or something equivalent. It all starts with this in your frame window message map:
ON_WM_INITMENUPOPUP()
Your OnInitMenuPopup handler will be called when the user selects a menu, before the menu is displayed.
I am trying to make a program where an image would disappear when a certain a button called hide in the application is pressed.
I know in Windows form application it would be something like this:
pictureBox1->Visible=true/false;
But that code wouldn't work in MFC
My code in MFC is
Cstatic pictureBox1 =(Cstatic)Getdialogitem(IDC_IMAGE1);
pictureBox1->Visible=false;
Try
pictureBox1->ShowWindow(SW_HIDE);
or
pictureBox1->ShowWindow(SW_SHOW);
In MFC, simply setting a member variable to a new value doesn't accomplish anything; you need to call functions that will take specific actions.