May 08, 2024, 05:35:21 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Help

Started by Rock Ridge Farm (Larry), February 10, 2006, 08:51:41 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rock Ridge Farm (Larry)

I have a problem.
I want to add a listview to the following code to be used in the DoViewData
subroutine.
I can not get it to work - can anyone help?

/*
+--------------------------------------------------------------------------+
| Aurora Stock Keeper - example program for Aurora                         |
| (c)2006 Lawrence H. Sikes                                                |
| No part of this code may be reporduced or used without prior consent.    |
+--------------------------------------------------------------------------+
| Compile as a windows exe                                                 |
+--------------------------------------------------------------------------+
| Track stocks in a mdb database                                           |
+--------------------------------------------------------------------------+
*/

#AutoDefine "off"
#use "shell32.lib"


// *************************************************************************
// *                      VARIABLE DEFINITIONS                             *
// *************************************************************************

#define LISTVIEW_1 1

string version = "Version 1.0  2/06/2006";

import int LoadImage alias LoadImageA(int hInstance,string *lpszName,int uType,int cxDesired,int cydesired,int fuLoad);

import int DeleteObject(int obj);
import int GetObject alias GetObjectA(int hgdiobj, int cbBuffer, void *lpvObject);

import int BitBlt(int hdcDest,int nXDest,int nYDest,int nWidth,
int nHeight,int hdcSrc,int nXSrc,int nYSrc,int dwRop);

CListView *pList;

// *****************************************************************************
// *                              GLOBAL CONSTANTS                             *
// *****************************************************************************

// Style constants not yet in system includes
const DS_MODALFRAME  = 0x0080;
const GCL_HCURSOR    = -12;
const IDC_ARROW      = 32512;
const IDC_HAND       = 0x7F89;
const SS_NOTIFY      = 0x0100;
const SS_CENTERIMAGE = 0x0200;
const SS_SUNKEN      = 0x1000;
const WM_LBUTTONDOWN = 513;

// General dialog constants
const IDCANCEL = 0;
const IDOK     = 1;

// TrackMouseEvent constants
const TME_HOVER = 1;
const TME_LEAVE = 2;
const WM_MOUSEHOVER = 0x2A1;
const WM_MOUSELEAVE = 0x2A3;

// Menu Constants (for program control)

const FILE_EXIT   =  1;

const STOCK_NEW   =  11;
const STOCK_EDIT  =  12;
const STOCK_UPD   =  13;
const STOCK_VIEW  =  14;

const HELP_ABOUT  =  21;
const HELP_HELP   = 122;

// Color constants
const RED   = 0x0000FF;
const GREEN = 0x00FF00;
const BLUE  = 0xFF0000;

// *****************************************************************************
// *                              API DECLARATIONS                             *
// *****************************************************************************

declare import, CreateWindowExA(
dwExStyle as unsigned INT,
lpClassName  as string,
    lpWindowName as string,
    int dwStyle,
    int x,
int y,
    int nWidth,
    int nHeight,
    int hWndParent,
    hMenu as unsigned int,
    hInstance as unsigned int,
    lpParam as pointer
),int;

declare import, GetModuleHandleA(int num),unsigned int;
declare import, GetSysColor(index as int),int;

declare import, GetTextExtentPoint32A(
hdc as unsigned int,
lpszStr as string,
cbString as int,
lpSize as POINT
),INT;


declare import, LoadCursorA(int hModule, int lpCursorName), int;

declare import, LoadImageA(
hInstance as unsigned int,
lpszName as POINTER,
uType as unsigned int,
cxDesired as INT,cydesired as INT,
fuLoad as unsigned int
),unsigned int;

declare import,SendMessageA(
hwnd as unsigned int,
uMsg as unsigned int,
wParam as unsigned int,
lParam as unsigned int
),unsigned int;

declare import, SetClassLongA(unsigned int hwnd, int nIndex, int dwNewLong),int;
declare import, SetCursor(int hCursor), int;

declare import, SetPropA(
unsigned int hWnd,
string lpString,
unsigned int hData
),int;

declare import, SetWindowPos(
unsigned int hwnd,
unsigned int hwndinsertafter,
int x,
int y,
int cx,
int cy,
unsigned int uFlags
),INT;

declare import, ShellExecuteA(
unsigned int hwnd,
pointer lpOperation,
pointer lpFile,
pointer lpParameters,
pointer lpDirectory,
int nShowCmd
),int;

declare import,_TrackMouseEvent(tme as TRACKMOUSEEVENT),int;

// Use to turn on debugging
DECLARE IMPORT,OutputDebugStringA(lpOuputString as STRING);

// **************************************************************************
// *                              STRUCTURES                                *
// **************************************************************************

// Listview structure
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;
}

struct BITMAP {
  int   bmType;
  int   bmWidth;
  int   bmHeight;
  int   bmWidthBytes;
  int   bmPlanes;
  int   bmBitsPixel;
  void *bmBits;
}


struct TRACKMOUSEEVENT
{
  unsigned int cbSize;
  unsigned int dwFlags;
  unsigned int hwndTrack;
  unsigned int dwHoverTime;
}

// *****************************************************************************
// *                                  CLASSES                                  *
// *****************************************************************************

// class StaticLink:CStatic
class StaticLink:CStatic
{
// overridden methods
declare OnMouseMove(int x, int y, int flags), int;
declare WndProc(unsigned int message, unsigned int wparam, unsigned int lparam),int;
// new methods
declare SetStaticText(string sText);
// class variables
string m_sText; // text displayed in control
}

StaticLink::OnMouseMove(int x, int y, int flags), int
{
TRACKMOUSEEVENT tme;

tme.cbSize      = len(TRACKMOUSEEVENT);
tme.dwFlags     = TME_HOVER | TME_LEAVE;
tme.hwndTrack   = m_hwnd;
tme.dwHoverTime = 25;

_TrackMouseEvent(tme);

return true;
}

StaticLink::SetStaticText(string sText)
{
m_sText = sText; // sets class variable for later use
SetText(m_sText); // put text into control
// set control's default cursor to null to eliminate flicker
SetClassLongA(this->m_hwnd,GCL_HCURSOR, null);
return;
}
StaticLink::WndProc(unsigned int message, unsigned int wparam, unsigned int lparam),int
{
select message
{
case WM_MOUSEHOVER:
::SetCursor(LoadCursorA(null,IDC_HAND));
case WM_LBUTTONDOWN:
DoSystem("http://" + m_sText);
}
return CStatic!!WndProc(message,wparam,lparam);
}

// class QuickDialog:Dialog
class QuickDialog:Dialog{
// Constructor/Destructor
declare  QuickDialog();
declare _QuickDialog();

// Overridden methods
declare OnClose(), int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl), int;
declare OnCreate(), int;
declare OnInitDialog(),int;
declare loadList(int listno, ClistView *plist),int;

// Class methods
declare Make(window *parent), void; // creates the dialog
declare SetTitle(string sTitle), void; // dialog title
declare SetCaption(string sCaption), void; // text under the image
declare SetImage(string sID), void; // the image
declare SetLink(string sLink), void; // http link under main text
declare SetText(string sText), void; // dialog main text

// Class variables
string m_sTitle;
string m_sCaption;
string m_sLink;
string m_sText;
int    m_TextHeight; // for main dialog text
unsigned int m_hImage;
StaticLink *pStatic;

// Class constants
const QD_OK      = 1; // for OnControl() method "quick dialog OK"
const QD_IMAGE   = 2;
const QD_CAPTION = 3;
const QD_TEXT    = 4;
const QD_LINK    = 5;
}

QuickDialog::QuickDialog(){
return;
}

QuickDialog::_QuickDialog(){
return;
}
QuickDialog::Make(window *parent), void{
Create(0,0,500,310,
AWS_POPUP|AWS_BORDER|AWS_DLGFRAME|AWS_SYSMENU|DS_MODALFRAME,
0,m_sTitle,parent);

AddControl(CTBUTTON,"OK",215,260,70,20,
ABS_OWNERDRAW|AWS_CHILD|AWS_VISIBLE|AWS_TABSTOP,0x0,
QD_OK);

AddControl(CTSTATIC,"",25,36,272,178,
ASS_BITMAP|AWS_CHILD|AWS_VISIBLE|SS_NOTIFY|SS_CENTERIMAGE|SS_SUNKEN,0x0,
QD_IMAGE);

AddControl(CTSTATIC,"",25,214,272,40,
AWS_CHILD|AWS_VISIBLE|SS_NOTIFY|ASS_MULTILINE,0x0,
QD_CAPTION);

AddControl(CTSTATIC,"",310,36,178,70,
AWS_CHILD|AWS_VISIBLE|ASS_MULTILINE|SS_NOTIFY,0x0,
QD_TEXT);

if(m_sLink <> ""){
AddControl(CTSTATIC,m_sLink,310,110,178,20,
AWS_CHILD|AWS_VISIBLE|ASS_MULTILINE|SS_NOTIFY,
0x0,QD_LINK);
}

return;
}

QuickDialog::OnControl(int nID, int nNotifyCode, unsigned int hControl), int{
select nID {
case QD_OK:
if(nNotifyCode = 0){
CloseDialog(IDOK);
return true;
}
}
return true;
}

QuickDialog::OnClose(), int{
delete pStatic;
CloseDialog(IDCANCEL);
return true;
}

QuickDialog::OnCreate(), int{

return true;
}

