john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

Custom buttons for Win CE

/* windows buttons have buggy behavior 
So replaced with custom buttons */  
/*  depends on drawRectangle and drawText and initializeColor and clearRect */

#define LINEMAX 256

#define BUTTONWIDTH 30
#define BUTTONHEIGHT 30
#define BUTTONMAX 3

struct button 
{   rectangle buttonRectangle;
    char name[ BUTTONWIDTH ];
};

button menu[ BUTTONMAX ];


VOID initializeMenuButtons (  VOID   )
{   
    strcpy( menu[ 0 ].name , "quit" );
    menu[ 0 ].buttonRectangle.left = 0 ;
    menu[ 0 ].buttonRectangle.top = 0 ;
    menu[ 0 ].buttonRectangle.right = BUTTONWIDTH ; 
    menu[ 0 ].buttonRectangle.bottom  = BUTTONHEIGHT ;
    menu[ 0 ].buttonRectangle.color = RGB( 255 , 0 , 0 ) ;

    strcpy( menu[ 1 ].name , "clear" );
    menu[ 1 ].buttonRectangle.left = 30 ;
    menu[ 1 ].buttonRectangle.top = 0 ;
    menu[ 1 ].buttonRectangle.right = 30 + BUTTONWIDTH ; 
    menu[ 1 ].buttonRectangle.bottom  = BUTTONHEIGHT ;
    menu[ 1 ].buttonRectangle.color = RGB( 0 , 0 , 0 ) ;

    strcpy( menu[ 2 ].name , "open" );
    menu[ 2 ].buttonRectangle.left = 60 ;
    menu[ 2 ].buttonRectangle.top = 0 ;
    menu[ 2 ].buttonRectangle.right = 60 + BUTTONWIDTH ; 
    menu[ 2 ].buttonRectangle.bottom  = BUTTONHEIGHT ;
    menu[ 2 ].buttonRectangle.color = RGB( 0 , 0 , 0 ) ;



}/* end function  initializeMenuButtons  */


VOID drawMenuButtons ( HWND hwnd   )
{
    int i=0;
    HDC  hdc;
    hdc = GetDC( hwnd );

/* crude clear erase */
ExtTextOut( hdc, (4*BUTTONWIDTH)+4  , 6  , NULL, NULL,
 L"                               " , wcslen( L"                               "   ), NULL);

    for( i=0; i< BUTTONMAX ; i++ )
    {
        drawRectangle( hwnd , menu[ i ].buttonRectangle.left ,    menu[ i ].buttonRectangle.top ,    menu[ i ].buttonRectangle.right ,  menu[ i ].buttonRectangle.bottom  , menu[ i ].buttonRectangle.color );

   drawText(  hwnd,  menu[ i ].name , menu[ i ].buttonRectangle.left +4 , menu[ i ].buttonRectangle.top +6 );

    }/*  end for */


    ReleaseDC(hwnd, hdc);    
}/* end function   drawMenuButtons  */

VOID customButtonCheck( HWND hwnd , int x , int y )
{
    HDC hdc;
    RECT rc;

    linebufferptr filetext ;
    char currentdirectory[ LINEMAX ] ;



/* quit button */
    if( (x > menu[ 0 ].buttonRectangle.left ) && (x < menu[ 0 ].buttonRectangle.right ) && ( y > menu[ 0 ].buttonRectangle.top
) && (y < menu[ 0 ].buttonRectangle.bottom 
 ) )
    {
         PostQuitMessage(0);   
    }
/* clear button */
    if( (x > menu[ 1 ].buttonRectangle.left ) && (x < menu[ 1 ].buttonRectangle.right ) && ( y > menu[ 1 ].buttonRectangle.top
) && (y < menu[ 1 ].buttonRectangle.bottom 
 ) )
    {
        clearRect(  hwnd );
        drawMenuButtons (  hwnd   );
    }
/* opem button */
    if( (x > menu[ 2 ].buttonRectangle.left ) && (x < menu[ 2 ].buttonRectangle.right ) && ( y > menu[ 2 ].buttonRectangle.top
) && (y < menu[ 2 ].buttonRectangle.bottom 
 ) )
    {
    filetext = initializeList(  filetext );
    strcpy( currentdirectory , "\\");

    getListing( filetext , currentdirectory );
  /*  displayList( filetext );

printf("\nempty ptr=%d\n", filetext  );
    displayList( filetext );
*/

    filetext = deleteList( filetext );

    }

} /* end function customButtonCheck */

  • « Graphical directory listing in Win CE (main file)
  • Create a linked list of files with c and Win CE »

Published

Jun 3, 2010

Category

c

~311 words

Tags

  • c 95
  • custom button 1
  • programming 9
  • win-ce 40