15.02 BUTTONBARs

15.02 BUTTONBARs

Postby nageswaragunupudi » Mon Feb 23, 2015 9:01 pm

It is possible to specify almost any image file as a bitmap for btnbmp and so buttons on the buttonbar, eg. bmp, png, ico, gif, jpg, etc (acceptable by freeimage). Larger image files will be reduced to fit the buttonsize, if necessary. It is also possible to specify a bitmap handle of memory buffer of an image.
In addition an exe file also can be specified and in that case, the first icon of the exe will be shown as the bitmap.
Resources and files need not be specified separately. We can use either FILE or RESOURCE clause followed by any files and/or resources.

Large image files are automatically re-sized to fit the size of the button. In the following example, some pngs and jpg are resized. This feature largely reduces the need to maintain bmp files of different sizes of the same image.

A small example showing a buttonbar built with ICO,EXE,GIF,PNG,AlphaBmp and JPG.
Image
Code: Select all  Expand view

function AnyImageBtn()

   local oWnd, oBar, oFont

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
   DEFINE WINDOW oWnd TITLE "BUTTONAR ANY IMAGE 15.02"
   oWnd:SetFont( oFont )

   DEFINE BUTTONBAR oBar OF oWnd SIZE 72,96 2007

   DEFINE BUTTON OF oBar FILE "c:\fwh\icons\fivetech.ico"         PROMPT "fivetech"+ CRLF+ "ICO"
   DEFINE BUTTON OF oBar FILE "c:\Program Files\Microsoft Office\Office14\Excel.exe" ;
                                                                  PROMPT "Excel"  + CRLF + "EXE"
   DEFINE BUTTON OF oBar FILE "c:\Program Files\Microsoft Office\Office14\powerpnt.exe" ;
                                                                  PROMPT "Excel"  + CRLF + "EXE"
   DEFINE BUTTON OF oBar FILE "c:\fwh\gifs\gif05.gif"             PROMPT "gif06"  + CRLF + "GIF"
   DEFINE BUTTON OF oBar FILE "c:\fwh\bitmaps\32x32\case.bmp"     PROMPT "32x32"  + CRLF + "BMP"
   DEFINE BUTTON OF oBar FILE "c:\fwh\bitmaps\pngs\image3.png"    PROMPT "image3" + CRLF + "PNG"
   DEFINE BUTTON OF oBar FILE "c:\fwh\bitmaps\AlphaBmp\ichat.bmp" PROMPT "IChat"  + CRLF + "ALPHABMP"
   DEFINE BUTTON OF oBar FILE "c:\fwh\bitmaps\olga1.jpg"          PROMPT "olga1"  + CRLF + "JPG"

   ACTIVATE WINDOW oWnd CENTERED
   RELEASE FONT oFont

return nil
 


In earlier versions, btnbmp can be shown transparently. Though this is not of a regular use, it is possible to show buttonbars also transparently like this:

Image

Code: Select all  Expand view

