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