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

📄 filebrowserdlg.cpp

📁 以前做NOKIA手机与PC通信时所参考的源代码,里面包括两个程序,一个是手机文件夹浏览源码,另一个手机SIS安装程序.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
Filename    : FileBrowserDlg.cpp
Part of     : File Browser
Description : Implementation of File Browser's dialog class
Version     : 3.2

This example is only to be used with PC Connectivity API version 3.2.
Compability ("as is") with future versions is not quaranteed.

Copyright (c) 2007 Nokia Corporation.
 
This material, including but not limited to documentation and any related 
computer programs, is protected by intellectual property rights of Nokia 
Corporation and/or its licensors.
All rights are reserved. Reproducing, modifying, translating, or 
distributing any or all of this material requires the prior written consent 
of Nokia Corporation. Nokia Corporation retains the right to make changes 
to this material at any time without notice. A copyright license is hereby 
granted to download and print a copy of this material for personal use only.
No other license to any other intellectual property rights is granted. The 
material is provided "as is" without warranty of any kind, either express or 
implied, including without limitation, any warranty of non-infringement, 
merchantability and fitness for a particular purpose. In no event shall 
Nokia Corporation be liable for any direct, indirect, special, incidental, 
or consequential loss or damages, including but not limited to, lost profits 
or revenue,loss of use, cost of substitute program, or loss of data or 
equipment arising out of the use or inability to use the material, even if 
Nokia Corporation has been advised of the likelihood of such damages occurring.
*/ 

#include "stdafx.h"
#include "FileBrowser.h"
#include "FileBrowserDlg.h"
#include "RenameDlg.h"
#include "CreateDlg.h"
#include "InfoDlg.h"
#include "FileOperationListener.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//===================================================================
// CFileBrowserDlg dialog

//===================================================================
// Constructor
//
//===================================================================
CFileBrowserDlg::CFileBrowserDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFileBrowserDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFileBrowserDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

//===================================================================
// Destructor
//
//===================================================================
CFileBrowserDlg::~CFileBrowserDlg()
{   
}

void CFileBrowserDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFileBrowserDlg)
	DDX_Control(pDX, IDC_STATIC_PHONE, m_staticPhone);
	DDX_Control(pDX, IDC_STATIC_PCFILES, m_staticPCFiles);
	DDX_Control(pDX, IDC_LIST_PHONES, m_lbPhones);
	DDX_Control(pDX, IDC_PCFILES, m_lbPCFiles);
	//}}AFX_DATA_MAP
	DDX_Control(pDX, IDC_CHECK_CACHE, m_CheckCache);
}

BEGIN_MESSAGE_MAP(CFileBrowserDlg, CDialog)
	//{{AFX_MSG_MAP(CFileBrowserDlg)    
	ON_BN_CLICKED(IDC_BUTTON_COPYPC2PHONE, OnButtonCopypc2phone)
	ON_BN_CLICKED(IDC_BUTTON_MOVEPC2PHONE, OnButtonMovepc2phone)
    ON_BN_CLICKED(IDC_BUTTON_COPYPHONE2PC, OnButtonCopyphone2pc)
	ON_BN_CLICKED(IDC_BUTTON_MOVEPHONE2PC, OnButtonMovephone2pc)
	ON_BN_CLICKED(IDC_BUTTON_CREATE, OnButtonCreate)
	ON_BN_CLICKED(IDC_BUTTON_RENAME, OnButtonRename)
	ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
	ON_WM_SYSCOMMAND()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_BUTTON_INFO, &CFileBrowserDlg::OnButtonInfo)
END_MESSAGE_MAP()

//===================================================================
// RefreshPhoneList
//
// Lists all connected phones to listbox
//===================================================================
void CFileBrowserDlg::RefreshPhoneList()
{    
    m_lbPhones.ListAllPhones();
}

//===================================================================
// CFileBrowserDlg message handlers

