BAlexandrov
asked on
Open new window with specified size and without menu and toolbar from an application
My application is written in C++. I need to open an browser window with specified size.
Now I generate one local html file with javascript that redirect to the domain I want (news page) and
make Create Process with iexplore.exe and pass this file as parameter. The problem is that it opens with menu and toolbar and with default size and position.
If I put an openwindow call in this html - it opens new window without toolbar and menubar but I cannot close the original window so I end up with two windows that is unacceptable.
Now I generate one local html file with javascript that redirect to the domain I want (news page) and
make Create Process with iexplore.exe and pass this file as parameter. The problem is that it opens with menu and toolbar and with default size and position.
If I put an openwindow call in this html - it opens new window without toolbar and menubar but I cannot close the original window so I end up with two windows that is unacceptable.
window.open("page.html","" ,"toolbar= no,locatio n=no,width =200,heigh t=200")
if you use the open window you cannot close the paernt, it's a security feature and i know of no way to change the current window to no toolbar no menu , but you can use window.resize(200,200) to resize the window
ASKER
I know about resizing of the current window but most important is to not have toolbar and menu bar.
Also I know that I cannot close parent window.
I need a sollution or workaround in my situation - opening a browser window from an application.
I have inspected command line parameters of explorer but nothing useful.
May be window messages that I can send or ole automation?
Also I do not want to make my form to contain browser object - I need separate browser process.
Also I know that I cannot close parent window.
I need a sollution or workaround in my situation - opening a browser window from an application.
I have inspected command line parameters of explorer but nothing useful.
May be window messages that I can send or ole automation?
Also I do not want to make my form to contain browser object - I need separate browser process.
you are using C++, are you using MFC also?
ASKER
Yes
i'm not sure how much good this will do you but it' all i have for opening a browser
ShellExecute(hwnd, "Open", "url", &O0, &O0, SW_NORMAL)
ShellExecute(hwnd, "Open", "url", &O0, &O0, SW_NORMAL)
try changing the SW_NORMAL to SW_fullscreen or SW_CHANELMODE, not sure if that will work
ASKER
This will open the browser window (my code is similar) but with menu and toolbar.
I can start it in chanel mode also with command line option too but it start on full screen and this is not an option.
I can start it in chanel mode also with command line option too but it start on full screen and this is not an option.
then i suggest you ask cs to move the question to the MFC or C++ chanel and see if you can get what you need there
IF you can get a handle to the window you could use the following function: SetWindowPos
BOOL SetWindowPos(
HWND hWnd, // handle to window
HWND hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
UINT uFlags // window-positioning options
);
It doesn't open the window at set size/position but it will modify the size/position of an existing window.
BOOL SetWindowPos(
HWND hWnd, // handle to window
HWND hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
UINT uFlags // window-positioning options
);
It doesn't open the window at set size/position but it will modify the size/position of an existing window.
ASKER
Thanks I have seen this function. It will work for setting the size but also I need that it does not have toolbar and manubar.
Also I need reliable method to get the handle of the new window.
Also I need reliable method to get the handle of the new window.
I think you will have to resort to automation to accomplish the toolbar/menubar hiding. If you use CreateProcess to start the app then you should be able to get the HWND reliably of that process.
Roshmon originally supplied me the following in answer to a question.
BOOL CProcessDlg::DoCreateProce ss()
{
STARTUPINFO StartupInfo;
CString CommandLine;
BOOL rc;
// I am putting the (exe) filename in quotes in case there are blanks etc. in it
CommandLine = CString('"') + m_Filename + CString("\" ") + m_Parameters;
memset(&StartupInfo, 0, sizeof(StartupInfo));
StartupInfo.cb = sizeof(StartupInfo);
rc = CreateProcess(NULL, (LPTSTR)(LPCTSTR)CommandLi ne, NULL, NULL, FALSE, 0,
NULL, NULL, &StartupInfo, &m_ProcessInformation);
if (!rc)
{
m_Message = ShowError("CreateProcess") ;
return FALSE;
}
switch (WaitForInputIdle(m_Proces sInformati on.hProces s, 10000))
{
case 0:
// The process has been created and has finished intializing
// so now we look for it
m_hProcessWnd = NULL;
EnumWindows(EnumWindowsPro c, (DWORD)this);
m_Message.Format("Started: %s\r\nprocess id: %i; window handle: %X",
CommandLine, m_ProcessInformation.dwPro cessId, m_hProcessWnd);
return TRUE;
case 0xFFFFFFFF:
m_Message = ShowError("WaitForInputIdl e");
break;
default: // WAIT_TIMEOUT
m_Message = "WaitForInputIdle timed out";
break;
}
return TRUE;
}
BOOL CALLBACK CProcessDlg::EnumWindowsPr oc(HWND hWnd, LPARAM lParam)
{
CProcessDlg *ppProcessDlg=(CProcessDlg *)lParam;
DWORD dwProcessId;
CString Message;
if (!hWnd) return TRUE;
GetWindowThreadProcessId(h Wnd, &dwProcessId);
if (pProcessDlg->m_ProcessInf ormation.d wProcessId != dwProcessId)
return TRUE;
if (!::IsWindowVisible(hWnd))
return TRUE;
pProcessDlg->m_hProcessWnd = hWnd;
return TRUE;
}
CString CProcessDlg::ShowError(LPC TSTR pFunction)
{
CString Message;
LPTSTR pMsgBuf;
FormatMessage(FORMAT_MESSA GE_ALLOCAT E_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM ,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&pMsgBuf, 0, NULL);
if (*pFunction)
Message.Format("%s from: %s", pMsgBuf, pFunction);
else
Message = pMsgBuf;
LocalFree(pMsgBuf);
return Message;
}
Roshmon originally supplied me the following in answer to a question.
BOOL CProcessDlg::DoCreateProce
{
STARTUPINFO StartupInfo;
CString CommandLine;
BOOL rc;
// I am putting the (exe) filename in quotes in case there are blanks etc. in it
CommandLine = CString('"') + m_Filename + CString("\" ") + m_Parameters;
memset(&StartupInfo, 0, sizeof(StartupInfo));
StartupInfo.cb = sizeof(StartupInfo);
rc = CreateProcess(NULL, (LPTSTR)(LPCTSTR)CommandLi
NULL, NULL, &StartupInfo, &m_ProcessInformation);
if (!rc)
{
m_Message = ShowError("CreateProcess")
return FALSE;
}
switch (WaitForInputIdle(m_Proces
{
case 0:
// The process has been created and has finished intializing
// so now we look for it
m_hProcessWnd = NULL;
EnumWindows(EnumWindowsPro
m_Message.Format("Started:
CommandLine, m_ProcessInformation.dwPro
return TRUE;
case 0xFFFFFFFF:
m_Message = ShowError("WaitForInputIdl
break;
default: // WAIT_TIMEOUT
m_Message = "WaitForInputIdle timed out";
break;
}
return TRUE;
}
BOOL CALLBACK CProcessDlg::EnumWindowsPr
{
CProcessDlg *ppProcessDlg=(CProcessDlg
DWORD dwProcessId;
CString Message;
if (!hWnd) return TRUE;
GetWindowThreadProcessId(h
if (pProcessDlg->m_ProcessInf
return TRUE;
if (!::IsWindowVisible(hWnd))
return TRUE;
pProcessDlg->m_hProcessWnd
return TRUE;
}
CString CProcessDlg::ShowError(LPC
{
CString Message;
LPTSTR pMsgBuf;
FormatMessage(FORMAT_MESSA
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&pMsgBuf, 0, NULL);
if (*pFunction)
Message.Format("%s from: %s", pMsgBuf, pFunction);
else
Message = pMsgBuf;
LocalFree(pMsgBuf);
return Message;
}
ASKER
Thanks!
I need also help in what exactly automation exists because I have'nt done that for IE.
An also a confirmation that there is no easyer method.
I need also help in what exactly automation exists because I have'nt done that for IE.
An also a confirmation that there is no easyer method.
I need also help in what exactly automation exists because I have'nt done that for IE.
Me neither.
Me neither.
Boris, as far as I can see CHtmlCtrl let you do what you want.
Try to find text below in MSDN October 2001
"I noticed that MFC 6.0 has a new CHtmlView that lets you view Web pages within a view. I would like to use CHtmlView in a dialog, but when I do, it crashes. Is there a corresponding CHtmlCtrl class like there is for CListView and CListCtrl"
I could not find this article at MSDN.microsoft.com.
Add
onload="window.location.hr ef='http://google.com'"
or whatever to about.htm and result seems to be your goal.
Let me know if you don't have this old MSDN.
Try to find text below in MSDN October 2001
"I noticed that MFC 6.0 has a new CHtmlView that lets you view Web pages within a view. I would like to use CHtmlView in a dialog, but when I do, it crashes. Is there a corresponding CHtmlCtrl class like there is for CListView and CListCtrl"
I could not find this article at MSDN.microsoft.com.
Add
onload="window.location.hr
or whatever to about.htm and result seems to be your goal.
Let me know if you don't have this old MSDN.
ASKER
No, this is not what I am looking for. See the follow up question please for more details.
https://www.experts-exchange.com/questions/20837036/250-point-more-for-old-question.html
https://www.experts-exchange.com/questions/20837036/250-point-more-for-old-question.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
//call:
class CAboutDialog : public CDialog {
DECLARE_DYNAMIC(CAboutDial og)
protected:
CMyHtmlCtrl m_page;
virtual BOOL OnInitDialog();
public:
CAboutDialog() : CDialog(IDD_ABOUTBOX, NULL) { }
};
IMPLEMENT_DYNAMIC(CAboutDi alog, CDialog)
BOOL CAboutDialog::OnInitDialog ()
{
VERIFY(CDialog::OnInitDial og());
VERIFY(m_page.CreateFromSt atic(IDC_H TMLVIEW, this));
m_page.LoadFromResource(_T ("about.ht m"));
return TRUE;
}
void CMyApp::OnAppAbout()
{
static CAboutDialog dlg; // static to remember state of hyperlinks
dlg.DoModal(); // run it
}
// class
#include "StdAfx.h"
#include "HtmlCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNAMIC(CHtmlCtr l, CHtmlView)
BEGIN_MESSAGE_MAP(CHtmlCtr l, CHtmlView)
ON_WM_DESTROY()
ON_WM_MOUSEACTIVATE()
END_MESSAGE_MAP()
//////////////////
// Create control in same position as an existing static control with
// the same ID (could be any kind of control, really)
//
BOOL CHtmlCtrl::CreateFromStati c(UINT nID, CWnd* pParent)
{
CStatic wndStatic;
if (!wndStatic.SubclassDlgIte m(nID, pParent))
return FALSE;
// Get static control rect, convert to parent's client coords.
CRect rc;
wndStatic.GetWindowRect(&r c);
pParent->ScreenToClient(&r c);
wndStatic.DestroyWindow();
// create HTML control (CHtmlView)
return Create(NULL, // class name
NULL, // title
(WS_CHILD | WS_VISIBLE ), // style
rc, // rectangle
pParent, // parent
nID, // control ID
NULL); // frame/doc context not used
}
////////////////
// Override to avoid CView stuff that assumes a frame.
//
void CHtmlCtrl::OnDestroy()
{
// This is probably unecessary since ~CHtmlView does it, but
// safer to mimic CHtmlView::OnDestroy.
if (m_pBrowserApp) {
m_pBrowserApp->Release();
m_pBrowserApp = NULL;
}
CWnd::OnDestroy(); // bypass CView doc/frame stuff
}
////////////////
// Override to avoid CView stuff that assumes a frame.
//
int CHtmlCtrl::OnMouseActivate (CWnd* pDesktopWnd, UINT nHitTest, UINT msg)
{
// bypass CView doc/frame stuff
return CWnd::OnMouseActivate(pDes ktopWnd, nHitTest, msg);
}
//////////////////
// Override navigation handler to pass to "app:" links to virtual handler.
// Cancels the navigation in the browser, since app: is a pseudo-protocol.
//
void CHtmlCtrl::OnBeforeNavigat e2( LPCTSTR lpszURL,
DWORD nFlags,
LPCTSTR lpszTargetFrameName,
CByteArray& baPostedData,
LPCTSTR lpszHeaders,
BOOL* pbCancel )
{
const char APP_PROTOCOL[] = "app:";
int len = _tcslen(APP_PROTOCOL);
if (_tcsnicmp(lpszURL, APP_PROTOCOL, len)==0) {
OnAppCmd(lpszURL + len);
*pbCancel = TRUE;
}
}
//////////////////
// Called when the browser attempts to navigate to "app:foo"
// with "foo" as lpszWhere. Override to handle app commands.
//
void CHtmlCtrl::OnAppCmd(LPCTST R lpszWhere)
{
// default: do nothing
}
// don't forget to make resource
ABOUT.HTM HTML DISCARDABLE "res\\about.htm"
//and put onload navigation there
class CAboutDialog : public CDialog {
DECLARE_DYNAMIC(CAboutDial
protected:
CMyHtmlCtrl m_page;
virtual BOOL OnInitDialog();
public:
CAboutDialog() : CDialog(IDD_ABOUTBOX, NULL) { }
};
IMPLEMENT_DYNAMIC(CAboutDi
BOOL CAboutDialog::OnInitDialog
{
VERIFY(CDialog::OnInitDial
VERIFY(m_page.CreateFromSt
m_page.LoadFromResource(_T
return TRUE;
}
void CMyApp::OnAppAbout()
{
static CAboutDialog dlg; // static to remember state of hyperlinks
dlg.DoModal(); // run it
}
// class
#include "StdAfx.h"
#include "HtmlCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNAMIC(CHtmlCtr
BEGIN_MESSAGE_MAP(CHtmlCtr
ON_WM_DESTROY()
ON_WM_MOUSEACTIVATE()
END_MESSAGE_MAP()
//////////////////
// Create control in same position as an existing static control with
// the same ID (could be any kind of control, really)
//
BOOL CHtmlCtrl::CreateFromStati
{
CStatic wndStatic;
if (!wndStatic.SubclassDlgIte
return FALSE;
// Get static control rect, convert to parent's client coords.
CRect rc;
wndStatic.GetWindowRect(&r
pParent->ScreenToClient(&r
wndStatic.DestroyWindow();
// create HTML control (CHtmlView)
return Create(NULL, // class name
NULL, // title
(WS_CHILD | WS_VISIBLE ), // style
rc, // rectangle
pParent, // parent
nID, // control ID
NULL); // frame/doc context not used
}
////////////////
// Override to avoid CView stuff that assumes a frame.
//
void CHtmlCtrl::OnDestroy()
{
// This is probably unecessary since ~CHtmlView does it, but
// safer to mimic CHtmlView::OnDestroy.
if (m_pBrowserApp) {
m_pBrowserApp->Release();
m_pBrowserApp = NULL;
}
CWnd::OnDestroy(); // bypass CView doc/frame stuff
}
////////////////
// Override to avoid CView stuff that assumes a frame.
//
int CHtmlCtrl::OnMouseActivate
{
// bypass CView doc/frame stuff
return CWnd::OnMouseActivate(pDes
}
//////////////////
// Override navigation handler to pass to "app:" links to virtual handler.
// Cancels the navigation in the browser, since app: is a pseudo-protocol.
//
void CHtmlCtrl::OnBeforeNavigat
DWORD nFlags,
LPCTSTR lpszTargetFrameName,
CByteArray& baPostedData,
LPCTSTR lpszHeaders,
BOOL* pbCancel )
{
const char APP_PROTOCOL[] = "app:";
int len = _tcslen(APP_PROTOCOL);
if (_tcsnicmp(lpszURL, APP_PROTOCOL, len)==0) {
OnAppCmd(lpszURL + len);
*pbCancel = TRUE;
}
}
//////////////////
// Called when the browser attempts to navigate to "app:foo"
// with "foo" as lpszWhere. Override to handle app commands.
//
void CHtmlCtrl::OnAppCmd(LPCTST
{
// default: do nothing
}
// don't forget to make resource
ABOUT.HTM HTML DISCARDABLE "res\\about.htm"
//and put onload navigation there
ASKER
Actually I found better workaround.
Opening first page and then another one and closing the original without security prompt!
test1.html
<HTML>
<script language="JavaScript" type="text/JavaScript">
<!--
function jump()
{
var sscWindow
sscWindow= window.open('test2.html', 'test2', 'scrollbars=yes,width=772, height=536 ');
if (window.focus)
{
sscWindow.focus()
}
return false;
}
//-->
</script>
<BODY>
<a href="#" onclick="jump();">Open test2</a>
</BODY>
</HTML>
test2.hml
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
<!--
opener.opener = opener;
opener.close();
//-->
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
sdvsbsdf
</body>
</html>
Opening first page and then another one and closing the original without security prompt!
test1.html
<HTML>
<script language="JavaScript" type="text/JavaScript">
<!--
function jump()
{
var sscWindow
sscWindow= window.open('test2.html', 'test2', 'scrollbars=yes,width=772,
if (window.focus)
{
sscWindow.focus()
}
return false;
}
//-->
</script>
<BODY>
<a href="#" onclick="jump();">Open test2</a>
</BODY>
</HTML>
test2.hml
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
<!--
opener.opener = opener;
opener.close();
//-->
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
sdvsbsdf
</body>
</html>