How to replace/update an ActiveX control in a MFC dialog - c++

I have an older MFC project build in VS 2003 that I want to port to VS 2010. The project uses an ActiveX control for grids, namely, VSFlexGrid7 from Component One. The problem is, that this version of the ActiveX control does not work in Windows 7 (which is what I have). There is a newer version of the grid, namely, VSFlexGrid8 which should be compatible with Windows 7.
The solution would be to replace all the older controls with the newer ones.
My question is, what would be the steps in replacing the controls, without touching other parts of the project. What is the simplest method to accomplish this? Do I have to modify classes, resource IDs, etc.?
[Solution: Replace CLSIDs in the .RC file]

The ActiveX control is bound to the resource file via the guid that represents the control. If you were to look inside the .rc file you will see the control with the associated guid. In your case, it's probably best to completely remove the control from the dialog (using the resource editor) assuming that you can drag the newer version onto the same dialog. Once you've done that, you'll need to generate a new class wrapper for the control. The class wizard should be able to handle that for you. Once you've got a new class wrapper that represents the control, you'll need to replace the prior wrapper class in your source code.

Usually the control is created somewhere in your dialog code with CreateInstance.
If the interface is compatible (I assume it is) , you just have to change the name or GUID that is used in the CreateInstance Code.

Related

Can I use COleControlModule in a vb.net windows forms app?

I am upgrading a windows forms app. The app uses an active x control (ocx) file. We have gotten the ocx to compile and can register it. The main class in the C++ active x control project is a COleControlModule. When I go to add the control to the windows forms app like this
Me.Controls.Add(Me.ActiveXClass)
I get
Unable to cast COM object of type 'System.__ComObject' to class type
'System.Windows.Forms.Control'.
I know the active x class is a com object and I know that this COleControlModule class must not be compatible with a windows forms control. Is there anything I can do to make this work?
Any help is greatly appreciated.
This isn't working because a Runtime Callable Wrapper (RCW) is not a Windows Forms control. Only Windows Forms controls will work; to use an ActiveX control with the form, you must generate a Windows Forms wrapper for the ActiveX control. This is done with Aximp.exe, typically via adding the control to the Toolbox, as Hans suggested and then dragging an instance of the control to the form.
The steps are:
Select 'Choose Items, either from the Tools menu or by right-clicking the Tools tab
Select the COM Components tab
Select the ActiveX control either directly from the list or through the Browse button
From the Tools dialog, select the newly-added component with the mouse and drag it to the form.
A reference to the ActiveX control will be added to the project, as in this sample with the Adobe PDF reader:
<ItemGroup>
<COMReference Include="AcroPDFLib">
<Guid>{05BFD3F1-6319-4F30-B752-C7A22889BCC4}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
<COMReference Include="AxAcroPDFLib">
<Guid>{05BFD3F1-6319-4F30-B752-C7A22889BCC4}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>aximp</WrapperTool>
<Isolated>False</Isolated>
</COMReference>
</ItemGroup>
Note there are two entries, one to generate a Runtime Callable Wrapper (via tlbimp), and another to generate the AxImp wrapper (via aximp). These will be viewable in Solution View, under the project's references.

Why is my listbox not resizing? (Dynamically resizing dialog components)