BOOL CFileBrowserDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
    // Initializing PC file list:
    m_lbPCFiles.Init(&m_staticPCFiles);

    // Initializing phone file list:
    m_lbPhones.Init(&m_staticPhone);

    RefreshPhoneList();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

//===================================================================
// OnButtonMovepc2phone
//
// Moves selected pc file to selected phone folder
//===================================================================
void CFileBrowserDlg::OnButtonMovepc2phone() 
{
    TRACE(L"CFileBrowserDlg::OnButtonMovepc2phone(): Begin\n");
    if(m_lbPCFiles.GetCurrentFile().IsEmpty())
    { // no PC file selected
        AfxMessageBox(L"Please select PC file to be moved.");
    }
    else
    {
		FSHANDLE hFS = m_lbPhones.GetFSHandle();
        if(hFS)
        {            
            CString strPCFile = m_lbPCFiles.GetCurrentFile(); // file name without path
            CString strPCFolder = m_lbPCFiles.GetCurrentFolder(); // e.g. 'c:\temp\'
            CString strPhoneFolder = m_lbPhones.GetSelectedFolder(); 
            if(strPhoneFolder.IsEmpty())
            {
                strPhoneFolder = m_lbPhones.GetCurrentFolder();
            }
            CFileOperationListener* pListener = new CFileOperationListener(m_hWnd, 
                hFS, 
                L"Moving", 
                strPCFolder + L"\\" + strPCFile, 
                L"-->" + strPhoneFolder);
            DWORD dwResult = CONAMoveFile(hFS, 
                CONA_DIRECT_PC_TO_PHONE, 
                strPCFile, 
                strPCFolder,  
                strPhoneFolder);
            delete pListener;
            pListener = NULL;
            if(dwResult != CONA_OK)
            {
                ErrorMessageDlg(L"CFileBrowserDlg::OnButtonMovepc2phone(): CONAMoveFile failed!", dwResult);                
            }
            else
            {
                // show updated folder listings
                m_lbPCFiles.ShowFiles();
                m_lbPhones.ShowPhoneFolder(strPhoneFolder);
                AfxMessageBox(L"Move completed succesfully!");
            }
        }
    }        
    TRACE(L"CFileBrowserDlg::OnButtonMovepc2phone(): End\n");
}


//===================================================================
// OnButtonCopypc2phone
//
// Copies selected pc file to selected phone folder
//===================================================================
void CFileBrowserDlg::OnButtonCopypc2phone() 
{
    TRACE(L"CFileBrowserDlg::OnButtonCopypc2phone(): Begin\n");
    if(m_lbPCFiles.GetCurrentFile().IsEmpty())
    {
        AfxMessageBox(L"Please select PC file to be copied.");
    }
    else
    {
		FSHANDLE hFS = m_lbPhones.GetFSHandle();
        if(hFS)
        {            
            CString strPCFile = m_lbPCFiles.GetCurrentFile(); // file name without path
            CString strPCFolder = m_lbPCFiles.GetCurrentFolder(); // e.g. 'c:\temp'
            CString strPhoneFolder = m_lbPhones.GetSelectedFolder(); 
            if(strPhoneFolder.IsEmpty())
            {
                strPhoneFolder = m_lbPhones.GetCurrentFolder();
            }
            CFileOperationListener* pListener = new CFileOperationListener(m_hWnd, 
                hFS, 
                L"Copying", 
                strPCFolder + L"\\" + strPCFile, 
                L"-->" + strPhoneFolder);
            DWORD dwResult = CONACopyFile(hFS, 
                CONA_DIRECT_PC_TO_PHONE | CONA_RENAME, 
                strPCFile, 
                strPCFolder,  
                strPhoneFolder);
            delete pListener;
            pListener = NULL;
            if(dwResult != CONA_OK)
            {
                ErrorMessageDlg(L"CFileBrowserDlg::OnButtonCopypc2phone(): CONACopyFile failed!", dwResult);                
            }
            else
            {
                // show updated folder listing
                m_lbPhones.ShowPhoneFolder(strPhoneFolder);
                AfxMessageBox(L"Copy completed succesfully!");
            }
        }
    }
    TRACE(L"CFileBrowserDlg::OnButtonCopypc2phone(): End\n");
}

