Paint Background in Frame Control

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
srvet_claudio
Posts: 1876
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 25 times
Been thanked: 68 times
Contact:

Paint Background in Frame Control

Post by srvet_claudio » Sun Sep 02, 2012 12:39 am

Hi all.
Since of the frame control is a transparent window is easy to put a background, painting directly on the client area with ON PAINT event.
I hope you find it useful.
Regards,
Claudio

Code: Select all

**********************************************************
* PROGRAMA:  Paint Background in Frame Control
* LENGUAJE:  HMG 3.0.43
* FECHA:     1 Setiembre 2012
* AUTOR:     Dr. CLAUDIO SOTO
* PAIS:      URUGUAY
* E-MAIL:    srvet@adinet.com.uy
* BLOG:      http://srvet.blogspot.com
**********************************************************

 
#include "hmg.ch" 

Function Main 

PRIVATE RGB_Color := BLUE

    DEFINE WINDOW Win1 ; 
        AT 0,0 ; 
        WIDTH 800 ; 
        HEIGHT 600 ;
        TITLE "Paint Background in Frame Control";        
        MAIN;  
		  ON PAINT Paint_Background_Frame()
		  
        DEFINE MAIN MENU
            DEFINE POPUP "Change Color" 
                  MENUITEM "BLUE"  ACTION {|| RGB_Color := BLUE,          Paint_Background_Frame()} 
                  MENUITEM "RED"   ACTION {|| RGB_Color := RED,           Paint_Background_Frame()} 
                  MENUITEM "BLACK" ACTION {|| RGB_Color := BLACK,         Paint_Background_Frame()}
                  MENUITEM "USER"  ACTION {|| RGB_Color := {250,100,23},  Paint_Background_Frame() }                   
            END POPUP
        END MENU 
        
        @  10,100 FRAME frame_1 CAPTION "Frame 1" WIDTH 500 HEIGHT 200 FONT "Times New Roman" SIZE 14 BOLD ITALIC UNDERLINE BACKCOLOR RED FONTCOLOR GREEN
        @ 150,150 BUTTON button_1 CAPTION "Click 1" ACTION MsgInfo ("Frame 1")
        @  50,150 LABEL  label_1 VALUE "Hello HMG World" FONT "Times New Roman" SIZE 14 BOLD  TRANSPARENT
        
        @ 300,100 FRAME frame_2 CAPTION "Frame 2" WIDTH 500 HEIGHT 200 FONT "ARIAL" SIZE 14 BOLD ITALIC UNDERLINE 
        @ 350,150 BUTTON button_2 CAPTION "Click 2" ACTION MsgInfo ("Frame 2")
        
    END WINDOW 	
	CENTER WINDOW Win1
	ACTIVATE WINDOW Win1        
Return


Procedure Paint_Background_Frame 
  #define OFFSET_INI  10         
  #define ROUND_WIDTH  5
  #define ROUND_HEIGHT 5
  
  FILL_FRAME (GetFormHandle("Win1"),; 
              win1.frame_1.ROW + OFFSET_INI,; 
              win1.frame_1.COL,; 
              win1.frame_1.WIDTH,; 
              win1.frame_1.HEIGHT - OFFSET_INI,; 
			     RGB_Color,;
              ROUND_WIDTH, ROUND_HEIGHT)
  
  InvalidateRect (GetFormHandle("Win1"), NIL ,.F.)   // Invalidate all client area
Return



*#########################################################################################################################
*   FUNCIONES EN C        
*#########################################################################################################################

#pragma begindump


#include <windows.h>
#include "hbapi.h"


// **************************************************************************
// *  FILL_FRAME ( hWnd , y, x, w, h,  {R,G,B}, Round_WIDTH, Round_HEIGHT)
// **************************************************************************
HB_FUNC (FILL_FRAME)
{
   HWND hWnd;
   HDC hDC;
   RECT rect;
   POINT round;
   HBRUSH hBrush;
   INT R,G,B;
   PHB_ITEM pArrayRect;
   
   
   hWnd        = (HWND)    hb_parnl (1);
   rect.top    = hb_parnl (2); 
   rect.left   = hb_parnl (3);
   rect.right  = rect.left + hb_parnl (4);
   rect.bottom = rect.top  + hb_parnl (5);	   
     
   if (HB_ISARRAY (6))
   {
      pArrayRect = hb_param (6, HB_IT_ARRAY);
      R = hb_arrayGetNI (pArrayRect, 1);
      G = hb_arrayGetNI (pArrayRect, 2);
      B = hb_arrayGetNI (pArrayRect, 3);      
      round.x  = hb_parnl (7);
      round.y  = hb_parnl (8);
      
      hDC = GetDC (hWnd);
      hBrush = CreateSolidBrush (RGB (R,G,B));      
      SelectObject (hDC, hBrush); 
      DPtoLP (hDC, (LPPOINT) &rect,  2);
      DPtoLP (hDC, (LPPOINT) &round, 1);      
      RoundRect(hDC, (int)rect.left, (int)rect.top, (int)rect.right, (int)rect.bottom, (int)round.x, (int)round.y);
      DeleteObject (hBrush);
      ReleaseDC(hWnd, hDC);       
   }        
}