QuickDialog::OnInitDialog(),int{
CStatic *pControl;

pControl = GetControl(QD_IMAGE);
pControl ->SetImage(m_hImage);

pControl = GetControl(QD_CAPTION);
pControl ->SetText(m_sCaption);

pControl = GetControl(QD_TEXT);
pControl ->SetText(m_sText);

if(m_sLink <> ""){
// create the static link and attach it to our static control
pControl = GetControl(QD_LINK);
pStatic= new(StaticLink,1);
pStatic->m_hWnd = pControl->m_hWnd;
SetPropA(pStatic->m_hWnd,"THIS",pStatic+0);
pStatic->SetStaticText(m_sLink);
pStatic ->SetColor(BLUE,GetSysColor(15));
SetFont("",8,"500",SFUNDERLINE,QD_LINK);
}

CenterWindow();
return true;
}

QuickDialog::SetTitle(string sTitle), void{
m_sTitle = sTitle;
return;
}

QuickDialog::SetCaption(string sCaption), void{
// this is the caption under the image, not the caption for the window itself
// one or two brief lines of text with "\n"
m_sCaption = sCaption;
return;
}

QuickDialog::SetImage(string sID), void{
// sID is the ID from the resource view
m_hImage = LoadImageA(GetModuleHandleA(0),sID,0,0,0,0);
if (m_hImage = null)
MessageBox(this,"Image failed to load","",0);
return;
}

QuickDialog::SetLink(string sLink){
// sLink is in the format www.blahblah.com
m_sLink = sLink;
return;
}

QuickDialog::SetText(string sText), void{
// lines separated by "\n"
m_sText = sText;
return;
}

// class CImageWindow:window
class CImageWindow:window{

// overridden methods
declare OnClose(),  int;
declare OnCreate(), int;
declare OnMenuPick(int nID), int;
declare SetBitmap(string *path);

// new methods
declare WriteCenteredText(int x1, int x2, int y, string s);
// class variables
def m_run as int;
CStatusBar *m_pStatus;
pointer m_pChild;
}

CImageWindow::OnClose(), int{
m_run = 0;
Destroy();
return True;
}

CImageWindow::OnCreate(), int{
m_run = 1;
CenterWindow();
return true;
}

CImageWindow::OnMenuInit(), int{
return true;
}

CImageWindow::OnMenuPick(int nID), int{
QuickDialog *d1;
ClistView *Plist;

select (nID) {
case FILE_EXIT:
m_run = 0;
case HELP_ABOUT:
d1 = new(QuickDialog,1);
d1->SetTitle("About");
d1->SetImage("Chart");
d1->SetCaption("Aurora Example Program");
d1->SetText("Aurora Stock Keeper\n\n"   +
"Version 1.0 2/06/2006\n"             +
"ÂÃ,© 2006 Lawrence H. Sikes\n\n" +
"All Rights Reserved");
d1->SetLink("rockridgefarm.com");
d1->Make(this);
d1->DoModal();
delete d1;
case STOCK_VIEW:
DoViewData();

default:
}
return True;
}

CImageWindow::WriteCenteredText(int x1, int x2, int y, string s),void{
// x1 is the leftmost limit, x2 the rightmost; y the distance from top
int offset;
point myPoint;

myPoint = GetTextSize(s); // width of string
offset = (x2 - x1 - myPoint.x) / 2; // offset from x1
WriteText(x1 + offset, y, s);
return;
}

CImageWindow :: SetBitmap(string *path){
BITMAP bm;
DeleteObject(m_hBitmap);
m_hBitmap = LoadImage(0, path, 0,0,0,16);
GetObject(m_hBitmap, len(BITMAP), bm);
int dc = GetHDC();
BitBlt(dc, 0,0,bm.bmWidth,bm.bmHeight,dc,0,0,0x00CC0020);
ReleaseHDC(dc, true);
return;
}

// *****************************************************************************
// *                              MAIN SUBROUTINE                              *
// *****************************************************************************

global sub main(){
def MainWin as CImageWindow;
Cstatic Stat;

menu m; // Unused or unready menu items are grayed
m.BeginMenu();
m.MenuTitle("&File");
m.MenuItem("E&xit",         AMF_ENABLED, FILE_EXIT);
m.MenuTitle("&Stock");
m.MenuItem("&New",          AMF_GRAYED,  STOCK_NEW);
m.MenuItem("&Edit",         AMF_GRAYED,  STOCK_EDIT);
m.MenuItem("&Update",       AMF_GRAYED,  STOCK_UPD);
m.MenuItem("&View",         AMF_ENABLED, STOCK_VIEW);
m.MenuTitle("&Help");
m.MenuItem("&About...",     AMF_ENABLED, HELP_ABOUT);
m.Separator();
m.MenuItem("&Help",         AMF_GRAYED,  HELP_HELP);
m.EndMenu();

MainWin.Create(0x80000000,0x80000000,0x80000000,0x80000000,
AWS_VISIBLE|AWS_OVERLAPPEDWINDOW|AWS_AUTODRAW,0,"Aurora Stock Keeper",null);
MainWin.SetWindowColor(0); // image background is black
MainWin.SetBitmap("C:\\aurora\\bmp\\aurora.bmp");
MainWin.DrawMode(TRANSPARENT);//text
MainWin.FrontPen(0xFFFFFF);//text
MainWin.SetFont("Arial", 20,100);//text
MainWin.WriteText(50, 400, "Aurora Stock Keeper");//text
// MainWin.AddControl(CTLISTVIEW,"",10,10,500,145,
// AWS_DISABLE|ALVS_REPORT|AWS_BORDER|AWS_HSCROLL|AWS_VSCROLL,
// AWS_EX_CLIENTEDGE,LISTVIEW_1);
MainWin.SetMenu(m.Detach());
MainWin.DrawMode(TRANSPARENT);

// message loop
do
{
wait();
}until MainWin.m_run = 0;
return;
}