//===================================================================
// OnButtonMovephone2pc
//
// Moves selected phone file to selected pc folder
//===================================================================
void CFileBrowserDlg::OnButtonMovephone2pc() 
{
    TRACE(L"CFileBrowserDlg::OnButtonMovephone2pc(): Begin\n");	
    CString strMessage = L"";
    CString file = m_lbPhones.GetCurrentFile();
    if(file.IsEmpty())
    {
        AfxMessageBox(L"Please select phone file to be moved.");
    }
    else
    {
		FSHANDLE hFS = m_lbPhones.GetFSHandle();
        if(hFS)
        {
            CString strPhoneFile = m_lbPhones.GetCurrentFile();            
            CString strPhoneFolder = m_lbPhones.GetSelectedFolder();
            CString strPCFolder = m_lbPCFiles.GetCurrentFolder();
            strMessage.Format(L"Are you sure you want to move phone file '%s' from folder '%s' to\nPC folder '%s'?", 
                strPhoneFile, strPhoneFolder, strPCFolder);
            if(AfxMessageBox(strMessage, MB_YESNO) == IDYES)
            {
                CFileOperationListener* pListener = new CFileOperationListener(m_hWnd, 
                    hFS, 
                    L"Moving", 
                    strPhoneFolder + L"\\" + strPhoneFile, 
                    L"-->" + strPCFolder);
                DWORD dwResult = CONAMoveFile(hFS, 
                    CONA_DIRECT_PHONE_TO_PC,
                    strPhoneFile, 
                    strPhoneFolder,
                    strPCFolder);
                delete pListener;
                pListener = NULL;
                if(dwResult != CONA_OK)
                {
                    ErrorMessageDlg(L"CFileBrowserDlg::OnButtonMovephone2pc(): CONAMoveFile failed!", dwResult);                
                }
                else
                {
                    // show updated folder listings
                    m_lbPhones.ShowPhoneFolder(strPhoneFolder);
                    m_lbPCFiles.ShowFiles();
                    AfxMessageBox(L"Move completed succesfully!");
                }
            }
        }
    }    
    TRACE(L"CFileBrowserDlg::OnButtonMovephone2pc(): End\n");
}

//===================================================================
// OnButtonCopyphone2pc
//
// Copies selected phone file to selected pc folder
//===================================================================
void CFileBrowserDlg::OnButtonCopyphone2pc() 
{
    TRACE(L"CFileBrowserDlg::OnButtonCopyphone2pc(): Begin\n");
    CString file = m_lbPhones.GetCurrentFile();
    if(file.IsEmpty())
    {
        AfxMessageBox(L"Please select phone file to be copied.");
    }
    else
    {
		FSHANDLE hFS = m_lbPhones.GetFSHandle();
        if(hFS)
        {
            CString strPhoneFile = m_lbPhones.GetCurrentFile();                        
            CString strPCFolder = m_lbPCFiles.GetCurrentFolder();
            CString strPhoneFolder = m_lbPhones.GetSelectedFolder(); 
            CFileOperationListener* pListener = new CFileOperationListener(m_hWnd, 
                hFS, 
                L"Copying", 
                strPhoneFolder + L"\\" + strPhoneFile, 
                L"-->" + strPCFolder);
            DWORD dwResult = CONACopyFile(hFS, 
                CONA_DIRECT_PHONE_TO_PC | CONA_RENAME, 
                strPhoneFile, 
                strPhoneFolder,
                strPCFolder);
            delete pListener;
            pListener = NULL;
            if(dwResult != CONA_OK)
            {

⌨️ 快捷键说明

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