#pragma enddump

Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
Rathinagiri
Posts: 5036
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 76 times
Been thanked: 87 times
Contact:

Post by Rathinagiri » Sun Sep 02, 2012 3:38 am

Thanks a lot Claudio. This will be very useful.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
esgici
Posts: 4252
Joined: Wed Jul 30, 2008 9:17 pm
Location: iskenderun / Turkiye
Has thanked: 131 times
Been thanked: 42 times
Contact:

Post by esgici » Sun Sep 02, 2012 4:38 am

Gracias Dr.

Saludos cordiales :)
Viva INTERNATIONAL HMG :D

chrisjx2002
Posts: 148
Joined: Wed Jan 06, 2010 5:39 pm
Been thanked: 1 time

Post by chrisjx2002 » Sun Sep 02, 2012 8:17 am

Hello,

Thanks for this nice new feature.

I compiled this program but I got an error : undefined reference HB_FUN_INVALIDATERECT

I miss something but what? :(

chrisjx2002
Posts: 148
Joined: Wed Jan 06, 2010 5:39 pm
Been thanked: 1 time

Post by chrisjx2002 » Sun Sep 02, 2012 8:20 am

Sorry... It is solved. I used the old 3.0.41 HMG version.

User avatar
srvet_claudio
Posts: 1876
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 25 times
Been thanked: 68 times
Contact:

Post by srvet_claudio » Sun Sep 02, 2012 6:22 pm

Thanks Rathi, Esgici and Chrisjx2002.
Regards,
Claudio.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
danielmaximiliano
Posts: 1973
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Has thanked: 10 times
Been thanked: 8 times
Contact:

Post by danielmaximiliano » Mon Sep 03, 2012 12:01 am

Hola Claudio :
Gracias por el aporte.
A veces es necesario tener o colocar un Frame dentro de la aplicación y aplicar un color apenas un poco diferente, de esa forma magnificar el area de ingreso de datos y resaltar area de información.
otra seria que el Frame se pudiera cambiar solo el color del marco, ya que el Control solo permite cambiar el Font. o color del Caption pero no el color del marco en si.
Tilos.jpg
Tilos.jpg (247.41 KiB) Viewed 1821 times
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`.HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp / Telegrams To cel +54 011 690 26 142

User avatar
danielmaximiliano
Posts: 1973
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Has thanked: 10 times
Been thanked: 8 times
Contact:

Post by danielmaximiliano » Mon Sep 03, 2012 2:04 am

Hola Claudio :
encontre algunas dificultades en implementar ON PAINT con pintar el control FRAME.

Code: Select all

DEFINE WINDOW Stock ;
              AT 5 ,5 ;
              WIDTH 1020 HEIGHT 710 ;
              TITLE "Stock Autoservicio Los Tilos" ;
              ICON 'Carritos';
              NOMAXIMIZE NOSIZE ;
              ON INIT  Stock.Text_8.Setfocus;
	      ON PAINT  Paint_Background_Window()
	      ON KEY ESCAPE ACTION {|| lDeleteallItems := .T. , ThisWindow.Release }

Code: Select all

Procedure Paint_Background_Frame
  #define OFFSET_INI  10         
  #define ROUND_WIDTH  5
  #define ROUND_HEIGHT 5
  For nFrame := 1 to 6
  cFrame:= 'Frame_'+alltrim(str(nFrame))
  FILL_FRAME (GetFormHandle("Stock")             ,;
              Stock.&(cFrame).ROW + OFFSET_INI   ,;
              Stock.&(cFrame).COL                ,;
              Stock.&(cFrame).WIDTH              ,;
              Stock.&(cFrame).HEIGHT - OFFSET_INI,;
              {153,255,204}                      ,;
              ROUND_WIDTH                        ,;
              ROUND_HEIGHT)
              
              msgbox('Pintando Frame:' + alltrim( str( nFrame ) ) )
   Next           
 
  InvalidateRect (GetFormHandle("Stock"), NIL ,.F.)   // Invalidate all client area
Return

intente usar text_8 para recibir el foco despues del inicio, pintar los FRAME y despues enviar el FOCO hacia el TEXt_1 que es la entrada de datos.
veia que no pintaba en control FRAME, asi que pude un mensaje en dicho Procediento y si pintaba. pero el Activarse la ventana asumia el pintado de la ventana pero no de los controles FRAME.
frame 1.jpg
frame 1.jpg (131.45 KiB) Viewed 1811 times
frame6.jpg
frame6.jpg (142.71 KiB) Viewed 1811 times
vemos que se pintan los 6 FRAME, el principal y los otros que contienen los refreridos TEXT_x
pero al activarse , no se ven pintados los FRAME.
control.jpg
control.jpg (151.72 KiB) Viewed 1811 times
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`.HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp / Telegrams To cel +54 011 690 26 142

User avatar
srvet_claudio
Posts: 1876
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 25 times
Been thanked: 68 times
Contact:

Post by srvet_claudio » Mon Sep 03, 2012 3:54 am

Hola Daniel.
Estuve haciendo varias pruebas con un frame adentro de otro y con varios controles adentro y no medió ningún problema.
Me podrías enviar a srvet@adinet.com.uy el trozo de código que la definición de la ventana "Stock" y contiene los frame y los controles que tienen adentro, adjuntame la/las imágenes que aparecen adentro del frame, así lo puedo estudiar mejor a simple vista no me doy cuenta porque no funciona.
¿Si eliminas el ON INIT funciona?
Saludos,
Claudio.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
danielmaximiliano
Posts: 1973
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Has thanked: 10 times
Been thanked: 8 times
Contact:

Post by danielmaximiliano » Mon Sep 03, 2012 8:53 pm

Hola Claudio :
Jugando un poco con lo numeros que controlan el 'Pintado' del Control FRAME llegue a 'mas o menos' que quede
como queria , como decia en uno de los POST anteriores (mas arriba) el control FRAME se pierde en un tipo de color, en mi caso RGB 204,255,204
para corregir ese problema use este metodo.

Code: Select all

Procedure Paint_Background_Frame
  #define OFFSET_INI   6         
  #define ROUND_WIDTH  6
  #define ROUND_HEIGHT 6
 
   cFrame:= 'Frame_1'
  
  FILL_FRAME (GetFormHandle("Stock")             ,;
              Stock.&(cFrame).ROW + 2            ,;
              Stock.&(cFrame).COL                ,;
              Stock.&(cFrame).WIDTH              ,;
              Stock.&(cFrame).HEIGHT             ,;
              {204,255,204}                      ,;
              ROUND_WIDTH                        ,;
              ROUND_HEIGHT)
              
  cFrame:= 'Frame_2'
  
  FILL_FRAME (GetFormHandle("Stock")             ,;
              Stock.&(cFrame).ROW + 5            ,;
              Stock.&(cFrame).COL  + 2           ,;
              Stock.&(cFrame).WIDTH -4           ,;
              Stock.&(cFrame).HEIGHT - 8         ,;
              {204,255,204}                      ,;
              ROUND_WIDTH                        ,;
              ROUND_HEIGHT)            
  For nFrame := 3 to 7
  
  cFrame:= 'Frame_'+alltrim(str(nFrame))
  
  FILL_FRAME (GetFormHandle("Stock")             ,;
              Stock.&(cFrame).ROW  +8            ,;
              Stock.&(cFrame).COL               ,;
              Stock.&(cFrame).WIDTH             ,;
              Stock.&(cFrame).HEIGHT  -8          ,;
              {153,255,204}                      ,;
              ROUND_WIDTH                        ,;
              ROUND_HEIGHT)
         
   Next           
 
  InvalidateRect (GetFormHandle("Stock"), NIL ,.F.)   // Invalidate all client area
Return
Stock Autoservicio.jpg
Stock Autoservicio.jpg (165.42 KiB) Viewed 1736 times
Gracias por tu tiempo y dedicación.
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`.HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp / Telegrams To cel +54 011 690 26 142

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest