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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

James RodgersWeb Applications DeveloperCommented:"page.html","","toolbar=no,location=no,width=200,height=200")
James RodgersWeb Applications DeveloperCommented:
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
BAlexandrovAuthor Commented:
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.
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

James RodgersWeb Applications DeveloperCommented:
you are using C++, are you using MFC also?
BAlexandrovAuthor Commented:
James RodgersWeb Applications DeveloperCommented:
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)

James RodgersWeb Applications DeveloperCommented:
try changing the SW_NORMAL to SW_fullscreen or SW_CHANELMODE, not sure if that will work
BAlexandrovAuthor Commented:
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.
James RodgersWeb Applications DeveloperCommented:
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
AndyAinscowFreelance programmer / ConsultantCommented:
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.
BAlexandrovAuthor Commented:
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.
AndyAinscowFreelance programmer / ConsultantCommented:
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::DoCreateProcess()
     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)CommandLine, NULL, NULL, FALSE, 0,
                              NULL, NULL, &StartupInfo, &m_ProcessInformation);
     if (!rc)
          m_Message = ShowError("CreateProcess");
          return FALSE;
     switch (WaitForInputIdle(m_ProcessInformation.hProcess, 10000))
     case 0:
          // The process has been created and has finished intializing
          // so now we look for it
          m_hProcessWnd = NULL;
          EnumWindows(EnumWindowsProc, (DWORD)this);
          m_Message.Format("Started: %s\r\nprocess id: %i; window handle: %X",
          CommandLine, m_ProcessInformation.dwProcessId, m_hProcessWnd);
          return TRUE;
     case 0xFFFFFFFF:
          m_Message = ShowError("WaitForInputIdle");
     default: // WAIT_TIMEOUT
          m_Message = "WaitForInputIdle timed out";

     return TRUE;

BOOL CALLBACK CProcessDlg::EnumWindowsProc(HWND hWnd, LPARAM lParam)
     CProcessDlg *ppProcessDlg=(CProcessDlg *)lParam;
     DWORD dwProcessId;
     CString Message;
     if (!hWnd) return TRUE;

     GetWindowThreadProcessId(hWnd, &dwProcessId);
     if (pProcessDlg->m_ProcessInformation.dwProcessId != dwProcessId)
          return TRUE;
     if (!::IsWindowVisible(hWnd))
          return TRUE;
     pProcessDlg->m_hProcessWnd = hWnd;

     return TRUE;

CString CProcessDlg::ShowError(LPCTSTR pFunction)
     CString Message;
     LPTSTR pMsgBuf;
                         NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                         (LPTSTR)&pMsgBuf, 0, NULL);

     if (*pFunction)
          Message.Format("%s from: %s", pMsgBuf, pFunction);
          Message = pMsgBuf;


     return Message;

BAlexandrovAuthor Commented:

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.
AndyAinscowFreelance programmer / ConsultantCommented:
I need also help in what exactly automation exists because I have'nt done that for IE.

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

or whatever to about.htm and result seems to be your goal.

Let me know if you don't have this old MSDN.
BAlexandrovAuthor Commented:
No, this is not what I am looking for. See the follow up question please for more details.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

class CAboutDialog : public CDialog {
      CMyHtmlCtrl m_page;
      virtual BOOL OnInitDialog();
      CAboutDialog() : CDialog(IDD_ABOUTBOX, NULL) { }


BOOL CAboutDialog::OnInitDialog()
      VERIFY(m_page.CreateFromStatic(IDC_HTMLVIEW, this));
      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__;


// Create control in same position as an existing static control with
// the same ID (could be any kind of control, really)
BOOL CHtmlCtrl::CreateFromStatic(UINT nID, CWnd* pParent)
      CStatic wndStatic;
      if (!wndStatic.SubclassDlgItem(nID, pParent))
            return FALSE;

      // Get static control rect, convert to parent's client coords.
      CRect rc;

      // 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 = 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(pDesktopWnd, 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::OnBeforeNavigate2( 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(LPCTSTR lpszWhere)
      // default: do nothing

// don't forget to make resource

ABOUT.HTM               HTML    DISCARDABLE     "res\\about.htm"

//and put onload navigation there
BAlexandrovAuthor Commented:
Actually I found better workaround.

Opening first page and then another one and closing the original without security prompt!

<script language="JavaScript" type="text/JavaScript">
function jump()
    var sscWindow
    sscWindow='test2.html', 'test2', 'scrollbars=yes,width=772,height=536');
    if (window.focus)
    return false;

<a href="#" onclick="jump();">Open test2</a>



<script language="JavaScript" type="text/JavaScript">
    opener.opener = opener;

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.