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 / qurydemo / qurydemo.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-06  |  13.3 KB  |  310 lines

  1. /*
  2.     Header File for QURYDEMO application
  3.     Created by Microsoft Corporation.
  4. */
  5. #ifdef WIN32
  6. #define CONSTSTR(name, str) const char name[]=str
  7. #else
  8. #define CONSTSTR(name, str) const char FAR * name=str
  9. #endif
  10.  
  11.  
  12. #ifdef RC_INVOKED
  13. #define ID(id) id
  14. #else
  15. #define ID(id) MAKEINTRESOURCE(id)
  16. #endif
  17.  
  18. /* Resource Identifiers */
  19.  
  20. #define BMP_NEWQUERY        ID(10)  // new window button bitmap
  21. #define BMP_RUNQUERY        ID(20)  // exec query button bitmap
  22. #define APPICON             ID(30)  // application icon
  23. #define QUERYWINDOWICON     ID(40)  // MDI Child window icon
  24. #define QURYDEMOMENU        ID(50)  // Application menu
  25. #define CONNECTDIALOG       ID(60)  // connect modal dialog box
  26. #define DISCONNECTDIALOG    ID(70)  // disconnect modal dialog box
  27. #define ABOUTDIALOG         ID(80)  // about modal dialog box
  28. #define MDICHILDDIALOG      ID(90)  // MDI Child modeless dialog box
  29. #define APPACCELERATOR      ID(100) // Accelerator table for the app
  30.  
  31. /* Menu Identifiers */
  32.  
  33. #define IDM_POPUPAPPSYS     10  // Placeholder, used by status bar
  34. #define IDM_POPUPMDISYS     20  // Placeholder, used by status bar
  35. #define IDM_POPUPLOGIN      100 // Placeholder, used by status bar
  36. #define IDM_CONNECT         110
  37. #define IDM_DRIVERCONNECT   120
  38. #define IDM_DISCONNECT      130 
  39. #define IDM_EXIT            140
  40. #define IDM_POPUPQUERY      150 // Placeholder, used by status bar
  41. #define IDM_QUERY           160
  42. #define IDM_NEW             170
  43. #define IDM_POPUPWINDOW     180     // Placeholder, used by status bar
  44. #define IDM_TILE            190
  45. #define IDM_CASCADE         200
  46. #define IDM_ICONS           210
  47. #define IDM_CLOSEALL        220
  48. #define IDM_POPUPHELP       230 // Placeholder, used by status bar
  49. #define IDM_APPHELP         240
  50. #define IDM_ABOUT           250
  51.  
  52. #define IDM_MDICHILD        260
  53.  
  54. /* child window ids */
  55.  
  56. #define IDW_TOOLBAR         10
  57. #define IDW_STATUSBAR       20
  58. #define IDW_MDICLIENT       30
  59.  
  60. #define IDW_CRSRLIST        10  // toolbar comboboxes
  61. #define IDW_STMTLIST        20
  62.  
  63. #define IDCOMBO_DATASOURCE  10  // connect dialog box controls
  64. #define IDTEXT_USERNAME     20
  65. #define IDTEXT_PASSWORD     30
  66.  
  67. #define IDLIST_HDBC         10  // disconnect dialog box controls
  68. #define IDLIST_STMT         20
  69. #define IDCLOSE_ACTVTY      30
  70. #define IDDISCONNECT        40
  71. #define IDICON_WARN         50
  72.  
  73. #define IDTEXT_PRMPT        10  // MDI child's modeless dialog controls
  74. #define IDTEXT_SQL          20
  75. #define IDLIST_RSLT         30
  76.  
  77. /* MDI Child Window Offsets */
  78.  
  79. #define CBWNDEXTRA          4   // storage in MDI Child Window
  80. #define GWLAPP_HDLG         0   // child dialog handle
  81.  
  82. /* Help File */
  83.  
  84. #define SAMPLESHELPFILE     "..\\doc\\odbcsmpl.hlp"
  85. #define HLP_QURYDEMO        30
  86.  
  87. /* Other Constants */
  88.  
  89. #define MAXCHILDWNDS        10          //maximum child windows allowed
  90. #define MAXBUFLEN           256         //display buffer size
  91. #define MAX_COL             15          //maximum column in result set
  92. #define MAX_ROW             100         //maximum number of rows
  93. #define MAXDATALEN          25          //maximum data length per column
  94. #define MAXDISPLAYSIZE      MAX_COL*(MAXDATALEN+1)
  95. #define MINWIDTH            415         //minimum width of app window
  96. #define MINHEIGHT           350         //minimum height of app window
  97. #define LISTTABSTOP         100         //tabstop in the display listbox
  98. #define LISTHORZSCROLL      (LISTTABSTOP*2)     //horizontal scroll for the listbox
  99. #define LISTHORZEXT         0           //horizontal extent inthe list box
  100. #define WINDOWMENUPLACE     2           //Window menu place for adding MDI child windows
  101. #define IDT_STATUSTIMER     1           //timer id
  102. #define TIMERDELAY          60000           //timer duration
  103. #define BTTNX               345         //first toolbar button location
  104. #define BTTNY               2           //button y position
  105. #define BTTNWIDTH           25                      //button width
  106. #define BTTNHEIGHT          23                      //button height
  107. #define BTTNMARGIN          5           //distance between toolbar buttons
  108. #define TOOLBARMARGINY      5           //fixed margin w/o combobox height
  109. #define STATUSBARMARGINY    8           //fixed margin w/o textbox height
  110.  
  111. /* String Constants */
  112.  
  113. #define POPUPLOGIN          "&Login"
  114. #define MENUITEMCONNECT     "&Connect... \aCtrl+C"
  115. #define MENUITEMDRIVERCONNECT   "D&river Connect... \aCtrl+R"
  116. #define MENUITEMDISCONNECT  "&Disconnect... \aCtrl+D"
  117. #define MENUITEMEXIT        "E&xit"
  118. #define POPUPQUERY          "&Query"
  119. #define MENUITEMQUERY       "&Execute SQL \aCtrl+E"
  120. #define MENUITEMNEW         "&New Query \aCtrl+N"
  121. #define POPUPWINDOW         "&Window"
  122. #define MENUITEMTILE        "&Tile"
  123. #define MENUITEMCASCADE     "&Cascade"
  124. #define MENUITEMICONS       "Arrange &Icons"
  125. #define MENUITEMCLOSEALL    "Close &All"
  126. #define POPUPHELP           "&Help"
  127. #define MENUITEMAPPHELP     "&Help on Qurydemo"
  128. #define MENUITEMABOUT       "&About Qurydemo..."
  129.  
  130. #ifdef WIN32
  131. #define ODBCFRAMECLASS      "QDEMO32MAIN"
  132. #else
  133. #define ODBCFRAMECLASS      "QDEMOMAIN"
  134. #endif
  135.  
  136. #define ODBCTOOLCLASS       "QDEMOTool"
  137. #define ODBCSTATUSCLASS     "QDEMOStatus"
  138. #define ODBCMDICLASS        "QDEMOMDI"
  139. #define COMBOBOXCLASS       "COMBOBOX"
  140. #define MDICLIENTCLASS      "MDICLIENT"
  141. #define UNTITLED            "Untitled"
  142. #define APPTITLE            "ODBC Sample Program"
  143. #define EXECERROR           "Execution Error"
  144. #define INITERROR           "Failed to initialize ODBC interface"
  145. #define CLASSERROR          "Failed to register application class"
  146. #define CREATEMAINERR       "Failed to create application main window"
  147. #define CREATECHILDERR      "Failed to create a new window"
  148. #define ALPHABETS           "abcdefghijklmnopqrstuvwxyz"
  149. #define TIMETEXT            "MM:MM MM"
  150. #define DATETEXT            "MMM-MM"
  151. #define TIMEFORMAT          " %I:%M %p"
  152. #define DATEFORMAT          " %b-%d"
  153. #define NODSNERR            "Please provide a Data Source"
  154. #define MOREINFO            "Incomplete Information"
  155. #define STATUSPOPUPAPPSYS   " Control menu for the application "
  156. #define STATUSPOPUPMDISYS   " Control menu for the window "
  157. #define STATUSRESTORE       " Restore window to normal "
  158. #define STATUSMOVE          " Move window "
  159. #define STATUSSIZE          " Size window "
  160. #define STATUSMINIMIZE      " Minimize window "
  161. #define STATUSMAXIMIZE      " Maximize window "
  162. #define STATUSCLOSE         " Close window "
  163. #define STATUSNEXTWINDOW    " Switch to next window "
  164. #define STATUSPREVWINDOW    " Switch to previous window "
  165. #define STATUSTASKLIST      " Bring up task list "
  166. #define STATUSPOPUPLOGIN    " Login and logout commands "
  167. #define STATUSCONNECT       " Connect with default parameters... "
  168. #define STATUSDRIVERCONNECT " Connect with driver dialogs... "
  169. #define STATUSDISCONNECT    " Close open connections... "
  170. #define STATUSEXIT          " Exit application "
  171. #define STATUSPOPUPQUERY    " Query commands "
  172. #define STATUSQUERY         " Execute SQL statement... "
  173. #define STATUSNEW           " New window on current connection... "
  174. #define STATUSPOPUPWINDOW   " Window management commands "
  175. #define STATUSTILE          " Tile all normal child windows "
  176. #define STATUSCASCADE       " Cascade all normal child windows "
  177. #define STATUSICONS         " Arrange iconic child windows "
  178. #define STATUSCLOSEALL      " Close all child windows "
  179. #define STATUSMDICHILD      " Activate the window marked as %d"
  180. #define STATUSPOPUPHELP     " Help commands "
  181. #define STATUSAPPHELP       " Display help on application "
  182. #define STATUSABOUT         " About application "
  183. #define STATUSDEFAULT       " Ready "
  184.  
  185. #define DEFDBNAME               "?"
  186. #define DSN_HDBC_FORMAT         "%s!%lX"
  187. #define DSN_HDBC_HSTMT_FORMAT   "DSN=%s!HDBC=%lX!HSTMT=%lX"
  188. #define SCANDSNHDBC_FORMAT      "%[^!]!%lX"
  189. #define SCANHDBC_FORMAT         "%*[^!]!%lX"
  190. #define SCANHDBC_TITLEFORMAT    "DSN=%*[^!]!HDBC=%lX"
  191. #define SCANHDBCHSTMT_FORMAT    "DSN=%*[^!]!HDBC=%lX!HSTMT=%lX"
  192. #define SCANHSTMT_TITLEFORMAT   "DSN=%*[^!]!HDBC=%*lX!HSTMT=%lX"
  193. #define SCAN_HDBC_FORMAT            "%*c%lX"
  194. #define SCAN_HDBC_TITLEFORMAT        "DSN=%*cHDBC=%lX"
  195.  
  196.  
  197. #define CUR_MARK            "<-"
  198. #define CURQUERY_STRING     "Query!%lX<-"
  199. #define QUERY_STRING        "Query!%lX"
  200. #define MAKECONNECT         "Please connect to a data source using Login menu."
  201. #define OPENWINDOW          "Please open a window from Query menu."
  202. #define NOHDBCERROR         "No Connection Available"
  203. #define NOHSTMTERROR        "No Query Window Available"
  204. #define MAXCHILDEXCEEDED    "Please close a child window and try again."
  205. #define MAXCHLDERR          "Error - Too many Child Windows"
  206. #define COLTRUNC_WARNG      "Number of columns in display truncated to %u"
  207. #define ROWTRUNC_WARNG      "Number of rows in display truncated to %u"
  208. #define TRUNCERR            "Data Truncation"
  209. #define CLOSEALLHDBC        "All open connections have been closed."
  210. #define LOGOUTINFO          "Log Out Information"
  211. #define SQLERR_FORMAT       "SQL Error State:%s, Native Error Code: %lX, ODBC Error: %s"
  212. #define SQLERRMSGTITLE      "SQL_ERROR results"
  213. #define SQLERRCNTDTITLE     "SQL_ERROR results continued"
  214. #define SQLWRNMSGTITLE      "SQL_SUCCESS_WITH_INFO results"
  215. #define SQLWRNCNTDTITLE     "SQL_SUCCESS_WITH_INFO results continued"
  216. #define NULLDATASTRING      "SQL_NULL_DATA"
  217.  
  218.  
  219.  
  220. /* Globals */
  221.  
  222. HWND        hWndFrame;      // Main Frame Window handle
  223. HWND        hWndToolbar;    // Toolbar window handle
  224. HWND        hWndCrsrList;   // hdbc(s) combobox on the tool bar
  225. HWND        hWndStmtList;   // hstmt(s) combobox on the tool bar
  226. HWND        hWndStatusbar;  // status bar handle
  227. HWND        hWndMDIClient;  // MDI Client window handle
  228. HWND        hWndActiveChild;// Current active MDI Child window
  229. HINSTANCE   hAppInstance;   // Application instance
  230. WORD        wStatusText;    // Status text state
  231. int         iTimex;         // Time box (on the status bar) width
  232. int         iDatex;         // Date box (on the status bar) width
  233. RECT        rectStatusText; // Text box on the status bar
  234.  
  235.  
  236.  
  237.  
  238. #ifdef __SQL    // internal to query.c
  239.  
  240. int         nChildCount;            // Number of child windows currently open
  241. SQLHENV     henv;                   // Environment Handle
  242. char        szDispBuffer[MAXDISPLAYSIZE+1]; // Display Buffer
  243. UCHAR       rgbData[MAX_COL][MAXDATALEN];   // Results Data Array
  244. SDWORD      dwDataLen[MAX_COL];     // Results Data Length Array
  245.  
  246. #endif
  247.  
  248. /* Macros and Function Prototypes */
  249.  
  250. #ifdef WIN32
  251. #define     ACTIVATEWINDOW(h)   SetForegroundWindow(h)
  252. #else
  253. #define     ACTIVATEWINDOW(h)   SetFocus(h)
  254. #endif
  255.  
  256. #define DRAWBTTNRECT(h,x,y,cx,cy)   MoveToEx(h,x+1,y,NULL);\
  257.                     LineTo(h,x+cx,y);\
  258.                     MoveToEx(h,x+cx,y+1,NULL);\
  259.                     LineTo(h,x+cx,y+cy);\
  260.                     MoveToEx(h,x+cx-1,y+cy,NULL);\
  261.                     LineTo(h,x,y+cy);\
  262.                     MoveToEx(h,x,y+cy-1,NULL);\
  263.                     LineTo(h,x,y);
  264.  
  265. #define DRAWBTTNLIFT1(h,x,y,cx,cy)  MoveToEx(h,x+1,y+cy-1,NULL);\
  266.                     LineTo(h,x+1,y+1);\
  267.                     LineTo(h,x+cx-1,y+1);
  268.  
  269. #define DRAWBTTNLIFT2(h,x,y,cx,cy)  MoveToEx(h,x+1,y+cy-1,NULL);\
  270.                     LineTo(h,x+cx-1,y+cy-1);\
  271.                     LineTo(h,x+cx-1,y);\
  272.                     MoveToEx(h,x+2,y+cy-2,NULL);\
  273.                     LineTo(h,x+cx-2,y+cy-2);\
  274.                     LineTo(h,x+cx-2,y+1);
  275.  
  276. int PASCAL      WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
  277. long    CALLBACK    MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  278. long    CALLBACK    ToolbarProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  279. long    CALLBACK    StatusbarProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  280. long    CALLBACK    MDIChildProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  281. BOOL    CALLBACK    ConnectDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  282. BOOL    CALLBACK    DisconnectDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  283. BOOL    CALLBACK    AboutDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  284. BOOL    CALLBACK    MDIChildDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  285. VOID    FAR PASCAL  DrawBitmap(HDC hDC, int iLeft, int iTop, HBITMAP hBitmap);
  286.  
  287. BOOL    FAR PASCAL  InitSQLEnvironment();
  288. void    FAR PASCAL  DisplayDatabases(HWND hWnd);
  289. BOOL    FAR PASCAL  ConnectDatabase(HWND hWnd);
  290. BOOL    FAR PASCAL  DriverConnectDatabase(HWND hWnd);
  291. void    FAR PASCAL  DisplayConnections(HWND hWndhdbc);
  292. void    FAR PASCAL  DisplayQueries(HWND hWndhstmt, HWND hWndhdbc, int nCrsrIndex);
  293. void    FAR PASCAL  NewQueryWindow();
  294. void    FAR PASCAL  ChangeCurrentQuery(HWND hWndStmtList);
  295. void    FAR PASCAL  ChangeCurrentCursor(HWND hWndCrsrList);
  296. void    FAR PASCAL  DisplayNewCrsrAndStmt();
  297. void    FAR PASCAL  FreeConnect(HWND hWndhdbc);
  298. void    FAR PASCAL  FreeQuery(HWND hWndhstmt, HWND hWndhdbc, int nIndex);
  299. void    FAR PASCAL  CloseQueryWindow(HWND hWnd);
  300. BOOL    FAR PASCAL  FreeSQLEnvironment();
  301. void    FAR PASCAL  ExecuteQuery();
  302. BOOL    FAR PASCAL  CloseDatabases();
  303.  
  304. #ifdef __SQL    // internal to query.c
  305.  
  306. void    FAR PASCAL  DisplayError(SQLRETURN nResult, HWND hWnd, SWORD fHandleType, SQLHANDLE handle);
  307.  
  308. #endif
  309. /******************************* End of File ********************************/
  310.