vncmenu.cpp
来自「这是一个比较复杂的远程控制工具,分为服务器与客户斋,让你了解socket编程的知」· C++ 代码 · 共 796 行 · 第 1/2 页
CPP
796 行
vnclog.Print(LL_INTINFO, VNCLOG("opening dialog box\n"));
m_properties.ShowAdmin(TRUE, TRUE);
PostQuitMessage(0);
}
}
}
}
// Process window messages
LRESULT CALLBACK vncMenu::WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
// This is a static method, so we don't know which instantiation we're
// dealing with. We use Allen Hadden's (ahadden@taratec.com) suggestion
// from a newsgroup to get the pseudo-this.
vncMenu *_this = (vncMenu *) GetWindowLong(hwnd, GWL_USERDATA);
// Beep(100,10);
// vnclog.Print(LL_INTINFO, VNCLOG("iMsg 0x%x \n"),iMsg);
switch (iMsg)
{
case WM_WTSSESSION_CHANGE:
{
switch( wParam )
{
case WTS_CONSOLE_CONNECT:
vnclog.Print(LL_INTERR, VNCLOG("++++++++++++++++++++++++++++++++++++WTS_CONSOLE_CONNECT\n"));
break;
case WTS_CONSOLE_DISCONNECT:
vnclog.Print(LL_INTERR, VNCLOG("WTS_CONSOLE_DISCONNECT\n"));
_this->m_server->KillAuthClients();
break;
case WTS_SESSION_LOCK:
vnclog.Print(LL_INTERR, VNCLOG("WTS_SESSION_LOCK\n"));
break;
case WTS_SESSION_UNLOCK:
vnclog.Print(LL_INTERR, VNCLOG("WTS_SESSION_UNLOCK\n"));
break;
default:
break;
}
break;
}
// Every five seconds, a timer message causes the icon to update
case WM_TIMER:
// *** HACK for running servicified
if (vncService::RunningAsService()) {
// Attempt to add the icon if it's not already there
_this->AddTrayIcon();
// Trigger a check of the current user
PostMessage(hwnd, WM_USERCHANGED, 0, 0);
}
// Update the icon
_this->FlashTrayIcon(_this->m_server->AuthClientCount() != 0);
break;
// DEAL WITH NOTIFICATIONS FROM THE SERVER:
case WM_SRV_CLIENT_AUTHENTICATED:
case WM_SRV_CLIENT_DISCONNECT:
// Adjust the icon accordingly
_this->FlashTrayIcon(_this->m_server->AuthClientCount() != 0);
if (_this->m_server->AuthClientCount() != 0) {
if (_this->m_server->RemoveWallpaperEnabled())
KillWallpaper();
} else {
if (_this->m_server->RemoveWallpaperEnabled())
RestoreWallpaper();
}
return 0;
// STANDARD MESSAGE HANDLING
case WM_CREATE:
return 0;
case WM_COMMAND:
// User has clicked an item on the tray menu
switch (LOWORD(wParam))
{
case ID_ONLINEHELP:
MessageBox(NULL,"http://ultravnc.sourceforge.net/help.htm","Info",0);
//ShellExecute(GetDesktopWindow(), "open", "http://ultravnc.sourceforge.net/help.htm", "", 0, SW_SHOWNORMAL);
break;
case ID_HOME:
MessageBox(NULL,"http://ultravnc.sourceforge.net","Info",0);
//ShellExecute(GetDesktopWindow(), "open", "http://ultravnc.sourceforge.net/index.html", "", 0, SW_SHOWNORMAL);
break;
case ID_DEFAULT_PROPERTIES:
// Show the default properties dialog, unless it is already displayed
vnclog.Print(LL_INTINFO, VNCLOG("show default properties requested\n"));
_this->m_properties.ShowAdmin(TRUE, FALSE);
_this->FlashTrayIcon(_this->m_server->AuthClientCount() != 0);
break;
case ID_PROPERTIES:
// Show the properties dialog, unless it is already displayed
vnclog.Print(LL_INTINFO, VNCLOG("show user properties requested\n"));
_this->m_propertiesPoll.Show(TRUE, TRUE);
_this->FlashTrayIcon(_this->m_server->AuthClientCount() != 0);
break;
case ID_ADMIN_PROPERTIES:
// Show the properties dialog, unless it is already displayed
vnclog.Print(LL_INTINFO, VNCLOG("show user properties requested\n"));
_this->m_properties.ShowAdmin(TRUE, TRUE);
_this->FlashTrayIcon(_this->m_server->AuthClientCount() != 0);
break;
case ID_OUTGOING_CONN:
// Connect out to a listening VNC viewer
{
vncConnDialog *newconn = new vncConnDialog(_this->m_server);
if (newconn)
{
newconn->DoDialog();
// delete newconn; // NO ! Already done in vncConnDialog.
}
}
break;
case ID_KILLCLIENTS:
// Disconnect all currently connected clients
_this->m_server->KillAuthClients();
break;
// sf@2002
case ID_LISTCLIENTS:
_this->m_ListDlg.Display();
break;
case ID_ABOUT:
// Show the About box
_this->m_about.Show(TRUE);
break;
case ID_CLOSE:
// User selected Close from the tray menu
_this->m_server->KillAuthClients();
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
}
return 0;
case WM_TRAYNOTIFY:
// User has clicked on the tray icon or the menu
{
// Get the submenu to use as a pop-up menu
HMENU submenu = GetSubMenu(_this->m_hmenu, 0);
// What event are we responding to, RMB click?
if (lParam==WM_RBUTTONUP)
{
if (submenu == NULL)
{
vnclog.Print(LL_INTERR, VNCLOG("no submenu available\n"));
return 0;
}
// Make the first menu item the default (bold font)
SetMenuDefaultItem(submenu, 0, TRUE);
// Get the current cursor position, to display the menu at
POINT mouse;
GetCursorPos(&mouse);
// There's a "bug"
// (Microsoft calls it a feature) in Windows 95 that requires calling
// SetForegroundWindow. To find out more, search for Q135788 in MSDN.
//
SetForegroundWindow(_this->m_nid.hWnd);
// Display the menu at the desired position
TrackPopupMenu(submenu,
0, mouse.x, mouse.y, 0,
_this->m_nid.hWnd, NULL);
return 0;
}
// Or was there a LMB double click?
if (lParam==WM_LBUTTONDBLCLK)
{
// double click: execute first menu item
SendMessage(_this->m_nid.hWnd,
WM_COMMAND,
GetMenuItemID(submenu, 0),
0);
}
return 0;
}
case WM_CLOSE:
// Only accept WM_CLOSE if the logged on user has AllowShutdown set
if (!_this->m_properties.AllowShutdown())
{
return 0;
}
// tnatsni Wallpaper fix
RestoreWallpaper();
break;
case WM_DESTROY:
// The user wants WinVNC to quit cleanly...
vnclog.Print(LL_INTINFO, VNCLOG("quitting from WM_DESTROY\n"));
PostQuitMessage(0);
return 0;
case WM_QUERYENDSESSION:
vnclog.Print(LL_INTERR, VNCLOG("WM_QUERYENDSESSION\n"));
break;
case WM_ENDSESSION:
vnclog.Print(LL_INTERR, VNCLOG("WM_ENDSESSION\n"));
break;
case WM_USERCHANGED:
// The current user may have changed.
{
char newuser[UNLEN+1];
if (vncService::CurrentUser((char *) &newuser, sizeof(newuser)))
{
vnclog.Print(LL_INTINFO,
// VNCLOG("usernames : old=\"%s\", new=\"%s\"\n"),
_this->m_username, newuser);
// Check whether the user name has changed!
if (strcmp(newuser, _this->m_username) != 0)
{
vnclog.Print(LL_INTINFO,
VNCLOG("user name has changed\n"));
// User has changed!
strcpy(_this->m_username, newuser);
// Redraw the tray icon and set it's state
_this->DelTrayIcon();
_this->AddTrayIcon();
_this->FlashTrayIcon(_this->m_server->AuthClientCount() != 0);
// We should load in the prefs for the new user
_this->m_properties.Load(TRUE);
_this->m_propertiesPoll.Load(TRUE);
}
}
}
return 0;
default:
// Deal with any of our custom message types
if (iMsg == MENU_PROPERTIES_SHOW)
{
// External request to show our Properties dialog
PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_PROPERTIES, 0), 0);
return 0;
}
if (iMsg == MENU_DEFAULT_PROPERTIES_SHOW)
{
// External request to show our Properties dialog
PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_DEFAULT_PROPERTIES, 0), 0);
return 0;
}
if (iMsg == MENU_ABOUTBOX_SHOW)
{
// External request to show our About dialog
PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_ABOUT, 0), 0);
return 0;
}
if (iMsg == MENU_SERVICEHELPER_MSG)
{
// External ServiceHelper message.
// This message holds a process id which we can use to
// impersonate a specific user. In doing so, we can load their
// preferences correctly
// vncService::ProcessUserHelperMessage(wParam, lParam);
// Modif Jeremy C.
if (!_this->m_properties.Lock_service_helper)
{
vncService::ProcessUserHelperMessage((WPARAM)&_this->m_server->m_impersonationtoken, lParam);
// - Trigger a check of the current user
PostMessage(hwnd, WM_USERCHANGED, 0, 0);
}
return 0;
}
if (iMsg == MENU_ADD_CLIENT_MSG)
{
// sf@2003 - Autoreconnect
// Dirty trick to avoid to add a new MSG... no time
if (lParam == 999)
{
_this->m_server->AutoReconnect(true);
return 0;
}
/*
// sf@2005 - FTNoUserImpersonation
// Dirty trick to avoid to add a new MSG... no time
if (lParam == 998)
{
_this->m_server->FTUserImpersonation(false);
return 0;
}
*/
// Add Client message. This message includes an IP address
// of a listening client, to which we should connect.
// If there is no IP address then show the connection dialog
if (!lParam) {
vncConnDialog *newconn = new vncConnDialog(_this->m_server);
if (newconn)
{
newconn->DoDialog();
// winvnc -connect fixed
//CHECH memeory leak
// delete newconn;
}
return 0;
}
unsigned short nport = 0;
char *nameDup = 0;
char szAdrName[64];
// sf@2003 - Values are already converted
if (_this->m_server->AutoReconnect() && strlen(_this->m_server->AutoReconnectAdr()) > 0)
{
nport = _this->m_server->AutoReconnectPort();
strcpy(szAdrName, _this->m_server->AutoReconnectAdr());
}
else
{
// Get the IP address stringified
struct in_addr address;
address.S_un.S_addr = lParam;
char *name = inet_ntoa(address);
if (name == 0)
return 0;
nameDup = strdup(name);
if (nameDup == 0)
return 0;
strcpy(szAdrName, nameDup);
// Free the duplicate name
if (nameDup != 0) free(nameDup);
// Get the port number
nport = (unsigned short)wParam;
if (nport == 0)
nport = INCOMING_PORT_OFFSET;
}
// sf@2003
// Stores the client adr/ports the first time we try to connect
// This way we can call this message again later to reconnect with the same values
if (_this->m_server->AutoReconnect() && strlen(_this->m_server->AutoReconnectAdr()) == 0)
{
_this->m_server->AutoReconnectAdr(szAdrName);
_this->m_server->AutoReconnectPort(nport);
}
// Attempt to create a new socket
VSocket *tmpsock;
tmpsock = new VSocket;
if (tmpsock) {
// Connect out to the specified host on the VNCviewer listen port
tmpsock->Create();
if (tmpsock->Connect(szAdrName, nport)) {
// Add the new client to this server
_this->m_server->AddClient(tmpsock, TRUE, TRUE);
} else {
delete tmpsock;
}
}
return 0;
}
// Process FileTransfer asynchronous Send Packet Message
if (iMsg == FileTransferSendPacketMessage)
{
vncClient* pClient = (vncClient*) wParam;
if (_this->m_server->IsClient(pClient)) pClient->SendFileChunk();
}
}
// Message not recognised
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?