home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / odbc / crsrdemo / crsrdemo.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-20  |  14.9 KB  |  338 lines

  1. /*--------------------------------------------------------------------------
  2.   Cursors.h -- General constants, types, prototypes and variables
  3.  
  4.   This code is furnished on an as-is basis as part of the ODBC SDK and is
  5.   intended for example purposes only.
  6.  
  7. --------------------------------------------------------------------------*/
  8.  
  9. #ifndef __CURSORS_H
  10. #define __CURSORS_H
  11.  
  12.  
  13. #ifdef    _M_ALPHA
  14. #define  Print(x,y,z) wsprintf(x,y,z)
  15. #else
  16. #define Print(x,y,z)  wvsprintf(x,y,z)
  17. #endif
  18.  
  19.  
  20. #ifdef INCL_GLOBAL
  21. #define GLOBAL
  22. #define INITHAND(name, type)    type name = NULL
  23. #ifdef WIN32
  24. #define CONSTSTR(name, str) const char name[]=str
  25. #else
  26. #define CONSTSTR(name, str) const char FAR * name=str
  27. #endif
  28. #else
  29. #define GLOBAL  extern
  30. #define INITHAND(name, type)    extern type name
  31. #ifdef WIN32
  32. #define CONSTSTR(name, str) extern const char name[]
  33. #else
  34. #define CONSTSTR(name, str) extern const char FAR * name
  35. #endif
  36. #endif
  37.  
  38.  
  39. // Constants ---------------------------------------------------------------
  40. #ifdef WIN32
  41. #define EXPFUNC __stdcall
  42. #define INTFUNC __stdcall
  43. #else
  44. #define EXPFUNC __export __far __pascal
  45. #define INTFUNC __pascal
  46. #endif
  47.  
  48.  
  49. #define INLINE __inline
  50.  
  51. // Miscellaneous
  52. #define cbMAXSQL    512                    // Maximum SQL string length
  53. #define cbSTRLEN    256                    // Maximum string length
  54. #define cbINTLEN    16                     // maximum length of an decimal
  55.                                            // integer in text format
  56. #define cbBUFSIZE   4096                   // Working buffer size
  57. #define cPOINTS 10                         // Font point size
  58. #define cxBORDER    6                      // Painting border
  59. #define cyBORDER    2                      // Painting border
  60. #define MAX_MAXBIND 200                    // maximum length of any column
  61. #define DEF_MAXBIND 50                     // default maximum length
  62.  
  63. // Miscellaneous strings
  64. CONSTSTR(szMDICLIENT,   "MDICLIENT");
  65. CONSTSTR(szCHILDCLASS,  "CursorsChild");
  66. CONSTSTR(szFRAMECLASS,  "CursorsFrame");
  67. CONSTSTR(szSTATICCLASS, "STATIC");
  68. CONSTSTR(szEDITCLASS,   "EDIT");
  69. CONSTSTR(szSCROLLCLASS, "SCROLLBAR");
  70. CONSTSTR(szDSNKEY,      "DSN=");
  71. CONSTSTR(szDATATRUNC,   "01004");
  72. CONSTSTR(szTITLEFMT,    "%s (CURSOR%04d)");
  73. CONSTSTR(szCURSORNAME,  "CURSOR%04d");
  74. CONSTSTR(szFONT,        "MS Sans Serif");
  75. CONSTSTR(szRECORD,      "Record:");
  76. CONSTSTR(szRECNUM,      "%6d");
  77. CONSTSTR(szHELPFILE,    "..\\doc\\odbcsmpl.hlp");  // Samples help file
  78. CONSTSTR(szKeyword,        "cursor demo features");
  79.  
  80. #define HLP_CRSRDEMO 40     // magic from help file
  81.  
  82. // Macros
  83. #define AllocPtr(x) GlobalAllocPtr(GHND, (x))
  84. #define FreePtr(x)      if ((x)) GlobalFreePtr((x))
  85. #define DBCError(hwnd,x)    ODBCError(hwnd,SQL_HANDLE_DBC, g_hdbc, (x))
  86. #define ENVError(hwnd,x)    ODBCError(hwnd,SQL_HANDLE_ENV, g_henv,  (x))
  87.  
  88. #define SUCCESS(x)  (((x)==SQL_SUCCESS) || ((x)==SQL_SUCCESS_WITH_INFO))
  89.  
  90. #define ISBLANK(x)      ((x) == ' ')
  91. #define ISCOMMA(x)      ((x) == ',')
  92. #define ISNUM(x)        (((x) >= '0') && ((x) <= '9'))
  93. #define ISLPAREN(x)     ((x) == '(')
  94. #define ISRPAREN(x)     ((x) == ')')
  95. #define ISPERIOD(x)     ((x) == '.')
  96. #define ISRETURN(x)     (((x) == '\n') || ((x) == '\r'))
  97. #define ISTAB(x)        ((x) == '\t')
  98. #define ISWHITE(x)      (ISBLANK(x) || ISTAB(x) || ISRETURN(x))
  99.  
  100. #define ROW_BINDING(x)  (x->fBindByRow ==   IDC_RADIO_BINDROW)
  101. #define IS_ALLWFETCH(x) (x->dwGuiFlags & GUIF_ALWAYSFETCH)
  102. #define UNREF_PARAM(x)  (x)
  103.  
  104. #define MAXNAME     100
  105.  
  106.  
  107. // Types -------------------------------------------------------------------
  108. typedef UWORD  FAR  *LPUWORD;
  109. typedef SDWORD FAR  *LPSDWORD;
  110.  
  111. typedef struct tagBIGCOL {                 // Big column structure
  112.     char        szName[cbSTRLEN];          //   Column name
  113.     LPSTR       lpsz;                      //   Pointer to column data
  114.     SDWORD      cb;                        //   Length of data
  115. } BIGCOL, FAR *LPBIGCOL;
  116.  
  117. typedef struct tagCOL {                    // Column structure
  118.     char        szName[cbSTRLEN];          //   Column name
  119.     SDWORD      cb;                        //   Column width (transfer width)
  120.     SDWORD      cbc;                       //   Column width (display  width)
  121.     SWORD       fCType;                    //   C type
  122.     SWORD       fSqlType;                  //   ODBC Sql type
  123.     LPSDWORD    lpcb;                      //   Pointer to returned width
  124.     LPBYTE      lpb;                       //   Pointer to returned data
  125. } COL, FAR *LPCOL;
  126.  
  127. typedef struct tagCHILD {                  // Child window variables
  128.     HWND        hwnd;                      //   Current window handle
  129.     BOOL        fInSetScroll;              //   In SetScroll function flag
  130.     BOOL        fIsMinimized;              //   Window minimized flag
  131.     BOOL        fHaveMouse;                //   Mouse captured flag
  132.     int         iMouseRow;                 //   Mouse down row
  133.  
  134.     int         ccols;                     //   Number of characters per line
  135.     int         crowwin;                   //   Rows per window
  136.     int         ccolwin;                   //   Character columns per window
  137.     HWND        hwndVScroll;               //   Vertical scroll bar
  138.     HWND        hwndHScroll;               //   Horizontal scroll bar
  139.     BOOL        fVScroll;                  //   Vertical scroll active flag
  140.     BOOL        fHScroll;                  //   Horizontal scroll active flag
  141.  
  142.     LPINT       lpnTabs;                   //   Array of tab values
  143.     char        szFmt[cbSTRLEN];           //   Format string
  144.     char *     rglpv;                     //   wvsprintf data array
  145.  
  146.     HRGN        hrgn;                      //   Clip region
  147.     LPSTR       lpsz;                      //   Working buffer
  148.  
  149.     SQLHSTMT    hstmt;                     //   ODBC statement handle
  150.     SQLHSTMT    hstmtTmp;                  //   Temp ODBC statement handle
  151.     LPSTR       sql;                       //   SQL statement
  152.  
  153.     SWORD       ccol;                      //   Number of result columns
  154.     LPCOL       lpcol;                     //   Column information array
  155.     BOOL        fResultSetExists;          //   Result set exists flag
  156.     BOOL        fDataFetched;              //   Data has been fetched flag
  157.     LPUWORD     lpfStatus;                 //   Row status array
  158.  
  159.     BOOL        fBindByRow;                //   Row-wise binding flag
  160.     LPBYTE      lpb;                       //   Row-wise binding buffer
  161.     SDWORD      cbrow;                     //   Row-wise binding step quantity
  162.  
  163.     UWORD       fConcurrency;              //   Scroll concurrency
  164.     SDWORD      crowKeyset;                //   Keyset option
  165.     UWORD       crowRowset;                //   Rowset option
  166.     BOOL        fRowset;                   //   crowRowset has been modified
  167.     char        szRowset[cbINTLEN];        //   text format buffer of inputed
  168.                                            //   crowRowset
  169.  
  170.     BOOL        fAsync;                    //   Async enabled flag
  171.     BOOL        fCanceled;                 //   Request canceled flag
  172.     UWORD       irowPos;                   //   Positioned row (via SQLSetPos)
  173.     SDWORD      irow;                      //   First row in row set (absolute)
  174.     UWORD       cBind;                     //   Number of bound columns
  175.     BOOL        fBind;                     //   cBind's been modified 
  176.     char        szBind[cbINTLEN];          //   a buffer to store the
  177.                                            // text format of inputed cBind
  178.     BOOL        fBindAll;                  //   Bind all columns flag
  179.     UWORD       ccolRetrieved;             //   Number of retrieved columns
  180.  
  181.     SDWORD      arow;                      //   Fetch absolute value
  182.     SDWORD      rrow;                      //   Fetch relative value
  183.     UCHAR       szQualifier[MAXNAME];      //   qualifier name
  184.     UCHAR       szTable[MAXNAME];          //   table name
  185.     UCHAR       szUser[MAXNAME];           //   user name
  186.     UCHAR       szType[MAXNAME];           //   table type (for SQLtables)
  187.     UCHAR       szColName[MAXNAME];        //   column name (for SQLColumns)
  188.     UWORD       dwOperation;               //   operation to perform  (mistype)
  189.     DWORD       dwGuiFlags;                //   flags and state to the gui
  190.     SDWORD      crowMaxBind;               //   max length to bind col to
  191.     BOOL        fMaxBind;                  //   crowMaxBind has been modified
  192.     char        szMaxBind[cbINTLEN];       //   the text format buffer of the 
  193.                                            //   inputed crowMaxBind
  194.     DWORD       crowCurrent;               //   current actual size of rowset
  195.     BOOL        fNoConcurrency;            //   driver doesn't support concur
  196.     BOOL        fNoCursorType;             //   no cursor type
  197.     UWORD       dwRadioButton;             //   What radio button in info dlg?
  198.     UWORD       FetchOP;
  199. #ifdef THREAD
  200.     CRITICAL_SECTION ThreadCreation;
  201.     HANDLE hThread;
  202. #endif
  203. } CHILD, FAR *LPCHILD;
  204.  
  205. #define     OPER_SELECT     1
  206. #define     OPER_TABLES     2
  207. #define     OPER_PRIVS      3
  208. #define     OPER_STATS      4
  209. #define     OPER_PROCS      5
  210. #define     OPER_COLUMN     6
  211. #define     OPER_TYPES      7
  212.  
  213.  
  214. #define     GUIF_TABLES_RADIO   0x00001     // 'tables' radio button set
  215. #define     GUIF_ALWAYSFETCH    0x00002     // always fetch first
  216.  
  217. #define SetDlgText(hdlg,id,text)  Edit_SetText(GetDlgItem(hdlg,id), text)
  218.  
  219. // dialog pair -- dialog and id
  220.  
  221. typedef struct tagDialogPair{
  222.     LPSTR   szDlgPairTitle;
  223.     int     iDlgPairDlgId;
  224. } DIALOG_PAIR;
  225.  
  226.  
  227.  
  228.  
  229. // Prototypes --------------------------------------------------------------
  230. // General routines
  231. void INTFUNC AdjustMenus(void);
  232. int  INTFUNC DoDialog(HWND, int, DLGPROC);
  233. void INTFUNC DoMessage(HWND, UINT);
  234. void INTFUNC GetCurrentValue(LPSTR, LPCOL, LPCHILD);
  235. BOOL INTFUNC IsUpdateable(SDWORD);
  236. void INTFUNC MakeTable(void);
  237. BOOL INTFUNC ODBCError(HWND, SWORD, SQLHANDLE, SQLRETURN);
  238. BOOL INTFUNC SetCurrentValue(LPSTR, LPCOL, LPCHILD);
  239. SQLRETURN INTFUNC PrepareStmt(LPCHILD lpchild);
  240. BOOL INTFUNC ProcessResults(LPCHILD lpchild);
  241.  
  242. // Window/Dialog procedures
  243. BOOL CALLBACK InitControlCallback( HWND , LPARAM);
  244.  
  245. INLINE  BOOL    SetOrGetCheck( HWND,  int   , BOOL);
  246. INLINE  VOID    SetOrGetEditArray( HWND, UCHAR FAR *, int);
  247.  
  248. VOID    INTFUNC  InitializeDialogControls( HWND hDlg, LPCHILD   lpChild);
  249. VOID    INTFUNC  ControlValue ( LPCHILD, HWND, HWND , int   , int );
  250. BOOL    INTFUNC  InitializeListBox( HWND, int, const DIALOG_PAIR FAR * , int, int);
  251. BOOL    INTFUNC  SetHiddenFields( HWND  hDlg, int       iAct);
  252. BOOL    INTFUNC  AlignToControl( HWND   hWnd, HWND  hDlg, int       iCtlId);
  253. BOOL    CALLBACK OptionsDlgProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam);
  254. VOID    INTFUNC  ClassOnCommand(HWND hWnd, int iId, HWND hWndCtl, UINT uNotify);
  255. BOOL    CALLBACK ChildOptDlgProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam);
  256. BOOL    CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
  257. BOOL    CALLBACK AbsDlgProc(HWND, UINT, WPARAM, LPARAM);
  258. BOOL    CALLBACK DataDlgProc(HWND, UINT, WPARAM, LPARAM);
  259. BOOL    CALLBACK FindDlgProc(HWND, UINT, WPARAM, LPARAM);
  260. BOOL    CALLBACK MakeTableDlgProc(HWND, UINT, WPARAM, LPARAM);
  261. BOOL    CALLBACK OptDlgProc(HWND, UINT, WPARAM, LPARAM);
  262. BOOL    CALLBACK RelDlgProc(HWND, UINT, WPARAM, LPARAM);
  263. BOOL    CALLBACK StmtDlgProc(HWND, UINT, WPARAM, LPARAM);
  264. BOOL    CALLBACK TableDlgProc(HWND, UINT, WPARAM, LPARAM);
  265. BOOL    CALLBACK UpdateDlgProc(HWND, UINT, WPARAM, LPARAM);
  266. BOOL    CALLBACK SQLTablesDlgProc(HWND,UINT,WPARAM,LPARAM);
  267.  
  268. LRESULT CALLBACK ChildProc(HWND, UINT, WPARAM, LPARAM);
  269. LRESULT CALLBACK FrameProc(HWND, UINT, WPARAM, LPARAM);
  270.  
  271.  
  272. // Variables ---------------------------------------------------------------
  273. GLOBAL  HWND        g_hwnd;                // Main window handle
  274. GLOBAL  HWND        g_hwndClient;          // MDI client window handle
  275. GLOBAL  HWND        g_hwndChildDialog;     // child dialog if active
  276. GLOBAL  HINSTANCE   g_hinst;               // Instance handle
  277. GLOBAL  HACCEL      g_haccel;              // Accelerators
  278.  
  279. GLOBAL  HMENU       g_hmenuInit;           // Pre-connection menu
  280. GLOBAL  HMENU       g_hmenuInitWindow;     //   Windows menu (for MDI)
  281. GLOBAL  HMENU       g_hmenuFrame;          // Connection made menu
  282. GLOBAL  HMENU       g_hmenuFrameWindow;    //   Windows menu (for MDI)
  283. GLOBAL  HMENU       g_hmenuChild;          // Child window menu
  284. GLOBAL  HMENU       g_hmenuChildWindow;    //   Windows menu (for MDI)
  285.  
  286. GLOBAL  int         g_cxVScroll;           // Width  of vertical scroll bar
  287. GLOBAL  int         g_cyHScroll;           // Height of horizontal scroll bar
  288.  
  289. GLOBAL  int         g_cx;                  // Width  of a character
  290. GLOBAL  int         g_cy;                  // Height of a character
  291.  
  292. GLOBAL  int         g_cxRecord;            // Width of record count area
  293. GLOBAL  int         g_cxRecnum;            // Width of record number
  294.  
  295. GLOBAL  HFONT       g_hfontName;           // Column name font
  296. GLOBAL  HFONT       g_hfontData;           // Data font
  297.  
  298. GLOBAL  HBRUSH      g_hbrWin;              // Window background brush
  299. GLOBAL  HBRUSH      g_hbrBtn;              // Button face brush
  300. GLOBAL  HBRUSH      g_hbrScroll;           // Scroll bar brush
  301.  
  302. GLOBAL  SQLHENV     g_henv;                // ODBC environment handle
  303. GLOBAL  SQLHDBC     g_hdbc;                // ODBC connection handle
  304.  
  305. GLOBAL  SWORD       g_cbName;              // Maximum column name width
  306. GLOBAL  char        g_szQuoteChar[2];      // Identifier quote char
  307. GLOBAL  BOOL        g_fConnected;          // Connected flag
  308. GLOBAL  BOOL        g_fAsyncSupported;     // Driver supports async flag
  309. GLOBAL  char        g_szDSN[SQL_MAX_DSN_LENGTH+1];  // Data source name
  310. GLOBAL  int         g_cChild;              // Number of child windows
  311. GLOBAL  int         g_cCursor;             // Current cursor number
  312.  
  313. GLOBAL  char        g_szTable[cbSTRLEN];   // Make table name
  314. GLOBAL  SDWORD      g_mrows;               // Make table row count
  315.  
  316. GLOBAL  char        g_szTITLE[cbSTRLEN];   // App title
  317. GLOBAL  char        g_szNoRow[cbSTRLEN];   // No row string
  318. GLOBAL  char        g_szRowError[cbSTRLEN];// No row string
  319. GLOBAL  char        g_szNull[cbSTRLEN];    // Null column string
  320. GLOBAL  char        g_szRowDeleted[cbSTRLEN]; // Row deleted string
  321. GLOBAL  char        g_szUnknown[cbSTRLEN]; // Unknown string
  322.  
  323.  
  324.  
  325. // Constants ---------------------------------------------------------------
  326. #define WMU_INIT            (WM_USER+1)
  327. #define WMU_DROPTABLE       (WM_USER+2)
  328. #define WMU_INSERTREC       (WM_USER+4)
  329. #define WMU_CLEANUP         (WM_USER+5)
  330. #define WMU_CANCEL          (WM_USER+6)
  331. #define WMU_NEWOPTION       (WM_USER+7)         // new options child menu
  332. #define WMU_SETSUBTEXT      (WM_USER+8)         // set subtext (options group)
  333.  
  334. #define ACT_INIT            1                   // initialize control
  335. #define ACT_TRIGGER         2                   // control has been set
  336.  
  337. #endif // __CURSORS_H
  338.