home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / LISTCTRL.PAK / STCKINFO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  7.8 KB  |  264 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   stckinfo.c
  9. //
  10. //  PURPOSE:   Displays the "Edit Stock Information" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    CmdEditStockInfo - Displays the "Edit Stock Information" dialog box
  14. //    EditStockInfo    - Processes messages for "Edit Stock Information" 
  15. //                       dialog box.
  16. //    MsgESInit        - To initialize the dialogbox 
  17. //    MsgESCommand     - Process WM_COMMAND message sent to the dialog
  18. //    CmdESDone        - Free the dialog box and store the new data.
  19. //
  20. //  COMMENTS:
  21. //
  22. //
  23.  
  24. #include <windows.h>            // required for all Windows applications
  25. #include <windowsx.h>
  26. #include <commctrl.h>
  27.  
  28. #include "globals.h"            // prototypes specific to this application
  29. #include "listview.h"
  30. #include "resource.h"
  31.  
  32.  
  33. LRESULT CALLBACK EditStockInfo(HWND, UINT, WPARAM, LPARAM);
  34.  
  35. LRESULT MsgESInit(HWND, UINT, WPARAM, LPARAM);
  36. LRESULT MsgESCommand(HWND, UINT, WPARAM, LPARAM);
  37. LRESULT CmdESDone(HWND, WORD, WORD, HWND);
  38.  
  39. // Dialog message table definition.
  40. MSD rgmsdEditStockInfo[] =
  41. {
  42.     {WM_COMMAND,    MsgESCommand},
  43.     {WM_INITDIALOG, MsgESInit}
  44. };
  45.  
  46. MSDI msdiEditStockInfo =
  47. {
  48.     sizeof(rgmsdEditStockInfo) / sizeof(MSD),
  49.     rgmsdEditStockInfo,
  50.     edwpNone
  51. };
  52.  
  53. // Dialog command table definition.
  54. CMD rgcmdEditStockInfo[] =
  55. {
  56.     {IDOK,     CmdESDone},
  57.     {IDCANCEL, CmdESDone}
  58. };
  59.  
  60. CMDI cmdiEditStockInfo =
  61. {
  62.     sizeof(rgcmdEditStockInfo) / sizeof(CMD),
  63.     rgcmdEditStockInfo,
  64.     edwpNone
  65. };
  66.  
  67. //
  68. //  FUNCTION: CmdEditStockInfo(HWND, WORD, WORD, HWND)
  69. //
  70. //  PURPOSE: Displays the "Edit Stock Information" dialog box
  71. //
  72. //  PARAMETERS:
  73. //    hwnd      - Window handle
  74. //    wCommand  - IDM_EDITSTOCKINFO (unused)
  75. //    wNotify   - Notification number (unused)
  76. //    hwndCtrl  - NULL (unused)
  77. //
  78. //  RETURN VALUE:
  79. //
  80. //    Always returns 0 - Message handled
  81. //
  82. //  COMMENTS:
  83. //    To process the IDM_EDITSTOCKINFO message, call DialogBox() to display the
  84. //    dialog box.
  85.  
  86. #pragma argsused
  87. LRESULT CmdEditStockInfo(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  88. {
  89.     DialogBox(hInst, MAKEINTRESOURCE(IDD_EDITSTOCKINFO), hwnd, (DLGPROC)EditStockInfo);
  90.     return 0;
  91. }
  92.  
  93.  
  94. //
  95. //  FUNCTION: EditStockInfo(HWND, UINT, WPARAM, LPARAM)
  96. //
  97. //  PURPOSE:  Processes messages for "Edit Stock Information" dialog box.
  98. //
  99. //  PARAMETERS:
  100. //    hdlg - window handle of the dialog box
  101. //    wMessage - type of message
  102. //    wparam - message-specific information
  103. //    lparam - message-specific information
  104. //
  105. //  RETURN VALUE:
  106. //    TRUE - message handled
  107. //    FALSE - message not handled
  108. //
  109. //  COMMENTS:
  110. //
  111. //
  112.  
  113. LRESULT CALLBACK EditStockInfo(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  114. {
  115.     return DispMessage(&msdiEditStockInfo, hdlg, uMessage, wparam, lparam);
  116. }
  117.  
  118.  
  119. //
  120. //  FUNCTION: MsgESInit(HWND, UINT, WPARAM, LPARAM)
  121. //
  122. //  PURPOSE: To initialize the controls in the dialog box with the 
  123. //           stock information.
  124. //
  125. //  PARAMETERS:
  126. //    hwnd - The window handing the message.
  127. //    uMessage - The message number. (unused).
  128. //    wparam - Message specific data (unused).
  129. //    lparam - Message specific data (unused).
  130. //
  131. //  RETURN VALUE:
  132. //    Always returns 0 - message handled.
  133. //
  134. //  COMMENTS:
  135. //
  136.  
  137. #pragma argsused
  138. LRESULT MsgESInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  139. {
  140.      HWND hwndLV = GetDlgItem(GetParent(hdlg), IDD_LISTVIEW);
  141.      int iFocusItem = ListView_GetNextItem(hwndLV, -1, LVNI_ALL | LVNI_FOCUSED);
  142.      STOCKINFO *psi;
  143.     LV_ITEM   lvi;
  144.  
  145.     if (iFocusItem != -1)
  146.     {
  147.         lvi.mask     = LVIF_PARAM;
  148.         lvi.iItem    = iFocusItem;
  149.         lvi.iSubItem = 0;
  150.         
  151.         ListView_GetItem(hwndLV, &lvi);
  152.         psi = (STOCKINFO *)lvi.lParam;
  153.         
  154.         SetDlgItemText(hdlg, IDC_COMPANYNAME, psi->szCompany);
  155.           SetDlgItemText(hdlg, IDC_SYMBOL,      psi->szSymbol);
  156.         SetDlgItemText(hdlg, IDC_EXCHANGE,    psi->szExchange);
  157.         
  158.         SetDlgItemInt(hdlg, IDC_HIGH,         psi->iHigh,  FALSE);
  159.         SetDlgItemInt(hdlg, IDC_LOW,          psi->iLow,   FALSE);
  160.         SetDlgItemInt(hdlg, IDC_CLOSE,        psi->iClose, FALSE);
  161.         
  162.         SetDlgItemText(hdlg, IDC_NEWS,        psi->szNews);
  163.         
  164.         SendDlgItemMessage(hdlg, IDC_COMPANYNAME, EM_LIMITTEXT, IDC_MAXCOMPANYLEN-1,  0L);
  165.         SendDlgItemMessage(hdlg, IDC_SYMBOL,      EM_LIMITTEXT, IDC_MAXSYMBOLLEN-1,   0L);
  166.         SendDlgItemMessage(hdlg, IDC_EXCHANGE,    EM_LIMITTEXT, IDC_MAXEXCHANGELEN-1, 0L);
  167.         SendDlgItemMessage(hdlg, IDC_HIGH,        EM_LIMITTEXT, IDC_MAXDOLLARLEN-1,   0L);
  168.           SendDlgItemMessage(hdlg, IDC_LOW,         EM_LIMITTEXT, IDC_MAXDOLLARLEN-1,   0L);
  169.         SendDlgItemMessage(hdlg, IDC_CLOSE,       EM_LIMITTEXT, IDC_MAXDOLLARLEN-1,   0L);
  170.         SendDlgItemMessage(hdlg, IDC_NEWS,        EM_LIMITTEXT, IDC_MAXNEWSLEN-1,     0L);
  171.         
  172.         SetWindowLong(hdlg, DWL_USER, (LONG)psi);
  173.     }
  174.     else
  175.     {
  176.         MessageBox(hdlg, "Please select an item first", "LISTCTRL", MB_OK);
  177.         EndDialog(hdlg, FALSE);          // Exit the dialog
  178.         SetFocus(GetDlgItem(GetParent(hdlg), IDD_LISTVIEW));
  179.     }
  180.  
  181.      return TRUE;
  182. }
  183.  
  184. //
  185. //  FUNCTION: MsgESCommand(HWND, UINT, WPARAM, LPARAM)
  186. //
  187. //  PURPOSE: Process WM_COMMAND message sent to the dialog.
  188. //
  189. //  PARAMETERS:
  190. //    hwnd - The window handing the message.
  191. //    uMessage - The message number. (unused).
  192. //    wparam - Message specific data (unused).
  193. //    lparam - Message specific data (unused).
  194. //
  195. //  RETURN VALUE:
  196. //    Always returns 0 - message handled.
  197. //
  198. //  COMMENTS:
  199. //    Uses this DipsCommand function defined in wndproc.c combined
  200. //    with the cmdiEditStockInfo structure defined in this file to handle
  201. //    the command messages for the dialog box.
  202. //
  203.  
  204. #pragma argsused
  205. LRESULT MsgESCommand(HWND   hwnd,
  206.                             UINT   uMessage,
  207.                      WPARAM wparam, 
  208.                      LPARAM lparam)
  209. {
  210.     return DispCommand(&cmdiEditStockInfo, hwnd, wparam, lparam);
  211. }
  212.  
  213. //
  214. //  FUNCTION: CmdESDone(HWND, WORD, HWND)
  215. //
  216. //  PURPOSE: Free the dialog box and grab the new stock data.
  217. //
  218. //  PARAMETERS:
  219. //    hwnd - The window handling the command.
  220. //    wCommand - The command to be handled (unused).
  221. //    wNotify   - Notification number (unused)
  222. //    hwndCtrl - NULL (unused).
  223. //
  224. //  RETURN VALUE:
  225. //    Always returns TRUE.
  226. //
  227. //  COMMENTS:
  228. //    Calls EndDialog to finish the dialog session.
  229. //
  230.  
  231. #pragma argsused
  232. LRESULT CmdESDone(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  233. {
  234.      HWND hwndLV=GetDlgItem(GetParent(hdlg), IDD_LISTVIEW);
  235.      int iFocusItem = ListView_GetNextItem(hwndLV, -1, LVNI_ALL | LVNI_SELECTED);
  236.     BOOL bSuccess=0;
  237.     RECT rc;
  238.  
  239.     if (wCommand==IDOK)
  240.     {
  241.         STOCKINFO *psi = (STOCKINFO *)GetWindowLong(hdlg, DWL_USER);
  242.  
  243.         GetDlgItemText(hdlg, IDC_COMPANYNAME, psi->szCompany, IDC_MAXCOMPANYLEN);
  244.         GetDlgItemText(hdlg, IDC_SYMBOL, psi->szSymbol, IDC_MAXSYMBOLLEN);
  245.         GetDlgItemText(hdlg, IDC_EXCHANGE, psi->szExchange, IDC_MAXEXCHANGELEN);
  246.  
  247.         psi->iHigh  = GetDlgItemInt(hdlg, IDC_HIGH,  &bSuccess, FALSE);
  248.           psi->iLow   = GetDlgItemInt(hdlg, IDC_LOW,   &bSuccess, FALSE);
  249.         psi->iClose = GetDlgItemInt(hdlg, IDC_CLOSE, &bSuccess, FALSE);
  250.  
  251.         GetDlgItemText(hdlg, IDC_NEWS, psi->szNews, IDC_MAXNEWSLEN);
  252.  
  253.         ListView_GetItemRect(hwndLV, iFocusItem, &rc, LVIR_BOUNDS);
  254.  
  255.         InvalidateRect(hwndLV, &rc, TRUE);
  256.         UpdateWindow(hwndLV);
  257.     }
  258.  
  259.     EndDialog(hdlg, wCommand==IDOK);          // Exit the dialog
  260.     SetFocus(hwndLV);
  261.      return TRUE;
  262. }
  263.  
  264.