In the first post in this series, we saw how to disable AutoCAD’s ribbon. In the second post, we saw how to make (with some caveats) AutoCAD’s toolbars disappear. In this post we’re going to throw all that away and show how to get better results with a single line of code. <sigh>
But before all that, a big “thanks” to both James Meading and Alexander Rivilis, who have helped us get to this point.
James pointed out a fairly significant flaw in yesterday’s toolbar-hiding code (hence the mention of caveats, above), in that it didn’t place toolbars on multiple rows at exactly the same position when they’re made visible, once again. I started to work around this by making toolbars visible in the order of their “top” index: this seemed to work well enough in my cursory tests, but I didn’t see a little strangeness that I was planning on dealing with today.
But, overnight, Alexander provided some MFC code that disables AutoCAD's UI at a more basic level: disabling the complete AutoCAD frame with all of its user interface elements, avoiding us having to hide anything.
I took Alexander’s code and found a simple way to make it work from C# using P/Invoke. And that’s the code we’re going to see today:
public class Commands
static extern bool EnableWindow(IntPtr hWnd, bool bEnable);
public static void DisableUICommand()
public static void EnableUICommand()
public static void EnableUI(bool enable)
Here are the updated DU and EU commands in action, disabling and enabling the AutoCAD UI, respectively.
You’ll notice that disabling leaves the toolbars in their place and doesn’t grey them out, but that hovering over them shows that they’re properly disabled. While disabled, the ribbon is greyed out in much the way we saw at the beginning of the week.