December 06, 2022, 11:09:20 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Transparent Static control

Started by Pip1957, August 23, 2006, 11:44:51 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Pip1957

Hi all

How does one add a transparent static control to a dialog.

Pip1957


Ionic Wind Support Team

Didn't have an answer since I wasn't sure what your referring to.  All controls have background and foreground colors, even static ones. 

The background color is normally the same color as the background of the dialog.
Ionic Wind Support Team

Pip1957

I have a bitmap as the dialog background and wanted the static text background transparent

Ionic Wind Support Team

There isn't a way I can think of to make a stock static control transparent since there isn't a style to do it. However....

You could derive your own class from CStatic, override OnEraseBkgnd and return TRUE. 

Or you can override OnPaint in your dialog and use WriteText.

Or just add the text to the bitmap.

Or use a window instead of a dialog and use WriteText.



Ionic Wind Support Team

Pip1957

Cheers Paul will play with it and see

Earn

August 29, 2006, 05:44:53 PM #6 Last Edit: August 29, 2006, 09:21:34 PM by Earn
I played with this awhile ago, had to remember what I had done.
#define WM_CTLCOLORDLG 310
#define WM_CTLCOLORSTATIC 312
#define NULL_BRUSH 5

//***********ÂÃ,  API Functions ***********
declare import, CreateSolidBrush(clr as unsigned int),unsigned int;
declare import, CreatePatternBrush(brush as unsigned int),unsigned int;
declare import, GetStockObject(fnObject as unsigned int),unsigned int;
declare import, InvalidateRect(HWND as unsigned int, pRect as RECT, bErase as unsigned int),unsigned int;
declare import, LoadImage alias LoadImageA(int hInstance,string lpszName,int uType,int cxDesired,int cydesired,int fuLoad),unsigned int;
declare import, SetBkMode(hdc as INT, nBkMode as INT),INT;
declare import, SetTextColor(hdc as INT, crColor as INT),INT;
declare import, SetPropA(hwnd as unsigned int,lpString as STRING,hData as unsigned int),int;
declare import, DeleteObject(hObject as unsigned int),int;

// #################################################################################### //
// ######################## CTStatic - Transparent Static Control ##################### //
// #################################################################################### //

class CTStatic : CStatic
{
//overrides
declare CTStatic();
declare _CTStatic();
declare OnControlColor(unsigned int hdc,unsigned int hwnd),int;
//member variables
unsigned int m_hBrush;
}

CTStatic::CTStatic()
{
m_hBrush = GetStockObject(NULL_BRUSH);
}

CTStatic::_CTStatic()
{
if m_hBrush DeleteObject(m_hBrush);
}

CTStatic::OnControlColor(unsigned int hdc,unsigned int hwnd)
{
SetTextColor(hdc,m_fg);
SetBkMode(hdc,TRANSPARENT);
return m_hBrush;
}


// #################################################################################### //
// #########################ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Color DialogÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ####################### //
// #################################################################################### //

class ColorDialog : CDialog
{
//overrides
declare ColorDialog();
declare _ColorDialog();
//declare OnInitDialog(),int;
declare WndProc(unsigned int message, unsigned int wparam, unsigned int lparam),int;
//public methods
declare SetBackColor(unsigned int cBack);
declare SetBackImage(string pImage);
//member variables
unsigned int m_hBrush;
CTStatic *m_pCTStatic;
}

ColorDialog::ColorDialog()
{
m_hBrush = NULL;
m_pCTStatic = NULL;
}

ColorDialog::_ColorDialog()
{
if m_hBrush DeleteObject(m_hBrush);
if m_pCTStatic <> NULL Delete m_pCTStatic;
}

ColorDialog::SetBackColor(unsigned int cBack)
{
m_hBrush = CreateSolidBrush(cBack);
InvalidateRect(m_hWnd, GetClientRect(), 1);
}

ColorDialog::SetBackImage(string pImage)
{
unsigned int hBitmap;
hBitmap = LoadImage(0, pImage, 0,0,0,0x10);
m_hBrush = CreatePatternBrush(hBitmap);
InvalidateRect(m_hWnd, GetClientRect(), 1);
}

ColorDialog::WndProc(unsigned int message, unsigned int wparam, unsigned int lparam),int
{
ÂÃ,  if (message = WM_CTLCOLORDLG) AND (m_hBrush <> NULL)
ÂÃ,  ÂÃ,  return m_hBrush;

ÂÃ,  return CDialog!!WndProc( message, wparam, lparam);
}

// #################################################################################### //
// #########################ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, MAIN PROGRAMÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, ####################### //
// #################################################################################### //

#define EDIT_1 1
#define STATIC_2 2
#define STATIC_3 3
#define EDIT_4 4
#define BUTTON_5 5
#define BUTTON_6 6
#define BUTTON_7 7

class myDialog:ColorDialog
{
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
}

global sub main()
{
myDialog d1;
d1.Create(0,0,300,202,0x80C80080,0,"Color Dialog",0);
d1.AddControl(CTEDIT,"Paul",125,50,142,19,0x50800000,0x200,EDIT_1);
d1.AddControl(CTSTATIC,"First Name",30,50,85,20,0x5000010B,0x0,STATIC_2);
d1.AddControl(CTSTATIC,"Last Name",30,82,85,20,0x5000010B,0x0,STATIC_3);
d1.AddControl(CTEDIT,"Turley",125,82,142,19,0x50800000,0x200,EDIT_4);
d1.AddControl(CTBUTTON,"Red",0,176,138,26,0x5000000B,0x0,BUTTON_5);
d1.AddControl(CTBUTTON,"Image",137,176,26,26,0x50000080,0x0,BUTTON_6);
d1.AddControl(CTBUTTON,"Green",162,176,138,26,0x5000000B,0x0,BUTTON_7);
d1.SetBackColor(RGB(10,50,250));

d1.DoModal();
return 0;
}

