How does Windows change Aero Glass color? - colors

I'm using Windows 7 RTM and I wonder how the control panel is able to update the Aero Glass color so smoothly without restarting the DWM (uxsms). DwmSetColorizationColor isn't working any more...

The following methods should be of interest to you:
[DllImport("dwmapi.dll", EntryPoint = "#127", PreserveSig = false)]
public static extern void DwmGetColorizationParameters(out WDM_COLORIZATION_PARAMS parameters);
[DllImport("dwmapi.dll", EntryPoint = "#131", PreserveSig = false)]
public static extern void DwmSetColorizationParameters(WDM_COLORIZATION_PARAMS parameters, uint uUnknown);
public struct WDM_COLORIZATION_PARAMS {
public uint Color1;
public uint Color2;
public uint Intensity;
public uint Unknown1;
public uint Unknown2;
public uint Unknown3;
public uint Opaque;
}
Make sure you make a call to DwmIsCompositionEnabled before calling the DwmSetColorizationParameters method or it will fail.
As you can see some of the arguments/properties are unknown.
For more information, here is a link (in German)

Related

Acumatica calling ApplyState method in Scan and Receive screen

Good day
I am trying to call the ApplyState(state) function. This is a protected function inside PX.Objects.IN.INScanReceive.
I am reading a QR code and the value has a lot/serial number and expiry date. The idea is to set the 2 values during the ProcessItemBarcode function call. The problem is when calling the base method the state is set and the "screens state" wants me to scan the lot/serial.
What I need to do is call the ProcessConfirm() or ApplyState(state). But calling the functions inside ProcessItemBarcode is where I stuck:
using PX.Common;
using PX.Data;
using WMSBase = PX.Objects.IN.WarehouseManagementSystemGraph<PX.Objects.IN.INScanReceive, PX.Objects.IN.INScanReceiveHost, PX.Objects.IN.INRegister, PX.Objects.IN.INScanReceive.Header>;
using PX.Objects.IN;
namespace MyCustomPackage.Graph.Extension
{
public class INScanReceiveHostExtCustomPackage2 : PXGraphExtension<INScanReceive, INScanReceiveHost>
{
public static bool IsActive() => true;
#region Overrides ProcessItemBarcode
//ProcessItemBarcode
public delegate void ProcessItemBarcodeDelegate(string barcode);
[PXOverride]
public virtual void ProcessItemBarcode(string barcode, ProcessItemBarcodeDelegate baseMethod)
{
//..//logic go change barcode
baseMethod?.Invoke(barcode);
// Option one call ApplyState()
Base.ApplyState()
// Option2 one call ProcessLotSerialBarcode
// I dont know how to send the delegate
ProcessLotSerialBarcode(barcode, );
}
#endregion
#region Overrides ProcessLotSerialBarcode
//ProcessLotSerialBarcode
public delegate void ProcessLotSerialBarcodeDelegate(string barcode);
[PXOverride]
public virtual void ProcessLotSerialBarcode(string barcode, ProcessLotSerialBarcodeDelegate baseMethod)
{
baseMethod?.Invoke(barcode);
}
#endregion
[PXProtectedAccess]
public abstract class INScanReceiveHostExtProtectedAccess : PXGraphExtension<INScanReceiveHostExtCustomPackage, INScanReceive, INScanReceiveHost>
{
[PXProtectedAccess(typeof(INScanReceive))]
protected abstract void ProcessItemBarcode(string barcode);
[PXProtectedAccess(typeof(INScanReceive))]
protected abstract void ApplyState(string state);
[PXProtectedAccess(typeof(INScanReceive))]
protected abstract void ProcessLotSerialBarcode(string barcode);
}
}
}
This is not the preferred method but when I can't figure out another option I will copy the source from Acumatica, e.g. Static methods and private ones. I will make note in my code that they were copied so I can make sure to duplication the process when versions change. You can then call those methods locally. Not elegant but works for me :)

Bring Window To Foreground When MainWindowHandle Is 0

