Set the contrast of LCD screen in C#

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hello all,

I have a device which is running on WinCE 4.2 (not PPC)

In the device is a LCD (not TFT) color screen.
I would like to set the contrast (not the backlight) of the screen, how can
I do this in C# ?


Thanks,
Peter.
 
This is entirely specific to the hardware as there isn't a standard API for
these display settings in Windows CE. You'll need to check with the device
manufacturer.

Peter
 
Thank you very much Sergey,

Good link, makes sence, remains only the question how to use it in the C# ?
Must I P/Invoke Coredll.dll ?
A little example in C# would be very nice.

Peter.




Sergey Bogdanov said:
The structure ContrastCmdInputParm (Windows CE 2.10+) [1] and the
function ExtEscape could help you.


[1]
http://msdn.microsoft.com/library/d...wceddk5/html/wce50lrfcontrastcmdinputparm.asp

HTH,
Sergey
Hello all,

I have a device which is running on WinCE 4.2 (not PPC)

In the device is a LCD (not TFT) color screen.
I would like to set the contrast (not the backlight) of the screen, how can
I do this in C# ?


Thanks,
Peter.
 
To call ExtEscape you will a need handle of Device Context - for this
use GetDC(IntPtr.Zero). For parameter InData you may pass an array of 2
integers (ContrastCmdInputParm structure) or just pass the structure.
Since ConstrastCmdInputParm structure contains blittable types, it could
be passed as is.


const int CONTRASTCOMMAND = 6149;
const int CONTRAST_CMD_GET = 0; // Parm=Ignored, Out=Current setting
const int CONTRAST_CMD_SET = 1; // Parm=NewSet, Out=Resulting setting
const int CONTRAST_CMD_INCREASE = 2; // Parm=Amount, Out=Resulting setting
const int CONTRAST_CMD_DECREASE = 3; // Parm=Amount, Out=Resulting setting
const int CONTRAST_CMD_DEFAULT = 4; // Parm=Ignored, Out=Resulting setting
const int CONTRAST_CMD_MAX = 5; // Parm=Ignored, Out=Max value


[DllImport("coredll")]
extern static void ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("coredll")]
extern static IntPtr ExtEscape(IntPtr hDC, int Esc, int cbInData, int[]
InData, int cbOutData, IntPtr OutData);
[DllImport("coredll")]
private static extern IntPtr GetDC(IntPtr hwnd);
 
Hello Sergey,

Thanks again, I tried to make it work but with no succes.....
I'm doing something wrong but can't figure out what the problem is, it's
compiling OK but the contrast is not changed....

If you can help me once again, I will be very thankfull !!

Peter.
public void button1_Click(object sender, System.EventArgs e)

{

IntPtr hDC = GetDC(IntPtr.Zero);

IntPtr Test;

int Esc = QUERYESCSUPPORT;

ContrastCmdInputParm szContrast;



szContrast.command = CONTRAST_CMD_GET;

szContrast.parm = 0;

if ( ExtEscape(hDC, QUERYESCSUPPORT, Marshal.SizeOf(Esc.GetType()), ref Esc,
0, IntPtr.Zero ) == IntPtr.Zero )

{

MessageBox.Show("not supported");

}

else

{


int[] vpm = new int[2];

vpm[0] = CONTRAST_CMD_SET;

vpm[1] = 104;

//ExtEscape(hDC, CONTRASTCOMMAND, vpm[0], vpm, 0, IntPtr.Zero);

ExtEscape( hDC, CONTRASTCOMMAND, CONTRAST_CMD_SET, vpm, 0, IntPtr.Zero );

// in C++

//ExtEscape( hDc, CONTRASTCOMMAND, sizeof(ContrastCmdInputParm), (char
*)&szContrast, 0, NULL );



}

ReleaseDC(IntPtr.Zero, hDC);

}

[DllImport("coredll")]

extern static IntPtr GetDC(IntPtr hWnd);

[DllImport("coredll")]

extern static void ReleaseDC(IntPtr hWnd, IntPtr hDC);

[DllImport("coredll")]

extern static IntPtr ExtEscape(IntPtr hDC, int Esc, int cbInData, int[]
InData, int cbOutData, IntPtr OutData);

[DllImport("coredll")]

extern static IntPtr ExtEscape(IntPtr hDC, int Esc, int cbInData, ref int
InData, int cbOutData, IntPtr OutData);

public struct ContrastCmdInputParm

