How to access clipboard in VS 2017 extension project - visual-studio-2017

I try to interact with windows clipboard via SVsUIHierWinClipboardHelper using this code:
var dataObject = new OleDataObject();
dataObject.SetText("sometext");
clipboardHelper.Copy(dataObject);
but it has no effect. How to copy a simple text to clipboard correctly?

You can just use .NET Clipboard class:
System.Windows.Clipboard.SetText("sometext");

Related

Convert Visual C++ code to Borland C++Builder

I have coded a program with Visual C++. But now I must put my code in a program which is coded with Borland C++Builder. I have a WebBrowser item on my form. In Visual C++, I write data to a textbox, get data from the textbox, and click a button on the WebBrowser with this code:
Write Data:
WebBrowser1->Document->GetElementById("okul_kod")->SetAttribute("value", TextBox2->Text);
Get Data:
textBox17->Text = WebBrowser1->Document->GetElementById("kay_cev")->GetAttribute("value");
Button Click:
WebBrowser1->Document->GetElementById("panelden_kayit")->InvokeMember("click");
I tried lots of things, and searched online, but I can't find how to convert this code to Borland C++Builder.
Can you please give me a clue or advice?
In C++Builder 6, its TCppWebBrowser VCL component is a thin wrapper for Internet Explorer's ActiveX control. Its Document property returns an IDispatch that you can use to gain access to IE's raw DOM interfaces directly (whereas Visual C++ appears to have wrapped those interfaces a little more nicely for you).
Try something like this:
#include <mshtml.h>
#include <utilcls.h>
// helpers for interface reference counting
// could alternatively use TComInterface instead of DelphiInterface
typedef DelphiInterface<IHTMLDocument3> _di_IHTMLDocument3;
typedef DelphiInterface<IHTMLElement> _di_IHTMLElement;
...
// Write Data:
_di_IHTMLDocument3 doc = CppWebBrowser1->Document;
_di_IHTMLElement elem;
OleCheck(doc->getElementById(WideString("okul_kod"), &elem));
if (elem) OleCheck(elem->setAttribute(WideString("value"), TVariant(Edit2->Text)));
// Get Data:
_di_IHTMLDocument3 doc = CppWebBrowser1->Document;
_di_IHTMLElement elem;
OleCheck(doc->getElementById(WideString("kay_cev"), &elem));
TVariant value;
if (elem) OleCheck(elem->getAttribute(WideString("value"), 2, &value));
Edit17->Text = value;
//Button Click:
_di_IHTMLDocument3 doc = CppWebBrowser1->Document;
_di_IHTMLElement elem;
OleCheck(doc->getElementById(WideString("panelden_kayit"), &elem));
if (elem) elem->click();

Since what version of IE does it begin supporting "Find on page" command?

I'm using web browser control in my dialog-based MFC project. I also like using the built-in IE's "find on page" functionality that brings up this window:
I can invoke it as such:
//pWebBrowser = pointer to IWebBrowser2
HRESULT hr;
CComVariant var1, var2;
if(SUCCEEDED(hr = pWebBrowser->ExecWB(OLECMDID_FIND, OLECMDEXECOPT_PROMPTUSER, &var1, &var2)))
{
//Done
}
This works great on my Windows 8.1 machine, but when I tried this code on an old Windows XP installation, I got this ... "thing" that totally breaks the flow in my app:
Does anyone know since what version of IE did they start supporting that "find on page" window?
The 'find on page' functionality was introduced in IE8, which highlights all instances of found words while allowing the user to continue the navigation normally.
Source: New features -> Inline search within pages

Example of setting italics in richtextbox with windows forms