// *****************************************************************************
// *                             OTHER SUBROUTINES                             *
// *****************************************************************************

sub DoSystem(string command, opt param as string){
ShellExecuteA(0,"open",command,param,0,1);
return;
}

sub DoViewData(){
CDatabase db;
CStringList *pDrivers,*pTables,*pColumns;
pointer pBindings;
string Symbol,Name,curstat;
int dbVal,lincnt;
string error;
double lstprc;

/*
pList = GetControl(LISTVIEW_1);
pList->InsertColumn(0,"Symbol");
pList->InsertColumn(1,"       Stock Name       ");
pList->InsertColumn(2," Status ");
pList->InsertColumn(3," Current Price");

// Database Stuff
pDrivers = db.EnumDrivers();

if(pDrivers = NULL) {
MessageBox(0,"Unable to enumerate database drivers","ERROR");
} else {
if(db.Connect("Microsoft Access Driver (*.mdb)",GETSTARTPATH() + "stockkeeper.mdb","")){
pTables = db.ListTables();
} else {
MessageBox(0,"Connection failed: " + GETSTARTPATH() + "stockeeper.mdb","ERROR");
}
}

//Build list and display
//example SQL statements to retrieve datasets
//dbExecSQL returns a handle to the executed statment or zero on failure.
//A valid statement handle is returned even on an empty result set.
dbVal = db.ExecSQL("SELECT * FROM Stock");
error = db.GetErrorCode(dbVal);

if len(error){
MessageBox(0,"\nError Code: " + error + "\nError Text: " + db.GetErrorText(dbVal)+ "\n\n","DB ERROR");
}

if(dbVal){
//db.Get returns TRUE if data has been retrieved and stored
//in the bound variables. Or FALSE if the end of data has been reached or an error occured
while db.Get(dbVal){
//Get the data and put it in the list.
db.GetData(dbVal,2,Symbol,TYPE_STRING);
pList->InsertItem(lincnt,Symbol,1);
db.GetData(dbVal,3,Name,TYPE_STRING);
pList->InsertItem(lincnt,Name,2);
db.GetData(dbVal,4,curstat,TYPE_STRING);
pList->InsertItem(lincnt,curstat,3);
db.GetData(dbVal,20,lstprc,TYPE_DOUBLE);
pList->InsertItem(lincnt,Str$(lstprc),4);
lincnt++;
}
db.FreeSQL(dbVal);
}
db.Disconnect();
*/
return;
}

Parker

Well for one, the GetControl method doesn't exist outside of a class, either include the DoViewData into your dialog class, or pass a parameter and do pList = dlg.GetControl.

Also, where that subroutine is being called, the dialog is never created, you'll have to do that either inside that subroutine (in which case you won't use the above comments) or somewhere else, probably before it's called.

I've only written one GUI program with Aurora though, and it doesn't use dialogs. I can't get it working either, sorry.

I would say to plan out what you are trying to do, maybe draw it out on paper, then start implementing code in a clean and logical manner, hopefully it will work. In my project I mentioned above, I started working with a dialog but was having lots of problems (it needed to be a child to a fullscreen window) so I made it start acting as a dialog by using EnableTabs and subclassing edit controls (it was easier than doing a derived class) to handle the enter key shortcut as a default button. Maybe that would work for you?

Sorry I can't be of more help...

Bruce Peaslee

February 11, 2006, 12:09:27 PM #2 Last Edit: February 25, 2006, 11:12:06 AM by peaslee
Here are the steps I go through, although there are probably as many systems as there are programmers.ÂÃ,  ÂÃ, ;)


  • Only add one thing at a time to the program. I usually get my interface up before I work on manipulating data.
  • I use the dialog editor because it provides the skeleton code and helps me remember the various pieces of the class.
  • Put the code from the dialog editor in its own text window and manipulated the variables there.
  • In this case I discarded the main program code (you already have that) and put the Make() and DoModal() code in the menu area.

This is a skeleton that you can work with:


/*
+--------------------------------------------------------------------------+
| Aurora Stock Keeper - example program for Aurora                         |
| (c)2006 Lawrence H. Sikes                                                |
| No part of this code may be reporduced or used without prior consent.    |
+--------------------------------------------------------------------------+
| Compile as a windows exe                                                 |
+--------------------------------------------------------------------------+
| Track stocks in a mdb database                                           |
+--------------------------------------------------------------------------+
*/

#AutoDefine "off"
#use "shell32.lib"


// *************************************************************************
// *                      VARIABLE DEFINITIONS                             *
// *************************************************************************

#define LISTVIEW_1 1

string version = "Version 1.0  2/06/2006";

import int LoadImage alias LoadImageA(int hInstance,string *lpszName,int uType,int cxDesired,int cydesired,int fuLoad);

import int DeleteObject(int obj);
import int GetObject alias GetObjectA(int hgdiobj, int cbBuffer, void *lpvObject);

import int BitBlt(int hdcDest,int nXDest,int nYDest,int nWidth,
int nHeight,int hdcSrc,int nXSrc,int nYSrc,int dwRop);

CListView *pList;

// *****************************************************************************
// *                              GLOBAL CONSTANTS                             *
// *****************************************************************************

// Style constants not yet in system includes
const DS_MODALFRAME  = 0x0080;
const GCL_HCURSOR    = -12;
const IDC_ARROW      = 32512;
const IDC_HAND       = 0x7F89;
const SS_NOTIFY      = 0x0100;
const SS_CENTERIMAGE = 0x0200;
const SS_SUNKEN      = 0x1000;
const WM_LBUTTONDOWN = 513;

// General dialog constants
const IDCANCEL = 0;
const IDOK     = 1;

// TrackMouseEvent constants
const TME_HOVER = 1;
const TME_LEAVE = 2;
const WM_MOUSEHOVER = 0x2A1;
const WM_MOUSELEAVE = 0x2A3;

// Menu Constants (for program control)

const FILE_EXIT   =  1;

const STOCK_NEW   =  11;
const STOCK_EDIT  =  12;
const STOCK_UPD   =  13;
const STOCK_VIEW  =  14;

const HELP_ABOUT  =  21;
const HELP_HELP   = 122;

// Color constants
const RED   = 0x0000FF;
const GREEN = 0x00FF00;
const BLUE  = 0xFF0000;

// *****************************************************************************
// *                              API DECLARATIONS                             *
// *****************************************************************************

declare import, CreateWindowExA(
dwExStyle as unsigned INT,
lpClassName  as string,
    lpWindowName as string,
    int dwStyle,
    int x,
int y,
    int nWidth,
    int nHeight,
    int hWndParent,
    hMenu as unsigned int,
    hInstance as unsigned int,
    lpParam as pointer
),int;

declare import, GetModuleHandleA(int num),unsigned int;
declare import, GetSysColor(index as int),int;

declare import, GetTextExtentPoint32A(
hdc as unsigned int,
lpszStr as string,
cbString as int,
lpSize as POINT
),INT;


declare import, LoadCursorA(int hModule, int lpCursorName), int;

declare import, LoadImageA(
hInstance as unsigned int,
lpszName as POINTER,
uType as unsigned int,
cxDesired as INT,cydesired as INT,
fuLoad as unsigned int
),unsigned int;

declare import,SendMessageA(
hwnd as unsigned int,
uMsg as unsigned int,
wParam as unsigned int,
lParam as unsigned int
),unsigned int;

declare import, SetClassLongA(unsigned int hwnd, int nIndex, int dwNewLong),int;
declare import, SetCursor(int hCursor), int;

declare import, SetPropA(
unsigned int hWnd,
string lpString,
unsigned int hData
),int;

declare import, SetWindowPos(
unsigned int hwnd,
unsigned int hwndinsertafter,
int x,
int y,
int cx,
int cy,
unsigned int uFlags
),INT;

declare import, ShellExecuteA(
unsigned int hwnd,
pointer lpOperation,
pointer lpFile,
pointer lpParameters,
pointer lpDirectory,
int nShowCmd
),int;

declare import,_TrackMouseEvent(tme as TRACKMOUSEEVENT),int;

// Use to turn on debugging
DECLARE IMPORT,OutputDebugStringA(lpOuputString as STRING);

// **************************************************************************
// *                              STRUCTURES                                *
// **************************************************************************

// Listview structure
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;
}

struct BITMAP {
  int   bmType;
  int   bmWidth;
  int   bmHeight;
  int   bmWidthBytes;
  int   bmPlanes;
  int   bmBitsPixel;
  void *bmBits;
}


struct TRACKMOUSEEVENT
{
  unsigned int cbSize;
  unsigned int dwFlags;
  unsigned int hwndTrack;
  unsigned int dwHoverTime;
}

// *****************************************************************************
// *                                  CLASSES                                  *
// *****************************************************************************


