mirror of https://github.com/OpenVPN/openvpn-gui
Apply transparency mask to the connecting-state checkmark image
Combine the image and mask in the connecting-state icon to form a bitmap with transparency for use as the checkmark. MSDN docs on SetMenuItemBitmaps is unclear about the use of color bitmaps for checkmarks, but this appears to display well. (Tested on Windows 10 only). Signed-off-by: Selva Nair <selva.nair@gmail.com>pull/406/head
parent
941c33f149
commit
f39dbf1cbb
|
@ -108,7 +108,8 @@ openvpn_gui_LDADD = \
|
||||||
-lnetapi32 \
|
-lnetapi32 \
|
||||||
-lole32 \
|
-lole32 \
|
||||||
-lshlwapi \
|
-lshlwapi \
|
||||||
-lsecur32
|
-lsecur32 \
|
||||||
|
-lmsimg32
|
||||||
|
|
||||||
openvpn-gui-res.o: $(openvpn_gui_RESOURCES) $(srcdir)/openvpn-gui-res.h
|
openvpn-gui-res.o: $(openvpn_gui_RESOURCES) $(srcdir)/openvpn-gui-res.h
|
||||||
$(RCCOMPILE) -i $< -o $@
|
$(RCCOMPILE) -i $< -o $@
|
||||||
|
|
|
@ -117,7 +117,7 @@
|
||||||
<PreprocessorDefinitions>HAVE_CONFIG_H;_MSC_VER</PreprocessorDefinitions>
|
<PreprocessorDefinitions>HAVE_CONFIG_H;_MSC_VER</PreprocessorDefinitions>
|
||||||
</ResourceCompile>
|
</ResourceCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>Netapi32.lib;Wtsapi32.lib;Comctl32.lib;Secur32.lib;Ws2_32.lib;Crypt32.lib;Shlwapi.lib;Winhttp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>Netapi32.lib;Wtsapi32.lib;Comctl32.lib;Secur32.lib;Ws2_32.lib;Crypt32.lib;Shlwapi.lib;Winhttp.lib;Msimg32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
<PreBuildEvent>
|
<PreBuildEvent>
|
||||||
<Command>copy config-msvc.h config.h</Command>
|
<Command>copy config-msvc.h config.h</Command>
|
||||||
|
@ -132,7 +132,7 @@
|
||||||
<PreprocessorDefinitions>_INC_MATH;WIN32_LEAN_AND_MEAN;UNICODE;_UNICODE;_CRT_NON_CONFORMING_WCSTOK;HAVE_CONFIG_H</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_INC_MATH;WIN32_LEAN_AND_MEAN;UNICODE;_UNICODE;_CRT_NON_CONFORMING_WCSTOK;HAVE_CONFIG_H</PreprocessorDefinitions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>Netapi32.lib;Wtsapi32.lib;Comctl32.lib;Secur32.lib;Ws2_32.lib;Crypt32.lib;Shlwapi.lib;Winhttp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>Netapi32.lib;Wtsapi32.lib;Comctl32.lib;Secur32.lib;Ws2_32.lib;Crypt32.lib;Shlwapi.lib;Winhttp.lib;Msimg32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
42
tray.c
42
tray.c
|
@ -66,8 +66,46 @@ CreateBitmaps()
|
||||||
{
|
{
|
||||||
HICON icon = LoadLocalizedIconEx(ID_ICO_CONNECTING, cx, cy);
|
HICON icon = LoadLocalizedIconEx(ID_ICO_CONNECTING, cx, cy);
|
||||||
ICONINFO iconinfo;
|
ICONINFO iconinfo;
|
||||||
GetIconInfo(icon, &iconinfo);
|
|
||||||
hbmpConnecting = iconinfo.hbmColor;
|
if (!GetIconInfo(icon, &iconinfo))
|
||||||
|
{
|
||||||
|
MsgToEventLog(EVENTLOG_ERROR_TYPE, L"Error loading ID_ICO_CONNECTING.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make a color bitmap with transparency for use as a
|
||||||
|
* checkmark for indicating the connecting state. We do this
|
||||||
|
* by combining the mask bitmap in the icon with its image bitmap.
|
||||||
|
* These bitmaps are created by the GetIconInfo call.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Create two DCs for drawing the images in memory */
|
||||||
|
HDC maskDC = CreateCompatibleDC(NULL), imgDC = CreateCompatibleDC(NULL);
|
||||||
|
if (!maskDC || !imgDC)
|
||||||
|
{
|
||||||
|
DeleteObject(iconinfo.hbmMask);
|
||||||
|
DeleteObject(iconinfo.hbmColor);
|
||||||
|
if (maskDC) DeleteDC(maskDC);
|
||||||
|
if (imgDC) DeleteDC(imgDC);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Load the image and mask bitmaps into the DCs saving the default one's */
|
||||||
|
HBITMAP def1 = (HBITMAP) SelectObject(imgDC, iconinfo.hbmColor);
|
||||||
|
HBITMAP def2 = (HBITMAP) SelectObject(maskDC, iconinfo.hbmMask);
|
||||||
|
|
||||||
|
/* Transfer bit blocks from mask to image -- transparent color is black */
|
||||||
|
TransparentBlt(imgDC, 0, 0, cx, cy, maskDC, 0, 0, cx, cy, RGB(0, 0, 0));
|
||||||
|
|
||||||
|
/* Save the result and restore the default bitmaps back in the DC */
|
||||||
|
hbmpConnecting = (HBITMAP) SelectObject(imgDC, def1);
|
||||||
|
SelectObject(maskDC, def2);
|
||||||
|
|
||||||
|
/* We don't need the mask bitmap -- free it */
|
||||||
|
DeleteObject(iconinfo.hbmMask);
|
||||||
|
|
||||||
|
DeleteDC(imgDC);
|
||||||
|
DeleteDC(maskDC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue