home *** CD-ROM | disk | FTP | other *** search
- // Listbox.cpp : Defines the initialization routines for the DLL and the exported functions
- // High Tech BASIC, Copyright (C) TransEra Corp 1999, All Rights Reserved.
- //
- /*************************************************************************
- * *
- * ListBox DLL (Win32 / MFC) *
- * Author: Sven Henze, Tech Soft GmbH *
- * Date: 03-Sep-1999 *
- * Last Update: 28-Sep-1999 *
- * *
- * This code is intended for the usage under BASIC for Windows V8.X *
- * *
- * Version info: *
- * 03-Sep-1999 V1.0▀ Initial release of DLL *
- * 27-Sep-1999 Getselitems added *
- * 14-Oct-1999 Bug repaired (new/edit in single selection style) *
- * *
- *************************************************************************/
-
-
- #include "stdafx.h"
- #include "Listbox.h"
- #include "ListboxDlg.h"
- #include "DialogThread.h"
- #include "assert.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
-
- //
- // Note!
- //
- // If this DLL is dynamically linked against the MFC
- // DLLs, any functions exported from this DLL which
- // call into MFC must have the AFX_MANAGE_STATE macro
- // added at the very beginning of the function.
- //
- // For example:
- //
- // extern "C" BOOL PASCAL EXPORT ExportedFunction()
- // {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // // normal function body here
- // }
- //
- // It is very important that this macro appear in each
- // function, prior to any calls into MFC. This means that
- // it must appear as the first statement within the
- // function, even before any object variable declarations
- // as their constructors may generate calls into the MFC
- // DLL.
- //
- // Please see MFC Technical Notes 33 and 58 for additional
- // details.
- //
-
- /////////////////////////////////////////////////////////////////////////////
- // CListBoxApp
-
- BEGIN_MESSAGE_MAP(CListBoxApp, CWinApp)
- //{{AFX_MSG_MAP(CListBoxApp)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CListBoxApp construction
-
- CListBoxApp::CListBoxApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CListBoxApp object
-
- CListBoxApp theApp;
-
-
- //****************************************************************************************************
- // begin global variables -- used to communicate between threads and different instances of classes
-
-
- ListboxDlg *g_plistDlg = NULL; // global pointer to button dialog used for setting focus and closing
- CWnd *g_pWnd; // global pointer to Dialog
- CWinThread *pThread;
-
- long g_Width; // width of the dialog box
- long g_Height; // the height of the window
- short g_ButtAppear;
- CString g_Title; // Window title
- CString g_Description; // Text above buttons will wrap to two lines if too long
- CString g_Lstrings;
- CListBox *g_pList; // global pointer to listbox control
-
- // end global variables
- //***************************************************************************************************
- // begin global functions not exported
-
- // end global functions not exported
- //*****************************************************************************************************
- // begin exported functions
-
-
- // Showlistbox is the main function for setting up and displaying the ListBox dialog box.
- // Params:
- // height is the desired height of the dialog window
- // width is the desired width of the dialog window and buttons
- // appearance is a variable which controls the apearance of the dialog
- // title is the text for the window title
- // description is the text for the group frame
-
- short Showlistbox(long height,long width,short appearance, char * title,char * description)
- { AFX_MANAGE_STATE(AfxGetStaticModuleState());
-
- short result = 0;
-
- if (g_plistDlg == NULL) // Button dialog already active
- {
- if (height < MINHEIGHT || height > MAXHEIGHT)
- {
- g_Height = MAXHEIGHT; // default to MAXLINES lines for bad input
- }
- else
- {
- g_Height = height; // save current number of visible lines
- }
-
- g_Width = width; // save width
- g_ButtAppear = appearance;
-
- g_Title = title;
- g_Description = description;
-
-
- pThread = AfxBeginThread(RUNTIME_CLASS (DialogThread)); // create thread to execute dialog
- Sleep(50); // wait until the thread is ready
- result = 1;
-
- }
-
- return(result);
- }
-
-
- // end Showbutton
- //*****************************************************************************************
- // Setfocus -- used to bring the ListBox dialog box to the foreground and activate.
-
-
- void Setfocus()
- {
- SetForegroundWindow(g_plistDlg->m_hWnd); // bring window to foreground and activate
- }
-
-
- // end Setfocus
- //*****************************************************************************************
- // Closebutton -- Used to close ListBox dialog box when running in its own thread.
-
-
- void Closelistbox()
- {
- if (g_plistDlg != NULL)
- {
- // now sets the return value !
-
- g_plistDlg->KillTimer(1); // stop timer from updating dialog
- g_plistDlg->EndDialog(0); // close dialog and allow spawned thread to run out
- g_plistDlg = NULL; // reset pointer to dialog
- //Sleep(0); // This line allows the thread to shut down before Basic regains control
- }
- }
-
-
- // end CloseListBox
- //*****************************************************************************************
- /////////////////////////////////////////////////////////////////////////////
-
-
- /******** Exported functions ***********/
-
-
- // ********** Addstring **********
- // Add a string to the ListBox (includes sorting)
- //
- // HTB Usage:
- // DLL GET "VOID Listbox:Addstring"
- // DIM A$[128]
- // A$="Hello"
- // Addstring("Teststring")
- // Addstring(A$) ! adds string "Hello"
- //
- void Addstring(char* str)
- {
-
- // ASSERT(g_pList != NULL);
-
- if (g_pList != NULL)
- {
- g_pList->AddString( str );
- }
-
- } // End (Addstring)
-
-
- // ********** Insertstring **********
- // Inserts a string to the ListBox at a specified position
- //
- // HTB Usage:
- // DLL GET "VOID Listbox:Insertstring"
- // DIM A$[128]
- // INTEGER P
- // A$="Hello"
- // P=8
- // Addstring(3,"Teststring")
- // Addstring((P),A$)
- //
- void Insertstring(short sel, char * str)
- {
-
- // ASSERT(g_pList != NULL);
-
- if (g_pList != NULL)
- {
- g_pList->InsertString( sel-1, str );
- }
-
- } // End (Insertstring)
-
-
- // ********** Getcount **********
- // Get number of items in ListBox
- //
- // HTB Usage:
- // DLL GET "SHORT Listbox:Getcount"
- // INTEGER P
- // P=FNGetcount
- //
- short Getcount()
- {
-
- // ASSERT(g_pList != NULL);
-
- int cnt;
-
- if (g_pList == NULL)
- {
- Sleep(50); // wait until the thread is ready
- }
-
- if (g_pList != NULL)
- {
- cnt=g_pList->GetCount();
- }
-
- return(cnt);
-
- } // End (Getcount)
-
-
-
- // ********** Setsel **********
- // set/toggle selection of a ListBox item
- //
- // HTB Usage:
- // DLL GET "VOID Listbox:Setsel"
- // INTEGER Sel
- // Sel=9
- // Setsel((Sel))
- // Setsel(5)
- //
- void Setsel(short sel)
- {
-
- bool selstat;
-
- selstat = ((g_pList->GetSel(sel-1)) == 0);
-
- if( SingleSelection )
- { // single selection listbox
- if (g_pList != NULL)
- {
- g_pList->SetCurSel((int)sel-1);
- }
-
- }
- else
- { // multiple selection listbox
- if (g_pList != NULL)
- {
- g_pList->SetSel((int)sel-1,selstat);
- }
-
- }
-
- } // End (Setsel)
-
-
-
- // ********** Getsel **********
- // Retrieves the selection state of a ListBox item
- //
- // HTB Usage:
- // DLL GET "SHORT Listbox:Getsel"
- // INTEGER Sel,Gsel
- // Sel=9
- // Gsel=FNGetsel((Sel))
- // Gsel=FNGetsel(5)
- //
- short Getsel(short sel)
- {
-
- int selstat = 0;
-
- if (g_pList != NULL)
- {
- selstat = g_pList->GetSel((int)sel-1);
-
- if (selstat==LB_ERR)
- {
- selstat = 0;
- }
-
- if (selstat > 0)
- {
- selstat = 1;
- }
-
- }
-
- return(selstat);
-
- } // End (Getsel)
-
-
-
- // ********** Getselcount **********
- // Retrieves the number of selected items in ListBox
- // works with both single and multiple listboxes !
- //
- // HTB Usage:
- // DLL GET "SHORT Listbox:Getselcount"
- // INTEGER Gselcnt
- // Gselcnt=FNGetselcount
- //
- short Getselcount()
- {
-
- int selstat;
-
- if( SingleSelection )
- {
- if (g_pList != NULL)
- {
- selstat = g_pList->GetCurSel();
- }
-
- if ( selstat == LB_ERR )
- {
- selstat = 0;
- }
- else
- {
- selstat=1;
- }
-
- }
- else
- {
- if (g_pList != NULL)
- {
- selstat = g_pList->GetSelCount();
- }
-
- if ( selstat == LB_ERR )
- {
- selstat = 0;
- }
-
- }
-
- return(selstat);
-
- } // End (Getselcount)
-
-
-
- // ********** Deletestring **********
- // Deletes an item in a ListBox
- //
- // HTB Usage:
- // DLL GET "VOID Listbox:Deletestring"
- // INTEGER Sel
- // Sel=9
- // Deletestring((Sel))
- // Deletestring(4)
- //
- void Deletestring(short sel)
- {
-
- int selstat;
-
- if (g_pList != NULL)
- {
- selstat = g_pList->DeleteString((int)sel-1);
-
- }
-
- } // End (Deletestring)
-
-
-
- // ********** Resetcontent **********
- // Resets the content of a ListBox
- //
- // HTB Usage:
- // DLL GET "VOID Listbox:Resetcontent"
- // Resetcontent
- //
- void Resetcontent()
- {
- if (g_pList != NULL)
- {
- g_pList->ResetContent();
- }
-
- } // End (Resetcontent)
-
-
-
- // ********** Getsel **********
- // Shows files and directories
- //
- // HTB Usage:
- // DLL GET "VOID Listbox:Dirlist"
- // INTEGER Attr
- // DIM Wildc$[256]
- // Gsel=FNDirlist(Attr, Wildc$)
- //
- void Dirlist( short attr, char * wildcards)
- {
- if (g_pList != NULL)
- {
- g_pList->Dir( attr, wildcards );
-
- }
-
- } // End (Dirlist)
-
-
-
- // ********** Findstring **********
- // Find the first appearance of a string in a ListBox (not case-sensitive)
- //
- // HTB Usage:
- // DLL GET "SHORT Listbox:Findstring"
- // DIM Search$[128]
- // INTEGER Start
- // A$="Search string"
- // Start=8 ! Search start at listbox entry 8
- // Findstring(8,(Search$))
- // Findstring((Start),"Search for")
- //
- short Findstring( short start, char * search )
- {
- int result = 0;
-
- if (g_pList != NULL)
- {
- if(search != NULL)
- {
- result = g_pList->FindString( (int)start-1, search );
-
- if (result == LB_ERR)
- {
- result = 0;
- }
- else
- {
- result++;
- }
-
- } // search not NULL
-
- } // g_pList not NULL
-
- return(result);
-
- } // End (Findstring)
-
-
-
- // ********** Findstringexact **********
- // Find a complete string in a ListBox (case-sensitive)
- //
- // HTB Usage:
- // DLL GET "SHORT Listbox:Findstringexact"
- // DIM Search$[128]
- // INTEGER Start
- // A$="Complete search string"
- // Start=0 ! Search the whole list box
- // Findstringexact(8,(Search$))
- // Findstringexact((Start),"Search for complete string")
- //
- short Findstringexact( short start, char * search )
- {
- int result = 0;
-
- if (g_pList != NULL)
- {
- if(search != NULL)
- {
- result = g_pList->FindStringExact( (int)start-1, search );
-
- if (result == LB_ERR)
- {
- result = 0;
- }
- else
- {
- result++;
- }
-
- } // search not NULL
-
- } // g_pList not NULL
-
- return(result);
-
- } // End (Findstringexact)
-
-
-
- // ********** Gettextlen **********
- // Returns the string length of a specified ListBox entry
- //
- // HTB Usage:
- // DLL GET "SHORT Listbox:Gettextlen"
- // INTEGER Sel
- // Sel=4
- // Gettextlen((Sel))
- // Gettextlen(10)
- //
- short Gettextlen( short sel )
- {
- int result;
- if (g_pList != NULL)
- {
- result = g_pList->GetTextLen( (int)sel-1);
-
- if (result == LB_ERR)
- {
- result = 0;
- }
- else
- {
- result += 5; // just to be sure !
- }
-
- }
- else
- {
- result = NULL;
- }
-
- return(result);
-
- } // End (Gettextlen)
-
-
-
- // ********** Gettext **********
- // Returns the string of a specified listbox entry
- //
- // HTB Usage:
- // DLL GET "VOID Listbox:Gettext"
- // DIM Text$[256]
- // INTEGER Sel
- // Sel=4
- // Gettext((Sel), Text$)
- // Gettext(10, Text$)
- //
- void Gettext( short sel, char *item )
- {
- int result;
-
- if (g_pList != NULL)
- {
- if (item != NULL)
- {
- result = g_pList->GetText( (int)sel-1, item);
-
- if (result == LB_ERR)
- {
- *item = '\0'; // zero string indicates error !
-
- } // got an error
-
- } // item not NULL
-
- } // g_pList not NULL
-
- } // End (Gettext)
-
-
-
- // ********** Getselitems **********
- // Returns a list of all selected items. Not for single selection listboxes !
- // If called for a single selection listbox it returns -1
- //
- // HTB Usage:
- // DLL GET "VOID Listbox:Getselitems"
- // INTEGER Getlist(100)
- // INTEGER Maxitems
- // MAT Getlist=(0)
- // Getselitems(10, Getlist(*))
- // Maxitems=SIZE(Getlist,1)
- // Getselitems((Maxitems), Getlist(*))
- //
- short Getselitems( short nMaxItems, short* iarray)
- {
- if (SingleSelection)
- {
- return(-1); // does not work with single selection style
- }
-
- short i;
-
- for ( i = 1; i <= nMaxItems; i++)
- {
- if ( Getsel(i)==1 )
- {
- *iarray++ = i;
- }
-
- } // for loop
-
- return(0);
-
- } // End (Getselitems)
-
-
-
- // ********** Getcursel **********
- // Returns the index of the selected item (or 0 if no item is selected).
- // Only for single selection style listboxes
- //
- // HTB Usage:
- // DLL GET "SHORT Listbox:Getcursel"
- // INTEGER Cursel
- // Cursel=FNGetcursel
- // Maxitems=SIZE(Getlist,1)
- // Getcursel((Maxitems), Getlist(*))
- //
- short Getcursel()
- {
- int result;
-
- if (SingleSelection)
- {
- if (g_pList != NULL)
- {
- result = g_pList->GetCurSel();
-
- if (result == LB_ERR)
- {
- result = 0; // zero indicates error !
- }
- else
- {
- result++;
- }
-
- } // list not NULL if statement
- else
- {
- result = 0;
- }
-
- }
- else
- {
- result = -1; // does only work with single selection style
- }
-
- return(result);
-
- } // End (Getcursel)
-