|
纯纯的Win32 API实现,下面是VNC的文件传输实现:
https://github.com/TurboVNC/turbovnc/blob/master/win/vncviewer/FileTransfer.cpp
- LRESULT CALLBACK FileTransfer::FileTransferDlgProc(HWND hwnd, UINT uMsg,
- WPARAM wParam,
- LPARAM lParam)
- {
- FileTransfer *_this = (FileTransfer *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- int i;
- switch (uMsg) {
- case WM_INITDIALOG:
- {
- SetForegroundWindow(hwnd);
- CenterWindow(hwnd);
- return TRUE;
- }
- break;
- case WM_HELP:
- help.Popup(lParam);
- return 0;
- case WM_COMMAND:
- {
- switch (LOWORD(wParam)) {
- case IDC_CLIENTPATH:
- switch (HIWORD(wParam)) {
- case EN_SETFOCUS:
- SetWindowText(GetDlgItem(hwnd, IDC_FTCOPY), noactionText);
- EnableWindow(GetDlgItem(hwnd, IDC_FTCOPY), FALSE);
- return TRUE;
- }
- break;
- case IDC_SERVERPATH:
- switch (HIWORD(wParam)) {
- case EN_SETFOCUS:
- SetWindowText(GetDlgItem(hwnd, IDC_FTCOPY), noactionText);
- EnableWindow(GetDlgItem(hwnd, IDC_FTCOPY), FALSE);
- return TRUE;
- }
- break;
- case IDC_EXIT:
- case IDCANCEL:
- PostMessage(hwnd, WM_CLOSE, 0, 0);
- return TRUE;
- case IDC_CLIENTUP:
- SetWindowText(GetDlgItem(hwnd, IDC_FTCOPY), noactionText);
- EnableWindow(GetDlgItem(hwnd, IDC_FTCOPY), FALSE);
- SendMessage(_this->m_hwndFTProgress, PBM_SETPOS, 0, 0);
- SetWindowText(_this->m_hwndFTStatus, "");
- if (strcmp(_this->m_ClientPathTmp, "") == 0) return TRUE;
- for (i = (int)(strlen(_this->m_ClientPathTmp) - 2); i >= 0; i--) {
- if (_this->m_ClientPathTmp[i] == '\\') {
- _this->m_ClientPathTmp[i] = '\0';
- break;
- }
- if (i == 0) _this->m_ClientPathTmp[0] = '\0';
- }
- _this->ShowClientItems(_this->m_ClientPathTmp);
- return TRUE;
- case IDC_SERVERUP:
- SetWindowText(GetDlgItem(hwnd, IDC_FTCOPY), noactionText);
- EnableWindow(GetDlgItem(hwnd, IDC_FTCOPY), FALSE);
- SendMessage(_this->m_hwndFTProgress, PBM_SETPOS, 0, 0);
- SetWindowText(_this->m_hwndFTStatus, "");
- if (strcmp(_this->m_ServerPathTmp, "") == 0) return TRUE;
- for (i = (int)(strlen(_this->m_ServerPathTmp) - 2); i >= 0; i--) {
- if (_this->m_ServerPathTmp[i] == '\\') {
- _this->m_ServerPathTmp[i] = '\0';
- break;
- }
- if (i == 0) _this->m_ServerPathTmp[0] = '\0';
- }
- _this->SendFileListRequestMessage(_this->m_ServerPathTmp, 0);
- return TRUE;
- case IDC_CLIENTRELOAD:
- SetWindowText(GetDlgItem(hwnd, IDC_FTCOPY), noactionText);
- EnableWindow(GetDlgItem(hwnd, IDC_FTCOPY), FALSE);
- SendMessage(_this->m_hwndFTProgress, PBM_SETPOS, 0, 0);
- SetWindowText(_this->m_hwndFTStatus, "");
- _this->ShowClientItems(_this->m_ClientPath);
- return TRUE;
- case IDC_SERVERRELOAD:
- SetWindowText(GetDlgItem(hwnd, IDC_FTCOPY), noactionText);
- EnableWindow(GetDlgItem(hwnd, IDC_FTCOPY), FALSE);
- SendMessage(_this->m_hwndFTProgress, PBM_SETPOS, 0, 0);
- SetWindowText(_this->m_hwndFTStatus, "");
- _this->SendFileListRequestMessage(_this->m_ServerPathTmp, 0);
- return TRUE;
- case IDC_FTCOPY:
- // First, check if the action is supported by the server.
- if (_this->m_bFTCOPY == FALSE) {
- // Upload was requested.
- if (!_this->m_clientconn->m_clientMsgCaps.IsEnabled(rfbFileUploadRequest) ||
- !_this->m_clientconn->m_clientMsgCaps.IsEnabled(rfbFileUploadData)) {
- MessageBox(hwnd, "Sorry but the server does not support uploading files.",
- "Error", MB_OK | MB_ICONEXCLAMATION);
- char buf[MAX_PATH];
- SPRINTF(buf, "File upload not supported by server");
- SetWindowText(_this->m_hwndFTStatus, buf);
- return TRUE;
- }
- } else {
- // Download was requested.
- if (!_this->m_clientconn->m_clientMsgCaps.IsEnabled(rfbFileDownloadRequest) ||
- !_this->m_clientconn->m_serverMsgCaps.IsEnabled(rfbFileDownloadData)) {
- MessageBox(hwnd, "Sorry but the server does not support downloading files.",
- "Error", MB_OK | MB_ICONEXCLAMATION);
- char buf[MAX_PATH];
- SPRINTF(buf, "File download not supported by server");
- SetWindowText(_this->m_hwndFTStatus, buf);
- return TRUE;
- }
- }
- // Now, try to upload/download.
- SetWindowText(GetDlgItem(hwnd, IDC_FTCOPY), noactionText);
- EnableWindow(GetDlgItem(hwnd, IDC_FTCOPY), FALSE);
- if (_this->m_ClientPath[0] == '\0' ||
- _this->m_ServerPath[0] == '\0') {
- SetWindowText(_this->m_hwndFTStatus,
- "Cannot transfer files: illegal directory.");
- return TRUE;
- }
- if (_this->m_bFTCOPY == FALSE) {
- _this->m_bTransferEnable = TRUE;
- _this->m_bReportUploadCancel = TRUE;
- EnableWindow(GetDlgItem(hwnd, IDC_FTCANCEL), TRUE);
- _this->FileTransferUpload();
- } else {
- return _this->SendMultipleFileDownloadRequests();
- }
- return TRUE;
- case IDC_FTCANCEL:
- // Check if we allowed to interrupt the transfer.
- if (_this->m_bUploadStarted &&
- !_this->m_clientconn->m_clientMsgCaps.IsEnabled(rfbFileUploadFailed)) {
- char buf[MAX_PATH];
- SPRINTF(buf, "Sorry, but interrupting upload is not supported by the server");
- SetWindowText(_this->m_hwndFTStatus, buf);
- return TRUE;
- }
- if (_this->m_bDownloadStarted &&
- !_this->m_clientconn->m_clientMsgCaps.IsEnabled(rfbFileDownloadCancel)) {
- char buf[MAX_PATH];
- SPRINTF(buf, "Sorry, but interrupting download is not supported by the server");
- SetWindowText(_this->m_hwndFTStatus, buf);
- return TRUE;
- }
- // Now try to cancel the operation.
- SetWindowText(GetDlgItem(hwnd, IDC_FTCOPY), noactionText);
- EnableWindow(GetDlgItem(hwnd, IDC_FTCOPY), FALSE);
- _this->m_bTransferEnable = FALSE;
- EnableWindow(GetDlgItem(hwnd, IDC_FTCANCEL), FALSE);
- return TRUE;
- case IDC_CLIENTBROWSE_BUT:
- SetWindowText(GetDlgItem(hwnd, IDC_FTCOPY), noactionText);
- EnableWindow(GetDlgItem(hwnd, IDC_FTCOPY), FALSE);
- SendMessage(_this->m_hwndFTProgress, PBM_SETPOS, 0, 0);
- SetWindowText(_this->m_hwndFTStatus, "");
- _this->CreateFTBrowseDialog(FALSE);
- return TRUE;
- case IDC_SERVERBROWSE_BUT:
- SetWindowText(GetDlgItem(hwnd, IDC_FTCOPY), noactionText);
- EnableWindow(GetDlgItem(hwnd, IDC_FTCOPY), FALSE);
- SendMessage(_this->m_hwndFTProgress, PBM_SETPOS, 0, 0);
- SetWindowText(_this->m_hwndFTStatus, "");
- _this->CreateFTBrowseDialog(TRUE);
- return TRUE;
- }
- }
- break;
- case WM_NOTIFY:
- switch (LOWORD(wParam)) {
- case IDC_FTCLIENTLIST:
- switch (((LPNMHDR)lParam)->code) {
- case NM_SETFOCUS:
- SetWindowText(GetDlgItem(hwnd, IDC_FTCOPY), uploadText);
- EnableWindow(GetDlgItem(hwnd, IDC_FTCOPY), TRUE);
- _this->m_bFTCOPY = FALSE;
- return TRUE;
- case LVN_GETDISPINFO:
- _this->OnGetDispClientInfo((NMLVDISPINFO *)lParam);
- return TRUE;
- case LVN_ITEMACTIVATE:
- LPNMITEMACTIVATE lpnmia = (LPNMITEMACTIVATE)lParam;
- _this->ProcessListViewDBLCLK(_this->m_hwndFTClientList,
- _this->m_ClientPath,
- _this->m_ClientPathTmp,
- lpnmia->iItem);
- return TRUE;
- }
- break;
- case IDC_FTSERVERLIST:
- switch (((LPNMHDR)lParam)->code) {
- case NM_SETFOCUS:
- SetWindowText(GetDlgItem(hwnd, IDC_FTCOPY), downloadText);
- EnableWindow(GetDlgItem(hwnd, IDC_FTCOPY), TRUE);
- _this->m_bFTCOPY = TRUE;
- return TRUE;
- case LVN_GETDISPINFO:
- _this->OnGetDispServerInfo((NMLVDISPINFO *)lParam);
- return TRUE;
- case LVN_ITEMACTIVATE:
- LPNMITEMACTIVATE lpnmia = (LPNMITEMACTIVATE)lParam;
- _this->ProcessListViewDBLCLK(_this->m_hwndFTServerList,
- _this->m_ServerPath,
- _this->m_ServerPathTmp,
- lpnmia->iItem);
- return TRUE;
- }
- break;
- }
- break;
- case WM_CLOSE:
- _this->m_clientconn->m_fileTransferDialogShown = false;
- _this->m_FTClientItemInfo.Free();
- _this->m_FTServerItemInfo.Free();
- {
- VNCviewerApp32 *pApp = (VNCviewerApp32 *)(_this->m_clientconn->m_pApp);
- pApp->RemoveModelessDialog(hwnd);
- }
- DestroyWindow(hwnd);
- return TRUE;
- }
- return 0;
- }
复制代码
|
|