Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i'm able to load the console at run time but it comes in a separate window.
I like to have this window inside my SDI project and skip the view, which a don't have any use for. I have split the may view into two, one is a FormView second remained the old. Now i want to have the console to be instead.

What I have tried:

MFC
#pragma comment(linker, "/entry:WinMainCRTStartup /subsystem:console")

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{

	//calculate client size
	CRect cr;
	GetWindowRect(&cr);

	// Create the main splitter with 1 row and 2 columns
	if (!m_mainSplitter.CreateStatic(this, 1, 2))
	{
		MessageBox("Error setting up m_mainSplitter", "ERROR", MB_OK | MB_ICONERROR);
		return FALSE;
	}

	// The views for each pane must be created 
	if (!m_mainSplitter.CreateView(0, 0, RUNTIME_CLASS(CINBToolView),
		CSize(cr.Width() / 2, cr.Height()), pContext))
	{
		MessageBox("Error setting up splitter view", "ERROR", MB_OK | MB_ICONERROR);
		return FALSE;
	}

	if (!m_mainSplitter.CreateView(0, 1, RUNTIME_CLASS(CSTART_SCREEN),
		CSize(cr.Width() / 2, cr.Height()), pContext))
	{
		MessageBox("Error setting up splitter view", "ERROR", MB_OK | MB_ICONERROR);
		return FALSE;
	}

	//change flag to show splitter created
	m_bInitSplitter = true;

	//return TRUE instead of the parent method since that would
	//not show our window
	return TRUE;

}

LRESULT CMainFrame::OnLoadNewForm(WPARAM wParam, LPARAM lParam)
{
	CRect cr;
	GetWindowRect(&cr);

	AfxMessageBox("Called from MainFrame");
	m_mainSplitter.ShowWindow(SW_HIDE);
	m_mainSplitter.UpdateWindow();

	m_mainSplitter.DeleteView(0,1);

	if (!m_mainSplitter.CreateView(0, 1, RUNTIME_CLASS(CService),
		CSize(cr.Width() / 2, cr.Height()), &m_Context))
	{
		MessageBox("Error setting up splitter view", "ERROR", MB_OK | MB_ICONERROR);
		return FALSE;
	}

	return 0;
}
Posted
Updated 17-Nov-23 7:01am
v2

As far as I can remember, you cannot embed an actual console window in your application. You can, however, create a normal edit control with fonts and colors that looks like a console window, and just pass the input and output to a hidden console your app can launch. You'd be simulating the console window in your app.

That may have changed with the release of Windows Terminal, but I haven't dug into that API to see what's possible.

[EDIT]
Curiosity got to me. So...
Pseudoconsoles – Windows Desktop - Windows Console | Microsoft Learn[^]
Creating a Pseudoconsole session - Windows Console | Microsoft Learn[^]
Windows Command-Line: Introducing the Windows Pseudo Console (ConPTY) - Windows Command Line[^]
 
Share this answer
 
v2
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900