QURYDEMO.H

//----------------------------------------------------------------------------- 
// Microsoft OLE DB Main Include File
// Copyright (C) 1994 - 1996 By Microsoft Corporation.
//
// @doc
//
// @module main include file
//
//-----------------------------------------------------------------------------

#ifdef RC_INVOKED
#define ID(id) id
#else
#define ID(id) MAKEINTRESOURCE(id)
#endif

/* Resource Identifiers */
#define BMP_NEWQUERYID(10)// new window button bitmap
#define BMP_RUNQUERYID(20)// exec query button bitmap
#defineAPPICONID(30)// application icon
#define QUERYWINDOWICONID(40)// MDI Child window icon
#define QURYDEMOMENUID(50)// Application menu
#define INITDIALOGID(60)// connect modal dialog box
#define DISCONNECTDIALOGID(70)// disconnect modal dialog box
#define ABOUTDIALOGID(80)// about modal dialog box
#define MDICHILDDIALOGID(90)// MDI Child modeless dialog box
#define APPACCELERATORID(100)// Accelerator table for the app

/* Menu Identifiers */
#define IDM_POPUPAPPSYS10// Placeholder, used by status bar
#define IDM_POPUPMDISYS20// Placeholder, used by status bar
#define IDM_POPUPLOGIN100// Placeholder, used by status bar
#define IDM_INITIALIZE110
#define IDM_DISCONNECT120
#define IDM_EXIT130
#define IDM_POPUPQUERY140// Placeholder, used by status bar
#define IDM_QUERY150
#define IDM_NEW160
#define IDM_POPUPSCHEMA170 // Placeholder, used by status bar
#define IDM_TYPES 180
#define IDM_TABLES 190
#define IDM_COLUMNS 200
#define IDM_POPUPWINDOW210 // Placeholder, used by status bar
#define IDM_TILE220
#define IDM_CASCADE230
#define IDM_ICONS240
#define IDM_CLOSEALL250
#define IDM_POPUPHELP260// Placeholder, used by status bar
#define IDM_APPHELP270
#define IDM_ABOUT280
#define IDM_MDICHILD290

#define IDM_CATALOGS 300
#define IDM_FOREIGN_KEYS 310
#define IDM_PRIMARY_KEYS 320
#define IDM_PROCEDURE_PARAMETERS 330
#define IDM_PROCEDURES 340
#define IDM_SCHEMATA 350
#define IDM_INDEXES 360 //added

/* child window ids */
#define IDW_TOOLBAR10
#define IDW_STATUSBAR20
#define IDW_MDICLIENT30

#define IDW_CRSRLIST10// toolbar comboboxes
#define IDW_COMMANDLIST20

#define IDCOMBO_PROVIDER10// connect dialog box controls
#define IDCOMBO_NAME20
#define IDTEXT_USERID30
#define IDTEXT_PASSWORD40
#define IDENUM 50

#define IDLIST_SESSION10// disconnect dialog box controls
#define IDLIST_COMMAND20
#define IDCLOSE_ACTVTY30
#define IDDISCONNECT40
#define IDICON_WARN50

#define IDTEXT_PRMPT10// MDI child's modeless dialog controls
#define IDTEXT_SQL20
#define IDLIST_RSLT30

/* MDI Child Window Offsets */
#define CBWNDEXTRA4// storage in MDI Child Window
#define GWLAPP_HDLG0// child dialog handle

/* Other Constants */
#define MAXCHILDWNDS 10//maximum child windows allowed
#define MAXBUFLEN256//display buffer size
#define MAX_COL35//maximum column in result set
#define MAX_ROW100//maximum number of rows
#define MAXDATALEN25//maximum data length per column
#define MAXCOLNAMELEN20
#define MAXCOLNDATALENGTH 23
#define MAXDISPLAYSIZEMAX_COL*(MAXDATALEN+1)
#defineMINWIDTH415//minimum width of app window
#defineMINHEIGHT350//minimum height of app window
#define LISTTABSTOP100//tabstop in the display listbox
#define LISTHORZSCROLL(LISTTABSTOP*2)//horizontal scroll for the listbox
#define LISTHORZEXT0//horizontal extent inthe list box
#define WINDOWMENUPLACE2//Window menu place for adding MDI child windows
#define IDT_STATUSTIMER1//timer id
#define TIMERDELAY60000//timer duration
#define BTTNX345//first toolbar button location
#define BTTNY2//button y position
#defineBTTNWIDTH25 //button width
#define BTTNHEIGHT23 //button height
#define BTTNMARGIN5//distance between toolbar buttons
#define TOOLBARMARGINY5//fixed margin w/o combobox height
#define STATUSBARMARGINY8//fixed margin w/o textbox height

/* String Constants */
#define POPUPLOGIN"&Login"
#define MENUITEMCONNECT"&Connect... \aCtrl+C"
#define MENUITEMDISCONNECT"&Unitialize... \aCtrl+U"
#defineMENUITEMEXIT"E&xit"
#define POPUPQUERY"&Command"
#define MENUITEMQUERY"&Execute Command Text \aCtrl+E"
#define MENUITEMNEW"&New Command \aCtrl+N"
#define POPUPSCHEMA"&Schema \aCtrl+S"
#define MENUITEMTYPES"&PROVIDER_TYPES \aCtrl+P"
#defineMENUITEMTABLES"T&ABLES \aCtrl+A"
#define MENUITEMCOLUMNS"&COLUMNS \aCtrl+C"
#define POPUPWINDOW"&Window"
#define MENUITEMTILE"&Tile"
#defineMENUITEMCASCADE"&Cascade"
#define MENUITEMICONS"Arrange &Icons"
#defineMENUITEMCLOSEALL"Close &All"
#define POPUPHELP"&Help"
#define MENUITEMAPPHELP"&Help on Qurydemo \aF1"
#defineMENUITEMABOUT"&About Qurydemo..."

#define OLEDBFRAMECLASS"QDEMO32MAIN"

#define OLEDBTOOLCLASS"QDEMOTool"
#define OLEDBSTATUSCLASS"QDEMOStatus"
#define OLEDBMDICLASS"QDEMOMDI"
#define COMBOBOXCLASS"COMBOBOX"
#define MDICLIENTCLASS"MDICLIENT"
#define UNTITLED"Untitled"
#define APPTITLE"Microsoft OLE DB Sample Query Program"
#defineEXECERROR"Execution Error"
#define INITERROR"Failed to initialize Session interface"
#define CLASSERROR"Failed to register application class"
#define CREATEMAINERR"Failed to create application main window"
#define CREATECHILDERR"Failed to create a new Command"
#define ALPHABETS"abcdefghijklmnopqrstuvwxyz"
#define TIMETEXT"MM:MM MM"
#define DATETEXT"MMM-MM"
#define TIMEFORMAT" %I:%M %p"
#define DATEFORMAT" %b-%d"
#define NOPROVIDERERR"Please provide a Data Source"
#define MOREINFO"Incomplete Information"

#define STATUSPOPUPAPPSYS " Control menu for the application "
#define STATUSPOPUPMDISYS" Control menu for the window "
#define STATUSRESTORE " Restore window to normal "
#define STATUSMOVE " Move window "
#define STATUSSIZE " Size window "
#define STATUSMINIMIZE " Minimize window "
#define STATUSMAXIMIZE " Maximize window "
#define STATUSCLOSE " Close window "
#define STATUSNEXTWINDOW " Switch to next window "
#define STATUSPREVWINDOW " Switch to previous window "
#define STATUSTASKLIST " Bring up task list "
#define STATUSPOPUPLOGIN" Login and logout commands "
#define STATUSCONNECT" Connect with default parameters... "
#define STATUSDISCONNECT" Release open sessions... "
#define STATUSEXIT" Exit application "
#define STATUSPOPUPQUERY" Commands "
#define STATUSQUERY" Execute Command text... "
#define STATUSNEW" New Command on current Session... "
#define STATUSPOPUPSCHEMA" IDBSchema Commands "

#define STATUSCATALOGS" DBSCHEMA_CATALOGS Rowset "
#define STATUSCOLUMNS" DBSCHEMA_COLUMNS Rowset "
#define STATUSFOREIGN_KEYS" DBSCHEMA_FOREIGN_KEYS Rowset "
#define STATUSPRIMARY_KEYS" DBSCHEMA_PRIMARY_KEYS Rowset "
#define STATUSPROCEDURE_PARAMETERS" DBSCHEMA_PROCEDURE_PARAMETERS Rowset "
#define STATUSPROCEDURES" DBSCHEMA_PROCEDURES Rowset "
#define STATUSSCHEMATA" DBSCHEMA_SCHEMATA Rowset "
#define STATUSTYPES" DBSCHEMA_PROVIDER_TYPES Rowset "
#define STATUSTABLES" DBSCHEMA_TABLES Rowset "

