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