myDialog::OnClose(),int
{
CloseDialog(1);
return true;
}

myDialog::OnInitDialog(),int
{
/* Initialize any controls here */
CStatic *pStatic = GetControl(STATIC_2);
//subclass the control
m_pCTStatic = new(CTStatic,1);
m_pCTStatic->m_hWnd = pStatic->m_hWnd;
SetPropA(m_pCTStatic->m_hWnd,"THIS",m_pCTStatic);

pStatic = GetControl(STATIC_3);
//subclass the control
//m_pCTStatic = new(CTStatic,1);
m_pCTStatic->m_hWnd = pStatic->m_hWnd;
SetPropA(m_pCTStatic->m_hWnd,"THIS",m_pCTStatic);

/* Initialize any controls here */
CControl *pControl;
pControl = GetControl(STATIC_2);pControl->SetColor(RGB(255,255,255),0);
pControl = GetControl(STATIC_3);pControl->SetColor(RGB(255,255,255),0);
SetFont("ARIAL",12,800,0,STATIC_2);
SetFont("ARIAL",12,800,0,STATIC_3);
pControl = GetControl(BUTTON_5);pControl->SetColor(RGB(255,0,0),0);
pControl = GetControl(BUTTON_7);pControl->SetColor(RGB(0,255,0),0);

CButton *pbControl;
unsigned int hBitmap;
hBitmap = LoadImage(0, "\\Ball.bmp", 0,0,0,0x10);
pbControl = GetControl(BUTTON_6);pbControl->SetImage(hBitmap);

CenterWindow();
return true;
}

myDialog::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select nID
{
case EDIT_1:
/* respond to edit notifications here */
case EDIT_4:
/* respond to edit notifications here */
case BUTTON_5:
if(nNotifyCode = 0)
{
/*button clicked*/
SetBackColor(RGB(255,0,0));
}
case BUTTON_6:
if(nNotifyCode = 0)
{
/*button clicked*/
SetBackImage("\\Ball.bmp");ÂÃ,  //set path to your bitmap
}
case BUTTON_7:
if(nNotifyCode = 0)
{
/*button clicked*/
SetBackColor(RGB(0,255,0));
}
}
return true;
}



@Paul,
It would sure be nice to be able to specify a derived class in the ADDCONTROL method.
Instead of having to do:
ÂÃ,  d1.AddControl(CTSTATIC,"First Name",30,50,85,20,0x5000010B,0x0,STATIC_2);

and then:
ÂÃ,  CStatic *pStatic = GetControl(STATIC_2);
ÂÃ,  m_pCTStatic = new(CTStatic,1);
ÂÃ,  m_pCTStatic->m_hWnd = pStatic->m_hWnd;
ÂÃ,  SetPropA(m_pCTStatic->m_hWnd,"THIS",m_pCTStatic);

just do something like:
ÂÃ,  d1.AddControl(CTCUSTOM,"First Name",30,50,85,20,0x5000010B,0x0,STATIC_2,m_pCTStatic);

Idunno, just a thought. :-\
Earn

Pip1957


Earn

I was playing with this again and tried setting the text color of STATIC_2 to black and STATIC_3 to white.

pControl = GetControl(STATIC_2);pControl->SetColor(RGB(0,0,0),0);ÂÃ,  //set text black
pControl = GetControl(STATIC_3);pControl->SetColor(RGB(255,255,255),0);ÂÃ,  //set text white

Seems that the text color for both of the controls ends up with the last SetColor called.ÂÃ,  White in this case.ÂÃ,  What am I misunderstanding? ???

Earn

Ionic Wind Support Team

Because your referencing the same object even though they are different physical controls.   Look at your code below:


CStatic *pStatic = GetControl(STATIC_2);
//subclass the control
m_pCTStatic = new(CTStatic,1);
m_pCTStatic->m_hWnd = pStatic->m_hWnd;
SetPropA(m_pCTStatic->m_hWnd,"THIS",m_pCTStatic);

pStatic = GetControl(STATIC_3);
//subclass the control
//m_pCTStatic = new(CTStatic,1);
m_pCTStatic->m_hWnd = pStatic->m_hWnd;
SetPropA(m_pCTStatic->m_hWnd,"THIS",m_pCTStatic);


There is only one CTStatic class being created.  And your setting the 'this' property of both of the intrinisc static controls to point to this single class instance.  You need a separate instance of the class for each static control.  So you will need two variables, m_pCTStatic and m_pCTStatic2, or whatever.

Paul.
Ionic Wind Support Team

Earn

Hmmm.ÂÃ,  That does make sense and I swear I tried it but I'll try it again...

Earn

I know I did this very same thing to no avail.ÂÃ,  Now it works right off.ÂÃ,  Ain't that the way it goes... grrr.
Thanks Paul

Another question.ÂÃ,  How would I go about making the transparent static control more "self contained?"?ÂÃ,  Where the main program would just create it rather than creating a static control and then subclassing it?
Earn

Ionic Wind Support Team

Don't use AddControl.   Use the Create method of the CStatic control, which is inherited by your class.

AddControl is just designed to add the built in classes.
Ionic Wind Support Team