26 Feb 2017 @ 12:21 PM 

BASeCamp Network Menu, which I wrote about previously, was a handy little tool for connecting to my VPN networks. It, however, had one disadvantage- It was clearly out of place- the style was “outdated” for the OS themes:

BCNetMenu displaying available VPN connections.

As we can see above, the style it uses is more like Office 2003, Windows XP, etc. Since the program is intended for Windows 10, that was a bit of a style issue, I think. Since none of the other Renderers really fit the bill, I set about writing my own “Win10” style menu foldout ToolStrip Renderer; Since the intent was merely to provide for drawing this menu, I’ve skipped certain features as a result to make it a bit easier.

Windows 10 uses an overwhelmingly “flat” style. This worked in my favour since that makes it fairly easy to draw using that style. Windows Forms- and thus the ContextMenuStrip one attaches to the NotifyIcon, allows overriding the standard drawing logic with a ToolStripRenderer implementation; so the first step was to create a class which I derived from the ToolStripSystemRenderer. This attempts to mimic the appearance of many Windows 10 foldouts by first drawing a dark background, then drawing a color over top. However- the color over top is where things were less clear. We want to use the Accent Color that is defined in the Windows Display Properties. How do we find that?

As it happens, dwmapi.dll has us covered. However, it bears warning that this is currently an undocumented function- we need to reference it by ordinal, and since it’s undocumented, it could be problematic when it comes to future compatibility. It’s very much a “use at your own risk” function:

This function uses DWMCOLORIZATIONPARAMS, which we of course, need to define:

Once defined, we can now create a helper method that will give us a straight-up color value:

We allow for an “Opaque” parameter to specify whether the caller wants the Alpha value or not; of course, t he caller could always do this itself but the entire point of functions is to reduce code so may as well put it in this way. it takes the 32-bit integer representing the color and splits it into it’s appropriate byte-sized components through shift operators, and uses those to construct an appropriate Color to return.

Using this color to paint over an opaque dark background (the color used with the Taskbar Right-click menu, for example) gives the following Menu, using the new WIndows 10 Renderer I created:

Not a bad representation, if I say so myself! Not perfect, mind you, but certainly fits better than the Professional ToolStrip Renderer, so I don’t think calling it a success would be entirely out of band. A more interesting problem presents itself, however- When configured in the display properties to have transparency effects,The default Windows 10 Network foldout has a “Blur” effect. How can we do the same thing?

After unsuccessful experiments with DwmExtendGlassIntoFrame and related functions, I eventually stumbled on the SetWindowCompositionAttribute(). This could be used to set an accent on a window directly- including, setting Blur Behind. Of course, as with any P/Invoke, one needs to prepare yourself for the magical journey with some declarations:

If the Blur setting is enabled, then the EnableBlur function is called to enable blur; otherwise, to disable blur. In both cases, it tosses in the Handle of the ToolStrip that is opening, which, apparently, is the Window handle to the actual menu’s “Window”, so it actually works as intended:

I also found that darker colours being drawn seemed to be “more” transparent. Best I could determine was that there is some kind of transclucency key; the closer to black, the more “clear” the glass appears. References I found suggest that SetLayeredWindowAttributes() could be used to adjust the colour key, but I wasn’t able to get it to work as I intended; Since the main effect is that the “Disabled” text, which is gray, appears like more “clear” glass within the coloured blurred menu, I found it to be fine.

It will still be ideal to write additional custom draw routines in order to allow checked/selected items in the listing to be more apparent. As it stands the default “Check” draw routine appears more like an overlay on the top left of the icon, but it’s easy to miss; it would be better to custom draw the items entirely, and instead of a checkmark perhaps highlight the Icon in some fashion to indicate selection.

Posted By: BC_Programming
Last Edit: 26 Feb 2017 @ 12:21 PM

EmailPermalinkComments Off on Win10 Styling for Windows Forms Menus
 31 Aug 2013 @ 5:18 AM 

Having recently started a new Job, my responsibilities entail the necessity of using a Workplace VPN connection on occasion. My current connection setup is rather simple: My Laptop has a Wireless-N Adapter built-in, and I use that to connect to the Router/Modem provided by the ISP. The laptop is running Windows 8.1. Initially, connecting to the VPN with that system proved troublesome. My first snag was trying to figure out what the heck a “provider” was. I tried a few of the options, and because I was unable to get them to work, I gave up, chalking it up to some change to VPN connectivity made by Windows 8 or 8.1.