{

public int command;

public int parm;

};

const int QUERYESCSUPPORT = 8;

const int CONTRASTCOMMAND = 6149;

const int CONTRAST_CMD_GET = 0;

const int CONTRAST_CMD_SET = 1;

const int CONTRAST_CMD_INCREASE = 2;

const int CONTRAST_CMD_DECREASE = 3;

const int CONTRAST_CMD_DEFAULT = 4;





Sergey Bogdanov said:
To call ExtEscape you will a need handle of Device Context - for this
use GetDC(IntPtr.Zero). For parameter InData you may pass an array of 2
integers (ContrastCmdInputParm structure) or just pass the structure.
Since ConstrastCmdInputParm structure contains blittable types, it could
be passed as is.


const int CONTRASTCOMMAND = 6149;
const int CONTRAST_CMD_GET = 0; // Parm=Ignored, Out=Current setting
const int CONTRAST_CMD_SET = 1; // Parm=NewSet, Out=Resulting setting
const int CONTRAST_CMD_INCREASE = 2; // Parm=Amount, Out=Resulting setting
const int CONTRAST_CMD_DECREASE = 3; // Parm=Amount, Out=Resulting setting
const int CONTRAST_CMD_DEFAULT = 4; // Parm=Ignored, Out=Resulting setting
const int CONTRAST_CMD_MAX = 5; // Parm=Ignored, Out=Max value


[DllImport("coredll")]
extern static void ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("coredll")]
extern static IntPtr ExtEscape(IntPtr hDC, int Esc, int cbInData, int[]
InData, int cbOutData, IntPtr OutData);
[DllImport("coredll")]
private static extern IntPtr GetDC(IntPtr hwnd);

--
Best regards,
Sergey Bogdanov

Thank you very much Sergey,

Good link, makes sence, remains only the question how to use it in the C# ?
Must I P/Invoke Coredll.dll ?
A little example in C# would be very nice.

Peter.
 
Does QUERYESCSUPPORT return Zero? If so then the device capabilitie of
this function was not implemented by an OEM.
 
Sergey,

Thanks for your time !
I just recieved some eC++ code from the OEM so I guess that it is possible
to set the contrast, maybe I did something wrong in my C# code ?
(I'm not familiar with eC++ coding and they are not familiar with C# code
:-))

It would be great if you can help me to solve this problem,
Thanks again Sergey !!

Peter.


#define QUERYESCSUPPORT 8

#define CONTRASTCOMMAND 6149

#define CONTRAST_CMD_GET 0

#define CONTRAST_CMD_SET 1

#define CONTRAST_CMD_INCREASE 2

#define CONTRAST_CMD_DECREASE 3

#define CONTRAST_CMD_DEFAULT 4

struct ContrastCmdInputParm {

int command;

int parm;

};



DWORD GetContrast( void )

{

ContrastCmdInputParm szContrast;

HDC hdcLCD;

DWORD dwContrast = -1;

int i;

// Do we have support for get mode info

i = CONTRASTCOMMAND;

hdcLCD = CreateDC(NULL, NULL, NULL, NULL);

if (hdcLCD)

{

if (ExtEscape(hdcLCD, QUERYESCSUPPORT, 4, (LPCSTR) &i, 0, 0))

{

szContrast.command = CONTRAST_CMD_GET;

szContrast.parm = 0;

dwContrast = ExtEscape( hdcLCD, CONTRASTCOMMAND, sizeof(struct
ContrastCmdInputParm), (char *)&szContrast, 0, NULL );

}

}

return dwContrast;

}

// dwContrast Must be a value from 0 to 256

void SetContrast( DWORD dwContrast)

{

ContrastCmdInputParm szContrast;

HDC hdcLCD = CreateDC(NULL, NULL, NULL, NULL);

szContrast.command = CONTRAST_CMD_SET;

szContrast.parm = dwContrast;

dwContrast = ExtEscape( hdcLCD, CONTRASTCOMMAND, sizeof(struct
ContrastCmdInputParm), (char *)&szContrast, 0, NULL );

}
 
Peter, sorry for my long delay. Have you tried to run this eVC code?
I've compiled it and it seems that my device doesn't support constranst
changes... Maybe it'll help you:

IntPtr hDC = GetDC(IntPtr.Zero);

int[] vpm = new int[2];
vpm[0] = CONTRAST_CMD_SET;
vpm[1] = 0;

