Google
 
Web ppczone.net

View Full Version : How to get brightness on WindowsMobile 5 PocketPC?


Luzinoff@mail.ru
06-05-2006, 09:12 AM
I tried to use ChangeDisplaySettingsEx function:

[DllImport("coredll.dll")]
private static extern int ChangeDisplaySettingsEx(string
lpszDeviceName,
IntPtr Mode, IntPtr hwnd, uint dwflags, IntPtr lParam);

....
[StructLayoutAttribute(LayoutKind.Sequential)]
private struct VIDEOPARAMETERS
{
public Guid Guid;
public uint dwOffset;
public uint dwCommand;
public uint dwFlags;
public uint dwMode;
public uint dwTVStandard;
public uint dwAvailableModes;
public uint dwAvailableTVStandard;
public uint dwFlickerFilter;
public uint dwOverScanX;
public uint dwOverScanY;
public uint dwMaxUnscaledX;
public uint dwMaxUnscaledY;
public uint dwPositionX;
public uint dwPositionY;
public uint dwBrightness;
public uint dwContrast;
public uint dwCPType;
public uint dwCPCommand;
public uint dwCPStandard;
public uint dwCPKey;
public uint bCP_APSTriggerBits;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public byte[] bOEMCopyProtection;
};

....
m_objVideoParameters.Guid = new
Guid("02C62061-1097-11d1-920F-00A024DF156E");
m_objVideoParameters.dwOffset = 0;
m_objVideoParameters.dwCommand = VP_COMMAND_GET;
m_objVideoParameters.dwFlags = VP_FLAGS_BRIGHTNESS;
m_objVideoParameters.bOEMCopyProtection = new byte[256];

uint unVPSize = 16 + 21 * 4 + 256;
IntPtr ptVideoParams = MemoryManage.LocalAlloc(MemoryManage.LPTR,
unVPSize);
Marshal.StructureToPtr(m_objVideoParameters, ptVideoParams, false);

int nResult = ChangeDisplaySettingsEx(null, IntPtr.Zero, IntPtr.Zero,
CDS_VIDEOPARAMETERS, ptVideoParams);

m_objVideoParameters =
(VIDEOPARAMETERS)Marshal.PtrToStructure(ptVideoPar ams,
typeof(Brightness.VIDEOPARAMETERS));

nResult == DISP_CHANGE_SUCCESSFUL, but objVideoParameters still == 0.

What's wrong in my code?

r_z_aret@pen_fact.com
06-06-2006, 07:37 AM
Questions about programming are far more likely to get answered in a
newsgroup for programmers. I _think_ you are using C#, so I just used
google (http://groups.google.com/advanced_group_search) to look up
c# ChangeDisplaySettingsEx
and got 19 hits. I took a quick look and am pretty sure I saw relevant
and useful info. If nothing else, you should find a more relevant
newsgroup.


On 5 Jun 2006 06:12:57 -0700, Luzinoff@mail.ru wrote:

>I tried to use ChangeDisplaySettingsEx function:
>
> [DllImport("coredll.dll")]
> private static extern int ChangeDisplaySettingsEx(string
>lpszDeviceName,
> IntPtr Mode, IntPtr hwnd, uint dwflags, IntPtr lParam);
>
>...
> [StructLayoutAttribute(LayoutKind.Sequential)]
> private struct VIDEOPARAMETERS
> {
> public Guid Guid;
> public uint dwOffset;
> public uint dwCommand;
> public uint dwFlags;
> public uint dwMode;
> public uint dwTVStandard;
> public uint dwAvailableModes;
> public uint dwAvailableTVStandard;
> public uint dwFlickerFilter;
> public uint dwOverScanX;
> public uint dwOverScanY;
> public uint dwMaxUnscaledX;
> public uint dwMaxUnscaledY;
> public uint dwPositionX;
> public uint dwPositionY;
> public uint dwBrightness;
> public uint dwContrast;
> public uint dwCPType;
> public uint dwCPCommand;
> public uint dwCPStandard;
> public uint dwCPKey;
> public uint bCP_APSTriggerBits;
> [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
> public byte[] bOEMCopyProtection;
> };
>
>...
>m_objVideoParameters.Guid = new
>Guid("02C62061-1097-11d1-920F-00A024DF156E");
>m_objVideoParameters.dwOffset = 0;
>m_objVideoParameters.dwCommand = VP_COMMAND_GET;
>m_objVideoParameters.dwFlags = VP_FLAGS_BRIGHTNESS;
>m_objVideoParameters.bOEMCopyProtection = new byte[256];
>
>uint unVPSize = 16 + 21 * 4 + 256;
>IntPtr ptVideoParams = MemoryManage.LocalAlloc(MemoryManage.LPTR,
>unVPSize);
>Marshal.StructureToPtr(m_objVideoParameters, ptVideoParams, false);
>
>int nResult = ChangeDisplaySettingsEx(null, IntPtr.Zero, IntPtr.Zero,
>CDS_VIDEOPARAMETERS, ptVideoParams);
>
>m_objVideoParameters =
>(VIDEOPARAMETERS)Marshal.PtrToStructure(ptVideoPar ams,
>typeof(Brightness.VIDEOPARAMETERS));
>
>nResult == DISP_CHANGE_SUCCESSFUL, but objVideoParameters still == 0.
>
>What's wrong in my code?

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 478
Boston, MA 02116
www.penfact.com