Access to Word's Canvas

Add-in Express™ Support Service
That's what is more important than anything else

Access to Word's Canvas
Draw on Word's Canvas 
NICKLAUS METNIK




Posts: 8
Joined: 2019-11-28
Hello,

I have a client requirement to draw on the actual Word canvas (or maybe it's a task pane, idk).
I've been digging around and can't seem to figure out how to access it to mark it up (see attached photo).
Bonus would be to allow scrolling and painting together.

If someone can point me in the correct direction (if any) that would be phenomenal!

Thank you,

Nick Metnik

[img]https://www.dropbox.com/s/52y2tn4la5oj4ne/Example.jpg?dl=0[/img]
Posted 28 Nov, 2019 13:26:02 Top
Andrei Smolin


Add-in Express team


Posts: 19138
Joined: 2006-05-11
Hello NICKLAUS,

Unfortunately, your description leaves room for interpretation. Let's assume for a moment that you are able draw such a line. What's next? How would that line behave if the user scrolls the document down?

Maybe, it would be okay if you insert a line shape in the document? In this case, the Word object model does support this: your shape will be part of the document.

As to the task pane, do you need to draw on it?


Andrei Smolin
Add-in Express Team Leader
Posted 29 Nov, 2019 03:37:37 Top
NICKLAUS METNIK




Posts: 8
Joined: 2019-11-28
Hello Andrei,

Thank you for the response and help. The line shape is a good suggestion, however there's a lot more to this without going into deep details. There's a need to draw more that just the line on different pages. I also thought of using a background image but as you know, that extends across all pages in a section, no good.

I'm calling it a canvas, but maybe it's a task pane. I'm not sure what it is but I can't find it digging through code.
If it clears things up, it's the Print Layout View and I would constantly redraw as a user scrolls.

I'd prefer to use GDI so the markup never ends up in the actual document, printing, and exporting. They will be visual guides only.

If what I refer to as the canvas IS a task pane, then what task pane is it? If it is a task pane then I know I'll be able to draw on it for sure.

Does that clear things up?


Nick Metnik
Posted 29 Nov, 2019 10:14:00 Top
NICKLAUS METNIK




Posts: 8
Joined: 2019-11-28
If I can't get at the canvas directly, I'm looking into the alternative of using the active window handle but it draws beneath everything. I can tell because the window has a red border.



    Word.Window window = AddinModule.CurrentInstance.WordApp.ActiveWindow;
                Word.PageSetup page = AddinModule.CurrentInstance.WordApp.ActiveDocument.PageSetup;
                Word.View view = AddinModule.CurrentInstance.WordApp.ActiveWindow.ActivePane.View;

                IntPtr hwnd = new IntPtr(window.Hwnd);
                IntPtr hdc = GetWindowDC(hwnd);

                using (Graphics g = Graphics.FromHdc(hdc))
                {
                    SolidBrush brush = new SolidBrush(Color.Red);
                    g.FillRectangle(brush, g.VisibleClipBounds);
                }
                ReleaseDC(IntPtr.Zero, hdc);
Posted 29 Nov, 2019 23:08:25 Top
Andrei Smolin


Add-in Express team


Posts: 19138
Joined: 2006-05-11
Hello Nick,

NICKLAUS METNIK writes:
Does that clear things up?


No. I don't understand your final goal and I suppose this influences my understanding.

Say, if you need to have that line (and other graphics) to be part of the document, you can use a shape. If you want that line to be drawn on top of the window displaying a preview of the document, you should anchor it in some way to something in that window e.g. an existing control (such as button) or text in the preview; then you'll need to deal with scrolling and resizing the window; this assumes you'll use a lot of Windows API.

If you don't want to disclose any sensitive information, you can send me an email: find the support email address in {Add-in Express installation folder}\readme.txt; please make sure your email contains a link to this topic.


Andrei Smolin
Add-in Express Team Leader
Posted 02 Dec, 2019 09:29:58 Top
NICKLAUS METNIK




Posts: 8
Joined: 2019-11-28
Hello Andrei,

It's much more complex than using shapes, these are visual guides that the client does not want in their document.
It's clear to me that I have to do custom painting, account for scrolling, page layout, and even zooming.

What would be helpful is to know what that Word canvas is called and if your software has a way to get to it so I can get my rectangle bounds off of it if possible or even a handle to use for drawing.

Thank you,

Nick
Posted 02 Dec, 2019 21:41:40 Top
Andrei Smolin


Add-in Express team


Posts: 19138
Joined: 2006-05-11
Hello Nick,

Add-in Express doesn't provide such a possibility.

You may find layered windows useful; see https://docs.microsoft.com/en-us/windows/win32/winmsg/window-features#layered-windows.


Andrei Smolin
Add-in Express Team Leader
Posted 03 Dec, 2019 05:36:45 Top
NICKLAUS METNIK




Posts: 8
Joined: 2019-11-28
Thank you Andrei for all of your time. I'll continue down the layered windows path.

Have a great week sir,

Nick
Posted 03 Dec, 2019 09:10:12 Top
Andrei Smolin


Add-in Express team


Posts: 19138
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 04 Dec, 2019 02:39:57 Top