I'm looking for a complete, working example of how to set text to italics in a Windows Forms Rich Text Box, using C++.
All the examples are similar to the following:
System::Drawing::Font comment_font =
gcnew System::Drawing::Font(m_rich_text_script->SelectionFont,
System::Drawing::FontStyle::Italic);
m_rich_text_script->SelectionFont = comment_font;
I'm getting the error:
error C3673: 'System::Drawing::Font' : class does not have a copy-constructor
I believe the error is because I'm not including the header file for System::Drawing::Font.
I searched the web and stack overflow for "C++ Windows Forms italic" and none of them show the filename to include. Interestingly, the MSDN sites to not show the #include for C++.
I am using Visual Studio 2010 on a Windows CLR project on the Win7 platform.
Background: I moved the definition of methods from Form1.h to Form1.cpp and #included "Form1.hpp".
Try using a handle to a System::Drawing::Font object instead of a stack variable:
System::Drawing::Font^ comment_font = ...
Below is a complete C++ class that, given a rich text box, sets its selection font to italic:
namespace SetToItalic
{
public ref class SomeClass
{
public:
static void SetRichTextBoxSelectionFontToItalic(
System::Windows::Forms::RichTextBox^ textBox)
{
System::Drawing::Font^ comment_font =
gcnew System::Drawing::Font(
textBox->SelectionFont,
System::Drawing::FontStyle::Italic);
textBox->SelectionFont = comment_font;
}
};
}
I have verified this using the toolchain provided with Visual Studio 2013 by having a C# Windows Forms application call into a C++/CLI assembly with the above code.

Microsoft Office OneNote C++ APIs?

I was looking into modifying Microsoft Office OneNote contents via c++ programming. Specifically at using Quick Filing Dialog Box Interfaces. But all the examples available in there are for C#, I want to know whether API for C++ is available, if so where can I start to learn them. I just wanted to use that dialog box get the OneNote section and insert my content as a page in that section.
As Daniel Escapa writes:
Open Visual Studio and create a new C++ project. For my example I am creating a Win32 Console App:
Now I want to add the OneNote2007 header file, OneNote12.h. You can find that attached with this document. Make sure to copy it to the folder with your C++ source files as well as add it to your header files like this:
Add a new #include for OneNote:
#include "OneNote12.h"
Now just connect to OneNote like you would any other COM API. Please see here for an example:
CoInitialize(NULL);
IApplication* piOneNote;
CoCreateInstance(__uuidof(Application), NULL,
CLSCTX_LOCAL_SERVER, __uuidof(IApplication), (void**)&piOneNote);
if(piOneNote)
{
BSTR temp;
HRESULT hr = piOneNote->GetHierarchy(NULL, hsNotebooks, &temp);
wprintf(L"%s", temp);
}

Programming with Qt creator and Cocoa ( copying the selected text from the current application)

I would like to know if there is a way to use the Cocoa API in a Qt application.
I've already used the Windows API to get the selected text from the active application.
I'd like to do the same with mac os.
I tried to make a simple "hello world" application C++ with xCode, including the <Cocoa/Cocoa.h> but it didn't work as I excepted.
Is there a way to get this "hello word" application to build with Cocoa?
And, also If that is possible, can I get the selected text from the active windows with Cocoa API?
EDIT :
All right, so I successfully build something using Cocoa.h, thanks to this thread : How to mix Qt, C++ and Obj-C/Cocoa.
For the selection problem you could check out the answers I posted which tell you how to do it.
For those who could be interested : I found a way to get the current selected text.
Just by simulating cmd + c :
So thanks to this thread, I changed the code to obtain the "c" key which is represented by the integer 8 (Found in NSEvent.h), so here's the code :
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
CGEventRef saveCommandDown = CGEventCreateKeyboardEvent(source, (CGKeyCode)8, YES);
CGEventSetFlags(saveCommandDown, kCGEventFlagMaskCommand);
CGEventRef saveCommandUp = CGEventCreateKeyboardEvent(source, (CGKeyCode)8, NO);
CGEventPost(kCGAnnotatedSessionEventTap, saveCommandDown);
CGEventPost(kCGAnnotatedSessionEventTap, saveCommandUp);
CFRelease(saveCommandUp);
CFRelease(saveCommandDown);
CFRelease(source);
Now you just have to access the clipboard from Qt to get the selection. (If ask, I can put the code to do so)
Anyway, thanks to the stackoverflow community ;)