function TranspBtnBar

   local oWnd, oBar, oBtn, oFont, oBrush

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
   DEFINE BRUSH oBrush FILE "c:\fwh\bitmaps\olga1.jpg" RESIZE
   DEFINE WINDOW oWnd TITLE "TRANSPARENT BUTTONBAR" BRUSH oBrush
   oWnd:SetFont( oFont )

   DEFINE BUTTONBAR oBar OF oWnd SIZE 72,96
   oBar:lTransparent := .t.

   DEFINE BUTTON OF oBar FILE "c:\fwh\bitmaps\metro\metro-back-48.png" ;
                                                                  PROMPT "Back"  + CRLF + "metro"  FLAT TRANSPARENT
   DEFINE BUTTON OF oBar FILE "c:\Program Files\Microsoft Office\Office14\Excel.exe" ;
                                                                  PROMPT "Excel"  + CRLF + "exe"   FLAT TRANSPARENT
   DEFINE BUTTON OF oBar FILE "c:\Program Files\Microsoft Office\Office14\winword.exe" ;
                                                                  PROMPT "Word"   + CRLF + "EXE"   FLAT TRANSPARENT
   DEFINE BUTTON OF oBar FILE "c:\fwh\gifs\loading.gif"           PROMPT "loading"+ CRLF+ "gif"    FLAT TRANSPARENT
   DEFINE BUTTON OF oBar FILE "c:\fwh\bitmaps\32x32\copy.bmp"     PROMPT "copy"   + CRLF + "bmp"   FLAT TRANSPARENT
   DEFINE BUTTON OF oBar FILE "c:\fwh\bitmaps\32x32\paste.bmp"    PROMPT "paste"  + CRLF + "bmp"   FLAT TRANSPARENT
   DEFINE BUTTON OF oBar FILE "c:\fwh\bitmaps\pngs\image3.png"    PROMPT "image3" + CRLF + "png"   FLAT TRANSPARENT
   DEFINE BUTTON OF oBar FILE "c:\fwh\bitmaps\AlphaBmp\visa.bmp"  PROMPT "Visa"   + CRLF + "Alpha" FLAT TRANSPARENT
   DEFINE BUTTON OF oBar FILE "c:\fwh\bitmaps\AlphaBmp\ichat.bmp" PROMPT "IChat"  + CRLF + "Alpha" FLAT TRANSPARENT
   DEFINE BUTTON OF oBar FILE "c:\fwh\bitmaps\metro\users.bmp"    PROMPT "users"  + CRLF + "metro" FLAT TRANSPARENT
   DEFINE BUTTON OF oBar FILE "c:\fwh\bitmaps\metro\exit.bmp"     PROMPT "exit"   + CRLF + "metro" FLAT TRANSPARENT

   for each oBtn in oBar:aControls
      oBtn:SetColor( CLR_WHITE, CLR_BLACK )
   next

   ACTIVATE WINDOW oWnd CENTERED
   RELEASE FONT oFont
   RELEASE BRUSH oBrush

return nil
 


In the same manner, any image file (including exe file) can be specified as bitmap for XBrowse. Here is an example showing list of applications with their icons shown as bitmaps.

Image
Code: Select all  Expand view

function XbrExeIcons()

   local cPath := "c:\\Program Files\\Microsoft Office\\Office14\\"
   local aDir, aExe := {}
   local ownd, oBrw, oFont

   aDir     := Directory( cPath + "*.exe" )
   AEval( aDir, { |a| AAdd( aExe, cPath + a[ 1 ] ) } )

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-16
   DEFINE WINDOW oWnd TITLE "MS OFFICE PROGRAMS"
   oWnd:SetFont( oFont )
   @ 0,0 XBROWSE oBrw OF oWnd DATASOURCE aDir COLUMNS 1 HEADERS "Program" ;
      LINES NOBORDER

   WITH OBJECT oBrw
      :aCols[ 1 ]:AddBitmap( aExe )
      :aCols[ 1 ]:bBmpData := { || oBrw:nArrayAt }
      //
      :CreateFromCode()
   END
   oWnd:oClient   := oBrw
   ACTIVATE WINDOW oWnd CENTERED
   RELEASE FONT oFont

return nil
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10316
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: 15.02 BUTTONBARs

Postby cnavarro » Mon Feb 23, 2015 9:35 pm

Mr Rao, thanks
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6504
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: 15.02 BUTTONBARs

Postby mastintin » Tue Feb 24, 2015 8:00 am

nages ...

Code: Select all  Expand view


METHOD CreateButtons()  CLASS TXBrwColumn

 .......

  @ 0,0 BTNBMP ::oBtnElip OF ::oBrw NOBORDER SIZE 0,0

      WITH OBJECT ::oBtnElip
         if Empty( aBitmap )
            :cCaption := IfNil( ::cBtnCaption, "..." )
         else
            :hBitmap1   := aBitmap[ BITMAP_HANDLE ]
            :hPalette1  := aBitmap[ BITMAP_PALETTE ]
            :cCaption := ""
            :HasAlpha(  :hBitmap1, 1 )  // added transparent for png files ...
         endif
         :bAction := {|| ::RunBtnAction() }
         :SetFont( ::DataFont )
          aColors:= Eval( ::bClrBtn ,.f. )
         :SetColor( aColors[ 1 ], aColors[ 2 ] )
      END

 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: 15.02 BUTTONBARs

