⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wndproc.c

📁 DBVIEW is a small Windows application that highlights the use of the builtin database functions:
💻 C
📖 第 1 页 / 共 2 页
字号:
            }
            case IDCANCEL:
                EndDialog(hwnd, 0);
                break;
        }
        return (TRUE);
    }
    return (FALSE);
}



BOOL CALLBACK AddRecDlgProc( HWND  hWnd,UINT  message, WPARAM  wParam, LPARAM  lParam )
{
  WORD wNotifyCode, wID;
  HWND hwndCtl;
  static INSERTSTRUCT * pInsert;
  wNotifyCode = HIWORD(wParam); // notification code
  wID = LOWORD(wParam);         // item, control, or accelerator identifier
  hwndCtl = (HWND) lParam;      // handle of control

  switch(message)
  {
    case WM_INITDIALOG:
        // Should return nonzero to set focus to the first control in the
        // dialog, or zero if this routine sets the focus manually.
        pInsert = (INSERTSTRUCT *) lParam;
        return (TRUE);

      case WM_COMMAND:
      {
            switch(wID)
            {
                case IDCANCEL:
                        EndDialog(hWnd, IDCANCEL);
                        break;
                case IDC_SAVE:
                {
                    BOOL bTranslS, bTranslUS;
                    DWORD  cbLong, cbULong, cbString, cbBlob;
                    TCHAR * pszLong, * pString;
                    BYTE  * pBlob;
                    UINT    unChars;
                    pInsert->pString = NULL;
                    pInsert->pBlob = NULL;

                    cbLong = SendDlgItemMessage(hWnd, IDC_LONG, WM_GETTEXTLENGTH, 0, 0);

                    cbULong = SendDlgItemMessage(hWnd, IDC_ULONG, WM_GETTEXTLENGTH, 0, 0);
                    pszLong = LocalAlloc( LPTR , max(cbULong, (cbLong * sizeof(TCHAR) + sizeof(TCHAR))));

                    cbString = SendDlgItemMessage(hWnd, IDC_STRING, WM_GETTEXTLENGTH, 0, 0);
                    pString = (TCHAR *) LocalAlloc( LPTR , (cbString * sizeof(TCHAR) + sizeof(TCHAR)));

                    cbBlob = SendDlgItemMessage(hWnd, IDC_BLOB, WM_GETTEXTLENGTH, 0, 0);
                    pBlob = (BYTE *) LocalAlloc( LPTR , (cbBlob * sizeof(TCHAR) + sizeof(TCHAR)));

                    pInsert->shNumber = (short) GetDlgItemInt(hWnd,IDC_SHORT,&bTranslS,TRUE );    
                    pInsert->ushNumber = GetDlgItemInt(hWnd,IDC_USHORT,&bTranslUS,FALSE );    
                    
                    if ( pszLong )
                    {
                        if ( unChars = GetDlgItemText(hWnd,IDC_LONG,pszLong, cbLong) )
                            pInsert->lNumber = _ttol(pszLong);
                        else
                            pInsert->lNumber = 0;

                    }
                                           
                    if ( pszLong)
                    {
                        if ( unChars = GetDlgItemText(hWnd,IDC_ULONG,pszLong,cbULong) )
                            pInsert->ulNumber = (unsigned long) _ttol(pszLong);
                        else
                            pInsert->ulNumber = 0;
                    }

                    if ( pString)
                    {
                        if ( unChars = GetDlgItemText(hWnd,IDC_STRING, pString, (INT) cbString))
                            pInsert->pString = pString;
                    }
                    if ( pBlob)
                    {
                        if ( unChars = GetDlgItemText(hWnd,IDC_BLOB,(TCHAR *)pBlob, cbBlob) )
                        {
                            pInsert->pBlob = pBlob;
                            pInsert->cbBlob = cbBlob * sizeof(TCHAR);
                        }
                        else
                            pInsert->cbBlob = 0;
                    }
                    else
                        pInsert->cbBlob = 0;
                    
                    if ( pszLong )
                        LocalFree(pszLong);

                    EndDialog(hWnd, IDOK);
                    break;
                }
                default:
                    return(FALSE);
            }
            break;
      }
      default:
          return(FALSE);
  }
  return (TRUE);
}



//
//  FUNCTION:   Main_OnNotify(HWND, int, LPNMHDR)
//
//  PURPOSE:    Handles any notifications the treeview control spits out.
//
//  PARAMETERS:
//      hwnd    - handle of the window receiving the notification
//      idCtl   - identifies the control sending the notification
//      pnmh    - points to a NMHDR struct with more inforamation regarding the
//                notification
//
//  RETURN VALUE:
//      (LRESULT) Dependant on the specific notification.  See Below.
//
//  COMMENTS:
//