class StockView:cdialog
{
//overridden methods
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
// class methods
declare Make(cwindow *parent), void;
// member variables
// class constants
const SV_CMD_OK      = 1;
const SV_LV_LISTVIEW = 2;
}

StockView::Make(cwindow *parent), void
{
Create(0,0,391,333,
AWS_POPUP|AWS_BORDER|AWS_DLGFRAME|AWS_SYSMENU|DS_MODALFRAME,
0,"Stock View",parent);

AddControl(CTLISTVIEW,"",70,44,250,215,
AWS_CHILD|AWS_VISIBLE|AWS_BORDER|ALVS_AUTOARRANGE|ALVS_SORTASCENDING|ALVS_SINGLESEL|ALVS_REPORT,
0,SV_LV_LISTVIEW);

AddControl(CTBUTTON,"OK",160,288,70,20,
ABS_OWNERDRAW|AWS_CHILD|AWS_VISIBLE,
0,SV_CMD_OK);

return 0;
}

StockView::OnClose(),int
{
CloseDialog(false);
return true;
}

StockView::OnInitDialog(),int
{
CenterWindow();
return true;
}

StockView::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select nID
{
case SV_LV_LISTVIEW:
/* respond to control notifications here */
case SV_CMD_OK:
if(nNotifyCode = 0)
{
CloseDialog(true);
}
}
return true;
}

// class StaticLink:CStatic
class StaticLink:CStatic
{
// overridden methods
declare OnMouseMove(int x, int y, int flags), int;
declare WndProc(unsigned int message, unsigned int wparam, unsigned int lparam),int;
// new methods
declare SetStaticText(string sText);
// class variables
string m_sText; // text displayed in control
}

StaticLink::OnMouseMove(int x, int y, int flags), int
{
TRACKMOUSEEVENT tme;

tme.cbSize      = len(TRACKMOUSEEVENT);
tme.dwFlags     = TME_HOVER | TME_LEAVE;
tme.hwndTrack   = m_hwnd;
tme.dwHoverTime = 25;

_TrackMouseEvent(tme);

return true;
}

StaticLink::SetStaticText(string sText)
{
m_sText = sText; // sets class variable for later use
SetText(m_sText); // put text into control
// set control's default cursor to null to eliminate flicker
SetClassLongA(this->m_hwnd,GCL_HCURSOR, null);
return;
}
StaticLink::WndProc(unsigned int message, unsigned int wparam, unsigned int lparam),int
{
select message
{
case WM_MOUSEHOVER:
::SetCursor(LoadCursorA(null,IDC_HAND));
case WM_LBUTTONDOWN:
DoSystem("http://" + m_sText);
}
return CStatic!!WndProc(message,wparam,lparam);
}

// class QuickDialog:Dialog
class QuickDialog:CDialog{
// Constructor/Destructor
declare  QuickDialog();
declare _QuickDialog();

// Overridden methods
declare OnClose(), int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl), int;
declare OnCreate(), int;
declare OnInitDialog(),int;
declare loadList(int listno, ClistView *plist),int;

// Class methods
declare Make(cwindow *parent), void; // creates the dialog
declare SetTitle(string sTitle), void; // dialog title
declare SetCaption(string sCaption), void; // text under the image
declare SetImage(string sID), void; // the image
declare SetLink(string sLink), void; // http link under main text
declare SetText(string sText), void; // dialog main text

// Class variables
string m_sTitle;
string m_sCaption;
string m_sLink;
string m_sText;
int    m_TextHeight; // for main dialog text
unsigned int m_hImage;
StaticLink *pStatic;

// Class constants
const QD_OK      = 1; // for OnControl() method "quick dialog OK"
const QD_IMAGE   = 2;
const QD_CAPTION = 3;
const QD_TEXT    = 4;
const QD_LINK    = 5;
}

QuickDialog::QuickDialog(){
return;
}

QuickDialog::_QuickDialog(){
return;
}
QuickDialog::Make(cwindow *parent), void{
Create(0,0,500,310,
AWS_POPUP|AWS_BORDER|AWS_DLGFRAME|AWS_SYSMENU|DS_MODALFRAME,
0,m_sTitle,parent);

AddControl(CTBUTTON,"OK",215,260,70,20,
ABS_OWNERDRAW|AWS_CHILD|AWS_VISIBLE|AWS_TABSTOP,0x0,
QD_OK);

AddControl(CTSTATIC,"",25,36,272,178,
ASS_BITMAP|AWS_CHILD|AWS_VISIBLE|SS_NOTIFY|SS_CENTERIMAGE|SS_SUNKEN,0x0,
QD_IMAGE);

AddControl(CTSTATIC,"",25,214,272,40,
AWS_CHILD|AWS_VISIBLE|SS_NOTIFY|ASS_MULTILINE,0x0,
QD_CAPTION);

AddControl(CTSTATIC,"",310,36,178,70,
AWS_CHILD|AWS_VISIBLE|ASS_MULTILINE|SS_NOTIFY,0x0,
QD_TEXT);

if(m_sLink <> ""){
AddControl(CTSTATIC,m_sLink,310,110,178,20,
AWS_CHILD|AWS_VISIBLE|ASS_MULTILINE|SS_NOTIFY,
0x0,QD_LINK);
}

return;
}

