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

📄 treeutils.cpp

📁 wince用EVC编译的蓝牙扫描,文件传输,耳机控制软件.完完整软件包!MIPS,ARM编译通过 obexparser.lib filebrowser.cpp devicechooser.cpp
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#include "TreeUtils.h"


HINSTANCE                  g_treeHInst;
extern HWND                g_hWnd;
HWND                       g_hwndTV;    // handle to tree view control 
WNDPROC                    g_wndProcOrigTV;

HTREEITEM AddItemToTree(HWND tree, UINT nMask, LPCTSTR lpszItem, int nImage,
                        int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
                        HTREEITEM hParent, HTREEITEM hInsertAfter)
{
    //assert(::IsWindow(tree));
    TVINSERTSTRUCT tvis;
    tvis.hParent = hParent;
    tvis.hInsertAfter = hInsertAfter;
    tvis.item.mask = nMask;
    tvis.item.pszText = (LPTSTR) lpszItem;
    tvis.item.iImage = nImage;
    tvis.item.iSelectedImage = nSelectedImage;
    tvis.item.state = nState;
    tvis.item.stateMask = nStateMask;
    tvis.item.lParam = lParam;
    return (HTREEITEM)::SendMessage(tree, TVM_INSERTITEM, 0, (LPARAM)&tvis);
}

BOOL InitTreeViewImageLists(HINSTANCE hInst, HWND hwndTV) 
{ 
    HIMAGELIST himl;  // handle to image list 
    HICON hIcon;     // handle to bitmap 
    INT index;
    
    // Create the image list. 
    if ((himl = ImageList_Create(16,16, 
        FALSE, 10, 0)) == NULL) 
        return FALSE; 
    
    // Add tbitmaps. 
	hIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_FOLDER), IMAGE_ICON, 16, 16, 0); 
    index = ImageList_AddIcon(himl, hIcon);
    ASSERT(index != -1);
    DeleteObject(hIcon); 

	hIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_FILE), IMAGE_ICON, 16, 16, 0); 
    index = ImageList_AddIcon(himl, hIcon);
    ASSERT(index != -1);
    DeleteObject(hIcon); 
       
    // Associate the image list with the tree view control. 
    TreeView_SetImageList(hwndTV, himl, TVSIL_NORMAL);
    
    return TRUE; 
} 



BOOL DoPopup( HWND hWnd, int x, int y )
{
    HMENU hMenu;

    if( !(hMenu = LoadMenu( g_treeHInst, MAKEINTRESOURCE( IDR_POPUPMENU ) )) ) 
    {
        MessageBox(NULL, L"Error Loading Popup", L"Error", MB_OK);
        return FALSE;
    }
    if( !TrackPopupMenu(
            GetSubMenu( hMenu, 0 ),
            TPM_LEFTALIGN, // TPM_LEFTBUTTON is default.
            x + 5,
            y + 5,
            0,
            g_hWnd, 
            NULL ) ) 
    {
        MessageBox(NULL, L"Error Loading Popup", L"Error", MB_OK);   
        return FALSE;
    }
    DestroyMenu( hMenu );
    return TRUE;
}


LRESULT CALLBACK TreeViewWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    switch( message )
    {
    case WM_RBUTTONDOWN:      
           DoPopup( hWnd, LOWORD(lParam), HIWORD(lParam) );
           return 0;
    }
    
    return CallWindowProc( g_wndProcOrigTV, hWnd, message, wParam, lParam );
}


HWND CreateATreeView(HINSTANCE hInst, HWND hwndParent)
{ 
    RECT rcClient;  // dimensions of client area 
    g_treeHInst = hInst;
    
    // Ensure that the common control DLL is loaded. 
    InitCommonControls(); 
    
    // Get the dimensions of the parent window's client area, and create 
    // the tree view control. 
    GetClientRect(hwndParent, &rcClient); 
    g_hwndTV = CreateWindowEx(0, WC_TREEVIEW, TEXT("Tree View"), 
        WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT, 
        0, 0, 0,0, 
        hwndParent, 0, hInst, NULL); 
    
    InitTreeViewImageLists(hInst, g_hwndTV);
    
    //make a menu 
    g_wndProcOrigTV = (WNDPROC)SetWindowLong(g_hwndTV,
                                              GWL_WNDPROC,
                                              (LONG)TreeViewWndProc);
    
    return g_hwndTV;
} 

⌨️ 快捷键说明

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