Postby nageswaragunupudi » Tue Feb 24, 2015 8:33 am

mastintin wrote:nages ...

Code: Select all  Expand view


METHOD CreateButtons()  CLASS TXBrwColumn

 .......

  @ 0,0 BTNBMP ::oBtnElip OF ::oBrw NOBORDER SIZE 0,0

      WITH OBJECT ::oBtnElip
         if Empty( aBitmap )
            :cCaption := IfNil( ::cBtnCaption, "..." )
         else
            :hBitmap1   := aBitmap[ BITMAP_HANDLE ]
            :hPalette1  := aBitmap[ BITMAP_PALETTE ]
            :cCaption := ""
            :HasAlpha(  :hBitmap1, 1 )  // added transparent for png files ...
         endif
         :bAction := {|| ::RunBtnAction() }
         :SetFont( ::DataFont )
          aColors:= Eval( ::bClrBtn ,.f. )
         :SetColor( aColors[ 1 ], aColors[ 2 ] )
      END

 

Thanks
1) Present code of this method is different than this.
2) Still painting of these buttons is somewhat primitive. We are considering total revision.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10316
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: 15.02 BUTTONBARs

Postby mastintin » Tue Feb 24, 2015 8:42 am

ok ...
nages in tgdiplus this change is hight recomendable...


Code: Select all  Expand view

METHOD New( cFile , cResname ) CLASS GDIBmp

/*
elseif !Empty(cFile)
      if File( cFile )
         cBuffer := MemoRead( cFile )
         nLen:= len(cBuffer)
       //  msginfo(nLen )
         if nLen < 65000
            ::hBmp:=GdiPlusImageLoadPNGFromSTR(cBuffer, Len( cBuffer ) )
         else
            msginfo("grande")
           ::hBmp:=GDIPLUSCREATEIMAGEFROMFILE( Ansitowide(cFile ) )
         endif
      else
        msginfo( "fichero no encontrado" )
      endif
   endif
*/


 elseif !Empty(cFile)
      if File( cFile )
         ::hBmp:= GDIPLUSIMAGELOADCACHEDFILE( cFile )
      else
          msginfo( "fichero no encontrado" )
      endif
  endif

 


and cpp code ...

Code: Select all  Expand view


 HB_FUNC( GDIPLUSIMAGELOADCACHEDFILE )
{

  FILE * fil = fopen (  hb_parc(1) , "rb" ) ;
  fseek ( fil , 0 , SEEK_END ) ;
  int filesize = ftell ( fil ) ;

  fseek ( fil , 0 , SEEK_SET ) ;
  HGLOBAL hglobal = GlobalAlloc ( GMEM_MOVEABLE , filesize ) ;

  char * adr = (char *)GlobalLock ( hglobal ) ;
  int nbytes = fread ( adr , 1 , filesize , fil ) ;
  fclose ( fil ) ;

  if ( nbytes != filesize )
      {
       MessageBox( GetActiveWindow(), "fallo", "No carga la imagen", 0x30 );
      } ;

 LPSTREAM pstm = NULL ;
 GlobalUnlock ( hglobal ) ;

 CreateStreamOnHGlobal ( hglobal, TRUE, &pstm ) ;

 Bitmap  *original = new  Bitmap( pstm,FALSE );

 int nWidth  = original->GetWidth()  ;
 int nHeight = original->GetHeight() ;

 Bitmap* newImage  = new Bitmap( nWidth, nHeight, original->GetPixelFormat() );

 Graphics * graphics = new Graphics( newImage );
 graphics->DrawImage( original ,0, 0, nWidth, nHeight);

 delete graphics ;
 delete original ;
 GlobalFree( hglobal );
 pstm->Release();

 hb_retnl( ( HB_LONG ) newImage );

}

 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: 15.02 BUTTONBARs

Postby nageswaragunupudi » Tue Feb 24, 2015 8:58 am

Thank you for all your help.
I would like to be in touch with you by personal email for further work on gdiplus.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10316
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 30 guests