QuickDialog::OnControl(int nID, int nNotifyCode, unsigned int hControl), int{
select nID {
case QD_OK:
if(nNotifyCode = 0){
CloseDialog(IDOK);
return true;
}
}
return true;
}

QuickDialog::OnClose(), int{
delete pStatic;
CloseDialog(IDCANCEL);
return true;
}

QuickDialog::OnCreate(), int{

return true;
}

QuickDialog::OnInitDialog(),int{
CStatic *pControl;

pControl = GetControl(QD_IMAGE);
pControl ->SetImage(m_hImage);

pControl = GetControl(QD_CAPTION);
pControl ->SetText(m_sCaption);

pControl = GetControl(QD_TEXT);
pControl ->SetText(m_sText);

if(m_sLink <> ""){
// create the static link and attach it to our static control
pControl = GetControl(QD_LINK);
pStatic= new(StaticLink,1);
pStatic->m_hWnd = pControl->m_hWnd;
SetPropA(pStatic->m_hWnd,"THIS",pStatic+0);
pStatic->SetStaticText(m_sLink);
pStatic ->SetColor(BLUE,GetSysColor(15));
SetFont("",8,"500",SFUNDERLINE,QD_LINK);
}

CenterWindow();
return true;
}

QuickDialog::SetTitle(string sTitle), void{
m_sTitle = sTitle;
return;
}

QuickDialog::SetCaption(string sCaption), void{
// this is the caption under the image, not the caption for the window itself
// one or two brief lines of text with "\n"
m_sCaption = sCaption;
return;
}

QuickDialog::SetImage(string sID), void{
// sID is the ID from the resource view
m_hImage = LoadImageA(GetModuleHandleA(0),sID,0,0,0,0);
if (m_hImage = null)
MessageBox(this,"Image failed to load","",0);
return;
}

QuickDialog::SetLink(string sLink){
// sLink is in the format www.blahblah.com
m_sLink = sLink;
return;
}

QuickDialog::SetText(string sText), void{
// lines separated by "\n"
m_sText = sText;
return;
}

// class CImageWindow:window
class CImageWindow:cwindow{

// overridden methods
declare OnClose(),  int;
declare OnCreate(), int;
declare OnMenuPick(int nID), int;
declare SetBitmap(string *path);

// new methods
declare WriteCenteredText(int x1, int x2, int y, string s);
// class variables
def m_run as int;
CStatusBar *m_pStatus;
pointer m_pChild;
}

CImageWindow::OnClose(), int{
m_run = 0;
Destroy();
return True;
}

CImageWindow::OnCreate(), int{
m_run = 1;
CenterWindow();
return true;
}

CImageWindow::OnMenuInit(), int{
return true;
}

CImageWindow::OnMenuPick(int nID), int{
QuickDialog *d1;
ClistView *Plist;
StockView *d2;

select (nID) {
case FILE_EXIT:
m_run = 0;
case HELP_ABOUT:
d1 = new(QuickDialog,1);
d1->SetTitle("About");
d1->SetImage("Chart");
d1->SetCaption("Aurora Example Program");
d1->SetText("Aurora Stock Keeper\n\n"   +
"Version 1.0 2/06/2006\n"             +
"ÂÃ,© 2006 Lawrence H. Sikes\n\n" +
"All Rights Reserved");
d1->SetLink("rockridgefarm.com");
d1->Make(this);
d1->DoModal();
delete d1;
case STOCK_VIEW:
d2 = new(StockView,1);
d2->Make(this);
d2->DoModal();
delete d2;

default:
}
return True;
}

CImageWindow::WriteCenteredText(int x1, int x2, int y, string s),void{
// x1 is the leftmost limit, x2 the rightmost; y the distance from top
int offset;
point myPoint;

myPoint = GetTextSize(s); // width of string
offset = (x2 - x1 - myPoint.x) / 2; // offset from x1
WriteText(x1 + offset, y, s);
return;
}

CImageWindow :: SetBitmap(string *path){
BITMAP bm;
DeleteObject(m_hBitmap);
m_hBitmap = LoadImage(0, path, 0,0,0,16);
GetObject(m_hBitmap, len(BITMAP), bm);
int dc = GetHDC();
BitBlt(dc, 0,0,bm.bmWidth,bm.bmHeight,dc,0,0,0x00CC0020);
ReleaseHDC(dc, true);
return;
}


// *****************************************************************************
// *                              MAIN SUBROUTINE                              *
// *****************************************************************************