#define STATUSPOPUPWINDOW" Window management commands "
#define STATUSTILE" Tile all normal child windows "
#define STATUSCASCADE" Cascade all normal child windows "
#define STATUSICONS" Arrange iconic child windows "
#define STATUSCLOSEALL" Close all child windows "
#define STATUSMDICHILD " Activate the window marked as %d"
#define STATUSPOPUPHELP" Help commands "
#define STATUSAPPHELP" Display help on application "
#define STATUSABOUT" About application "
#define STATUSDEFAULT" Ready "

#define DEFDBNAME"?"
#define PROVIDER_SESSION_FORMAT"%s!%lX"
#define PROVIDER_SESSION_COMMAND_FORMAT"Provider:=%s!Session=%lX!Command=%lX"
#define SCANPROVIDERSESSION_FORMAT"%[^!]!%lX"
#define SCANSESSION_FORMAT"%*[^!]!%lX"
#define SCANSESSION_TITLEFORMAT"Provider:=%*[^!]!Session=%lX"
#define SCANSESSIONCOMMAND_FORMAT"Provider:=%*[^!]!Session=%lX!Command=%lX"
#define SCANCOMMAND_TITLEFORMAT"Provider:=%*[^!]!Session=%*lX!Command=%lX"
#define CUR_MARK"<-"
#define CURQUERY_STRING"Command!%lX<-"
#define QUERY_STRING"Command!%lX"
#define MAKECONNECT"Please connect to a data source using Login menu."
#defineOPENWINDOW"Please open a window from Query menu."
#define NOSESSIONERROR"No Session Available"
#define NOCOMMANDERROR"No Command Window Available"
#define MAXCHILDEXCEEDED"Please close a child window and try again."
#define MAXCHLDERR"Error - Too many Child Windows"
#define COLTRUNC_WARNG"Number of columns in display truncated to %u"
#define ROWTRUNC_WARNG"Number of rows in display truncated to %u"
#define TRUNCERR"Data Truncation"
#define CLOSEALLSESSION"All open sessions have been released."
#define LOGOUTINFO"Log Out Information"
#define SQLERR_FORMAT"SQL Error State:%s, Native Error Code: %lX, OLEDB Error: %s"
#define SQLERRMSGTITLE"SQL_ERROR results"
#define SQLERRCNTDTITLE"SQL_ERROR results continued"
#define SQLWRNMSGTITLE"SQL_SUCCESS_WITH_INFO results"
#define SQLWRNCNTDTITLE"SQL_SUCCESS_WITH_INFO results continued"
#define NULLDATASTRING"SQL_NULL_DATA"

/* Globals */
//HWNDhWndFrame; // Main Frame Window handle
//HWNDhWndCrsrList; // hdbc(s) combobox on the tool bar
//HWNDhWndStmtList; // hstmt(s) combobox on the tool bar
//HWNDhWndMDIClient; // MDI Client window handle
//HWNDhWndActiveChild;// Current active MDI Child window
//HINSTANCEhAppInstance; // Application instance


/* Macros and Function Prototypes */
#ifdef WIN32
#defineACTIVATEWINDOW(h)SetForegroundWindow(h)
#else
#defineACTIVATEWINDOW(h)SetFocus(h)
#endif

#define DRAWBTTNRECT(h,x,y,cx,cy)MoveToEx(h,x+1,y,NULL);\
LineTo(h,x+cx,y);\
MoveToEx(h,x+cx,y+1,NULL);\
LineTo(h,x+cx,y+cy);\
MoveToEx(h,x+cx-1,y+cy,NULL);\
LineTo(h,x,y+cy);\
MoveToEx(h,x,y+cy-1,NULL);\
LineTo(h,x,y);

#define DRAWBTTNLIFT1(h,x,y,cx,cy)MoveToEx(h,x+1,y+cy-1,NULL);\
LineTo(h,x+1,y+1);\
LineTo(h,x+cx-1,y+1);

