Shaowen Cheng
May 17th, 1999, 03:25 AM
Hi, I encountered a requirement that my application shows fullscreen windows
without any caption bar, system menu, and windows border. (i.e. to emulate
a DOS application after clearing screen).
My approach is as follows. But only system menu disappears. Caption is still there
without an icon. Border remains too.
Is there anyone who can show me how to do it right? Thanks.
BOOL CWDPFApp::InitInstance()
{
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CWDPFDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CWDPFView));
AddDocTemplate(pDocTemplate);
// Connect the COleTemplateServer to the document template.
// The COleTemplateServer creates new documents on behalf
// of requesting OLE containers by using information
// specified in the document template.
//m_server.ConnectTemplate(clsid, pDocTemplate, TRUE);
// Note: SDI applications register server objects only if /Embedding
// or /Automation is present on the command line.
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Check to see if launched as OLE server
//if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
//{
// Register all OLE server (factories) as running. This enables the
// OLE libraries to create objects from other applications.
// COleTemplateServer::RegisterAll();
// Application was run with /Embedding or /Automation. Don't show the
// main window in this case.
// return TRUE;
//}
// When a server application is launched stand-alone, it is a good idea
// to update the system registry in case it has been damaged.
//m_server.UpdateRegistry(OAT_DISPATCH_OBJECT);
//COleObjectFactory::UpdateRegistryAll();
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// ================================================
// try to disable caption, border and system menu
// ================================================
ModifyStyle(WS_CAPTION | WS_BORDER | WS_SYSMENU, 0);
//if (!m_wndToolBar.Create(this) ||
// !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
//{
// TRACE0("Failed to create toolbar\n");
// return -1; // fail to create
//}
//if (!m_wndStatusBar.Create(this) ||
// !m_wndStatusBar.SetIndicators(indicators,
// sizeof(indicators)/sizeof(UINT)))
//{
// TRACE0("Failed to create status bar\n");
// return -1; // fail to create
//}
// TODO: Remove this if you don't want tool tips or a resizeable toolbar
//m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
// CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
//m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
//EnableDocking(CBRS_ALIGN_ANY);
//DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
// ================================================
// delete menu bar
// ================================================
if (cs.hMenu != NULL) {
::DestroyMenu(cs.hMenu);
cs.hMenu = NULL;
}
// ================================================
// set FULL screen
// ================================================
HDC hDC;
int ScreenX, ScreenY;
hDC = ::CreateDC("DISPLAY", NULL, NULL, NULL);
ScreenX = ::GetDeviceCaps(hDC, HORZRES);
ScreenY = ::GetDeviceCaps(hDC, VERTRES);
::DeleteDC(hDC);
cs.x = 0;
cs.y = 0;
cs.cx = ScreenX;
cs.cy = ScreenY;
// ================================================
// remove the system menu style bit from the window
// ================================================
//cs.style &= ~(WS_SYSMENU | WS_BORDER | WS_CAPTION );
return CFrameWnd::PreCreateWindow(cs);
}
void CWDPFView::OnInitialUpdate()
{
SetWindowText("view window");
}
BOOL CWDPFView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
// ================================================
// remove the system menu style bit from the window
// ================================================
cs.style &= ~(WS_BORDER | WS_CAPTION);
return CView::PreCreateWindow(cs);
}
without any caption bar, system menu, and windows border. (i.e. to emulate
a DOS application after clearing screen).
My approach is as follows. But only system menu disappears. Caption is still there
without an icon. Border remains too.
Is there anyone who can show me how to do it right? Thanks.
BOOL CWDPFApp::InitInstance()
{
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CWDPFDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CWDPFView));
AddDocTemplate(pDocTemplate);
// Connect the COleTemplateServer to the document template.
// The COleTemplateServer creates new documents on behalf
// of requesting OLE containers by using information
// specified in the document template.
//m_server.ConnectTemplate(clsid, pDocTemplate, TRUE);
// Note: SDI applications register server objects only if /Embedding
// or /Automation is present on the command line.
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Check to see if launched as OLE server
//if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
//{
// Register all OLE server (factories) as running. This enables the
// OLE libraries to create objects from other applications.
// COleTemplateServer::RegisterAll();
// Application was run with /Embedding or /Automation. Don't show the
// main window in this case.
// return TRUE;
//}
// When a server application is launched stand-alone, it is a good idea
// to update the system registry in case it has been damaged.
//m_server.UpdateRegistry(OAT_DISPATCH_OBJECT);
//COleObjectFactory::UpdateRegistryAll();
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// ================================================
// try to disable caption, border and system menu
// ================================================
ModifyStyle(WS_CAPTION | WS_BORDER | WS_SYSMENU, 0);
//if (!m_wndToolBar.Create(this) ||
// !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
//{
// TRACE0("Failed to create toolbar\n");
// return -1; // fail to create
//}
//if (!m_wndStatusBar.Create(this) ||
// !m_wndStatusBar.SetIndicators(indicators,
// sizeof(indicators)/sizeof(UINT)))
//{
// TRACE0("Failed to create status bar\n");
// return -1; // fail to create
//}
// TODO: Remove this if you don't want tool tips or a resizeable toolbar
//m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
// CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
//m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
//EnableDocking(CBRS_ALIGN_ANY);
//DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
// ================================================
// delete menu bar
// ================================================
if (cs.hMenu != NULL) {
::DestroyMenu(cs.hMenu);
cs.hMenu = NULL;
}
// ================================================
// set FULL screen
// ================================================
HDC hDC;
int ScreenX, ScreenY;
hDC = ::CreateDC("DISPLAY", NULL, NULL, NULL);
ScreenX = ::GetDeviceCaps(hDC, HORZRES);
ScreenY = ::GetDeviceCaps(hDC, VERTRES);
::DeleteDC(hDC);
cs.x = 0;
cs.y = 0;
cs.cx = ScreenX;
cs.cy = ScreenY;
// ================================================
// remove the system menu style bit from the window
// ================================================
//cs.style &= ~(WS_SYSMENU | WS_BORDER | WS_CAPTION );
return CFrameWnd::PreCreateWindow(cs);
}
void CWDPFView::OnInitialUpdate()
{
SetWindowText("view window");
}
BOOL CWDPFView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
// ================================================
// remove the system menu style bit from the window
// ================================================
cs.style &= ~(WS_BORDER | WS_CAPTION);
return CView::PreCreateWindow(cs);
}