IonicWind Software

Aurora Compiler => Coding Help - Aurora 101 => Topic started by: Vikki on November 29, 2006, 10:17:42 AM

Title: Need help understanding code snippet
Post by: Vikki on November 29, 2006, 10:17:42 AM
Hi everyone,

I'm going to give it the good ol college try and work on learning Aurora. I am looking through examples and trying to make sense of them. I found one that made sense to me to a point but I need a little help in understanding what is happening.

ÂÃ,  ÂÃ,  select(nID)
ÂÃ,  ÂÃ,  {
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  case 1:
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  if(nNotifyCode = 0)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Destroy();
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  case 2:
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  if(nNotifyCode = 0)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  {
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  CControl *pControl = GetControl(4);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  MessageBox(this,"OK Pressed",pControl->GetText());
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  SetFocus(4);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  }
ÂÃ,  ÂÃ,  }


This is a snippet from some code in the user guide.

First I don't understand why both cases use the same test. What is getting destroyed in the first test?

What happens is you enter your name in an edit box and click ok. Your name is then placed in the title bar of the window and a message box pops up. I can see that that happens in the second test but I can't see how what you enter in the text box gets placed in the title bar.

So, I understand that CControl is the control class. Is pControl a pointer to a control in that class?

I understand that GetControl(4) is getting the edit control and I understand kind of the GetText() and SetFocus(4) but how in the world is the text that is gotten placed in the title bar. I can't see where or how that happens.

I appreciate any help I can get.ÂÃ,  ;D



Full code of the example is below.

class kLearning : CWindow
{
ÂÃ,  ÂÃ,  declare virtual OnClose(),int;
ÂÃ,  ÂÃ,  declare virtual OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
ÂÃ,  ÂÃ,  declare virtual OnCreate(),int;
}

global sub main()
{
ÂÃ,  ÂÃ,  kLearning win;
ÂÃ,  ÂÃ,  win.Create(0,0,800,600,AWS_VISIBLE|AWS_SYSMENU,0,"Kids Learning",NULL);
ÂÃ,  ÂÃ,  win.EnableTabs(1);
ÂÃ,  ÂÃ,  win.AddControl(CTBUTTON,"Close",45,157,70,20,0x50000000|AWS_TABSTOP,0x0,1);
ÂÃ,  ÂÃ,  win.AddControl(CTBUTTON,"OK",183,157,70,20,0x50000001|AWS_TABSTOP,0x0,2);
ÂÃ,  ÂÃ,  win.AddControl(CTGROUPBOX,"Enter Your Name",19,10,254,134,0x50000007,0x0,3);
ÂÃ,  ÂÃ,  win.AddControl(CTEDIT,"",39,42,218,21,0x50800000|AWS_TABSTOP,0x200,4);
ÂÃ,  ÂÃ,  win.SetFocus(4);
ÂÃ,  ÂÃ,  win.GetControl(3)->SetColor(0,0xFFFFFF);
ÂÃ,  ÂÃ,  do{ wait();} until !win.IsValid();
}

kLearning::OnCreate()
{
ÂÃ,  ÂÃ,  CenterWindow();
ÂÃ,  ÂÃ,  return 0;
}

kLearning::OnClose()
{
ÂÃ,  ÂÃ,  Destroy();
ÂÃ,  ÂÃ,  return 0;
}

kLearning::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
ÂÃ,  ÂÃ,  select(nID)
ÂÃ,  ÂÃ,  {
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  case 1:
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  if(nNotifyCode = 0)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  Destroy();
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  case 2:
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  if(nNotifyCode = 0)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  {
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  CControl *pControl = GetControl(4);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  MessageBox(this,"OK Pressed",pControl->GetText());
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  SetFocus(4);
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  }
ÂÃ,  ÂÃ,  }
return 0;
}
Title: Re: Need help understanding code snippet
Post by: Vikki on November 29, 2006, 10:26:44 AM
Oh crud! Well some of it just came to me in a vision... ::)  ...

Case 1 and 2 are the control ids. Ok, I got that but I still don't understand the rest.
Title: Re: Need help understanding code snippet
Post by: Vikki on November 29, 2006, 10:31:47 AM
Ok, so I'm up to my old tricks again  :P *slaps forheard*

I got it. Sorry for the forum clutter with this thread.

Egads!
Title: Re: Need help understanding code snippet
Post by: Ionic Wind Support Team on November 29, 2006, 11:58:59 AM
So you understand now? 
Title: Re: Need help understanding code snippet
Post by: Vikki on November 29, 2006, 12:18:27 PM
I understand most of it. :)

I'm still not sure about:

CControl *pControl = GetControl(4);
......pControl->GetText()

Where did *pControl come from and why are we getting the edit control and getting the text. Is it like setting focus to the edit control and then getting the text?

I need to know this...  ;D ...

I think this might help me with how to control a child window from a control in another window maybe?
Title: Re: Need help understanding code snippet
Post by: Ionic Wind Support Team on November 29, 2006, 12:23:38 PM
CControl - is the name of a class, it is the base class of all controls.
CControl *pControl - is a pointer to a CControl class, just like a pointer to a udt.
CControl *pContol = GetControl(4)  - Returns a pointer to the control with an ID of 4.