#defineDRAWBTTNLIFT2(h,x,y,cx,cy)MoveToEx(h,x+1,y+cy-1,NULL);\
LineTo(h,x+cx-1,y+cy-1);\
LineTo(h,x+cx-1,y);\
MoveToEx(h,x+2,y+cy-2,NULL);\
LineTo(h,x+cx-2,y+cy-2);\
LineTo(h,x+cx-2,y+1);
// MAIN.CPP
intPASCALWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
longCALLBACKMainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
longCALLBACKToolbarProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
longCALLBACKStatusbarProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
longCALLBACKMDIChildProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOLCALLBACKConnectDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOLCALLBACKDisconnectDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOLCALLBACKAboutDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOLCALLBACKMDIChildDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
VOIDFAR PASCALDrawBitmap(HDC hDC, int iLeft, int iTop, HBITMAP hBitmap);

// QURYDEMO.CPP
BOOLFAR PASCALInitEnvironment();
voidFAR PASCALDisplayProviders(HWND hWnd);
BOOLFAR PASCAL ConnectDatabase(HWND hWnd);
voidFAR PASCALDisplayConnections(HWND hWndhdbc);
voidFAR PASCALDisplayICommands(HWND hWndhstmt, HWND hWndhdbc, int nCrsrIndex);
voidFAR PASCALNewICommandWindow();
voidFAR PASCALNewIOpenRowsetWindow();
voidFAR PASCALChangeCurrentICommand(HWND hWndStmtList);
voidFAR PASCALChangeCurrentCursor(HWND hWndCrsrList);
voidFAR PASCALDisplayNewCrsrAndICommand();
voidFAR PASCALFreeConnect(HWND hWndhdbc);
voidFAR PASCALFreeICommand(HWND hWndhstmt, HWND hWndhdbc, int nIndex);
voidFAR PASCALCloseICommandWindow(HWND hWnd);
voidFAR PASCALExecuteQuery();
BOOLFAR PASCALCloseIDBCreateCommand();
HRESULT DisplayDataSource(HWND hWnd);
HRESULTFreeEnvironment();
voidFAR PASCALGetSchemaRowset(GUID rguidSchema);

HRESULT EnumerateProviders ();

HRESULT ExecuteCommand
(
IUnknown*pIUnknown,
ICommand*pICommand,
LPWSTRwszBuffer,
IRowset**ppIRowset_out
);

HRESULT GetDataFromRowset
(
IRowset*pIRowset
);

HRESULT GetColumnsInfo
(
IRowset*pIRowset,
ULONG* pcCol,
DBCOLUMNINFO**ppColumnInfo,
WCHAR**ppStringsBuffer
);

HRESULT SetupBindings
(
ULONG cCol,
DBCOLUMNINFO*pColumnInfo,
DBBINDING*rgBind_out,
ULONG*cBind_out,
ULONG* pcMaxRowSize_out
);

HRESULT CreateAccessor
(
IRowset*pIRowset,
DBBINDING*rgBind,
ULONGcBind,
HACCESSOR*phAccessor_out
);

HRESULT GetData
(
IRowset*pIRowset,
ULONG cMaxRowSize,
HACCESSORhAccessor,
DBBINDING* rgBind,// needed for pretty printing
ULONG cBind, // for pretty printing
DBCOLUMNINFO*pColumnInfo, // for pretty printing
ULONGcCol,// for pretty printing
HWNDhList,
DWORDdwText,
DWORDaddString
);

HRESULT CleanupRowset
(
IRowset*pIRowset,
HACCESSOR hAccessor
);

void DumpRow
(
DBBINDING* rgBind,
ULONGcBind,
ULONGcMaxColWidth,
BYTE* pData,
HWNDhList,
DWORDdwText,
DWORDaddString
);

HRESULT GetDetailedErrorInfo
(
IUnknown * pBadObject,
GUID IID_BadIntereface,
char * szErrorDescription_out,
char * szErrorSource_out
);

void DumpError
( HRESULT hr,
LPSTR lpStrBuffer,
LPSTR lpSource,
LPSTR lpDescription
);

void DumpErrorHResult
(
HRESULT hr,
LPSTR lpStrBuffer
);

// How to lay out each column in memory.
// Note that bData should be DWORD aligned, since it may contain a DWORD.
struct COLUMNDATA
{
DBSTATUSwStatus;// status of column
DWORDdwLength;// length of data (not space allocated)
BYTEbData[1];// data here and beyond
};


/******************************* End of File ********************************/