So I turned to my Desktop machine, with Familiar ‘old’ Windows 7. The connection I use for the desktop is more interesting. Having recently moved the machine to a location outside of “Ethernet cable” Range of the router, I have had to find other solutions. Naturally the first issue is that my desktop has no Wireless adapter, and perhaps more importantly the one PCI Wireless Adapter I do have has failed or for some reason just doesn’t want to work. Maybe it saw the VMA awards and doesn’t want to admit it’s existence in the same reality as ‘twerking’ or whatever happened. I don’t know, I’m not actually a Hipster I just sorta pretend I am by repeating oft-used phrases from Reddit. Instead, I’ve used two solutions. The first is that I will simply bridge the connection from my Laptop’s wireless card and it’s Ethernet adapter, and then connect my laptop’s ethernet port to my desktop computer’s on-board gigabit NIC. This is usually my go-to approach for these situations, And it worked admirably in the past for my purposes. It worked well here, as well. I was able to use the internet, connect to IRC, and whatever.

Until, it came to connecting to my VPN, in which case this failed as well. I tried messing around with it for a few minutes then gave up and simply plugged in an old Wireless-G USB Adapter. (A DWL-G132). In order to get more than one-bar signal strength I had to use the front-USB ports, which has the side-effect of being close to my headphone jack. I primarily use headphones which presented a problem because the USB adapter caused quite loud interference with the headphone audio, enough to bug the heck out of me, anyway. But it worked, and let me work, so I dealt with it- and when I wasn’t working I disconnected the wireless adapter.

It got my my nerves, though- particularly since I couldn’t connect on the laptop itself, which is arguably a rather useful thing for checking E-mail or simply, you know, using the laptop for work purposes at all. For some reason it occurred to me, and embarassingly for the first time- that the reason I couldn’t connect on the laptop itself and the reason I couldn’t connect on my desktop when it was connecting through the laptop were probably related. This resulted in a Duh moment where I promised to never reveal this delayed bit of basic logic to anybody, at any point, a mantra I have stuck by for almost 48 hours and am breaking by making this post, because hey, it’s sorta funny too.

With that bit of genius Holmes-like deduction, I proceeded to try to explore why it wasn’t working on my laptop. First problem, the network was being noted as Public, rather than Private. As most of us are aware, Windows Firewall uses several rules and applies a stricter set of rules to Public networks, because otherwise when you use your laptop in a Starbucks people will put pictures of goat anuses in your pictures library, which will of course get mixed up in your extensive collection of gif files showing giraffes eating popsicles. Needless to say, you don’t want pictures of goat butts getting in the way of your Iced Tower collection. Now, being that this is a private, Home network with a WPA2 security key, I decided to throw caution to the wind and change it to a public network. This itself took a bit of figuring out. For those that need to perform similar steps, here is how I did so.


  1. Windows Key+R To open the Run dialog. start “secpol.msc”
  2. Selected the “Network List Manager Policies”, which is rivalled only by “Advanced Audit Policy Configuration” in terms of the sheer excitement and heart pumping adrenaline Rush you assume it must entail.
  3. Selected the wireless Connection. I right-clicked and selected “Properties”, then the “Network Location” tab and changed it to “Private”.

I repeated this procedure on the Desktop machine with the bridged connection, then disabled Windows Firewall on Private connections on both machines, to prevent that from going all “Nope” to my attempts to connect to the VPN, and I Was able to successfully connect to the VPN on my desktop via the bridged connection, and presumably the connection would also work on the laptop itself.



Posted By: BC_Programming
Last Edit: 31 Aug 2013 @ 05:18 AM

EmailPermalinkComments Off on VPN, Bridged connections and network type confusion
Tags: , ,
Categories: Networking

 Last 50 Posts
Change Theme...
  • Users » 47469
  • Posts/Pages » 391
  • Comments » 105


    No Child Pages.

Windows optimization tips

    No Child Pages.

Soft. Picks

    No Child Pages.

VS Fixes

    No Child Pages.

PC Build 1: “FASTLORD”

    No Child Pages.