Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8840817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:33:12+00:00 2026-06-14T10:33:12+00:00

When a thread is changed to a different desktop new consoles created with AllocConsole()

  • 0

When a thread is changed to a different desktop new consoles created with AllocConsole() appear in the original desktop. Message boxes and other windows created appear in the new desktop as would be expected, but console windows do not. The following code is a windows application example, however it still the result is the same whether or not it is a console application.

#include <Windows.h>

HDESK hDesk;

DWORD WINAPI Testing(void *)
{
    SetThreadDesktop(hDesk);
    AllocConsole();
    MessageBox(NULL, TEXT("Test"), NULL, MB_OK); //This will show on the new desktop
    FreeConsole();
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hDesk=CreateDesktop(TEXT("Testing"),NULL,NULL,NULL,GENERIC_ALL,NULL);
    SwitchDesktop(hDesk);

    DWORD thr;
    HANDLE thread = CreateThread (0, 0, Testing, 0, 0, &thr);

    WaitForSingleObject (thread, 10000); //Wait 10 seconds before automatically exiting.

    SwitchDesktop(GetThreadDesktop(GetCurrentThreadId())); //Return to previous desktop
    CloseDesktop(hDesk);
    return 0;
}

How can I make the console window be created in the second desktop?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:33:14+00:00Added an answer on June 14, 2026 at 10:33 am

    This behavior is understandable because the one console attached to a process is shared by all threads of that process and it makes sense to put that console on the desktop on which the process was launched rather than dynamically moving the console from desktop to desktop as consoles are allocated and freed by threads that are attached to different desktops. And if such movement of console window is allowed the behavior would be tougher to understand when consoles are shared between processes.

    To answer the question on how to associate with a console on a different desktop, I would suggest starting a blank console application window on the target desktop, whose primary responsibility would be to just keep the console window alive. All is has to do is do as

    int _tmain(int argc, _TCHAR* argv[])
    {
    Sleep(INFINITE);
    return 0;
    }
    

    And instead of calling AllocConsole, call AttachConsole with the process id of the newly launched process, and then call GetStdHandle to get handle to the console buffer for further calls to WriteConsole.

    To launch a new process in a target desktop different from the one the process (at first) is connected to you will have to set the desktop name in the STARTUPINFO structure that would be passed to CreateProcess call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to Ruby on Rails. I changed this thread, because i recognized
Thread A: a UI thread where the Gtkmm's message loop runs. Thread B: receives
Thread thread = new Thread(new Runnable() { @Override public void run() { try {
When we send a message, if the specified window was created by the calling
I have changed my thread as my last thread also same like that. But
We have an application with multiple subsystems running in different threads (ie one thread
Some Windows programs can use different icons for different files with the same extension.
I'm running a windows c++ multithreaded app in which one instance/thread of the server
I don't see the different between C#'s (and VB's) new async features, and .NET
I know the thread which says that rebase is for small changes of teamMates,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.