May 08, 2024, 01:15:52 PM

News:

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


Dialog window background

Started by Rock Ridge Farm (Larry), February 13, 2006, 09:15:04 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rock Ridge Farm (Larry)

Can the background of a dialog be changed?
How?

Parker

Dialog backgrounds can't be changed, but if a static control the full size of the dialog is created as the first control, you can set it to have an image or a color, and other controls created later will have precedence in the z-order so you will be able to see them.

Rock Ridge Farm (Larry)


Earn

Sure it can.ÂÃ,  Respond to the WM_CTLCOLORDLG message with a handle to a brush.

e.g.

case WM_CTLCOLORDLG
ÂÃ,  return CreateSolidBrush(RGB(10,10,160)) :'handle to a solid color brush

or use CreatePatternBrush(hBitmap) to use bitmap image or GetStockObject(StockObject) to use a stock object pattern.

Earn

Parker

Thanks. I'll have to keep that in mind. I was told it wasn't possible.

Bruce Peaslee

I, too, was told it wasn't possible, possibly by ParkerÂÃ,  :D

Anyway, it's something I wasn't aware of and very handy.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Rock Ridge Farm (Larry)

OK - now is someone going to explain this simply so I know what you are talking about?
To make Aurora attractive to the largest audiance, it needs to be simple enough for a dweeb
like me to understand.

Parker

Er... I'll try...

It was impossible in IBasic Standard because we couldn't do callbacks (an interpreter's functions don't have a real address like a compiled app's do), and since that's the first language I learned, I've just kind of assumed it wasn't possible. Although I have heard a couple of times how to do it, I've never actually done it so I forgot.

But you can, put #define WM_CTLCOLORDLG 310 at the top of your code. Then override the WndProc and handle that message like Earn said. Here's the declares too.

declare import, CreateSolidBrush (clr as unsigned int),unsigned int;
declare import, CreatePatternBrush (brush as unsigned int),unsigned int;


(yay, the color script for SMF works pretty well :D)

Bruce Peaslee

February 13, 2006, 10:29:29 PM #8 Last Edit: November 12, 2006, 05:38:37 PM by peaslee
Put the declares Parker listed and add this to your dialog class (my class is called QuickDialog):


QuickDialog::WndProc(unsigned int message, unsigned int wparam, unsigned int lparam)
{
  if (message = WM_CTLCOLORDLG)
    return CreateSolidBrush(RGB(255,0,0)); // for red

  return CWindow!!WndProc( message, wparam, lparam);
}


One should note that control colors might have to be adjusted as well to appear transparent.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Earn

OK now my turn to learn.ÂÃ, 

Let's say I use this all the time and want to create a CFancyDialog class that includes a ColorBackground(hBrush) function.ÂÃ,  How would this be implemented in Aurora?

Earn

Ionic Wind Support Team

Derive a class from Dialog, override the WndProc method as Bruce has shown, Add a member variable for the brush.

//put this in an include file.
class ColorDialog : dialog
{
//overrides
declare ColorDialog();
declare WndProc(unsigned int message, unsigned int wparam, unsigned int lparam),int;
//public methods
delcare SetBackColor(unsigned int cBack);
//member variables
unsigned int m_hBrush;
}

ColorDialog::ColorDialog()
{
m_hBrush = NULL;  //initial color is none, use whatever Windows wants.
}

ColorDialog::SetBackColor(unsigned int cBack)
{
m_hBrush = CreateSolidBrush(cBack);
}

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

  return dialog!!WndProc( message, wparam, lparam);
}

-----------------

Then just use ColorDialog as your base class for any dialog you want to be able to control the background color.  For example if your using the dialog editor and your create a dialog called "UserInfo" the editor will output:

class UserInfo:dialog
{
....
}

Which you simply change to

#include "colordlg.inc"
class UserInfo : ColorDialog
{
....
}


Paul.
Ionic Wind Support Team

Earn

Well thank you.ÂÃ,  That seems pretty simple.ÂÃ,  Do I assume correctly that the method that uses the class name [ColorDialog()] is called when an instance of the class is initiated?ÂÃ,  That's where you'd initialize any variables and....??ÂÃ, 
Earn

Ionic Wind Support Team

That is correct.  When you define a class variable

def a as someclass;

The compiler inserts code to call

someclass::someclass

Ionic Wind Support Team

Earn

Hmmmmm... I have it working in a single file compile but when I put the ColorDialog class into an include file I get a linking error:

Compiling...
ColorDlg.src
ColorDlg.inc

Linking...
Aurora Linker v1.0 Copyright ÂÃ,©2005 Ionic Wind Software
Unresolved external main
Error: Unresolved extern main
Error(s) in linking ColorDialog.exe


In another language that I use there's a $MAIN directive required. ;)ÂÃ,  Am I missing somthing like that here.

Ionic Wind Support Team

You need a main function to do something

global sub main()
{
}



Ionic Wind Support Team

Earn

February 15, 2006, 01:41:56 PM #15 Last Edit: February 23, 2006, 04:54:23 PM by Earn
Yep, got that from the skeleton handler of the dialog builder.

ColorDlg.src#include "ColorDlg.inc"

#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 UserInfo:ColorDialog
{
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
}

global sub main()
{
UserInfo d1;
d1.Create(0,0,300,202,0x80C80080,0,"Color Dialog",0);
d1.AddControl(CTEDIT,"Edit1",125,50,142,19,0x50800000,0x200,EDIT_1);
d1.AddControl(CTSTATIC,"First Name",48,52,70,20,0x5000010B,0x0,STATIC_2);
d1.AddControl(CTSTATIC,"Last Name",48,86,70,20,0x5000010B,0x0,STATIC_3);
d1.AddControl(CTEDIT,"Edit2",125,82,142,19,0x50800000,0x200,EDIT_4);
d1.AddControl(CTBUTTON,"Red",33,176,70,20,0x5000000B,0x0,BUTTON_5);
d1.AddControl(CTBUTTON,"Image",116,176,70,20,0x5000000B,0x0,BUTTON_6);
d1.AddControl(CTBUTTON,"Green",198,176,70,20,0x5000000B,0x0,BUTTON_7);
d1.SetBackColor(RGB(10,50,150));

d1.DoModal();
return 0;
}

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

UserInfo::OnInitDialog(),int
{
/* Initialize any controls here */
CenterWindow();
return true;
}

UserInfo::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;
}

ColorDlg.inc//put this in an include file.
#define WM_CTLCOLORDLG 310
declare import, CreateSolidBrush(clr as unsigned int),unsigned int;
declare import, CreatePatternBrush(brush 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;



class ColorDialog : CDialog
{
//overrides
declare ColorDialog();
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;
}

ColorDialog::ColorDialog()
{
m_hBrush = NULL;ÂÃ,  //initial color is none, use whatever Windows wants.
}

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 dialog!!WndProc( message, wparam, lparam);
}

Earn

Got it.  Had the ColorDlg.inc file inserted in the project.  Had to remove it from the project and it linked ok.