My app is Win32; I'm using VS 2015. I have a dialog box that contains a listbox. I set the listbox to be dynamically resized, but it does not change when the dialog is resized.
Here are the listbox' attributes:
The listbox is owner-drawn:
This is the default size of the dialog:
This is what the dialog looks like when I stretch in Test mode in the Resource Workshop Dialog Editor. Notice the inside listbox expands too, exactly as hoped:
However, when it's actually running, stretching the dialog does not increase the size of the listbox:
Why is this not working? Is there some additional voodoo I have to invoke to get it to actually work? Does this only work in MFC? What is the Win32 equivalent of CWnd::ExecuteDlgInit?
Note: I have already looked at https://msdn.microsoft.com/en-us/library/mt270148.aspx and http://mariusbancila.ro/blog/2015/07/27/dynamic-dialog-layout-for-mfc-in-visual-c-2015/, wherein I did not find an answer.
Does this only work in MFC?
Indeed, this only works when using MFC1.
What is the Win32 equivalent of CWnd::ExecuteDlgInit?
MFC is a library built on top of the Windows API. The windowing system in the Windows API does not provide any sort of layout management. If you want to see the Windows API equivalent, it's literally what is implemented in MFC.
So, why is this supported in the graphical resource editor then? Because that is where the layout information is generated. It's ultimately placed into a custom resource of type AFX_DIALOG_LAYOUT, where MFC picks it up to do its magic. If you aren't using MFC, that resource is simply ignored.
That's not to say that - in theory - you wouldn't be able to implement your own solution that reads the generated resource. As long as you can find documentation for the custom resource used by MFC. I didn't, but a look into the MFC source revealed, that it's pretty simple (a version WORD, followed by pairs of WORDs for horizontal and vertical move and size settings).
1 Or a library that understands the implementation details, such as the WTL.
This functionality is also supported in Windows Template Library!
https://sourceforge.net/p/wtl/git/ci/master/tree/Include/atlframe.h
If you have a look at the CDynamicDialogLayout class you can see how it works, and if you are using WTL you can even use the functionality yourself.
For the record, I was looking for the solution to this as well, when I resized a control on my dialog all of the dynamic resizing stopped working, although it worked fine in the Test Mode.
To fix it, in the the second link you posted there's a section on adding a function:
void CMFCDynLayoutDemoDlg::SetupDynamicLayout()
Where you re-setup the Dynamic Layout manager
Once I did this, it started working in the live version for me.
Very similar answer is in this post too:
Recalculate dynamic layout properties

How to add save file dialog in plug-in using 3d's max 2016 SDK (C++)?

I'm currently using 3d's Max 2016 SDK via MV Studio 2012. I've created usual project with Plugin Wizard, it creates panel with text and button (and does many actions inside the code, but that is not the theme).
So, now I want to add some button to activate Windows File Dialog to choose path (folder) and name of .bin-file that will be created afterwards.
I tried to find something in the toolbox at the resource editor but have not succeed.
What should I do?
As you said, you can use directly winapi to create your dialog, but the aesthetic result of the window should differ a bit from dialog already used in 3dsMax. Autodesk has made a lot of UI controls by themselves (or patched winapi ones) and provide their access in the SDK to have something homogeneous between the application and plugins.
What you are looking for here, is the function named DoMaxSaveAsDialog and should be available in Interface8.
Interface8 Class Reference
The problem is solved de-facto. Just used pushbutton and GetSaveFileName function from windows.h header.
For details, read here:
how to save file with GetSaveFileName in win32?

Using ListControl in a Dialog window

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.

Adding a tile to an MFC application

I have a C++ MFC application that has a bunch of dialogs which are defined in an .rc file. I need to add a tile to the application for pinning it to the start menu because the default "tile" that Windows creates from the icon doesn't look very good. Rewriting the whole application to use XAML instead of the .rc file isn't an option right now. The tile doesn't need to be interactive, just display a better looking picture than just slapping the small icon in.
Is there a way to add a tile to an MFC application with an .rc file?
If not, the other idea I had was to create a wrapper application which uses XAML to create a tile, and the only thing the wrapper application would do is launch the MFC application. Does anybody have a better solution?
I am using Visual Studio 2015.
The .ico file I'm using has 768x768, 512x512, 256x256, 150x150, 48x48, 32x32, and 16x16 versions of the image in it.
Edit
There was some confusion about what exactly I needed. Here is an annotated screen shot which hopefully shows the issue clearly.
One other clarification, I don't think this makes any difference, but I thought I'd add it just to be safe. The program does not need to run on Windows 8/8.1, just Windows7 and Windows10
After extensive research it is clear that this is not possible. Not only is it not possible with MFC, but the only way to create a tile (live or static) is with a Windows Universal App. So my solution here is to create a simple launcher program that starts up the MFC application and then exists. However, one caveat here is that Windows Universal programs are not allowed to directly run other programs. What they are allowed to do is open a file with it's default program. So I created a new file extension and assigned the default application to be the MFC program.
this->SetWindowText("SudeshMFCDemo");
https://msdn.microsoft.com/en-us/library/yhczy8bz(v=vs.90).aspx