home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_03 / 3n03006a < prev    next >
Text File  |  1992-02-08  |  9KB  |  278 lines

  1. /*
  2.  File name:    FADER2.C
  3.  Description:  SDK Dialog Editor (DIALOG.EXE) support funcs.
  4. */
  5.  
  6. #include <windows.h>
  7. #include <custcntl.h>
  8. #include "fader.h"
  9. #include "dialog.h"
  10.  
  11. /* Property string used internally for local handle of
  12.    CTLSTYLEDLG structure */
  13. static char szFaderCtlProp[] = "CtlDlgStyleData";
  14. extern HANDLE hGlobFaderInstance;
  15. extern char szGlobControlName[];
  16.  
  17. /* Data structure used internally to access data in
  18.    the style dialog box function. */
  19. typedef struct {
  20.    GLOBALHANDLE hCtlStyle;    /* Handle holds CTLSTYLE */
  21.    LPFNSTRTOID  lpfnStrToId;  /* convert string to ID */
  22.    LPFNIDTOSTR  lpfnIdToStr;  /* convert ID to string */
  23. } CTLSTYLEDLG, FAR *LPCTLSTYLEDLG, NEAR *NPCTLSTYLEDLG;
  24.  
  25. /* Forward declarations, for completeness */
  26.  
  27. LPCTLSTYLE FAR PASCAL CtlStyleLock (HWND hDlg);
  28. VOID FAR PASCAL CtlStyleUnlock (HWND hDlg);
  29. WORD FAR PASCAL GetIdString (HWND hDlg, LPSTR szId,
  30.      WORD wIdMaxLen);
  31. DWORD FAR PASCAL PutIdValue (HWND hDlg, LPSTR szId);
  32. BOOL FAR PASCAL FaderDlgFn (HWND hDlg, WORD wMessage,
  33.      WORD wParam, LONG lParam);
  34. BOOL FAR PASCAL FaderDlgCmdFn (HWND hDlg, WORD wParam,
  35.      LONG lParam);
  36.  
  37.  
  38. GLOBALHANDLE FAR PASCAL FaderInfo (void)
  39. {
  40.    GLOBALHANDLE hCtlInfo = NULL;
  41.    LPCTLINFO lpCtlInfo; WORD wNumTypes;
  42.  
  43.    hCtlInfo = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
  44.                         (DWORD) sizeof(CTLINFO));
  45.    if (hCtlInfo == NULL)
  46.       return NULL;
  47.    lpCtlInfo = (LPCTLINFO) GlobalLock(hCtlInfo);
  48.    lpCtlInfo->wVersion  = 0x0100;
  49.  
  50.    /* Initialize wCtlTypes to zero */
  51.    lpCtlInfo->wCtlTypes = 0;
  52.    lstrcpy(lpCtlInfo->szClass, szGlobControlName);
  53.    lstrcpy(lpCtlInfo->szTitle, szGlobControlName);
  54.    wNumTypes = lpCtlInfo->wCtlTypes;
  55.    if (wNumTypes == CTLTYPES) {
  56.       GlobalUnlock(hCtlInfo);
  57.       return hCtlInfo;
  58.       }
  59.    lpCtlInfo->Type[wNumTypes].wType   = 0;
  60.    lpCtlInfo->Type[wNumTypes].wWidth  = 12;
  61.    lpCtlInfo->Type[wNumTypes].wHeight = 24;
  62.    lpCtlInfo->Type[wNumTypes].dwStyle = WS_BORDER
  63.                           | WS_CHILD | WS_TABSTOP;
  64.    lstrcpy(lpCtlInfo->Type[wNumTypes].szDescr,
  65.                             szGlobControlName);
  66.    lpCtlInfo->wCtlTypes++;
  67.    GlobalUnlock(hCtlInfo);
  68.    return hCtlInfo;
  69. }
  70.  
  71.  
  72. BOOL FAR PASCAL FaderStyle (HWND hWnd, GLOBALHANDLE hCtlStyle,
  73.    LPFNSTRTOID lpfnStrToId, LPFNIDTOSTR lpfnIdToStr)
  74. {
  75.    LOCALHANDLE hCtlStyleDlg;
  76.    NPCTLSTYLEDLG npCtlStyleDlg;
  77.    int x;
  78.  
  79.    hCtlStyleDlg = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT,
  80.                                       sizeof(CTLSTYLEDLG));
  81.    if (hCtlStyleDlg == NULL)
  82.        return FALSE;
  83.    npCtlStyleDlg = (NPCTLSTYLEDLG) LocalLock(hCtlStyleDlg);
  84.    npCtlStyleDlg->hCtlStyle = hCtlStyle;
  85.    npCtlStyleDlg->lpfnStrToId = lpfnStrToId;
  86.    npCtlStyleDlg->lpfnIdToStr = lpfnIdToStr;
  87.    LocalUnlock(hCtlStyleDlg);
  88.  
  89.    /* Associate property with Dialog Editor's window. */
  90.    SetProp(hWnd, szFaderCtlProp, hCtlStyleDlg);
  91.  
  92.    /* Display control's Styles Dialog Box. */
  93.    x = DialogBoxParam(hGlobFaderInstance, "StyleDlg",
  94.                                 hWnd, FaderDlgFn, 0);
  95.    /* Remove property associated with
  96.       Dialog Editor's window. */
  97.    RemoveProp(hWnd, szFaderCtlProp);
  98.  
  99.    LocalFree(hCtlStyleDlg);
  100.    /* Return whether CTLSTYLE structure has been changed.*/
  101.    return x==IDOK;
  102. }
  103.  
  104.  
  105. BOOL FAR PASCAL FaderDlgFn (HWND hDlg, WORD wMsg,
  106.    WORD wParam, LONG lParam)
  107. {
  108.    BOOL bProcMsg = TRUE;
  109.    char szId[20];
  110.    LPCTLSTYLE lpCtlStyle;
  111.  
  112.    switch (wMsg)
  113.       {
  114.       case WM_INITDIALOG:
  115.          /* Set the "EDIT" control with the name of
  116.             this control's ID. */
  117.          GetIdString(hDlg, szId, sizeof(szId));
  118.          SetDlgItemText(hDlg, ID_VALUE, szId);
  119.  
  120.        /* Initialize check box w/Fader control's styles. */
  121.          lpCtlStyle = CtlStyleLock(hDlg);
  122.          SendDlgItemMessage(hDlg, ID_TRACK, BM_SETCHECK,
  123.             (BOOL) (lpCtlStyle->dwStyle & FDRS_TRACK), 1L);
  124.          CtlStyleUnlock(hDlg);
  125.          break;
  126.       case WM_COMMAND:
  127.          FaderDlgCmdFn(hDlg, wParam, lParam);
  128.          break;
  129.       default:
  130.          bProcMsg = FALSE;
  131.          break;
  132.    }
  133.    return bProcMsg;
  134. }
  135.  
  136.  
  137. BOOL FAR PASCAL FaderDlgCmdFn (HWND hDlg, WORD wParam,
  138.                                           LONG lParam)
  139. {
  140.    DWORD dwResult;
  141.    char szId[20];
  142.    LPCTLSTYLE lpCtlStyle;
  143.  
  144.    switch(wParam)
  145.       {
  146.       case IDOK:
  147. /* Convert the string ID value to its numeric equivalent. */
  148.          GetDlgItemText(hDlg, ID_VALUE, szId, sizeof(szId));
  149.          dwResult = PutIdValue(hDlg, szId);
  150.  
  151. /* If string ID not found or added, stay in Dialog box. */
  152.          if (LOWORD(dwResult) == 0)
  153.             break;
  154.  
  155.          /* Calculate the new control's styles. */
  156.          lpCtlStyle = CtlStyleLock(hDlg);
  157.  
  158.          /* Clear control-specific flags */
  159.          lpCtlStyle->dwStyle &= 0xFFFF0000L;
  160.  
  161.          if (SendDlgItemMessage(hDlg, ID_TRACK,
  162.                                     BM_GETCHECK, 0, 0L))
  163.             lpCtlStyle->dwStyle |= FDRS_TRACK;
  164.  
  165.          CtlStyleUnlock(hDlg);
  166.          EndDialog(hDlg, wParam);
  167.          break;
  168.       case IDCANCEL:
  169.          EndDialog(hDlg, wParam);
  170.          break;
  171.       case ID_VALUE:
  172. /* Disable IDOK button if no text exists in ID_VALUE box. */
  173.          if (HIWORD(lParam) == EN_CHANGE)
  174.             EnableWindow(GetDlgItem(hDlg, IDOK),
  175.                SendMessage(LOWORD(lParam), WM_GETTEXTLENGTH,
  176.                0, 0L) ? TRUE : FALSE);
  177.          break;
  178.       default:
  179.          return FALSE;
  180.          break;
  181.    }
  182.    return TRUE;
  183. }
  184.  
  185.  
  186. WORD FAR PASCAL FaderFlags (DWORD dwFlags, LPSTR szString,
  187.                                           WORD wMaxString)
  188. {
  189.    *szString = 0;
  190.    if (dwFlags & FDRS_TRACK)
  191.       lstrcat(szString, "FDRS_TRACK");
  192.    return lstrlen(szString);
  193. }
  194.  
  195.  
  196. LPCTLSTYLE FAR PASCAL CtlStyleLock (HWND hDlg) {
  197.    LOCALHANDLE hCtlStyleDlg;
  198.    NPCTLSTYLEDLG npCtlStyleDlg;
  199.    LPCTLSTYLE lpCtlStyle;
  200.  
  201.    if ( (hCtlStyleDlg=GetProp(GetParent(hDlg),
  202.                      szFaderCtlProp)) == NULL)
  203.        return NULL;
  204.    npCtlStyleDlg = (NPCTLSTYLEDLG) LocalLock(hCtlStyleDlg);
  205.    lpCtlStyle = (LPCTLSTYLE) GlobalLock(
  206.                         npCtlStyleDlg->hCtlStyle);
  207.    LocalUnlock(hCtlStyleDlg);
  208.    return lpCtlStyle;
  209. }
  210.  
  211. VOID FAR PASCAL CtlStyleUnlock (HWND hDlg) {
  212.    LOCALHANDLE hCtlStyleDlg;
  213.    NPCTLSTYLEDLG npCtlStyleDlg;
  214.  
  215.    if ((hCtlStyleDlg=GetProp(GetParent(hDlg),
  216.                         szFaderCtlProp)) == NULL)
  217.       return;
  218.    npCtlStyleDlg = (NPCTLSTYLEDLG) LocalLock(hCtlStyleDlg);
  219.    GlobalUnlock(npCtlStyleDlg->hCtlStyle);
  220.    LocalUnlock(hCtlStyleDlg);
  221. }
  222.  
  223. /* Convert number into ID string */
  224. WORD FAR PASCAL GetIdString (HWND hDlg, LPSTR szId,
  225.                                 WORD wIdMaxLen) {
  226.    LOCALHANDLE hCtlStyleDlg;
  227.    NPCTLSTYLEDLG npCtlStyleDlg;
  228.    LPCTLSTYLE lpCtlStyle;
  229.    WORD wIdLen;
  230.  
  231.    /* Property is associated with Dialog Editor's window.
  232.       Parent of the dialog box is the Dialog Editor. */
  233.    if (( hCtlStyleDlg=GetProp(GetParent(hDlg),
  234.                 szFaderCtlProp)) == NULL)
  235.        return 0;
  236.  
  237.    npCtlStyleDlg = (NPCTLSTYLEDLG) LocalLock(hCtlStyleDlg);
  238.    lpCtlStyle = (LPCTLSTYLE) GlobalLock(
  239.                                 npCtlStyleDlg->hCtlStyle);
  240.    /* Call the lpfnIdToStr function to convert the numeric
  241.       ID to its string equivalent. */
  242.    wIdLen = (*npCtlStyleDlg->lpfnIdToStr)
  243.               (lpCtlStyle->wId, szId, wIdMaxLen);
  244.    GlobalUnlock(npCtlStyleDlg->hCtlStyle);
  245.    LocalUnlock(hCtlStyleDlg);
  246.    return wIdLen;
  247. }
  248.  
  249. /* Convert ID string value to int and store in CTLSTYLE */
  250. DWORD FAR PASCAL PutIdValue (HWND hDlg, LPSTR szId) {
  251.    LOCALHANDLE hCtlStyleDlg;
  252.    NPCTLSTYLEDLG npCtlStyleDlg;
  253.    LPCTLSTYLE lpCtlStyle;
  254.    DWORD dwResult = 0;
  255.  
  256.    if ((hCtlStyleDlg=GetProp(GetParent(hDlg),
  257.                 szFaderCtlProp)) == NULL )
  258.       return NULL;
  259.    npCtlStyleDlg = (NPCTLSTYLEDLG) LocalLock(hCtlStyleDlg);
  260.  
  261.    /* Call the lpfnStrToId function to convert the string
  262.       ID to its numeric equivalent. */
  263.    dwResult = (*npCtlStyleDlg->lpfnStrToId)(szId);
  264.  
  265.    LocalUnlock(hCtlStyleDlg);
  266.  
  267.    /* If LOWORD is zero, string NOT found. */
  268.    if (LOWORD(dwResult) == 0)
  269.       return dwResult;
  270.  
  271.    /* LOWORD is not zero, numeric ID is in the HIWORD. */
  272.    lpCtlStyle = CtlStyleLock(hDlg);
  273.    lpCtlStyle->wId = HIWORD(dwResult);
  274.    CtlStyleUnlock(hDlg);
  275.    return dwResult;
  276. }
  277.  
  278.