I'm building an "import from Excel" function. It has to be in a DLL, called from a non-MFC app. Has to provide an image of the spreadsheet that users can drag a select box around (to select cells), then click an IMPORT button, and have the right thing happen. Having trouble getting the spreadsheet up, having a button adjacent to it, and having it happen in a DLL.
I went the route of an MFC dialog inside a DLL, but was blocked in trying to bring up an OLE client for excel on a window on the dialog. Only support I found for showing Excel using OLE required an SDI. I was able to get the automation functions to work, and I could read the cells and paint a "fake image" of them on my dialog... but I'm afraid that's going to be in non-compliance with my requirements.
So I tried creating an SDI. I was able to create an SDI that brought up Excel as an OLE Client. I was able to handle the "selection change" event, and go the cell data I needed. I was foiled at this point by 2 items:
Could not make this SDI work in an MFC DLL. Crash in CWinApp constructor, asserting that the AfxGetThread wasn't null. Moved "theApp" to be locally scoped within the single exported DLL function, but still couldn't get it to work, but with different symptoms: crashed when added AFX_MANAGE_STATE(AfxGetStaticModuleState( )); to exported DLL function, if I didn't use that, the OnInitInstance never was entered. Tried adding a call to the app's Run() function, but that didn't help. I can post this code if someone thinks they have an idea what the problem is.
Could not present a toolbar while the Excel client item was active. I could put my "import" (and other options) on the menubar at the top, but that's not evident enough. Even a floating toolbar was closed. It makes sense that it would do this, since it would be confusing to have a toolbar present that couldn't take actions on the currently active item... but in my case, it's a problem.
So now I'm thinking I need to go back to the dialog approach, and embed an ActiveX control that brings up an excel spreadsheet file to import.
Must either allow me to handle the selection change event, or must allow me to find what cells are selected (or were most recently selected if clicking the "import" button on my dialog causes the selected cells to become unselected).
It must also come with reasonable licensing terms, as this will be used in a commercial application that is widely-available to the public.
If anyone knows of a "quick fix" to either of the approaches I had been trying, that would be useful too.
Hope someone can help me!
If you just want to embed Excel, you don't need anything.
Just embed it into a standard OCX host control.
Related
I have a dialog type application that includes a MFC EditBrowse Control. This control includes a folder/magnifier icon on the right side where the user is supposed to click to bring up a folder browser pop-up.
That folder/magnifier icon displays properly in the dialog editor within Visual Studio, but at runtime it displays as a plain flat button. It behaves properly otherwise - that is, the browser pop-up pops up and the selected folder is displayed when the user clicks OK.
When run with the debugger a message is displayed in the VS Output Window saying "Can't load bitmap: 4299". That message is displayed after the CDialogEx::OnInitDialog() line within my OnInitDialog().
I've written test programs and they display the icon properly. I've also added additional EditBrowse controls in my original program, but they experience the same problem and just add another line of "can't load bitmap". I've also added other MFC controls and some of them also do not display their icons (or other stuff).
I've managed to affect the problem slightly by making calls to EnableBrowseButton() and EnableFolderBrowswButton() from my OnInitDialog. If I do that, I get an icon that looks like 3 horizontal dots:
which is better, but I'd prefer the folder/magnifier icon.
It's a complicated enough application I'd rather not re-write it from the beginning and furthermore I'd like to understand what is going on. I'm fairly certain this is a result of adding/deleting controls as the app was developed, but don't have a good idea on where to begin tracking down where things went awry.
Thoughts on how to debug this? BTW, this is VS 2010.
CMFCEditBrowseCtrl uses the Visual Manager to load the bitmap from MFC resources.
This resource is loaded in "afxribbon.rc"
Make sure the following these lines are included in the main *.rc file (this is how VS Wizard creates the *.rc file)
#if !defined(_AFXDLL)
#include "afxribbon.rc" // MFC ribbon and control bar resources
#endif
(I guess you can omit the #if/end statement, but it's probably there for a reason)
Alternatively, CMFCEditBrowseCtrl::SetBrowseButtonImage can be used to assign user icon.
I have made an application using VB6 and it’s already connected to an Access database.
Everything works perfectly: I have my table field shown in my VB application as it should be. My problem is that I don't know how to link between filed that is contain (yes/no) in Access with option botton in VB. I have them in frame but that’s all. Any help or code or even something to start with it.
Here’s a picture:
In the picture you will notice that it’s already (yes) but that is what VB6 gives me; it's suppose to be no anyway.
Option button is not a databound control. You will need to work directly with it's events and the data control to update or reflect the changes.
Another user has already suggested using a checkbox control, which IS a databound control.
Either way shouldn't prove too difficult, but the checkbox should be near plug and play.
I am creating a windows using win32:
HWND mainWnd = CreateWindow(...);
Now I can add gui elements as children of mainWnd. However this soon becomes a bit tedious and I want to use the designer built into Visual Studio to help me.
I noticed that under Add Resource there is a Dialog entry. Among the dialogs IDD_FORMVIEW seems the most general so I added one of these. Next I added gui elements to it using the designer.
Now I want to use this as a child of my mainWnd. How do I do this?
I found some examples using DialogBox, but I do not want a separate dialog, I want this window as a child of my mainWnd.
The designer in Visual Studio is appropriate for creating dialog boxes, not arbitrary windows.
That being said, there are a couple of approaches (in increasing order of difficulty):
Make your main window a dialog. Petzold's book has an example of using a dialog as the main window of the program. (If I recall correctly, it's the calculator example.)
Create the dialog and, before you show it, change its style to WS_CHILD, change its extended style to WS_EX_CONTROLPARENT, and parent it to your main window. For all the navigation stuff to work, you'll have to add IsDialogMessage calls in your message pump. This is do-able, but it's likely hard to get everything working well.
A mixture of 1 and 2 where you create one dialog for your main window, then create a second dialog for the content (with DS_CONTROL), and put the second dialog in the first. I've never tried this approach myself, but it seems like it should work.
Write your own code to parse the dialog resource and create the child windows, which is basically re-doing a lot of the work that CreateDialog does for you.
Given your desire to use the GUI to design the UI, I suspect only the first solution is simple enough that you would be interested.
Use the CreateDialog API to create the window from the resource. If you do not want it to look like a dialog then remove the titlebar style from the resource properties.
To use a dialog created from a dialog resource template you have to specify the DS_CONTROL window style in the template.
Read more about dialog boxes here.
Dialog resources are explained here
I need to know how to open the form of a program I am debugging.
I loaded an existing solution into VS2010, I can see the code, but I want to see the GUI part of the project, click on buttons and see what part of the code they take me to, set breakpoints where I feel like.
I don't know how to see the GUI in VS2010, where can I do that?
Also, where would be a good resource to learn the ins and outs of VS2010?
Depending on how the UI was created, there may or may not be a way to see the UI at design time. Particularly if this is an older Windows UI application, it's likely that the windows are created entirely in code, and there is no design-time UI for you to see.
There is a dialog editor, for dialog windows that are defined in resource (*.rc) files. CTRL-SHIFT-E brings up the Resource Viewer and you can look for things under the Dialog node. It is possible that your main window is a dialog-style window, as that's one of the options you get when you create a new MFC-based application.
Otherwise, your only option to see what your UI looks like is to run the program and see. Tracking down which UI elements do which actions in your program will require finding the appropriate event handlers or message handler methods (again, depending on what UI framework, if any, is in use) and setting breakpoints.
The generic answer is:
Hit F5 to starting Debugging mode. (Or under the Debug menu choose Start Debugging)
But it depends on how your project is setup and what type of project it is if F5 will work that easily for you.
What kind of program/language are you using?
With a form, I believe you have to File-->Open-->Project/Solution
Now if its a website, you would open Website. If you tried to open a windows form under a website then you wont see the design.
Typically you would just double click your form name (form1.cs) because then your design view will pop up or hit Shift+F7 or rightclick --> view designer. Then just double click whatever tools you have on your form (like a button) and it will automatically go to the button code.
If its a website, then it would be under website1.aspx while the code sits in website1.aspx.cs
But if none of that helps, here is a good place to learn this stuff
VisualStudioWalkthroughs
If you use the Visual FoxPro 9 Application Framework to create a desktop standalone application and add a database and form, the exported exe shows a Quick Start on load which shows the form to select.
If one wants to show up his own MAIN MENU form on the exe load, what's the way to do it? Using Set Main on the Menu Form does not work.
Here is a visual representation of the idea.
In its simplest steps then, aside from the "Wizards" you can use to build forms and bind to data environments, tables, grids, etc maybe this will help.
Create an empty project.
CREATE PROJECT MyApp
Go to the documents tab and add a new form. Put a few buttons as you've described on it. One of the buttons, allow to close the form, such as "Exit". Double click this exit button and put in the code
CLEAR EVENTS
THISFORM.RELEASE()
Since there are no "data entry" elements on this form, we need something to make it keep focus. Buttons alone don't just "do" that. Go to the properties sheet of the form and go down to "Window Type" and set it to "Modal" - meaning, keep this form up until its intentionally closed. (This also keeps as a baseline for you calling any OTHER forms from this one for your application.) Save the form, such as "MyMainForm".
Click on the "Code" tab of the project and do a new "Program". In its simplest context, put in
DO FORM MyMainForm
READ EVENTS
Save the program, such as MyStartupProgram. Once saved in the project, right-click on this program and select "Set Main" for this to be considered the single entry point to your entire application. Save, build the project and run it. You should be good to go.