The following code brings the window to the foreground, if the MainWindowHandle is not 0.
How can I bring a window to the front that has MainWindowHandle = 0?
This is for the Microsoft Excel - Compatibility Checker window that shows a GUI but does not have an icon in the task bar and has MainWindowHandle = 0.
I have no other instances of Excel running.
Add-Type #"
using System;
using System.Runtime.InteropServices;
public class Tricks {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
"#
$excel = (Get-Process | Where-Object { $_.ProcessName -eq 'EXCEL' }).MainWindowHandle
[void] [Tricks]::SetForegroundWindow($excel)
In Windows Task Manager, I can right click on 'Microsoft Excel - Compatibility Checker' and click on "Bring To Front" and that works. How can I mimic this functionality in Powershell?
Thanks to IInspectable for pointing me in the right direction.
This code gets the real MainWindowHandle value:
$TypeDef2 = #"
using System;
using System.Text;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace Api
{
public class WinStruct
{
public string WinTitle {get; set; }
public int MainWindowHandle { get; set; }
}
public class ApiDef
{
private delegate bool CallBackPtr(int hwnd, int lParam);
private static CallBackPtr callBackPtr = Callback;
private static List<WinStruct> _WinStructList = new List<WinStruct>();
[DllImport("User32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool EnumWindows(CallBackPtr lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
private static bool Callback(int hWnd, int lparam)
{
StringBuilder sb = new StringBuilder(256);
int res = GetWindowText((IntPtr)hWnd, sb, 256);
_WinStructList.Add(new WinStruct { MainWindowHandle = hWnd, WinTitle = sb.ToString() });
return true;
}
public static List<WinStruct> GetWindows()
{
_WinStructList = new List<WinStruct>();
EnumWindows(callBackPtr, IntPtr.Zero);
return _WinStructList;
}
}
}
"#
Add-Type -TypeDefinition $TypeDef2 -Language CSharpVersion3
$excelInstance = [Api.Apidef]::GetWindows() | Where-Object { $_.WinTitle.ToUpper() -eq "Microsoft Excel - Compatibility Checker".ToUpper() }
So now using this correct value, I can call the SetForegroundWindow() function:
Add-Type #"
using System;
using System.Runtime.InteropServices;
public class Tricks {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
}
"#
[void] [Tricks]::SetForegroundWindow($excelInstance.MainWindowHandle)
I wrote a detailed blog about this on my website.
I've put up a full example on GitHub of how to create an Excel file, edit it and run the above code in a different thread which you have to do because the Excel popup blocks the main thread.

Hello World for Pinvoke and Native Calls

I am trying to do a very basic hello world for Pinvoke and native calls.
I create a single solution with 2 projects (one for the dll and one for the universal windows app)
So I end up with a project heirachy like this
There is one method in my dll (file NativeCalls.cpp):
#include "pch.h"
#include "NativeCalls.h"
#include <stdio.h>
MYAPI void print_line(const char* str) {
printf("%s\n", str);
}
On the C# side of things I have my NativeCalls.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace MSSurfaceHubMonitoring
{
public static class NativeCalls
{
[DllImport("NativeCalls.dll")]
private static extern void print_line(string str);
public static void sayHelo()
{
print_line("Hello, PInvoke!");
}
}
}
At this point I will build and run it but get an error that it cannot find the dll
However I believe it to be the dependency and not the dll it self. I have changed the output directory of the dll to be in the root of where the UW app runs from (\bin\x86) so it really should be finding it. So like I said I think its the dependencies and not the actual dll.
Here is what I see in Dependency Walker
But I have installed all c++ packages I can get my hands on so I dont understand how to get the missing dependencies. Plus this is just a hello world, why do I need all these libraries.
FYI
My dll project is NOT referenced by the UW app. Im not sure thats needed or not? I dont think so though since this a runtime thing, so as long as the dll is there it should find it and read it. But regardless if I do try to add the project as a reference I get this error:
The biggest help to me was finding these method declarations (not even in the class)
extern "C" {
__declspec(dllexport) int getPageSize()
{
SYSTEM_INFO siSysInfo;
GetSystemInfo(&siSysInfo);
return siSysInfo.dwPageSize;
}
}
extern "C" {
__declspec(dllexport) Windows::Foundation::Collections::IMap<Platform::String^, int> ^getSystemInfo()
{
SYSTEM_INFO siSysInfo;
GetSystemInfo(&siSysInfo);
IMap<String^, int> ^ret =
ref new Platform::Collections::Map<String^, int>;
ret->Insert("oemId", siSysInfo.dwOemId);
ret->Insert("cpuCount", siSysInfo.dwNumberOfProcessors);
ret->Insert("pageSize", siSysInfo.dwPageSize);
ret->Insert("processorType", siSysInfo.dwProcessorType);
ret->Insert("maxApplicationAddress", siSysInfo.lpMinimumApplicationAddress);
ret->Insert("minApplicationAddress", siSysInfo.lpMaximumApplicationAddress);
ret->Insert("activeProcessorMask", siSysInfo.dwActiveProcessorMask);
return ret;
}
but in the end I was creating wrappers for things I didnt need to. in c# you can directly call the native methods without the need for a seperate dll or component project.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Monitoring
{
public static class NativeCallsWrapper
{
private static SYSTEM_INFO sysInfo = new SYSTEM_INFO();
private static MEMORYSTATUSEX mem = new MEMORYSTATUSEX();
[DllImport("kernel32.dll", SetLastError = false)]
public static extern void GetSystemInfo([In, Out] SYSTEM_INFO Info);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool GlobalMemoryStatusEx([In, Out] MEMORYSTATUSEX lpBuffer);
static NativeCallsWrapper()
{
GetSystemInfo(sysInfo);
GlobalMemoryStatusEx(mem);
}
[StructLayout(LayoutKind.Explicit)]
public struct SYSTEM_INFO_UNION
{
[FieldOffset(0)]
public UInt32 OemId;
[FieldOffset(0)]
public UInt16 ProcessorArchitecture;
[FieldOffset(2)]
public UInt16 Reserved;
}
public struct SYSTEM_INFO
{
public SYSTEM_INFO_UNION CpuInfo;
public UInt32 PageSize;
public UInt32 MinimumApplicationAddress;
public UInt32 MaximumApplicationAddress;
public UInt32 ActiveProcessorMask;
public UInt32 NumberOfProcessors;
public UInt32 ProcessorType;
public UInt32 AllocationGranularity;
public UInt16 ProcessorLevel;
public UInt16 ProcessorRevision;
}
[StructLayout(LayoutKind.Sequential)]
public class MEMORYSTATUSEX
{
public uint dwLength;
public uint dwMemoryLoad;
public ulong ullTotalPhys;
public ulong ullAvailPhys;
public ulong ullTotalPageFile;
public ulong ullAvailPageFile;
public ulong ullTotalVirtual;
public ulong ullAvailVirtual;
public ulong ullAvailExtendedVirtual;
public MEMORYSTATUSEX()
{
this.dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX));
}
}
public static GeneralStatistics getGeneralStatistics()
{
GeneralStatistics generalStatistics = new GeneralStatistics();
generalStatistics.numberOfProcesses = (int)sysInfo.NumberOfProcessors;
generalStatistics.memoryTotal = mem.ullTotalPhys / 1048;
generalStatistics.memoryInUse = (mem.ullTotalPhys - mem.ullAvailPhys) / 1048;
return generalStatistics;
}
}
}

CStatic not receiving WM_CTLCOLOR

I think I am missing something small here.
I am trying to make a class which inherits from CStatic with a transparent background. I have managed create an instance of the class and it is displayed in the parent CView. However when I add a OnCtlColor message handler going through the class view on Visual Studio to make the background transparent, it never fires.
Here is a code snippet:
Foo.h
class Foo: public CStatic
{
DECLARE_DYNAMIC(Foo)
public:
Foo();
virtual ~Foo();
virtual void CreateCtrl(CWnd * Parent, POINT TopLeft, SIZE sz);
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
};
Foo.cpp
void Foo::CreateCtrl(CWnd * Parent, POINT TopLeft, SIZE sz)
{
CRect Rect(TopLeft, sz);
Create(pItem->Value->GetBuffer(), WS_CHILD | WS_VISIBLE | SS_CENTER | SS_NOTIFY, Rect, Parent);
ShowWindow(SW_SHOW);
}
BEGIN_MESSAGE_MAP(Foo, CStatic)
ON_WM_CTLCOLOR_REFLECT()
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()
HBRUSH Foo::CtlColor(CDC* pDC, UINT nCtlColor)
{
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)GetStockObject(NULL_BRUSH);
}
BOOL Foo::OnEraseBkgnd(CDC* pDC)
{
return FALSE;
}
Can anyone suggest what I might be doing wrong?
WM_CTLCOLOR is sent to the parent window, not to the static control.
To catch the message in the static control class, you need to use ON_WM_CTLCOLOR_REFLECT in your message map, see MSDN Docs and use HBRUSH Foo::CtlColor(CDC* pDC, UINT nCtlColor).

How to specify individual List item's Font color in VC++ WTL

I have list box CListBox in which i need to specify the color of individual list item according to some condition. How can i achieve this.
Im running VS2005.
The application is a WTL Dialog based app.
You can create your own listbox(Ex:CColorListBox)
ColorListBox.h
class CColorListBox : public CListBox
{
// Construction
public:
CColorListBox();
// Attributes
public:
// Operations
public:
int AddString( LPCTSTR lpszItem, COLORREF rgb);
int InsertString( int nIndex, LPCTSTR lpszItem, COLORREF rgb);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CColorListBox)
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CColorListBox();
// Generated message map functions
protected:
//{{AFX_MSG(CColorListBox)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
ColorListBox.cpp
Here is an idea not exact code............
int CColorListBox::AddString( LPCTSTR lpszItem,COLORREF rgb )
{
int item = AddString(lpszItem);
if(item >=0)
SetItemData(item,rgb);
return item;
}
int CColorListBox::InsertString( int nIndex, LPCTSTR lpszItem, COLORREF rgb)
{
int item = ((CListBox*)this)->InsertString(nIndex,lpszItem);
if(item >=0)
SetItemData(item,rgb);
return item;
}
void CColorListBox::DrawItem(LPDRAWITEMSTRUCT lpdis)
{
}
This is what i did to implement the same functionality in ListViewCtrl.
I wrote a class to extend the CListViewCtrl.
class CListViewCtrlEx: public CWindowImpl<CListViewCtrlEx, CListViewCtrl>, public CCustomDraw<CListViewCtrlEx>
{
public:
BEGIN_MSG_MAP(CListViewCtrlEx)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
CHAIN_MSG_MAP_ALT(CCustomDraw<CListViewCtrlEx>, 1)
DEFAULT_REFLECTION_HANDLER()
END_MSG_MAP()
LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL bHandled);
DWORD OnPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW lpNMCustomDraw);
DWORD OnItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW lpNMCustomDraw);
void ForceMeasureItemMessage();
void DeleteItem(LPDELETEITEMSTRUCT /*lpDeleteItemStruct*/);
BOOL DeleteItem(int nItem);
void GetCellRect(int header_column, const CRect& item_rect, CRect& cell_rect);
};
The complete code is HERE.

Resources