global sub main(){
def MainWin as CImageWindow;
Cstatic Stat;

menu m; // Unused or unready menu items are grayed
m.BeginMenu();
m.MenuTitle("&File");
m.MenuItem("E&xit",         AMF_ENABLED, FILE_EXIT);
m.MenuTitle("&Stock");
m.MenuItem("&New",          AMF_GRAYED,  STOCK_NEW);
m.MenuItem("&Edit",         AMF_GRAYED,  STOCK_EDIT);
m.MenuItem("&Update",       AMF_GRAYED,  STOCK_UPD);
m.MenuItem("&View",         AMF_ENABLED, STOCK_VIEW);
m.MenuTitle("&Help");
m.MenuItem("&About...",     AMF_ENABLED, HELP_ABOUT);
m.Separator();
m.MenuItem("&Help",         AMF_GRAYED,  HELP_HELP);
m.EndMenu();

MainWin.Create(0x80000000,0x80000000,0x80000000,0x80000000,
AWS_VISIBLE|AWS_OVERLAPPEDWINDOW|AWS_AUTODRAW,0,"Aurora Stock Keeper",null);
MainWin.SetWindowColor(0); // image background is black
MainWin.SetBitmap("C:\\aurora\\bmp\\aurora.bmp");
MainWin.DrawMode(TRANSPARENT);//text
MainWin.FrontPen(0xFFFFFF);//text
MainWin.SetFont("Arial", 20,100);//text
MainWin.WriteText(50, 400, "Aurora Stock Keeper");//text
// MainWin.AddControl(CTLISTVIEW,"",10,10,500,145,
// AWS_DISABLE|ALVS_REPORT|AWS_BORDER|AWS_HSCROLL|AWS_VSCROLL,
// AWS_EX_CLIENTEDGE,LISTVIEW_1);
MainWin.SetMenu(m.Detach());
MainWin.DrawMode(TRANSPARENT);

// message loop
do
{
wait();
}until MainWin.m_run = 0;
return;
}

// *****************************************************************************
// *                             OTHER SUBROUTINES                             *
// *****************************************************************************

sub DoSystem(string command, opt param as string){
ShellExecuteA(0,"open",command,param,0,1);
return;
}


Good luck!

Edit: modified for current state of compiler.
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)

Bruce
I added code to cause something to dispaly in the listbox.
It compiles but crashes.
I added to the d2 dialog section the below code.

StkList = d2->GetControl(SV_LV_LISTVIEW);
StkList->InsertColumn(0,"Symbol");
StkList->InsertColumn(1,"       Stock Name       ");
StkList->InsertColumn(2," Status ");
StkList->InsertColumn(3," Current Price");

It crashes at the InsertColumn call.
What did I do wrong?

Ionic Wind Support Team

Probably because your calling it in a place where the listview doesn't exist yet.

Controls in a dialog don't exist until you call DoModal or ShowDialog.  GetControl will return a NULL pointer before that. 

You should initialize all controls in OnInitDialog.

As Bruce has mentioned start simply.  Create a dilaog in the dialog editor, add a listview and generate full skeleton source.  This is direct output from the editor:


#define LISTVIEW_1 1
class dlg:dialog
{
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
}

global sub main()
{
dlg d1;
d1.Create(0,0,300,202,0x80C80080,0,"Caption",0);
d1.AddControl(CTLISTVIEW,"",55,36,190,131,0x50008001,0x200,LISTVIEW_1);

d1.DoModal();
return 0;
}

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

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

dlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select nID
{
case LISTVIEW_1:
/* respond to control notifications here */
}
return true;
}


And this is the code changed to access the listview in OnInitDialog:


#define LISTVIEW_1 1
class dlg:dialog
{
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
}

global sub main()
{
dlg d1;
d1.Create(0,0,300,202,0x80C80080,0,"Caption",0);
d1.AddControl(CTLISTVIEW,"",55,36,190,131,0x50000001,0x200,LISTVIEW_1);

d1.DoModal();
return 0;
}

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

dlg::OnInitDialog(),int
{
/* Initialize any controls here */
CListView *List = GetControl(LISTVIEW_1);
if(list <> NULL)
{
List->InsertColumn(0,"Symbol");
List->InsertColumn(1,"       Stock Name       ");
List->InsertColumn(2," Status ");
List->InsertColumn(3," Current Price");
}
CenterWindow();
return true;
}

dlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select nID
{
case LISTVIEW_1:
/* respond to control notifications here */
}
return true;
}


Again with a dialog the "AddControl" method doesn't actually create the control, it adds a control definition to the internal dialog template.  Windows creates all of the controls when DoModal (or ShowDialog) is called.  So it is not safe to use GetControl until after that point.  The first message handler you can use GetControl is OnInitDialog.

Paul.
Ionic Wind Support Team

Rock Ridge Farm (Larry)

Thanks Paul - I now have it working.
Now if I can get it to talk to the internet. :)