PC Review


Reply
Thread Tools Rating: Thread Rating: 4 votes, 4.00 average.

Set the contrast of LCD screen in C#

 
 
Peter
Guest
Posts: n/a
 
      23rd Dec 2004
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.


 
Reply With Quote
 
 
 
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      23rd Dec 2004
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

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

"Peter" <pvdacker@N0_SPAM_home.nl> wrote in message
news:(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
 
 
 
Sergey Bogdanov
Guest
Posts: n/a
 
      24th Dec 2004
The structure ContrastCmdInputParm (Windows CE 2.10+) [1] and the
function ExtEscape could help you.


[1]
http://msdn.microsoft.com/library/de...dinputparm.asp

HTH,
Sergey

Peter wrote:
> 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.
>
>

 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      27th Dec 2004
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" <(E-Mail Removed)> schreef in bericht
news:OCH%(E-Mail Removed)...
> The structure ContrastCmdInputParm (Windows CE 2.10+) [1] and the
> function ExtEscape could help you.
>
>
> [1]
>

http://msdn.microsoft.com/library/de...dinputparm.asp
>
> HTH,
> Sergey
>
> Peter wrote:
> > 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.
> >
> >



 
Reply With Quote
 
Sergey Bogdanov
Guest
Posts: n/a
 
      27th Dec 2004
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


Peter wrote:
> 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.

 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      27th Dec 2004
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" <(E-Mail Removed)> schreef in bericht
news:%23Wb5nq$(E-Mail Removed)...
> 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
>
>
> Peter wrote:
> > 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.



 
Reply With Quote
 
Sergey Bogdanov
Guest
Posts: n/a
 
      27th Dec 2004
Does QUERYESCSUPPORT return Zero? If so then the device capabilitie of
this function was not implemented by an OEM.

--
Best regards,
Sergey Bogdanov

Peter wrote:
> 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.

 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      27th Dec 2004
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 );

}





"Sergey Bogdanov" <(E-Mail Removed)> schreef in bericht
news:u$(E-Mail Removed)...
> Does QUERYESCSUPPORT return Zero? If so then the device capabilitie of
> this function was not implemented by an OEM.
>
> --
> Best regards,
> Sergey Bogdanov
>
> Peter wrote:
> > 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.



 
Reply With Quote
 
Sergey Bogdanov
Guest
Posts: n/a
 
      3rd Jan 2005
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);


Peter wrote:
> 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 );
>
> }
>
>
>
>
>
> "Sergey Bogdanov" <(E-Mail Removed)> schreef in bericht
> news:u$(E-Mail Removed)...
>
>>Does QUERYESCSUPPORT return Zero? If so then the device capabilitie of
>>this function was not implemented by an OEM.
>>
>>--
>>Best regards,
>>Sergey Bogdanov
>>
>>Peter wrote:
>>
>>>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.

>
>
>



--
Best regards,
Sergey Bogdanov
 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      4th Jan 2005
Many, many thanks Sergey :-)))))) It works like a charm now !!!

Kind regards

Peter.

"Sergey Bogdanov" <(E-Mail Removed)> schreef in bericht
news:%(E-Mail Removed)...
> 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);
>
>
> Peter wrote:
> > 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 );
> >
> > }
> >
> >
> >
> >
> >
> > "Sergey Bogdanov" <(E-Mail Removed)> schreef in bericht
> > news:u$(E-Mail Removed)...
> >
> >>Does QUERYESCSUPPORT return Zero? If so then the device capabilitie of
> >>this function was not implemented by an OEM.
> >>
> >>--
> >>Best regards,
> >>Sergey Bogdanov
> >>
> >>Peter wrote:
> >>
> >>>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.

> >
> >
> >

>
>
> --
> Best regards,
> Sergey Bogdanov



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LG vx8100 housing,vx8100 LCD,vx8500 housing,vx8500 LCD,vx8600 housing,vx9900 LCD sale@cellphonepartszone.com Printers 0 30th Aug 2007 06:27 AM
brightness contrast lcd monitor mooky Windows XP Basics 4 19th May 2007 02:41 AM
dimensions - is the new 19" wide LCD as high as a 19" square lcd or 17'LCd rbt Video Cards 3 22nd Nov 2006 06:16 PM
RE:Changing contrast of LCD display. Terry Windows XP General 2 27th Oct 2004 03:09 PM
Re: Contrast/Brightness of LCD (laptop) Jupiter Jones [MVP] Windows XP Accessibility 0 29th Jul 2004 11:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:22 PM.