Set the contrast of LCD screen in C#

Discussion in 'Microsoft Dot NET Compact Framework' started by Peter, Dec 23, 2004.

  1. Peter

    Peter Guest

    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.
     
    Peter, Dec 23, 2004
    #1
    1. Advertisements

  2. 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:...
    > 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.
    >
    >
     
    Peter Foot [MVP], Dec 23, 2004
    #2
    1. Advertisements

  3. 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

    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.
    >
    >
     
    Sergey Bogdanov, Dec 24, 2004
    #3
  4. Peter

    Peter Guest

    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" <> schreef in bericht
    news:OCH%...
    > 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
    >
    > 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.
    > >
    > >
     
    Peter, Dec 27, 2004
    #4
  5. 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.
     
    Sergey Bogdanov, Dec 27, 2004
    #5
  6. Peter

    Peter Guest

    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" <> schreef in bericht
    news:%23Wb5nq$...
    > 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.
     
    Peter, Dec 27, 2004
    #6
  7. 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.
     
    Sergey Bogdanov, Dec 27, 2004
    #7
  8. Peter

    Peter Guest

    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" <> schreef in bericht
    news:u$...
    > 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.
     
    Peter, Dec 27, 2004
    #8
  9. 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" <> schreef in bericht
    > news:u$...
    >
    >>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
     
    Sergey Bogdanov, Jan 3, 2005
    #9
  10. Peter

    Peter Guest

    Many, many thanks Sergey :)))))) It works like a charm now !!!

    Kind regards

    Peter.

    "Sergey Bogdanov" <> schreef in bericht
    news:%...
    > 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" <> schreef in bericht
    > > news:u$...
    > >
    > >>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
     
    Peter, Jan 4, 2005
    #10
  11. Peter

    u0k0

    Joined:
    Jul 21, 2011
    Messages:
    2
    Likes Received:
    0
    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 !
     
    u0k0, Jul 21, 2011
    #11
  12. Peter

    Laxmi D

    Joined:
    Nov 28, 2011
    Messages:
    1
    Likes Received:
    0
    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
     
    Laxmi D, Nov 28, 2011
    #12
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keep LCD Screen On

    , Jan 12, 2006, in forum: Microsoft Dot NET Compact Framework
    Replies:
    6
    Views:
    223
  2. raju

    how to increase or decrease contrast/brightness in compact framework

    raju, Jun 22, 2006, in forum: Microsoft Dot NET Compact Framework
    Replies:
    2
    Views:
    467
    Norman Rericha
    Jun 22, 2006
  3. aLiTaN

    Set Screen Taps and Key Clicks Sound

    aLiTaN, Jun 26, 2007, in forum: Microsoft Dot NET Compact Framework
    Replies:
    3
    Views:
    287
    Guest
    Jun 26, 2007
  4. Dan

    Can't get form to go full screen over space at bottom of screen

    Dan, Jul 24, 2007, in forum: Microsoft Dot NET Compact Framework
    Replies:
    2
    Views:
    424
  5. juvi

    Possible to set touch screen sensitivity??

    juvi, Aug 25, 2008, in forum: Microsoft Dot NET Compact Framework
    Replies:
    1
    Views:
    581
    Chris Tacke, eMVP
    Aug 25, 2008
Loading...

Share This Page