Link to home
Start Free TrialLog in
Avatar of BAlexandrov
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.
Avatar of James Rodgers
James Rodgers
Flag of Canada image

window.open("page.html","","toolbar=no,location=no,width=200,height=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
Avatar of BAlexandrov
BAlexandrov

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.
you are using C++, are you using MFC also?
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)

try changing the SW_NORMAL to SW_fullscreen or SW_CHANELMODE, not sure if that will work
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.
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.
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.
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");
          break;
     default: // WAIT_TIMEOUT
          m_Message = "WaitForInputIdle timed out";
          break;
     }

     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;
     FormatMessage(FORMAT_MESSAGE_ALLOCATE_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;
}

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.

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.href='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.
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
ASKER CERTIFIED SOLUTION
Avatar of Nass89
Nass89
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
//call:

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

IMPLEMENT_DYNAMIC(CAboutDialog, CDialog)

BOOL CAboutDialog::OnInitDialog()
{
      VERIFY(CDialog::OnInitDialog());
      VERIFY(m_page.CreateFromStatic(IDC_HTMLVIEW, this));
      m_page.LoadFromResource(_T("about.htm"));
      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(CHtmlCtrl, CHtmlView)
BEGIN_MESSAGE_MAP(CHtmlCtrl, 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::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;
      wndStatic.GetWindowRect(&rc);
      pParent->ScreenToClient(&rc);
      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(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
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>