How to use google map API with MFC or QT in c++ language? - c++

I have a question how to use google map api in my developing program.
My program is being implemented by c++ language in Visual studio 2017 environment and MFC for graphical interface in usual.
I want to develop program of two versions using google map api.
The first one is to use the google map in my program without internet connection.
The second one is with internet connection.
If anyone know how to do it, please answer to my question.

Qt C++ provides a QWebChannel, which fills the gap between C++ applications and HTML/JavaScript applications.
You need to create a QWebChannel and register a JavaScript helper Object in C++. This object exposes public methods, which are invokable calling from JavaScript in HTML.
QWebEngineView::setUrl() hosts a page, which has Google Maps.
QWebEnginePage::runJavaScript() gives you the power of manipulating the map. C++ call JS, and JS call C++ --- this is truly powerful!

I faced the same need as yours. The solution I have found was to use an embedded browsing component and from that component access Google Maps.
See my article about this implementation.
Basically, here are the instructions for adding such component to your MFC application:
Open Visual C++ and follow these steps:
Choose New from the File menu.
Select MFC AppWizard (exe).
Enter the project name and select a location.
Click OK. When the dialog box for Step 1 appears, select the application type that is appropriate for your application—single document, multiple document, or dialog-based. Select "Dialog-based" for this example.
Click Next.
Select application features and support.
The dialog box for Step 2 asks you to select any features and support your application will need—an About box or automation support, for example. The WebBrowser control is an ActiveX control, so select ActiveX Controls. Click Next to go to the next step.
Select the project style.
The dialog box for Step 3 is used to define your project. You have only one project style option, Standard MFC. But you can indicate whether you want the IDE to generate comments in the source code, and you can specify how you want to use the MFC library. The default selections are appropriate for most applications. Click Next to go to the next step. Name the files and classes. The dialog box for Step 4 displays the names of all the files and classes that Visual C++ created. You can change these to more descriptive names or to names required by your specification. Click Finish.
Add a WebBrowser control.
The actual part that interface with Google Maps is embedded within an HTML code that should be also hosted, so my solution combines the browser's hosting with the interface with Google Maps.
The HTML code is formatted in this example:
HTML_TEXT.Format(L"<!DOCTYPE html><html><meta http-equiv=\"IE X-UA-Compatible\" content=\"IE = edge\"><body><div id =\"googleMap\" style=\"width:%dpx;height:%dpx\"><script>function myMap(){var mapProp = {center:new google.maps.LatLng(%f, %f), zoom : 10};var map = new google.maps.Map(document.getElementById(\"googleMap\"), mapProp);marker = new google.maps.Marker({position: new google.maps.LatLng(%f, %f),map: map});}</script><script src = \"https://maps.googleapis.com/maps/api/js?key=%s&callback=myMap\"></script></div></body></html>", w, h, Latitude, Longitude, Latitude, Longitude, API_KEY);
As you can see, you can generate a map with a marker pointing on a given location using Longitude and Latitude. You also need to obtain an API_KEY from Google.

Related

In Visual C++ 2017: Where in the property pages does it say what Application Types correspond to the projets?

I am trying to recreate a Visual C++ Solution that had about 30 projects so that the general organization will be cleaner.
The original "solution" was in fact a Visual C++ 6 workspace from the turn of the century, migrated into VS 2017.
Some of the projects will be close to being clones of the old ones.
When I try to create a project, I am asked what Application Type it must be:
Single Document/Multiple document/Dialog based or Multiple top level documents.
I thought I could guess this by looking at the property pages of the existing documents, but I can't seem to find it. Or am I likely to be going in the wrong direction?
As far as I'm concerned, we couldn't guess this by looking at the property pages of the existing documents. I suggest that you could check MainFrm.cpp in the project source file to distinguish the project from a single document / multiple documents / dialog based or multiple top-level documents.
A multiple documents:the document's frame window can hold multiple child windows.
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWndEx)
A single document:the document's frame window can hold only one document.
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx)
dialog based: There is no MainFrm.cpp in the source file.
multiple top-level documents:Creates a multiple top-level architecture for your application, where a view class is based on CView.
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx)
clicks New Frame on the File menu:
For more details, I suggest you could refer to the Application Type, MFC Application Wizard

Get List Of IE extensions inside IE extension

I am trying to get list of all IE extensions present inside IE-8. along with installation date of extension, version and other information.
The way i want to do this is Create a new IE extension and fetch list of all other extension in there.
Is there any way in IE to do this? May be a high level API.
Any suggestions will be a great help.
Thanks
There a number of different types of 'extensions' in IE.
Toolbars, BrowserHelpers, accelerators, searchProviders, menu and context menu extensions. These in turn can be scripted, COM based or PE file types.
The registry paths for each type of extension is documented on MSDN.