GetControl is being executed in the context of whatever class the snippit came from.  And would be the same as this->GetControl(4)

pControl->GetText() - Retrieves the text from the control with the id of 4.

Paul.
Title: Re: Need help understanding code snippet
Post by: Vikki on November 29, 2006, 12:29:40 PM
Thank you very much. I can't believe that I actually understood what you said.

Now, I should be able to move on.  :D  Weehoo!
Title: Re: Need help understanding code snippet
Post by: Vikki on November 30, 2006, 08:58:43 AM
Ok, so now I'm trying to change the color of the tab control. Maybe that's not possible?

Anywho, I've read through the colorcontrol.src but it's in a dialog and maybe that's my problem. I'm using a window. Anywho I have in OnCreate()

CControl *pControl = GetControl(2);
pControl->SetColor(RGB(0,0,0),RGB(0,0,0));

Now I know that both fore and background are set to black but this is just for testing. :)

Just to spice things up I've adapted Jerry's tactic of random variable assignment to move this snippet around through my code to no avail. It's back in OnCreate() and nothing happens. I also tried:

tab1.SetColor(RGB(0,0,0),RGB(0,0,0));

also to no avail. And while I'm here I can't figure out why the flatbuttons and flatseperators styles don't seem to be working for me. I tried to add the ownerdrawfixed to the styles and it didn't seem to change anything except removing my text from the tabs.

Any ideas? *I know you have ideas like maybe slapping me but you'll have to 'beat' me to it*ÂÃ,  ÂÃ, ::)
Title: Re: Need help understanding code snippet
Post by: Ionic Wind Support Team on November 30, 2006, 09:01:38 AM
OnCreate is called when the window is created, but before the Create method returns.  So your control probably doesn't exist yet.

win.Create(....   //OnCreate called
win.AddControl(...  //Control is created
//now the controls can be accessed
CControl *pControl = GetControl(2);
pControl->SetColor(RGB(0,0,0),RGB(0,0,0));
Title: Re: Need help understanding code snippet
Post by: Vikki on November 30, 2006, 09:06:38 AM
You'd be surprised to know that I thought that exact same thing!!!ÂÃ,  ;D However, I've got it after the creation stuff so I'm not sure now. Also, in the code below I don't have the ownerdrawnfixed because it didn't change anything for me when I had it there.

Here's the whole onCreate:


hEditor::OnCreate(),int
{
tab1.Create(0,0,640,480,AWS_BORDER|AWS_VISIBLE|AWS_TABSTOP|ATCS_FLATBUTTONS|ATCS_EX_FLATSEPARATORS|ATCS_TOOLTIPS|ATCS_HOTTRACK,TABID,"",this);
tab1.SetFont("Arial",12,400,0);
tab1.InsertTab(0,"HTML");
tab1.InsertTab(1,"CSS");
tab1.InsertTab(2,"JavaScript");
tab1.InsertTab(3,"VBScript");
tab1.InsertTab(4,"PHP");
//tooltips for the tabs
tab1.SetTip (0,tab1.GetTabText(0));
tab1.SetTip (1,tab1.GetTabText(1));
tab1.SetTip (2,tab1.GetTabText(2));
tab1.SetTip (3,tab1.GetTabText(3));
tab1.SetTip (4,tab1.GetTabText(4));

CControl *pControl = GetControl(2);
pControl->SetColor(RGB(200,200,0),RGB(255,255,255));

//HTML
rEdit.Create(6,70,615,370,0x50B010C4,IDRichEdit,"",this);
rEdit.SHOWWINDOW(SWSHOW);

//CSS
rCSS.Create(6,70,615,370,0x50B010C4,IDCSS,"",this);

//JavaScript
rJS.Create(6,70,615,370,0x50B010C4,IDJS,"",this);


//VBScript
rVB.Create(6,70,615,370,0x50B010C4,IDVBSCRIPT,"",this);

//PHP
rPHP.Create(6,70,615,370,0x50B010C4,IDPHP,"",this);

CenterWindow();
return true;
}


Edit:

And I tried putting it in sub main in several different ways and it still didn't work.
Title: Re: Need help understanding code snippet
Post by: Ionic Wind Support Team on November 30, 2006, 09:36:51 AM
Actually, having a slapping head moment, tab controls don't respond to SetColor the way other controls do.  Also ATCS_EX_FLATSEPARATORS can't be specified in the style.  It has to be sent to the control using the TCM_SETEXTENDEDSTYLE message. 

I'll wrap that message in the next update. 

As for the colors...searching the net now.

Title: Re: Need help understanding code snippet
Post by: Vikki on November 30, 2006, 09:51:26 AM
Cool! Thank you!!
Title: Re: Need help understanding code snippet
Post by: Vikki on November 30, 2006, 12:14:53 PM
I got it!!! Flat tabs!! Weeehooo!