IonicWind Software

Aurora Compiler => GUI => Topic started by: Jeffers on May 02, 2006, 01:53:06 PM

Title: Whew!
Post by: Jeffers on May 02, 2006, 01:53:06 PM
Hi all. Just got started and am working out Aurora.

I can get a dialog showing a listview, but I cant get a window to do it!

I can get a window to show a menu, but not a dialog.

Can anyone give me any pointers? I am trying very slowly to understand and I am taking small steps, but I fear not small enough! :-[

Regards Jeff :)
Title: Re: Whew!
Post by: Zen on May 02, 2006, 01:56:50 PM
Hi Jeffers. I havnt really delved into the realms of Aurora GUI yet. I've been way to busy with a few other things but i dont think you can put menus on dialogs can you? Or maybe you can but just not meant to. But the dialog class is inherited from the window class so i dont see why not.

Lewis
Title: Re: Whew!
Post by: Mike Stefanik on May 02, 2006, 01:57:44 PM
It'd probably be helpful if you could show us the code you've tried. If it's relatively short, you can just put it inside code tags in your message. Larger programs can be zipped up and attached to messages (click on the Additional Options link below the message edit window).
Title: Re: Whew!
Post by: Jeffers on May 02, 2006, 02:13:43 PM
Hi Mike/ Lewis.

What I would normally do with IB is too design the window as a base and build dialogs around it. What I am trying to learn is how to do the same thing using Aurora. I can create a window with menus and a listview control, but I havent figured out how to insert columns and size them. Example below.....

This compiles ok but crashes on execution.

image attached. error info.

The only reason I tried building a dialog is that the listview control is documented in the forum, and that menu creation is possible in IB. scuse the IB references, its the only language I know. :-[

Regards Jeff :)

/*Windows Skeleton
Compile as a WINDOWS target*/
struct NMLISTVIEW
{
def hwndFrom as unsigned int;
def idFrom as INT;
def code as INT;
    def iItem as INT;
    def iSubItem as INT ;
    def uNewState as unsigned int;
    def uOldState as unsigned int;
    def uChanged as unsigned int;
    def ptActionx as INT;
def ptActiony as INT;
    def lParam as INT;
}

#define LISTVIEW_1 1

class SkelWin : CWindow
{
//virtual overrides used by our window
declare OnCreate(),int;
declare OnClose(),int;
declare OnMenuPick(int nID),int;
declare OnSize(int nType,int cx,int cy),int;
declare OnMenuInit(unsigned int hmenu),int;
//variables used by our window
int l,t,w,h,size,run;
}

SkelWin::OnCreate(),int
{
CenterWindow();
CListView *pList = GetControl(LISTVIEW_1);
pList->InsertColumn(0,"Title");
pList->InsertColumn(1,"Description");
plist->InsertColumn(2,"Link");
plist->SetColumnWidth(0,200);
pList->SetColumnWidth(1,350);
plist->SetColumnWidth(2,335);

pList->SetExtendedStyle(ALVS_EX_FLATSB|ALVS_EX_FULLROWSELECT|ALVS_EX_GRIDLINES|ALVS_EX_LABELTIP);
size = 1;
run = 1;
return true;
}

SkelWin::OnClose(),int
{
run = 0;
return true;
}

SkelWin::OnMenuPick(int nID),int
{
select( nID )
{
case 1:
//Connect();
CASE 5:
//Quit
run = 0;
}
return true;
}

SkelWin::OnSize(int nType,int cx,int cy),int
{
rc = GetClientRect();
l = rc.Left;
t = rc.Top;
w = rc.Right - rc.Left;
h = rc.Bottom - rc.Top;
return true;
}

SkelWin::OnMenuInit(unsigned int hmenu),int
{
CMenu m;
m.Attach(hmenu);
m.Detach();
DrawMenuBar();
return false;
}

global sub main()
{
SkelWin win;
CMenu m;
m.BeginMenu();
m.MenuTitle("&File");
m.MenuItem("Connect",0,1);
m.MenuItem( "Quit",0,5 );
m.EndMenu();

win.Create(0,0,895,555,AWS_CAPTION|AWS_VISIBLE|AWS_BORDER|AWS_SYSMENU|AWS_AUTODRAW|AWS_SIZE,0,"Skel",NULL);
win.SetMenu(m.Detach());
win.AddControl(CTLISTVIEW,"",1,1,892,550,AWS_VISIBLE|ALVS_REPORT|AWS_BORDER,AWS_EX_CLIENTEDGE,LISTVIEW_1);

do
{
wait();
}until win.run = 0;
return;
//'win' is automatically closed here since the class destructor calls Destroy();
}

Title: Re: Whew!
Post by: Ionic Wind Support Team on May 02, 2006, 02:14:30 PM
A menu can be added to a dialog in the OnInitDialog handler.  Until then the dialog doesn't exist.

You can add any control to a window by using the AddControl method of the window class.

See the addressbook.src example showing a menu in a dialog.

This example shows how to add controls to a window:


//TestWindow definition
class TestWindow : CWindow
{
declare virtual OnClose(),int;
declare virtual OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
declare virtual OnCreate(),int;
}

global sub main()
{
TestWindow win;
win.Create(0,0,300,212,AWS_VISIBLE|AWS_SYSMENU,0,"Test Window",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);
CControl *pControl = win.GetControl(3);
pControl->SetColor(0,0xFFFFFF);
do{ wait();} until !win.IsValid();
}

TestWindow::OnCreate()
{
CenterWindow();
return 0;
}

TestWindow::OnClose()
{
Destroy();
return 0;
}

