I am building a textEdit application with MFC. Is there a way to create a hyperlink automatically when a user write web address? It's like when you write a web address "www.google.com" the application detects web address and create a hyperlink right away. I have searched documents that explains about this, but couldn't find it.
You'll probably want to use the CRichEditCtrl, which uses the RTF spec to do rich text highlighting. This can include underline and colors, which you could use to create a hyperlink. See RTF syntax for hyperlink for more info.
I think you'll still have to detect clicking on that hyperlink, but that's perhaps a separate issue.
Be aware, Jake, that MFC is a bit of an outdated UI framework. If you know what you're doing and why you need to use it, great, but if you're just getting into UI programming, I'd suggest something more modern, like WPF or any of the XAML-based spin-offs.
Related
I needed a lightweight HTML editor to generate "rich text" emails, the catch being that I need to be able to extract and inject the content as HTML. This also needed to have spellchecking.
Previously I had been able to achieve this without spellchecking using an ActiveX control, however since MFC has the CRichEditCtrl and CHtmlEditCtrl, I determined I would have much more luck with the spellchecking going down this route.
So I have attempted to utilise the hunspell library and have had reasonable success. However I have only been able to get it working with CRichEditCtrl. Trying to create an HTML editor out of this RichEditCtrl has proven difficult, and I can't believe that there is no way to interact with a CHtmlEditCtrl.
Can anyone recommend any documentation or sample projects that have achieved this? I have sort of been able to hack it in using a CHtmLEditCtrl underneath the CRichEditCtrl, but this has just caused more problems. Thanks! Hope I've explained myself properly.
I need to develop a search module for an mfc ribbon application using C++. I have used auto complete feature in C#.NET but never worked on any mfc ribbon application. I want auto complete search with an icon image as prefix of each suggestion, just like Facebook search. I have also consulted this article, but that uses CComboBox, I need to use CMFCRibbonCombobox in my program because I tried with CCombobox but that was causing problems. Any help will be appreciated.
you need to create your own CMFCRibbonComboBox derived class, that will be pretty much a copy of the CMFCRibbonFontCombBox without the fonts.to check how you draw the images you can check the CMFCRibbonFontComboBox::OnDrawDropListItem implementation.
Then I think that you will have to dynamicaly add it to the ribbon.
I made a small program in C++ that can type text into a notepad document, it does so using FindWindow and FindWindowEx, but I was only able to do that because I knew the names of the windows I was trying to access (in this case it was "Notepad" for the doc and "Edit" for the text area).
If I didn't know the names how would I go about figuring that out? Lets hypothetically say I wanted to make text appear in Chrome's URL box, how would I figure out what the name of that box is so I can use FindWindowEx on it?
The least painful approach to automating 3rd party applications is to use UI Automation. It allows you to navigate UI hierarchies as well as operate on the individual objects.
All native windows controls support UI Automation out of the box. UI Automation also works with frameworks, that do not implement their UI using native controls (e.g. Qt). Particularly with Qt, tools like Spy++ will not give you the information you need.
Run the other app and then use a tool like Spy++, Winspector, etc to look at the other program's window hierarchy to find what you need.
I have what seems like a simple task. I wrote a Windows application using C++. Now I need to add to it a capability to print forms -- nothing fancy, just plain text, with lines, tables, and simple graphics. Besides printing, a user needs to be able to preview on the screen all forms being printed.
Previously I was able to get away with this task by using an embedded Internet Explorer control and design all forms in HTML (which I like -- the HTML part.) But the problem comes with IE... hmm... I wish I had a nickel every time I heard that phrase :) Anyway, IE can print an HTML page but it does not provide any easy way for users of my software to customize page size, page margins, etc.
I spent a good deal of the last week trying to make IE Print Templates work with what I need ... but eventually failed. That stuff is very poorly documented and what I was able to do seems to randomly crash on me. So at this point I gave up on IE...
So my question to you -- is there a way to incorporate printing into my C++ program for the purposes like I described above?
If I remember correctly, printers have their own HDC, and you can draw on it. That'll work if have something simple. If you want to render HTML page using pure WinAPI, you're in big trouble.
I'd advise to abandon winapi and try GUI framework instead.
Qt 4(and 5, most likely) has text editor that can display rich text, layout engine for rich text, component that can display web pages. Read documentation a bit, and you will most likely find a way to render web page onto printer instead of screen. So far it looks like exactly what you would need.
Using Qt will add dependencies (20+ MB of DLLs for your project), but, IMO< it is a better idea than trying to use IE COM interfaces.
If you don't want to use Qt, you could try something like WebKIT, but I had some bad experiences with it, plus Qt might be just easier to use.
Additional info on printing: Printing with Qt.
Try searching for GDI, if you want to use win32 builtins.
Or use another toolkit like wxWidgets. Or consider writing to PDF with some library. Or let LaTeX do the heavy lifting - writing text files is easy. The LaTeX-way works as long as you don't want to modify your output depending on the layout (one Use-Case that doesn't work with LaTeX is the "balance" at the top/bottom of each page.)
Consider having your program generate XML files and using XSLT to render them into HTML.
By attaching stylesheets you will make it much easier to customize the presentation.
I was looking into trying to get my C++ application to do the following:
Open internet explorer
Open a webpage
Enter a name and password into specific forms in the webpage
Click the submit button on the webpage to open a new page
From my searching on the Internet it seems like using COM may make this possible, although I may be incorrect on that. I am doing my best to learn COM at the moment but some help would be great. I'm looking to do this without using MFC.
I have noticed this question which I kind of what I am looking for but I am having trouble understanding the suggested solutions. For example, I do not have a IWebBrowser2 option in my toolbox.
EDIT:
To make my question clearer, I had this task complete in a C# version by simply running a coded UI test but this will not work with C++. I am looking to open IE (not in the application itself), find the username and password forms, pass them string, then find the submit button on the page and click it.
This is very possible from c++. You will have to dive into the winapi to do some Keystroke stuff as well as window handling.
I'm not going to go into all of the code, but you have to do something like the following:
Start ie (if you give it a command line arg with the webpage, it will
open that page).
Make sure the ie window is focused (either just wait
if you want to keep it simple or use window's api to go through each
open HANDLE and find the window you want)
Use SendInput to send an Alt + D (to gain focus to the url bar, in firefox it will be a CTRL + L instead)
Use SendInput and javascript injection to modify the DOM as necessary
You can also submit the form (after everything is as you want it) using the above JS injection capability.
Yes, it is possible, but you have to embed a web browser control in your application, and it is not straightforward (I don't think you can automate DHTML in an external instance of Internet Explorer via COM).
I see that you don't want to use MFC, and this complicates even more the problem. Perhaps you can do it via ATL, I advise against even trying to do it without a framework.
If you could use MFC, then you could use a CDHtmlDialog form and access the underlying COM interfaces to automate the actions.
In the past, I developed an MFC application that used HTML as its user interface, but I used the CDHTMLView class that you can find here: http://www.codeproject.com/Articles/1783/Integrating-DHTML-into-MFC-Views
You can use this as an entry point for learning how to deal with DHTML events and how to play around with the IWebBrowser2 interface.
You should really take a look at WebDriver which is able to do exactly what you are describing. See (http://code.google.com/p/selenium/wiki/InternetExplorerDriverInternals) for more information about the InternetExplorerDriver internals. Even if you are not able to use the project directly, you can certainly browse the source to get a better idea of how what you want to do can be achieved.
What you want to do makes not much sense.
There are many APIs available to embed a browser view into your program. For example Qt offers this.
Then you can just do your HTTP POST request yourself and display the answer you get in your browser view.
That is a much cleaner solution.
Pro tip: Don't use Internet Explorer.