int r = ExtEscape(hDC, CONTRASTCOMMAND, 8, vpm, 0, IntPtr.Zero);
ReleaseDC(IntPtr.Zero, hDC);

....

const int CONTRASTCOMMAND = 6149;
const int CONTRAST_CMD_SET = 1;

[DllImport("coredll")]
extern static IntPtr GetDC(IntPtr hWnd);

[DllImport("coredll")]
extern static void ReleaseDC(IntPtr hWnd, IntPtr hDC);

[DllImport("coredll")]
extern static int ExtEscape(IntPtr hDC, int Esc, int cbInData, int []
InData, int cbOutData, IntPtr OutData);
 
Many, many thanks Sergey :-)))))) It works like a charm now !!!

Kind regards

Peter.

Sergey Bogdanov said:
Peter, sorry for my long delay. Have you tried to run this eVC code?
I've compiled it and it seems that my device doesn't support constranst
changes... Maybe it'll help you:

IntPtr hDC = GetDC(IntPtr.Zero);

int[] vpm = new int[2];
vpm[0] = CONTRAST_CMD_SET;
vpm[1] = 0;

int r = ExtEscape(hDC, CONTRASTCOMMAND, 8, vpm, 0, IntPtr.Zero);
ReleaseDC(IntPtr.Zero, hDC);

...

const int CONTRASTCOMMAND = 6149;
const int CONTRAST_CMD_SET = 1;

[DllImport("coredll")]
extern static IntPtr GetDC(IntPtr hWnd);

[DllImport("coredll")]
extern static void ReleaseDC(IntPtr hWnd, IntPtr hDC);

[DllImport("coredll")]
extern static int ExtEscape(IntPtr hDC, int Esc, int cbInData, int []
InData, int cbOutData, IntPtr OutData);

Sergey,

Thanks for your time !
I just recieved some eC++ code from the OEM so I guess that it is possible
to set the contrast, maybe I did something wrong in my C# code ?
(I'm not familiar with eC++ coding and they are not familiar with C# code
:-))

It would be great if you can help me to solve this problem,
Thanks again Sergey !!

Peter.


#define QUERYESCSUPPORT 8

#define CONTRASTCOMMAND 6149

#define CONTRAST_CMD_GET 0

#define CONTRAST_CMD_SET 1

#define CONTRAST_CMD_INCREASE 2

#define CONTRAST_CMD_DECREASE 3

#define CONTRAST_CMD_DEFAULT 4

struct ContrastCmdInputParm {

int command;

int parm;

};



DWORD GetContrast( void )

{

ContrastCmdInputParm szContrast;

HDC hdcLCD;

DWORD dwContrast = -1;

int i;

// Do we have support for get mode info

i = CONTRASTCOMMAND;

hdcLCD = CreateDC(NULL, NULL, NULL, NULL);

if (hdcLCD)

{

if (ExtEscape(hdcLCD, QUERYESCSUPPORT, 4, (LPCSTR) &i, 0, 0))

{

szContrast.command = CONTRAST_CMD_GET;

szContrast.parm = 0;

dwContrast = ExtEscape( hdcLCD, CONTRASTCOMMAND, sizeof(struct
ContrastCmdInputParm), (char *)&szContrast, 0, NULL );

}

}

return dwContrast;

}

// dwContrast Must be a value from 0 to 256

void SetContrast( DWORD dwContrast)

{

ContrastCmdInputParm szContrast;

HDC hdcLCD = CreateDC(NULL, NULL, NULL, NULL);

szContrast.command = CONTRAST_CMD_SET;

szContrast.parm = dwContrast;

dwContrast = ExtEscape( hdcLCD, CONTRASTCOMMAND, sizeof(struct
ContrastCmdInputParm), (char *)&szContrast, 0, NULL );

}
 
Hello guys, I have saw that this post is of 6 years and more but it is the only one thing that I have read to work for this problem. I am making a tool , which should set the screen contrast just as Peter , it should be in C# , but if I have a solution in C++ or something common I will try to integrate it in some way in my C# code, I have read the whole article but still can not make an application, which works I do not know what is eC++ , so please if you read this in some magic help me to achieve my goal, you can e-mail me as you wish it is very important. Thank you in advance !
 
Hi peter,

If you don't mind, can you share with us code which you used to conrol the contrast(working code)?

Even i am trying to control backlight as well as contrast programmatically in wince 6.0 , imx27(bsp).

Thanks a lot. Waiting for your reply.

Laxmi
 
Back
Top