HEAD.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:13k
源码类别:

Windows编程

开发平台:

Visual C++

  1. //**  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. //**  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
  3. //**  TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR
  4. //**  A PARTICULAR PURPOSE.
  5. //**
  6. //**  Copyright (C) 1993 - 1997 Microsoft Corporation. All Rights Reserved.
  7. //**
  8. //**  head.c
  9. //**
  10. //**  DESCRIPTION:
  11. //**     Window proc for IDF head pane
  12. //**
  13. //************************************************************************
  14. #include <windows.h>
  15. #include <windowsx.h>
  16. #include <mmsystem.h>
  17. #include <commctrl.h>
  18. #include "idfedit.h"
  19. #include "tridee.h"
  20. /*+
  21.  *
  22.  *-=================================================================*/
  23. STATICFN void LoadTree (
  24.    HWND      hWndT,
  25.    struct _instrum_info * piSelect,
  26.    LPIDFHEAD pih)
  27. {
  28.    HTREEITEM htiSelect = NULL;
  29.    HTREEITEM htiParent = TVI_ROOT;
  30.    struct _instrum_info * pi;
  31.    UINT  ii;
  32.    TreeView_DeleteAllItems(hWndT);
  33.    for (pi = &pih->ai[ii = 0]; ii < pih->nInstrum; ++ii, ++pi)
  34.       {
  35.       TV_INSERTSTRUCT ti;
  36.       HTREEITEM       hti;
  37.       ZeroMemory (&ti, sizeof(ti));
  38.       ti.hParent        = TVI_ROOT;
  39.       ti.hInsertAfter   = TVI_SORT;
  40.       ti.item.mask      = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
  41.       ti.item.state     = TVIS_EXPANDED;
  42.       ti.item.stateMask = 0xFF;
  43.       ti.item.lParam    = (LPARAM)pi;
  44.       if (pi->pInstrum)
  45.          ti.item.pszText = pi->pInstrum->szInstID;
  46.       else if (pi->pList)
  47.          {
  48.          LPRIFF pRiff = FindListChunk(pi->pList, FCC_hdr);
  49.          if (pRiff && pRiff->cb >= sizeof(IDFHEADER))
  50.             ti.item.pszText = ((LPIDFHEADER)(pRiff+1))->abInstID;
  51.          }                                                             
  52.          
  53.       assert (ti.item.pszText);
  54.       if ( ! ti.item.pszText)
  55.          continue;
  56.       hti = TreeView_InsertItem (hWndT, &ti);
  57.       if (piSelect && (piSelect == pi))
  58.          htiSelect = hti;
  59.       }
  60.    if (htiSelect)
  61.       {
  62.       assert (piSelect);
  63.       TreeView_SelectItem (hWndT, htiSelect);
  64.       }
  65. }
  66. /*+
  67.  *  HeadPrivate
  68.  *
  69.  *-=================================================================*/
  70. static LONG WINAPI HeadPrivate (
  71.    HWND   hWnd,
  72.    UINT   wMsgID,
  73.    WPARAM wParam,
  74.    LPARAM lParam)
  75.    {
  76.    LONG       lRet = 0l;               // return value from this routine
  77.    LPIDFHEAD  pih;
  78.    pih = (LPVOID) GetWindowLong (hWnd, GWL_USERDATA);
  79.    switch (wMsgID)
  80.       {
  81.       case HM_REFRESH_TREE:
  82.          LoadTree(pih->hWndTree, pih->piSelect, pih);
  83.          InvalidateRect (hWnd, NULL, FALSE);
  84.          break;
  85.       }
  86.    return lRet;
  87.    }
  88. /*+
  89.  *  HeadCommands
  90.  *
  91.  *-=================================================================*/
  92. LONG WINAPI HeadCommands (
  93.    HWND   hWnd,
  94.    WPARAM wParam,
  95.    LPARAM lParam)
  96.    {
  97.    LONG       lRet = 0l;               // return value from this routine
  98.    LPIDFHEAD  pih;
  99.    pih = (LPVOID) GetWindowLong (hWnd, GWL_USERDATA);
  100.    switch (GET_WM_COMMAND_ID(wParam,lParam))
  101.       {
  102.       }
  103.    return lRet;
  104.    }
  105. /*+
  106.  *  
  107.  *
  108.  *-=================================================================*/
  109. STATICFN BOOL WINAPI HandleInstrumentsSelChange (
  110.     HWND      hWnd,
  111.     LPNMHDR   lpnm,
  112.     LPIDFHEAD pih)
  113. {
  114.    LPNM_TREEVIEW pntv = (LPVOID)lpnm;
  115.    LPTV_ITEM     pti  = &pntv->itemNew;
  116.    //TV_ITEM       ti;
  117.    struct _instrum_info * pi;
  118.    //char          szSingle[MAX_ALIAS];
  119.    //BOOL          bChange = FALSE;
  120.    if (!pih)
  121.       return FALSE;
  122.    // if there was a valid previous selection.
  123.    // make sure that there a now changes to be
  124.    // saved off before we allow selection to proceed.
  125.    //
  126.    pi = (LPVOID)pntv->itemNew.lParam;
  127.    if (pi && !pi->pInstrum &&
  128.        (pih->piSelect == pi) && 
  129.        (pih->pInstrumSelect == &pih->instrum) &&
  130.        (pih->instrum.bChanged))
  131.       {
  132.       assert (0);
  133.       // need to save changes made to the instrument data
  134.       //
  135.       pi->pInstrum = CopyForEditing (&pih->instrum, sizeof(pih->instrum));
  136.       pih->bChanged = TRUE;
  137.       }
  138.    // setup ti to get text & # of children
  139.    // from the IDF filename entry.
  140.    //
  141.    //ti.mask       = TVIF_PARAM;
  142.    //ti.mask       = TVIF_TEXT | TVIF_PARAM;
  143.    //ti.pszText    = szSingle;
  144.    //ti.cchTextMax = NUMELMS(szSingle);
  145.    //ti.hItem      = pti->hItem;
  146.    //TreeView_GetItem (lpnm->hwndFrom, &ti);
  147.    //pi = (LPVOID)ti.lParam;
  148.    pi = (LPVOID)pti->lParam;
  149.    if (!pi)
  150.       return FALSE;
  151.    // if the selected instrument has no editable data set, 
  152.    // copy the raw RIFF data into the temp edit set
  153.    // and display instrument settings from there.
  154.    //
  155.    pih->piSelect = NULL;
  156.    pih->pInstrumSelect = NULL;
  157.    if (pih->nInstrum)
  158.       {
  159.       pih->piSelect = pi;
  160.       pih->pInstrumSelect = pi->pInstrum;
  161.       if (!pi->pInstrum)
  162.          {
  163.          CopyInstrumData (&pih->instrum, pi->pList);
  164.          pih->pInstrumSelect = &pih->instrum;
  165.          }
  166.       }
  167.    View_SetData (pih->hWndInstrument, pih->pInstrumSelect);
  168.    View_InvalidateLines (pih->hWndInstrument, 0, 0);
  169.    return TRUE;
  170. }
  171. /*+
  172.  *  HeadNotifications
  173.  *
  174.  *-=================================================================*/
  175. LONG WINAPI HeadNotifications (
  176.    HWND     hWnd,
  177.    LPNMHDR  lpnm)
  178.    {
  179.    LONG       lRet = 0l;               // return value from this routine
  180.    LPIDFHEAD  pih;
  181.    pih = (LPVOID) GetWindowLong (hWnd, GWL_USERDATA);
  182.    switch (lpnm->idFrom)
  183.       {
  184.       case IDL_INSTRUMENTS:
  185.          switch (lpnm->code)
  186.             {
  187.             case TVN_SELCHANGED:
  188.                 HandleInstrumentsSelChange (hWnd, lpnm, pih);
  189.                 break;
  190.             //case NM_DBLCLK:
  191.             //    break;
  192.             case TVN_ENDLABELEDIT:
  193.                 {
  194.                 TV_DISPINFO * ptv = (LPVOID)lpnm;
  195.                 struct _instrum_info * pi = (LPVOID)ptv->item.lParam;
  196.                 if (!pi)
  197.                    break;
  198.                 if (!pi->pInstrum)
  199.                    {
  200.                    if (pih->piSelect == pi && pih->pInstrumSelect == &pih->instrum)
  201.                       pi->pInstrum = CopyForEditing (&pih->instrum, sizeof(pih->instrum));
  202.                    else
  203.                       {
  204.                       assert (0); // shoundn't be able to label edit without first selecting
  205.                       pi->pInstrum = HeapAlloc (gs.idf.hEditHeap, 0, sizeof(INSTRUMENT));
  206.                       CopyInstrumData (pi->pInstrum, pi->pList);
  207.                       }
  208.                    }
  209.                   
  210.                 lstrcpyn (pi->pInstrum->szInstID, ptv->item.pszText, NUMELMS(pi->pInstrum->szInstID));
  211.                 pi->pInstrum->bChanged = TRUE;
  212.                 pih->bChanged = TRUE;
  213.                 View_InvalidateLines (pih->hWndInstrument, 0, 0);
  214.                 lRet = 1;
  215.                 }
  216.                 break;
  217.             }
  218.          break;
  219.       case IDC_CURRENT_INSTRUM:
  220.          switch (lpnm->code)
  221.             {
  222.             case VN_CHANGE:
  223.                if (pih->pInstrumSelect)
  224.                   {
  225.                   if (pih->pInstrumSelect == &pih->instrum)
  226.                      {
  227.                      assert (!pih->piSelect->pInstrum);
  228.                      if ( ! pih->piSelect->pInstrum)
  229.                         {
  230.                         pih->pInstrumSelect =
  231.                         pih->piSelect->pInstrum = CopyForEditing (&pih->instrum, sizeof(pih->instrum));
  232.                         View_SetData (pih->hWndInstrument, pih->pInstrumSelect);
  233.                         View_InvalidateLines (pih->hWndInstrument, 0, 0);
  234.                         }
  235.                      }
  236.                   pih->pInstrumSelect->bChanged = TRUE;
  237.                   pih->bChanged = TRUE;
  238.                   }
  239.                else
  240.                   {
  241.                   assert (0);
  242.                   }
  243.                break;
  244.             }
  245.          break;
  246.       }
  247.    return lRet;
  248.    }
  249. /*+
  250.  *  HeadWndProc
  251.  *
  252.  *-=================================================================*/
  253. LONG CALLBACK HeadWndProc (
  254.    HWND   hWnd,
  255.    UINT   wMsgID,
  256.    WPARAM wParam,
  257.    LPARAM lParam)
  258.    {
  259.    LONG       lRet = 0l;               // return value from this routine
  260.    if (wMsgID >= WM_USER && wMsgID < 0x8000)
  261.       lRet = HeadPrivate (hWnd, wMsgID, wParam, lParam);
  262.    else
  263.    switch (wMsgID)
  264.       {
  265.       case WM_COMMAND:
  266.          lRet = HeadCommands (hWnd, wParam, lParam);
  267.          break;
  268.       case WM_NOTIFY:
  269.          lRet = HeadNotifications (hWnd, (LPNMHDR)lParam);
  270.          break;
  271.       case WM_SIZE:
  272.          {
  273.          LPIDFHEAD pih = (LPVOID) GetWindowLong (hWnd, GWL_USERDATA);
  274.          HDC hDC;
  275.          TEXTMETRIC tm;
  276.          #define BORDER 0
  277.          hDC = GetDC (hWnd);
  278.          //if (pih->hFont)
  279.          //   SelectObject (hDC, pih->hFont);
  280.          GetTextMetrics (hDC, &tm);
  281.          pih->ptClient.y = tm.tmHeight + tm.tmExternalLeading + 6;
  282.          pih->ptClient.x = 0;
  283.          ReleaseDC (hWnd, hDC);
  284.          pih->sClient.cx = LOWORD(lParam) - pih->ptClient.x;
  285.          pih->sClient.cy = HIWORD(lParam) - pih->ptClient.y;
  286.          SetWindowPos (pih->hWndTree, NULL,
  287.                        pih->ptClient.x, pih->ptClient.y,
  288.                        pih->cxTree, pih->sClient.cy,
  289.                        SWP_NOZORDER);
  290.          SetWindowPos (pih->hWndInstrument, NULL,
  291.                        pih->ptClient.x + pih->cxTree + BORDER, pih->ptClient.y,
  292.                        pih->sClient.cx - pih->cxTree - BORDER, pih->sClient.cy,
  293.                        SWP_NOZORDER);
  294.          }
  295.          break;
  296.       case WM_CREATE:
  297.          {
  298.          LPCREATESTRUCT    lpCreate = (LPCREATESTRUCT)lParam;
  299.          LPIDFHEAD         pih;
  300.          SetWindowLong (hWnd, GWL_USERDATA, 0);
  301.          pih = (LPVOID)lpCreate->lpCreateParams;
  302.          if (!pih)
  303.              return -1;
  304.          SetWindowLong (hWnd, GWL_USERDATA, (LONG)pih);
  305.          pih->cxTree = LOWORD(GetDialogBaseUnits()) * 20;
  306.          pih->hWndTree = 
  307.              CreateWindowEx (fdwExStyle | WS_EX_NOPARENTNOTIFY,
  308.                              WC_TREEVIEW,
  309.                              "",
  310.                              TVS_DISABLEDRAGDROP |
  311.                              TVS_SHOWSELALWAYS |
  312.                              TVS_EDITLABELS |
  313.                              WS_CHILD | WS_VISIBLE | WS_BORDER,
  314.                              0, 0, pih->cxTree, 0,
  315.                              hWnd,
  316.                              (HMENU)IDL_INSTRUMENTS,
  317.                              hInst,
  318.                              NULL);
  319.          if ( ! pih->hWndTree)
  320.             lRet = -1;
  321.          pih->hWndInstrument = 
  322.              CreateWindowEx (fdwExStyle | WS_EX_NOPARENTNOTIFY,
  323.                              cszInstrumClass,
  324.                              "",
  325.                              WS_CHILD | WS_VISIBLE | WS_BORDER,
  326.                              pih->cxTree + 6, 0, 200, 0,
  327.                              hWnd,
  328.                              (HMENU)IDC_CURRENT_INSTRUM,
  329.                              hInst,
  330.                              &pih->vi);
  331.          if ( ! pih->hWndInstrument)
  332.             lRet = -1;
  333.          LoadTree (pih->hWndTree, &pih->ai[0], pih);
  334.          LoadString (hInst, IDS_TREE_LABEL, pih->szTreeLabel, NUMELMS(pih->szTreeLabel));
  335.          LoadString (hInst, IDS_VIEW_LABEL, pih->szViewLabel, NUMELMS(pih->szViewLabel));
  336.          TrideeCreate(hWnd);
  337.          }
  338.          break;
  339.       case WM_DESTROY:
  340.          {
  341.          LPIDFHEAD pih = (LPVOID) GetWindowLong (hWnd, GWL_USERDATA);
  342.          if (pih && pih != &gs.idf)
  343.             HeapFree (GetProcessHeap(), 0, pih);
  344.          SetWindowLong (hWnd, GWL_USERDATA, 0);
  345.          TrideeDestroy(hWnd);
  346.          }
  347.          break;
  348.       case WM_ERASEBKGND:
  349.          {
  350.          RECT rc;
  351.          LPIDFHEAD pih = (LPVOID) GetWindowLong (hWnd, GWL_USERDATA);
  352.          HDC  hDC = (HDC)wParam;
  353.          int  cx = 2;
  354.          int  cy = 4;
  355.          lRet = DefWindowProc (hWnd, wMsgID, wParam, lParam);
  356.          GetClientRect (hWnd, &rc);
  357.          SetTextColor (hDC, GetSysColor (COLOR_BTNTEXT));
  358.          SetBkColor (hDC, GetSysColor (COLOR_BTNFACE));
  359.          SetTextAlign (hDC, TA_TOP | TA_LEFT);
  360.          ExtTextOut (hDC, cx, cy, ETO_CLIPPED, &rc, 
  361.                      pih->szTreeLabel, lstrlen(pih->szTreeLabel), NULL);
  362.          cx = pih->ptClient.x + pih->cxTree + BORDER +2;
  363.          ExtTextOut (hDC, cx, cy, ETO_CLIPPED, &rc, 
  364.                      pih->szViewLabel, lstrlen(pih->szViewLabel), NULL);
  365.          rc.bottom = rc.top + 2;
  366.          TrideeWellShadow(hDC, &rc);
  367.          }
  368.          break;
  369.       case WM_PAINT:
  370.          {
  371.          PAINTSTRUCT ps;           // structure for BeginPaint
  372.          HDC         hDC;          // DC to draw info into
  373.          LPIDFHEAD pih = (LPVOID) GetWindowLong (hWnd, GWL_USERDATA);
  374.          // and draw the info into our client area
  375.          //
  376.          hDC = BeginPaint (hWnd, &ps);
  377.          EndPaint (hWnd, &ps);
  378.          }
  379.          break;
  380.       default:
  381.          lRet = DefWindowProc (hWnd, wMsgID, wParam, lParam);
  382.       }
  383.    return lRet;
  384.    }