October 29, 2025, 12:56:11 PM

News:

IWBasic runs in Windows 11!


ListBox for in IWBasic with or without classes

Started by Techno, September 06, 2015, 04:53:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Techno

Hi all,

Can some one rewritten the demo example from aurora with and without using classes. I don't find any example demo in the iwbasic or ebasic directory
I want the learn how it works the listbox in IWBasic.
Thanks



#define IDC_LISTBOX 1000
#define IDC_EDIT 1001
#define IDC_ADD      1002
#define IDC_DELETE   1003
#define GROUP_6      1004
#define IDC_MOVEUP   1005
#define IDC_MOVEDOWN 1006

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

global sub main()
{
// note: CDlg.style has extra flag set: 0x800 = DS_CENTER;  0x80CA0880
// note: CTLISTBOX has extra bit set:   0x001 = LBS_NOTIFY; 0x50B10141
CDlg dlg;
dlg.Create(0,0,300,328,0x80CA0880,0,"Listbox example",0);
dlg.AddControl(CTLISTBOX,"",16,10,264,170,0x50B10141,0x200,IDC_LISTBOX);
dlg.AddControl(CTEDIT,"Click Add to move me to the listbox ->",20,215,192,20,0x50810080,0x200,IDC_EDIT);
dlg.AddControl(CTDEFBUTTON,"Add",217,214,70,21,0x50010001,0x0,IDC_ADD);
dlg.AddControl(CTBUTTON,"Delete/Edit",216,188,70,20,0x50010000,0x0,IDC_DELETE);
dlg.AddControl(CTGROUPBOX,"Move",18,240,60,69,0x50000007,0x0,GROUP_6);
dlg.AddControl(CTBUTTON,"Up",26,256,39,19,0x50010000,0x0,IDC_MOVEUP);
dlg.AddControl(CTBUTTON,"Down",26,279,39,19,0x50010000,0x0,IDC_MOVEDOWN);

dlg.DoModal();
return 0;
}

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

CDlg::OnInitDialog(),int
{
CListBox *listbox = GetControl(IDC_LISTBOX);
listbox->AddString("hello from first item");
listbox->AddString("Get & SetText in TextBoxes");
listbox->AddString("CDlg::OnInitDialog()");
listbox->AddString("unsigned int hControl");
listbox->AddString("Ionic Wind Software");
listbox->AddString("Powered by SMF 1.1.3");
listbox->AddString("Report to moderator");
listbox->AddString("« previous next »");
listbox->AddString("SMF © 2006-2007, Simple Machines LLC");

GetControl(IDC_DELETE)->Enable(false);
GetControl(IDC_MOVEUP)->Enable(false);
GetControl(IDC_MOVEDOWN)->Enable(false);
}


CDlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
CListBox *listbox = GetControl(IDC_LISTBOX);
CEdit    *edit    = GetControl(IDC_EDIT);
int selected = listbox->GetCurSel();
int count;

switch (nID | (nNotifyCode<<16))
{
case (IDC_LISTBOX | (LBNSELCHANGE<<16)): // selection in listbox has changed
count = listbox->GetCount();
int CanMoveUp = (selected > 0);
int CanMoveDown = (selected < (count-1));
GetControl(IDC_MOVEUP)->Enable(CanMoveUp);
GetControl(IDC_MOVEDOWN)->Enable(CanMoveDown);
GetControl(IDC_DELETE)->Enable(selected >= 0);

case (IDC_LISTBOX | (LBNDBLCLK<<16)): // listbox item was doubleclicked
if (selected > 0)
{
edit->SetText(listbox->GetItemText(selected));
}

case IDC_ADD: // button Add
listbox->AddString(edit->GetText());
edit->SetText("");
listbox->SetCurSel(listbox->GetCount()-1);
// force buttons update
OnControl(IDC_LISTBOX, LBNSELCHANGE, 0);

case IDC_DELETE: // button Delete/edit
if (selected != -1)
{
edit->SetText(listbox->GetItemText(selected));
listbox->DeleteString(selected);
}

case IDC_MOVEUP: // button Move up
if (selected > 0)
{
listbox->InsertString(selected-1, listbox->GetItemText(selected));
listbox->DeleteString(selected+1);
listbox->SetCurSel(selected-1);
}

case IDC_MOVEDOWN: // button Move down
count = listbox->GetCount();
if ((selected >= 0) && (selected < (count-1)))
{
listbox->InsertString(selected+2, listbox->GetItemText(selected));
listbox->DeleteString(selected);
listbox->SetCurSel(selected+1);
}
}
return true;
}

LarryMc

First of all, you don't need to create a CLASS for the Listbox control to work in IWBasic; doing so is a total was of time.

Using the Listbox Control like any other control is ample for implementing the Listbox.

And since that it is true I'm going to tell you like I've told you before:

Make an attempt on your own and then if you have specific questions we can help you.

The section in the Help file in the 3.03 version of IWBasic is still a WIP but it does contain all the fundamental info.
You have EBasic which contains all the info and you also have IWB+ which will generate the basic code structure for you.

So, like I said, try it on your on and then come back with your questions.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Techno

Quote from: LarryMc on September 06, 2015, 11:59:24 AM
First of all, you don't need to create a CLASS for the Listbox control to work in IWBasic; doing so is a total was of time.

Using the Listbox Control like any other control is ample for implementing the Listbox.

And since that it is true I'm going to tell you like I've told you before:

Make an attempt on your own and then if you have specific questions we can help you.

The section in the Help file in the 3.03 version of IWBasic is still a WIP but it does contain all the fundamental info.
You have EBasic which contains all the info and you also have IWB+ which will generate the basic code structure for you.

So, like I said, try it on your on and then come back with your questions.

What does it maen "WIP"?

billhsln

When all else fails, get a bigger hammer.

Andy

Here is an example listbox program I have written for you - see attached.

Hope that explains it for you.

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.