Author Topic: Visio Addon code to refresh/redraw a diagram during execution  (Read 432 times)

0 Members and 1 Guest are viewing this topic.

caolen

  • Newbie
  • *
  • Posts: 6
I have created a Visio Addon in C++ that pulls data, changes shape sizes, colors and positions and then iterates.  At the end of each iteration I want the diagram to refresh and redraw itself to show all the changes.  But, the diagram does not refresh until the last iteration is complete and the Addon finishes.

How do I force a diagram refresh/redraw from within my Visio Addon code, at the end of each iteration?

Thanks,
Carl

vojo

  • Hero Member
  • *****
  • Posts: 1513
Re: Visio Addon code to refresh/redraw a diagram during execution
« Reply #1 on: May 12, 2020, 04:01:52 PM »
you probably don't want to redraw after everyshape
- takes a long time if lots of shapes

probably want to redraw for every 10 shapes or so.

I don't know much how visio interacts with C++...curious why C++ vs a VBA macro?

So thoughts
- you may want to pause during shape updates...may signal to visio to redraw
- I would think there is a call to update screen (I know VBA has that for excel so that you can control screen updates).
- I doubt live dynamics setting on the shape shapesheet would do this (if so, might be slow)

By the way, if you get this licked, you probably have a foundation for visio animation ;-)

Yacine

  • Hero Member
  • *****
  • Posts: 2703
Re: Visio Addon code to refresh/redraw a diagram during execution
« Reply #2 on: May 13, 2020, 01:22:13 AM »
doevents?
Yacine

Nikolay

  • Hero Member
  • *****
  • Posts: 942
    • UnmanagedVisio
Re: Visio Addon code to refresh/redraw a diagram during execution
« Reply #3 on: May 13, 2020, 04:23:21 AM »
Amazing. Someone is still writing Visio Addons in C++  ;D

Unless you explicitly disabled redraw during the diagram generation, Visio should redraw all by itself.
If it's not happening then there must be a bug/issue somewhere, hard to tell without seeing the code.

If you did disable redraw, you need to re-enable it after you are done...
There are two Visio application object properties related to this:

https://docs.microsoft.com/en-us/office/vba/api/visio.application.showchanges
https://docs.microsoft.com/en-us/office/vba/api/visio.application.screenupdating

BTW, in Soviet Russia in C++, the magical "DoEvents" thing looks like this:

Code
void DoEvents()
{
  MSG msg;
  if(::PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  {
    ::TranslateMessage(&msg);
    ::DispatchMessage(&msg);
  }
}
« Last Edit: May 13, 2020, 04:30:28 AM by Nikolay »

caolen

  • Newbie
  • *
  • Posts: 6
Re: Visio Addon code to refresh/redraw a diagram during execution
« Reply #4 on: May 13, 2020, 08:42:17 AM »
Vojo, Yacine, Nikolay, thanks for your replies.  -and for your gentle patience with me using “ancient Sanskrit” (C++) for writing my Visio Addon!   :)

Can you please tell me more about “doevents?”  I checked the visio.application.getShowChanges(&vbool).  It was turned “on" and is working fine.

I can get my diagram to redraw /refresh at the end of each iteration by inserting a MessageBox command.  But then, my user has to click the “OK” box each time to resume the next iteration.  What can I use to automatically create and dismiss this "MessageBox" event?  I really just want the user to start the Addon, sit back and watch the show, briefly pausing to view each iteration.

cbstrTemp = _T("Iteration: ");
cbstrTemp.Append(cbstr_k);

app.putShowChanges(true);   // This was already “on.”  I didn’t really need to put it.
VARIANT_BOOL vboolShowChanges;
app.getShowChanges(&vboolShowChanges);
if (vboolShowChanges) {
   MessageBox(GetActiveWindow(), _T("app.getShowChanges returns TRUE."), cbstrTemp, MB_OK);
   Sleep(500);
}

Nikolay

  • Hero Member
  • *****
  • Posts: 942
    • UnmanagedVisio
Re: Visio Addon code to refresh/redraw a diagram during execution
« Reply #5 on: May 13, 2020, 09:55:14 AM »
You could try inserting that "DoEvents" function from my previous post in place of the MessageBox and Sleep.

caolen

  • Newbie
  • *
  • Posts: 6
Re: Visio Addon code to refresh/redraw a diagram during execution
« Reply #6 on: May 13, 2020, 10:28:57 AM »
Nikolay,  I tried inserting the DoEvents(); call instead of the MsgBox & Sleep.  But, it didn't work.  Only the last iteration was refreshed/redrawn.

app.getShowChanges(&vboolShowChanges);
if (vboolShowChanges) {
   DoEvents();
   // MessageBox(GetActiveWindow(), _T("app.getShowChanges returns TRUE."), cbstrTemp, MB_OK);
   // Sleep(500);
}

What else can I try?

Nikolay

  • Hero Member
  • *****
  • Posts: 942
    • UnmanagedVisio
Re: Visio Addon code to refresh/redraw a diagram during execution
« Reply #7 on: May 13, 2020, 10:42:30 AM »
Okay the magic didn't work then...  :)
I'm not sure - could you maybe share something that can be used to reproduce the issue?