Home » Developing U++ » UppHub » Ole Automation [FEATURE REQUEST?]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Ole Automation [FEATURE REQUEST?] [message #40841 is a reply to message #40817] |
Mon, 23 September 2013 06:49   |
iST1
Messages: 107 Registered: August 2013
|
Experienced Member |
|
|
I struggle with the problem of embedding Word. This is howto (::SetParent way is the same as in correctly worked http://www.codeproject.com/Articles/3582/Word-Control-for-NE T):
class MainFrm : public TopWindow {
public:
OfficeSheet sheet;
OfficeDoc doc;
MainFrm() {}
void TestExcel() {
if (sheet.IsAvailable("Open")) {
sheet.Init("Open");
} else if (sheet.IsAvailable("Microsoft")) {
sheet.Init("Microsoft");
}
sheet.AddSheet(true);
EmbedAsFrame("XLMAIN");
}
void TestWord() {
if (doc.IsAvailable("Open")) {
doc.Init("Open");
} else if (doc.IsAvailable("Microsoft")) {
doc.Init("Microsoft");
}
doc.AddDoc(true);
EmbedAsFrame("Opusapp");
}
void EmbedAsFrame(const String &className) {
HWND embeded = FindWindow(className, NULL);
::SetParent(embeded, GetHWND());
Rect r = GetScreenView();
Rect pr = GetScreenClient(GetHWND());
MoveWindow(embeded, r.left - pr.left, r.top - pr.top, r.Width(), r.Height(), 0);
}
};
GUI_APP_MAIN
{
MainFrm w;
w.Open();
//w.TestExcel();//embeded
#if 1
w.TestWord();//opened in separated window
#else
//if we manualy opened some Word, it embeded
w.EmbedAsFrame("Opusapp");
#endif
w.Run();
[Updated on: Mon, 23 September 2013 06:56] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Ole Automation [FEATURE REQUEST?] [message #40855 is a reply to message #40854] |
Mon, 23 September 2013 16:07   |
 |
koldo
Messages: 3461 Registered: August 2008
|
Senior Veteran |
|
|
| iST1 wrote on Mon, 23 September 2013 15:29 | I do not have Office > 2003, but can you give me some advice about frame removing? Something like this
int counter = ActiveWindow.Application.CommandBars.Count;
for(int i = 0; i < counter;i++)
ActiveWindow.Application.CommandBars[i].Enabled=false;
}
Also can be Close method added to Automation?
|
Hello iST1
I do not know what do you mean with "frame removing".
What would have to do Close()?
This code is better but flickering remains:
#include <OfficeAutomation/OfficeAutomation.h>
using namespace Upp;
class WordFrm : public TopWindow {
public:
WordFrm() {
Sizeable().Zoomable();
embedded = 0;
}
void Embed() {
if (doc.IsAvailable("Microsoft"))
doc.Init("Microsoft");
doc.AddDoc(true);
embedded = FindWindow("Opusapp", NULL);
LONG lStyle = GetWindowLong(embedded, GWL_STYLE);
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU | WS_BORDER | WS_DLGFRAME | WS_SIZEBOX);
SetWindowLong(embedded, GWL_STYLE, lStyle);
LONG lExStyle = GetWindowLong(embedded, GWL_EXSTYLE);
lExStyle &= ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE);
SetWindowLong(embedded, GWL_EXSTYLE, lExStyle);
SetWindowPos(embedded, NULL, 0,0,0,0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
::SetParent(embedded, GetHWND());
Layout();
}
private:
OfficeDoc doc;
HWND embedded;
virtual void Layout() {
if (embedded == 0)
return;
Rect r = GetScreenView();
Rect pr = GetScreenClient(embedded);
MoveWindow(embedded, r.left - pr.left, r.top - pr.top, r.Width(), r.Height(), TRUE);
}
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
if (message == WM_SIZE)
Layout();
return TopWindow::WindowProc(message, wParam, lParam);
}
};
GUI_APP_MAIN
{
WordFrm w;
w.Open();
w.Embed();
w.Run();
}
Best regards
Iñaki
[Updated on: Mon, 23 September 2013 16:09] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Ole Automation [FEATURE REQUEST?] [message #40875 is a reply to message #40872] |
Fri, 27 September 2013 11:12   |
iST1
Messages: 107 Registered: August 2013
|
Experienced Member |
|
|
Installed: MS Office 2007 and Open Office 4.
In #if 1 code opened MS Doc + MS Excel
In #if 0 code (in sub thread) opened MS Doc + Open Calc
Why MS Excel inavaylable in thread and how to set the priority for Microsoft? Thread used to preinit costly loading.
class OfficeTest : public TopWindow {
public:
typedef OfficeTest CLASSNAME;
OfficeTest() {
#if 1
Check();
#else
Thread().Start(THISBACK(Check));
#endif
}
void Check() {
if (sheet.IsAvailable("Microsoft")) {
sheet.Init("Microsoft");
sheet.AddSheet(true);
} else if (sheet.IsAvailable("Open")) {
sheet.Init("Open");
sheet.AddSheet(true);
}
if (doc.IsAvailable("Microsoft")) {
doc.Init("Microsoft");
doc.AddDoc(true);
} else if (doc.IsAvailable("Open")) {
doc.Init("Open");
doc.AddDoc(true);
}
}
private:
OfficeSheet sheet;
OfficeDoc doc;
};
GUI_APP_MAIN
{
OfficeTest().Run();
}
[Updated on: Fri, 27 September 2013 11:25] Report message to a moderator
|
|
|
|
|
|
| Re: Ole Automation [FEATURE REQUEST?] [message #40884 is a reply to message #40872] |
Mon, 30 September 2013 08:17   |
 |
koldo
Messages: 3461 Registered: August 2008
|
Senior Veteran |
|
|
| iST1 wrote on Thu, 26 September 2013 17:47 | This is strange, because .net code here work perfectly with Word 2007 and use the analogue of the VBA above code + SetParent method.
|
Hello iST1
I have tried that code and it works well, although as I previously reported it does not remove the menus.
You can see the explanation here ( http://social.msdn.microsoft.com/Forums/office/en-US/c329f3e 5-0e25-44a2-8b07-1182d428de37/how-to-disable-menu-bar-in-wor d-2007-programmatically-in-c). In summary:
Word 2007 (and later versions) no longer use the CommandBars (Menu and toolbars) for the UI. This was changed, for various reasons, not least of which to explicitly prevent applications running out-of-process from interfering in the application's UI. Among other considerations, this is a security measure to prevent outside apps from leveraging the Office object models for "bad intentions".
So the short answer to your request is that there is no way for your app to affect an Office UI that implements the Ribbon (Office Fluent UI). The Ribbon can be defined only by RibbonXML embedded in an Office document, or that is part of a COM Add-in (implements the IDT2Exensibility interface).
Possibly, you could create a custom template that contains a RibbonXML with startFromScratch attribute set to True. That will reduce available Ribbon commands to a minimum. It's not possible, however, to remove all commands from the UI. Certain ones in Office 2007 are always enabled, in order to allow the user to have final control over the Office environment.
Best regards
Iñaki
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Ole Automation [FEATURE REQUEST?] [message #41080 is a reply to message #17864] |
Wed, 30 October 2013 08:52  |
keltor
Messages: 73 Registered: February 2012
|
Member |
|
|
Hello,
sorry to hijack the thread, I just want to ask something that I think is most relevant here than anywhere else. Does anybody know how to create an ActiveX control with U++ so that it can be embedded, for instance, in a Word document? For instance, how to modify the Scatter control so that one can display, and possibly scroll around, graphs inside Word or PowerPoint or any other COM server.
Thanks,
Kel
|
|
|
|
Goto Forum:
Current Time: Sun Oct 04 17:37:38 GMT+2 2026
Total time taken to generate the page: 0.01788 seconds
|