-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_handler_win.cpp
115 lines (96 loc) · 3.34 KB
/
client_handler_win.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "client_handler.h"
#include <string>
#include <windows.h>
#include <shlobj.h>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "resource.h"
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url) {
REQUIRE_UI_THREAD();
//if (m_BrowserId == browser->GetIdentifier() && frame->IsMain()) {
// // Set the edit window text
// SetWindowText(m_EditHwnd, std::wstring(url).c_str());
//}
}
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title) {
REQUIRE_UI_THREAD();
// Set the frame window title bar
CefWindowHandle hwnd = browser->GetHost()->GetWindowHandle();
if (m_BrowserId == browser->GetIdentifier()) {
// The frame window will be the parent of the browser window
hwnd = GetParent(hwnd);
}
SetWindowText(hwnd, std::wstring(title).c_str());
}
void ClientHandler::SendNotification(NotificationType type) {
// UINT id;
// switch (type) {
// case NOTIFY_CONSOLE_MESSAGE:
// id = ID_WARN_CONSOLEMESSAGE;
// break;
// case NOTIFY_DOWNLOAD_COMPLETE:
// id = ID_WARN_DOWNLOADCOMPLETE;
// break;
// case NOTIFY_DOWNLOAD_ERROR:
// id = ID_WARN_DOWNLOADERROR;
// break;
// default:
// return;
// }
// PostMessage(m_MainHwnd, WM_COMMAND, id, 0);
}
void ClientHandler::SetLoading(bool isLoading) {
//ASSERT(m_EditHwnd != NULL && m_ReloadHwnd != NULL && m_StopHwnd != NULL);
//EnableWindow(m_EditHwnd, TRUE);
//EnableWindow(m_ReloadHwnd, !isLoading);
//EnableWindow(m_StopHwnd, isLoading);
}
//void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) {
// ASSERT(m_BackHwnd != NULL && m_ForwardHwnd != NULL);
// EnableWindow(m_BackHwnd, canGoBack);
// EnableWindow(m_ForwardHwnd, canGoForward);
//}
void ClientHandler::CloseMainWindow() {
::PostMessage(m_MainHwnd, WM_CLOSE, 0, 0);
}
//void ClientHandler::SetWindowTitle(const std::wstring text) {
//BYTE* u8_Mem = (BYTE*)GlobalAlloc(GMEM_FIXED, 100);
//WCHAR* u16_Text = (WCHAR*)u8_Mem;
//wcscpy(u16_Text, text.c_str());
//::SetWindowText(m_MainHwnd, (LPCWSTR) text.c_str());
// ::SetWindowText(m_MainHwnd, text.c_str());
//}
std::string ClientHandler::GetDownloadPath(const std::string& file_name) {
std::string path;
TCHAR szFolderPath[MAX_PATH] = {0};
// This is the recommended way to select a directory
// in Win95 and NT4.
BROWSEINFO bi = {0};
bi.hwndOwner = GetMainHwnd();
//bi.pidlRoot = NULL;
//bi.pszDisplayName = szFolderPath;
bi.lpszTitle = L"Select a folder";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
// Set the callback function
//bi.lpfn = NULL;
LPITEMIDLIST pIIL = ::SHBrowseForFolder(&bi);
if(pIIL != NULL)
if (::SHGetPathFromIDList(pIIL, (TCHAR *)&szFolderPath)) {
if (szFolderPath != L""){
path = CefString(szFolderPath);
path += "\\" + file_name;
}
LPMALLOC pMalloc = 0;
if(SUCCEEDED(SHGetMalloc(&pMalloc))){
pMalloc->Free(pIIL);
pMalloc->Release();
}
}
return path;
}