Get all macros from Microsoft Word (using automation)

I'm writing a C++ MFC program which automate MS Word using their interfaces.
From my app I was able to open MS Word, open macro window but I need to retrieve all macros from a combobox and add them in my app and so later on user can choose which macro he wants to apply to some document.
Can retrieving be done with GetProperty method? If it can you can show me an example?
You can use Document.VBProject to get access to the VBA code (to get to the macros in the document). Here is how to do it in word using VBA/C#. You can just rewrite that code using C++.
Note that MFC is not the easiest way to work with word automation, but you can do it using MFC as well. There is more than one approach available when you do automation with MFC. You may do this with MFC-only-way (i.e. in style from 90x, using object wrappers), or use e.g. #import directive.
GetProperty is basically a generic method, which can be to get some properties of the object it is applied to, i.e. it is not specific for macros.
Note also that end-user must have "Trust programmatic access to VBA project" enabled to allow your code to get the macros (this is a checkbox in word security settings, turned OFF by default). May be a show-stopper.

Using a dialog box to graphically retrieve user input

I am not new in C++ but this is my first time developing a Win32 program. It has to be graphical and so I have been attempting to get user input using an input/dialog box with no success.
I have read this topic on MSDN and found it helpful, but I get an error about IDD_PASSWORD and IDE_PASSWORD not being defined. Declaring them in resource.h and giving arbitrary values (like 110, 111) yields no results. Other attempts I have tried to modify the auto-generated about box, which also yields no results after modification, I noticed that if i change the value of IDD_ABOUTBOX in resource.h from 103, this also does not work. I also tried using the .rc under Resource View, but still no results.
So I'd like to know if the resource box templates have predefined constant numbers that i have to use, if so where because I searched that too or if there is another way to obtain user input in a windowed application. I just want to obtain an integer, that's all.
There is nothing magic in the numbers assigned to resources. The numbers are what the code actually uses to identify the resources. Visual Studio just allows you to assign symbolic names to those numbers through the use of C macros (i.e., #define) to make your code easier to read. These values are all defined in the file resource.h by convention, and although you can modify that file manually, you usually should not do so—let the Visual Studio Resource Editor handle that for you.
The problem you're running into is that you actually have to create those resources first before the numbers will mean anything. When you create a new Win32 project, Visual Studio will automatically create an about box dialog and give it the symbolic ID IDD_ABOUTBOX. However, there is no such IDD_PASSWORD dialog created by default in a new project, and there isn't one built into Windows.
You can create this dialog yourself using the Dialog Editor (part of Visual Studio's Resource Editor), which is pretty easy to do as it allows you to drag controls around on the dialog where WYSIWYG. When you add a new dialog box to your project's resources, you will be given the option to name it anything you like. You can use IDD_PASSWORD if you want, or any other name. A numeric ID will be assigned automatically based on an algorithm; generally the lowest available number is used.
The article you linked to is assuming that you have already added a dialog to your project with the symbolic name IDD_PASSWORD (which is probably a mistake on the part of the author). All it shows you is how to display that dialog once it exists as part of your project's resources.
It's going to be somewhat difficult to learn Win32 programming just by reading the MSDN documentation. I strongly suggest getting a book that explains it more clearly and in a more logical order. The canonical text is Charles Petzold's Programming Windows, 5th Edition. Note that you will need to make sure you get the 5th edition, as the newer editions digress from their Win32 roots and start talking about completely unrelated things like C# and Silverlight.
If you absolutely must learn by trial-and-error and MSDN, start reading about dialog box resources here.

App Shortcut without pinning to Start Screen in Windows 8 using C++

Our company has an installer written in C++ that creates program shortcuts using IShellLink as described in:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb776891%28v=vs.85%29.aspx
On Windows 8 all shortcuts created in the Start Menu will also show as titles on the Start Screen. What we're looking to do is programmically control which icons are shown on the Start Screen. In the following article it describes the option "System.AppUserModel.StartPinOption" as:
To create add an app shortcut without pinning it to the Start screen
view, you can set the following property on the shortcut:
System.AppUserModel.StartPinOption = 1. The symbolic name for 1 is
APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL.
http://msdn.microsoft.com/en-us/library/windows/desktop/jj673981%28v=vs.85%29.aspx
This appears to be possible using the Windows Installer, however I haven't found a way to accomplish the same functionality programmatically in C++ given our context.
If anyone has any information about this, or an example of some sort, it would be much appreciated.
One thing I found was that "..NewInstall" literally means that. User customizations to the tiles seem to be retained even after you delete/update the .lnk files. This is probably a good thing as updates won't reset the user's environment, but it does mean that I needed to use fresh installs of Windows 8 during testing. I used a VM box to minimize the pain. At least I don't know how to delete the properties once set from within the environment.