本文整理匯總了C++中CloseDesktop函數的典型用法代碼示例。如果您正苦於以下問題:C++ CloseDesktop函數的具體用法?C++ CloseDesktop怎麽用?C++ CloseDesktop使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CloseDesktop函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: InputDesktopSelected
bool InputDesktopSelected()
{
DWORD dummy;
char threadname[256];
char inputname[256];
HDESK threaddesktop = GetThreadDesktop(GetCurrentThreadId());
HDESK inputdesktop = OpenInputDesktop(0, FALSE,
DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
if (inputdesktop == NULL) return FALSE;
if (!GetUserObjectInformation(threaddesktop, UOI_NAME, &threadname, 256, &dummy)) {
CloseDesktop(inputdesktop);
return FALSE;
}
if (!GetUserObjectInformation(inputdesktop, UOI_NAME, &inputname, 256, &dummy)) {
CloseDesktop(inputdesktop);
return FALSE;
}
CloseDesktop(inputdesktop);
if (strcmp(threadname, inputname) != 0)
{
//if (strcmp(inputname, "Screen-saver") == 0)
{
return SelectDesktop();
}
return FALSE;
}
return TRUE;
}
示例2: SelectDesktop
bool SelectDesktop()
{
HDESK desktop;
HDESK old_desktop;
DWORD dummy;
char new_name[256];
desktop = OpenInputDesktop(0, FALSE,
DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
if (desktop == NULL) return FALSE;
old_desktop = GetThreadDesktop(GetCurrentThreadId());
if (!GetUserObjectInformation(desktop, UOI_NAME, &new_name, 256, &dummy)) {
CloseDesktop(desktop);
return FALSE;
}
if(!SetThreadDesktop(desktop)) {
CloseDesktop(desktop);
return FALSE;
}
CloseDesktop(old_desktop);
return TRUE;
}
示例3: SwitchInputDesktop
bool SwitchInputDesktop()
{
BOOL bRet = false;
DWORD dwLengthNeeded;
HDESK hOldDesktop, hNewDesktop;
char strCurrentDesktop[256], strInputDesktop[256];
hOldDesktop = GetThreadDesktop(GetCurrentThreadId());
memset(strCurrentDesktop, 0, sizeof(strCurrentDesktop));
GetUserObjectInformation(hOldDesktop, UOI_NAME, &strCurrentDesktop, sizeof(strCurrentDesktop), &dwLengthNeeded);
hNewDesktop = OpenInputDesktop(0, FALSE, MAXIMUM_ALLOWED);
memset(strInputDesktop, 0, sizeof(strInputDesktop));
GetUserObjectInformation(hNewDesktop, UOI_NAME, &strInputDesktop, sizeof(strInputDesktop), &dwLengthNeeded);
if (lstrcmpi(strInputDesktop, strCurrentDesktop) != 0)
{
SetThreadDesktop(hNewDesktop);
bRet = true;
}
CloseDesktop(hOldDesktop);
CloseDesktop(hNewDesktop);
return bRet;
}
示例4: VNCLOG
// - SelectDesktop(char *)
// Switches the current thread into a different desktop, by name
// Calling with a valid desktop name will place the thread in that desktop.
// Calling with a NULL name will place the thread in the current input desktop.
BOOL
vncService::SelectDesktop(char *name, HDESK *new_desktop)
{
//return false;
// Are we running on NT?
if (IsWinNT())
{
HDESK desktop;
vnclog.Print(LL_INTERR, VNCLOG("SelectDesktop \n"));
if (name != NULL)
{
vnclog.Print(LL_INTERR, VNCLOG("OpenInputdesktop2 named\n"));
// Attempt to open the named desktop
desktop = OpenDesktop(name, 0, FALSE,
DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
}
else
{
vnclog.Print(LL_INTERR, VNCLOG("OpenInputdesktop2 NULL\n"));
// No, so open the input desktop
desktop = OpenInputDesktop(0, FALSE,
DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
}
// Did we succeed?
if (desktop == NULL) {
vnclog.Print(LL_INTERR, VNCLOG("OpenInputdesktop2 \n"));
return FALSE;
}
else vnclog.Print(LL_INTERR, VNCLOG("OpenInputdesktop2 OK\n"));
// Switch to the new desktop
if (!SelectHDESK(desktop)) {
// Failed to enter the new desktop, so free it!
if (!CloseDesktop(desktop))
vnclog.Print(LL_INTERR, VNCLOG("SelectDesktop failed to close desktop\n"));
return FALSE;
}
if (new_desktop)
{
if (*new_desktop)
CloseDesktop(*new_desktop);
*new_desktop = desktop;
}
// We successfully switched desktops!
return TRUE;
}
return (name == NULL);
}
示例5: check_winsta
static BOOL CALLBACK
check_winsta(wchar_t* winsta_name, LPARAM)
{
debug(L"entering enum_winsta_proc, winsta_name = %s\n", winsta_name);
// open the window station and connect to it
// (TODO: figure out what permissions are really needed here)
//
HWINSTA winsta = OpenWindowStation(winsta_name, FALSE, MAXIMUM_ALLOWED);
if (winsta == NULL) {
debug(L"OpenWindowStation error: %u\n", GetLastError());
return TRUE;
}
HWINSTA old_winsta = GetProcessWindowStation();
if (SetProcessWindowStation(winsta) == FALSE) {
debug(L"SetProcessWindowStation error: %u\n", GetLastError());
if (CloseWindowStation(winsta) == FALSE) {
debug(L"CloseWindowStation error: %u\n", GetLastError());
}
return TRUE;
}
if (CloseWindowStation(old_winsta) == FALSE) {
debug(L"CloseWindowStation error: %u\n", GetLastError());
}
// open the "default" desktop and connect to it (if present)
// (TODO: figure out what permissions are really needed here)
//
HDESK desktop = OpenDesktop(L"default", 0, FALSE, MAXIMUM_ALLOWED);
if (desktop == NULL) {
debug(L"OpenDesktop error: %u\n", GetLastError());
return TRUE;
}
HDESK old_desktop = GetThreadDesktop(GetCurrentThreadId());
if (SetThreadDesktop(desktop) == FALSE) {
debug(L"SetThreadDesktop error: %u\n", GetLastError());
if (CloseDesktop(desktop) == FALSE) {
debug(L"CloseDesktop error: %u\n", GetLastError());
}
return TRUE;
}
if (CloseDesktop(old_desktop) == FALSE) {
debug(L"CloseDesktop error: %u\n", GetLastError());
}
// check_this_winsta() returns TRUE if it found the pid, FALSE if not
//
BOOL found = check_this_winsta();
if (found) {
SetLastError(ERROR_SUCCESS);
}
// return TRUE to keep searching
return ! found;
}
示例6: Test_OpenInputDesktop
void Test_OpenInputDesktop()
{
HDESK hDeskInput ,hDeskInput2;
HDESK hDeskInitial;
BOOL ret;
HWINSTA hwinsta = NULL, hwinstaInitial;
DWORD err;
hDeskInput = OpenInputDesktop(0, FALSE, DESKTOP_ALL_ACCESS);
ok(hDeskInput != NULL, "OpenInputDesktop failed\n");
hDeskInitial = GetThreadDesktop( GetCurrentThreadId() );
ok(hDeskInitial != NULL, "GetThreadDesktop failed\n");
ok(hDeskInput != hDeskInitial, "OpenInputDesktop returned thread desktop\n");
hDeskInput2 = OpenInputDesktop(0, FALSE, DESKTOP_ALL_ACCESS);
ok(hDeskInput2 != NULL, "Second call to OpenInputDesktop failed\n");
ok(hDeskInput2 != hDeskInput, "Second call to OpenInputDesktop returned same handle\n");
ok(CloseDesktop(hDeskInput2) != 0, "CloseDesktop failed\n");
ret = SetThreadDesktop(hDeskInput);
ok(ret == TRUE, "SetThreadDesktop for input desktop failed\n");
ret = SetThreadDesktop(hDeskInitial);
ok(ret == TRUE, "SetThreadDesktop for initial desktop failed\n");
ok(CloseDesktop(hDeskInput) != 0, "CloseDesktop failed\n");
/* Try calling OpenInputDesktop after switching to a new winsta */
hwinstaInitial = GetProcessWindowStation();
ok(hwinstaInitial != 0, "GetProcessWindowStation failed\n");
hwinsta = CreateWindowStationW(L"TestWinsta", 0, WINSTA_ALL_ACCESS, NULL);
ok(hwinsta != 0, "CreateWindowStationW failed\n");
ret = SetProcessWindowStation(hwinsta);
ok(ret != 0, "SetProcessWindowStation failed\n");
hDeskInput = OpenInputDesktop(0, FALSE, DESKTOP_ALL_ACCESS);
ok(hDeskInput == 0, "OpenInputDesktop should fail\n");
err = GetLastError();
ok(err == ERROR_INVALID_FUNCTION, "Got last error: %lu\n", err);
ret = SetProcessWindowStation(hwinstaInitial);
ok(ret != 0, "SetProcessWindowStation failed\n");
ret = CloseWindowStation(hwinsta);
ok(ret != 0, "CloseWindowStation failed\n");
}
示例7: SwitchInputDesktop
// get the current input desktop name and compare with
// the desktop the call thread attached ,if not equal,
// then switch to the input desktop
BOOL SwitchInputDesktop()
{
HDESK threaddesk = GetThreadDesktop(GetCurrentThreadId());
HDESK inputdesk = OpenInputDesktop(0, DF_ALLOWOTHERACCOUNTHOOK,GENERIC_ALL);
if (inputdesk == NULL)
{
DebugOutF(filelog::log_error,("OpenInputDesktop failed with %d"),GetLastError());
return FALSE;
}
DWORD len=0;
TCHAR szThread[MAX_PATH];
TCHAR szInput[MAX_PATH];
szThread[0] = _T('\0');
szInput[0] = _T('\0');
BOOL res = FALSE;
try
{
// get desktop name
if(!GetUserObjectInformation(threaddesk, UOI_NAME, szThread, MAX_PATH, &len)){
DebugOutF(filelog::log_error,("GetUserObjectInformation failed with %d"),GetLastError());
throw FALSE;
}
if (!GetUserObjectInformation(inputdesk, UOI_NAME, szInput, MAX_PATH, &len)) {
DebugOutF(filelog::log_error,("GetUserObjectInformation failed with %d"),GetLastError());
throw FALSE;
}
//compare,if not equal,then switch to the input desktop
if (_tcsicmp(szThread, szInput) != 0)
{
if(!SetThreadDesktop(inputdesk)){
DebugOutF(filelog::log_error,("SetThreadDesktop %s failed with %d"),szInput,GetLastError());
throw FALSE;
}
DebugOutF(filelog::log_info,("switch input desktop %s"),szInput);
res = TRUE;
}
}
catch(BOOL b1)
{
res = b1;
}
if(threaddesk)CloseDesktop(threaddesk);
if(inputdesk)CloseDesktop(inputdesk);
return res;
}
示例8: KillWindow
void KillWindow() {
window_ready=false;
wglMakeCurrent(NULL,NULL); // release GL rendering context
if (hRC) {
wglDeleteContext(hRC);
hRC=NULL;
}
if (hWnd && hDC) {
ReleaseDC(hWnd,hDC);
}
hDC = NULL;
if (hWnd) {
DestroyWindow(hWnd);
}
hWnd = NULL;
if (hOriginalWindowStation) {
SetProcessWindowStation(hOriginalWindowStation);
CloseWindowStation(hInteractiveWindowStation);
hInteractiveWindowStation = NULL;
}
if (hOriginalDesktop) {
SetThreadDesktop(hOriginalDesktop);
CloseDesktop(hInteractiveDesktop);
hInteractiveDesktop = NULL;
}
}
示例9: freeLogonSID
void WindowsUser::logout()
{
// Free the buffer for the logon SID.
if (pSid_)
{
freeLogonSID(&pSid_);
}
// Close the handles to the interactive window station and desktop.
if (winstaHandle_)
{
CloseWindowStation(winstaHandle_);
winstaHandle_ = NULL;
}
if (deskHandle_)
{
CloseDesktop(deskHandle_);
deskHandle_ = NULL;
}
// Close the handle to the client's access token.
if (tokenHandle_)
{
RevertToSelf();
CloseHandle(tokenHandle_);
tokenHandle_ = NULL;
}
}
示例10: OpenInputDesktop
LRESULT CIdlePreventDlg::SendWakeEvent(WPARAM wparam, LPARAM lparam)
{
// This ensures we only send wake events while the machine isn't locked. Seems Windows queues some events and sometimes they happen at once as soon as you unlock the computer.
HDESK test = OpenInputDesktop(DF_ALLOWOTHERACCOUNTHOOK, TRUE,DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |DESKTOP_SWITCHDESKTOP |GENERIC_WRITE);
if (test != NULL)
{
if(RDPFriendlyWakeEnabled)
{
keybd_event(VK_RSHIFT,0xB6, KEYEVENTF_KEYUP, 0);
}
else
{
INPUT mouseInput[1];
mouseInput[0].mi.dx = 0;
mouseInput[0].mi.dy = 0;
mouseInput[0].mi.mouseData = 0;
mouseInput[0].mi.dwFlags = MOUSEEVENTF_MOVE;
mouseInput[0].mi.time = 0;
mouseInput[0].mi.dwExtraInfo = NULL;
SendInput(1, mouseInput, sizeof(mouseInput));
SetThreadExecutionState(ES_DISPLAY_REQUIRED);
}
}
CloseDesktop(test);
return 0;
}
示例11: GetThreadDesktop
BOOL
vncService::SelectHDESK(HDESK new_desktop)
{
// Are we running on NT?
if (IsWinNT())
{
HDESK old_desktop = GetThreadDesktop(GetCurrentThreadId());
DWORD dummy;
char new_name[256];
if (!GetUserObjectInformation(new_desktop, UOI_NAME, &new_name, 256, &dummy)) {
vnclog.Print(LL_INTERR, VNCLOG("GetUserObjectInformation() failed\n"));
return FALSE;
}
vnclog.Print(LL_INTINFO, VNCLOG("SelectHDESK() to %s (%x) from %x\n"),
new_name, new_desktop, old_desktop);
// Switch the desktop
if(!SetThreadDesktop(new_desktop)) {
vnclog.Print(LL_INTERR, VNCLOG("unable to SetThreadDesktop(), error=%d\n"), GetLastError());
return FALSE;
}
// Switched successfully - destroy the old desktop
if (!CloseDesktop(old_desktop))
vnclog.Print(LL_INTERR, VNCLOG("SelectHDESK failed to close old desktop %x, error=%d\n"), old_desktop, GetLastError());
return TRUE;
}
return TRUE;
}
示例12: SimulateCtrlAltDelThreadFn
void *
SimulateCtrlAltDelThreadFn(void *context)
{
HDESK old_desktop = GetThreadDesktop(GetCurrentThreadId());
HDESK winlogon_desk = 0;
// Switch into the Winlogon desktop
if (!vncService::SelectDesktop("Winlogon", &winlogon_desk))
{
vnclog.Print(LL_INTERR, VNCLOG("failed to select logon desktop\n"));
vncTimedMsgBox::Do(
sz_ID_CADERROR,
sz_ID_ULTRAVNC_WARNING,
MB_ICONINFORMATION | MB_OK
);
return FALSE;
}
// 9 April 2008 jdp
// turn off capslock if on
ClearKeyState(VK_CAPITAL);
vnclog.Print(LL_ALL, VNCLOG("generating ctrl-alt-del\n"));
// Fake a hotkey event to any windows we find there.... :(
// Winlogon uses hotkeys to trap Ctrl-Alt-Del...
PostMessage(HWND_BROADCAST, WM_HOTKEY, 0, MAKELONG(MOD_ALT | MOD_CONTROL, VK_DELETE));
// Switch back to our original desktop
if (old_desktop != NULL)
{
vncService::SelectHDESK(old_desktop);
CloseDesktop(winlogon_desk);
}
return NULL;
}
示例13: thread_proc
static DWORD WINAPI thread_proc(void *param)
{
THREAD_DATA* current_data = (THREAD_DATA*)param;
MSG msg;
HDESK hdesk = NULL;
int iwnd;
if(current_data->Desktop)
{
hdesk = CreateDesktopW(current_data->Desktop, NULL, NULL, 0, DESKTOP_ALL_ACCESS, NULL );
SetThreadDesktop(hdesk);
}
/* create test window */
current_data->hWnd = CreateWindowW(L"TestClass", L"test", WS_OVERLAPPEDWINDOW,
100, 100, 500, 500, NULL, NULL, 0, NULL);
SetEvent( current_data->StartEvent );
iwnd = get_iwnd(current_data->hWnd);
/* Use MsgWaitForMultipleObjects to let the thread process apcs */
while( GetMessage(&msg, 0,0,0) )
{
if(msg.message > 0 && msg.message < WM_APP && msg.message != WM_TIMER )
record_message(&data[iwnd].cache, iwnd, msg.message, POST, msg.wParam,0);
DispatchMessage(&msg);
}
if(hdesk)
CloseDesktop(hdesk);
return 0;
}
示例14: GuiDeinitFrontEnd
static VOID NTAPI
GuiDeinitFrontEnd(IN OUT PFRONTEND This)
{
PGUI_CONSOLE_DATA GuiData = This->Context;
DPRINT("Send PM_DESTROY_CONSOLE message and wait on hGuiTermEvent...\n");
PostThreadMessageW(GuiData->InputThreadId, PM_DESTROY_CONSOLE, 0, (LPARAM)GuiData);
NtWaitForSingleObject(GuiData->hGuiTermEvent, FALSE, NULL);
DPRINT("hGuiTermEvent set\n");
NtClose(GuiData->hGuiTermEvent);
GuiData->hGuiTermEvent = NULL;
CloseDesktop(GuiData->Desktop); // NtUserCloseDesktop
CloseWindowStation(GuiData->WinSta); // NtUserCloseWindowStation
DPRINT("Destroying icons !! - GuiData->hIcon = 0x%p ; ghDefaultIcon = 0x%p ; GuiData->hIconSm = 0x%p ; ghDefaultIconSm = 0x%p\n",
GuiData->hIcon, ghDefaultIcon, GuiData->hIconSm, ghDefaultIconSm);
if (GuiData->hIcon != NULL && GuiData->hIcon != ghDefaultIcon)
{
DPRINT("Destroy hIcon\n");
DestroyIcon(GuiData->hIcon);
}
if (GuiData->hIconSm != NULL && GuiData->hIconSm != ghDefaultIconSm)
{
DPRINT("Destroy hIconSm\n");
DestroyIcon(GuiData->hIconSm);
}
This->Context = NULL;
DeleteCriticalSection(&GuiData->Lock);
ConsoleFreeHeap(GuiData);
DPRINT("Quit GuiDeinitFrontEnd\n");
}
示例15: SetUserDesktop
int SetUserDesktop( int mode )
{
static HWINSTA hwinstaSave;
static HDESK hdeskSave;
static HWINSTA hwinstaUser;
static HDESK hdeskUser;
if(mode == 1) {
hwinstaSave = GetProcessWindowStation();
hdeskSave = GetThreadDesktop(GetCurrentThreadId());
hwinstaUser = OpenWindowStation("WinSta0", FALSE, MAXIMUM_ALLOWED);
if (hwinstaUser == NULL)
return 0;
SetProcessWindowStation(hwinstaUser);
hdeskUser = OpenDesktop("Default", 0, FALSE, MAXIMUM_ALLOWED);
if (hdeskUser == NULL) {
SetProcessWindowStation(hwinstaSave);
CloseWindowStation(hwinstaUser);
return 0;
}
SetThreadDesktop(hdeskUser);
}
else if(mode == 0) {
SetThreadDesktop(hdeskSave);
SetProcessWindowStation(hwinstaSave);
CloseDesktop(hdeskUser);
CloseWindowStation(hwinstaUser);
}
return 0;
}