Solved

Open new window with specified size and without menu and toolbar from an application

Posted on 2003-12-11
19
30,349 Views
Last Modified: 2013-11-20
  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.
0
Comment
Question by:BAlexandrov
  • 7
  • 6
  • 3
  • +2
19 Comments
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9919337
window.open("page.html","","toolbar=no,location=no,width=200,height=200")
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9919342
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
0
 
LVL 6

Author Comment

by:BAlexandrov
ID: 9919370
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.
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9919820
you are using C++, are you using MFC also?
0
 
LVL 6

Author Comment

by:BAlexandrov
ID: 9919941
Yes
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9919972
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)

0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9920009
try changing the SW_NORMAL to SW_fullscreen or SW_CHANELMODE, not sure if that will work
0
 
LVL 6

Author Comment

by:BAlexandrov
ID: 9920067
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.
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9920113
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
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9927839
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.
0
 
LVL 6

Author Comment

by:BAlexandrov
ID: 9928189
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.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9928311
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;
}

0
 
LVL 6

Author Comment

by:BAlexandrov
ID: 9928632
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.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9928732
I need also help in what exactly automation exists because I have'nt done that for IE.

Me neither.
0
 
LVL 15

Expert Comment

by:OMC2000
ID: 10017107
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.
0
 
LVL 6

Author Comment

by:BAlexandrov
ID: 10020926
No, this is not what I am looking for. See the follow up question please for more details.
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20837036.html
0
 
LVL 5

Accepted Solution

by:
Nass89 earned 500 total points
ID: 10032949
Thanks
0
 
LVL 15

Expert Comment

by:OMC2000
ID: 10041104
//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
0
 
LVL 6

Author Comment

by:BAlexandrov
ID: 10128057
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>
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 84
Include multiple hostnames in this command? 3 52
Separate into files by filename 12 67
post4 challenge 28 83
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now