TestWindow::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: Whew!
Post by: Jeffers on May 02, 2006, 02:20:50 PM
Thanks Paul. How about a listview control? I can create it ok but cannot find the right place to place the config info i.e.

CListView *pList = GetControl(LISTVIEW_1);
pList->InsertColumn(0,"Title");
pList->InsertColumn(1,"Description");
plist->InsertColumn(2,"Link");
plist->SetColumnWidth(0,200);
pList->SetColumnWidth(1,350);
plist->SetColumnWidth(2,335);


Regards Jeff :)
Title: Re: Whew!
Post by: Ionic Wind Support Team on May 02, 2006, 02:25:53 PM
Depends.

In a dialog you should initialize any control in OnInitDialog.  Just like in IB.

For a window you can initialize it right after it is created with AddControl.  OnCreate is not a suitable place since the control would not have been added to your window yet.

win.Create(0,0,895,555,AWS_CAPTION|AWS_VISIBLE|AWS_BORDER|AWS_SYSMENU|AWS_AUTODRAW|AWS_SIZE,0,"Skel",NULL);

Calls OnCreate before it returns so your program would not have gotten to the AddControl statement yet.

In either case it is good programming practice to check pointer return values:


CListView *pList = GetControl(LISTVIEW_1);
if(pList)
{
    pList->InsertColumn(0,"Title");
    pList->InsertColumn(1,"Description");
    plist->InsertColumn(2,"Link");
    plist->SetColumnWidth(0,200);
    pList->SetColumnWidth(1,350);
    plist->SetColumnWidth(2,335);
}


Title: Re: Whew!
Post by: Ionic Wind Support Team on May 02, 2006, 02:28:18 PM
You could, of course, move the AddControl statement to OnCreate like so:


SkelWin::OnCreate(),int
{
   CenterWindow();
   AddControl(CTLISTVIEW,"",1,1,892,550,AWS_VISIBLE|ALVS_REPORT|AWS_BORDER,AWS_EX_CLIENTEDGE,LISTVIEW_1)
   CListView *pList = GetControl(LISTVIEW_1);
   pList->InsertColumn(0,"Title");
   pList->InsertColumn(1,"Description");
   plist->InsertColumn(2,"Link");
   plist->SetColumnWidth(0,200);
   pList->SetColumnWidth(1,350);
   plist->SetColumnWidth(2,335);

   pList->SetExtendedStyle(ALVS_EX_FLATSB|ALVS_EX_FULLROWSELECT|ALVS_EX_GRIDLINES|ALVS_EX_LABELTIP);
   size = 1;
   run = 1;
   return true;
}
Title: Re: Whew!
Post by: Jeffers on May 02, 2006, 02:41:53 PM
Sorry I tried both suggestions, I got different compiler errors each time.

Regards Jeff :'(

Quote(1) Code placed in OnCreate()
Compiling...
Window.src
File: F:\My Documents\Programming\Aurora\RSS\Window.src (36) syntax error - CListView
File: F:\My Documents\Programming\Aurora\RSS\Window.src (123) unexpected end of file: SUB -

Error(s) in compiling "F:\My Documents\Programming\Aurora\RSS\Window.src"

(2) Code placed in 'global sub main()'
Compiling...
Window.src
File: F:\My Documents\Programming\Aurora\RSS\Window.src (93) Warning: undeclared function 'GetControl'
F:\My Documents\Programming\Aurora\RSS\Window.src:92: error: symbol `GetControl' undefined
F:\My Documents\Programming\Aurora\RSS\Window.src:111: error: phase error detected at end of assembly.
Error(s) in assembling "F:\My Documents\Programming\Aurora\RSS\Window.asm"
Title: Re: Whew!
Post by: Ionic Wind Support Team on May 02, 2006, 02:50:36 PM
Because of a missing semicolon at the end of the AddControl line.
Title: Re: Whew!
Post by: Jeffers on May 02, 2006, 03:03:30 PM
hehe. Thanks Paul. Now that works ok by placing the code in OnCreate(), however using


win.AddControl(CTLISTVIEW,"",1,1,892,550,AWS_VISIBLE|ALVS_REPORT|AWS_BORDER,AWS_EX_CLIENTEDGE,LISTVIEW_1);
CListView *pList = GetControl(LISTVIEW_1);
if(pList)
{
    pList->InsertColumn(0,"Title");
    pList->InsertColumn(1,"Description");
    plist->InsertColumn(2,"Link");
    plist->SetColumnWidth(0,200);
    pList->SetColumnWidth(1,350);
    plist->SetColumnWidth(2,335);
pList->SetExtendedStyle(ALVS_EX_FLATSB|ALVS_EX_FULLROWSELECT|ALVS_EX_GRIDLINES|ALVS_EX_LABELTIP);
}


Still causes a compiler error related to GetControl. i.e.

QuoteCompiling...
Window.src
File: F:\My Documents\Programming\Aurora\RSS\Window.src (105) Warning: undeclared function 'GetControl'
F:\My Documents\Programming\Aurora\RSS\Window.src:104: error: symbol `GetControl' undefined
F:\My Documents\Programming\Aurora\RSS\Window.src:123: error: phase error detected at end of assembly.
Error(s) in assembling "F:\My Documents\Programming\Aurora\RSS\Window.asm"

Regards Jeff :)
Title: Re: Whew!
Post by: Ionic Wind Support Team on May 02, 2006, 03:10:39 PM
GetControl is a method of the Window class.  So if you are using it outside of a class method you need to specify the variables.

win.GetControl(...)

Get it ?
Title: Re: Whew!
Post by: Jeffers on May 02, 2006, 03:30:47 PM
 ;D Getting there!

Thanks Paul.

Regards Jeff :)