LRESULT WINAPI Main_OnNotify(HWND hwnd, int idCtl, LPNMHDR pnmh)
{
    HTREEITEM hti, htiNext;

    switch (pnmh->code)
    {
        // A directory node has been collapsed.  Now we can remove the child items
        // from the node.

        case TVN_SELCHANGED:
        {

            HTREEITEM hti;
            TV_ITEM      ParentItem;
            TCHAR szEntryName[CEDB_MAXDBASENAMELEN];
            LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW) pnmh;

            if ( bRemovingProps )
                break;

            OutputDebugString(TEXT("Item selected\r\n"));


            // Check to see if this is a database or property
            // if item has no parent then database
            if ( !(hti=TreeView_GetParent(pnmh->hwndFrom, pnmtv->itemNew.hItem )) )
            {
                
                OutputDebugString(TEXT("Display Database Information\r\n"));

                // Get the text parent
                pnmtv->itemNew.mask |= TVIF_TEXT;
                pnmtv->itemNew.pszText = szEntryName;
                pnmtv->itemNew.cchTextMax =  CEDB_MAXDBASENAMELEN;

                if (!TreeView_GetItem(pnmtv->hdr.hwndFrom, &pnmtv->itemNew))
                    return (FALSE);
                else
                {
                    // Show DB Properties
                    ShowDBInformation(szEntryName);

                }

            }
            else                                                             // database property
            {
                DWORD dwOpenHandle = (DWORD) INVALID_HANDLE_VALUE;
                ParentItem.hItem = hti;
                ParentItem.mask = TVIF_PARAM;

                if ( TreeView_GetItem(pnmh->hwndFrom, &ParentItem) )
                    dwOpenHandle = ParentItem.lParam;

                OutputDebugString(TEXT("Display Database Property Information\r\n"));

                // Get the text child property
                pnmtv->itemNew.mask |= (TVIF_TEXT | TVIF_PARAM);
                pnmtv->itemNew.pszText = szEntryName;
                pnmtv->itemNew.cchTextMax = CEDB_MAXDBASENAMELEN;

                if (!TreeView_GetItem(pnmtv->hdr.hwndFrom, &pnmtv->itemNew))
                    return (FALSE);
                else
                {
                   ShowPropDesc(pnmtv->itemNew.lParam, dwOpenHandle, -1);

                }


            }
            break;
        }



        case TVN_ITEMEXPANDED:
        {
            LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW) pnmh;

            if (pnmtv->action == TVE_COLLAPSE)
            {
                OutputDebugString(TEXT("Item collapsed\r\n"));

                // Now actually remove the child items within this directory
                hti = TreeView_GetChild(pnmh->hwndFrom, pnmtv->itemNew.hItem);
                while (hti)
                {
                    htiNext = TreeView_GetNextSibling(pnmh->hwndFrom, hti);
                    TreeView_DeleteItem(pnmh->hwndFrom, hti);
                    hti = htiNext;
                }
            }

            return (FALSE);
        }
            
    // A node is expanding or collapsing.  We need to update the folder
    // images to reflect either a closed or open folder depending on it's
    // new state.
        case TVN_ITEMEXPANDING:
        {
            // cast the NMHDR into a treeview notify structure
            LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW) pnmh;

            if (pnmtv->action == TVE_COLLAPSE)
            {
                OutputDebugString(TEXT("Item collapsing\r\n"));

                // Retrieve the image from the current item
                pnmtv->itemNew.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
                TreeView_GetItem(pnmh->hwndFrom, &(pnmtv->itemNew));

                // Set the item's image to the closed folder
                pnmtv->itemNew.iImage = IMAGE_CLOSED;
                pnmtv->itemNew.iSelectedImage = IMAGE_CLOSED;
        
                TreeView_SetItem(pnmh->hwndFrom, &(pnmtv->itemNew));
            }
            else
            {
                TCHAR szDBName[CEDB_MAXDBASENAMELEN];
                OutputDebugString(TEXT("Item expanding\r\n"));

                // Retrieve the image from the current item
                pnmtv->itemNew.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
                TreeView_GetItem(pnmh->hwndFrom, &(pnmtv->itemNew));

                // Set the item's image to the closed folder
                pnmtv->itemNew.iImage = IMAGE_OPEN;
                pnmtv->itemNew.iSelectedImage = IMAGE_OPEN;
                TreeView_SetItem(pnmh->hwndFrom, &(pnmtv->itemNew));

                // Get the text for the first item
                pnmtv->itemNew.mask |= (TVIF_TEXT|TVIF_PARAM);
                pnmtv->itemNew.pszText = szDBName;
                pnmtv->itemNew.cchTextMax =  CEDB_MAXDBASENAMELEN;
                if (!TreeView_GetItem(pnmtv->hdr.hwndFrom, &pnmtv->itemNew))
                    return (FALSE);
                else
                    EnumDbaseProps(pnmtv->hdr.hwndFrom, (HTREEITEM)pnmtv->itemNew.hItem, pnmtv->itemNew.lParam);

            }

            return (FALSE); // return value is ignored
        }

    // The mouse has been clicked within the control.  We need to determine
    // if the click is over the state image and if so toggle the check box.
        case NM_CLICK:
        {
            UINT                    state;
            DWORD                   dwPos;
            TV_HITTESTINFO            tvhti;
            HTREEITEM               htiItemClicked;
            POINT                   point;
            HWND                    hwndTV = GetDlgItem(hwnd, IDC_TREEVIEW);
            TV_ITEM                    tvi;
    
            // Find out where the cursor was
            dwPos = GetMessagePos();
            point.x = LOWORD(dwPos);
            point.y = HIWORD(dwPos);

            ScreenToClient(hwndTV, &point);

            tvhti.pt = point;
            htiItemClicked = TreeView_HitTest(hwndTV, &tvhti);

            // Now get the state information from the item and toggle it
            if (tvhti.flags & TVHT_ONITEMSTATEICON)
            {
                // Fill out the TV_ITEM struct to get the state image mask and
                // get the item from the control
                tvi.hItem = htiItemClicked;
                tvi.mask = TVIF_STATE;
                tvi.stateMask = TVIS_STATEIMAGEMASK;
                TreeView_GetItem(hwndTV, &tvi);

                // Now toggle the state
                state = tvi.state;
                tvi.state = (state & INDEXTOSTATEIMAGEMASK(TVIS_GCNOCHECK)) ?
                        INDEXTOSTATEIMAGEMASK(TVIS_GCCHECK) :
                            INDEXTOSTATEIMAGEMASK(TVIS_GCNOCHECK);

                // And finally set the new state of the item back into the
                // control
                TreeView_SetItem(hwndTV, &tvi);
            }

        return (0L);    // Return value is ignored
        }
    }
    return (0L);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -