| Index: chrome/client/clientDlg.cpp
|
| ===================================================================
|
| --- chrome/client/clientDlg.cpp (revision 0)
|
| +++ chrome/client/clientDlg.cpp (revision 0)
|
| @@ -0,0 +1,138 @@
|
| +// clientDlg.cpp : implementation file
|
| +//
|
| +
|
| +#include "stdafx.h"
|
| +#include "client.h"
|
| +#include "clientDlg.h"
|
| +#include <process.h>
|
| +
|
| +#ifdef _DEBUG
|
| +#define new DEBUG_NEW
|
| +#endif
|
| +
|
| +// CclientDlg dialog
|
| +
|
| +
|
| +
|
| +
|
| +CclientDlg::CclientDlg(CWnd* pParent /*=NULL*/)
|
| + : CDialog(CclientDlg::IDD, pParent)
|
| +{
|
| + m_hProc = 0;
|
| + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
| +}
|
| +
|
| +void CclientDlg::DoDataExchange(CDataExchange* pDX)
|
| +{
|
| + CDialog::DoDataExchange(pDX);
|
| +}
|
| +
|
| +BEGIN_MESSAGE_MAP(CclientDlg, CDialog)
|
| + ON_WM_PAINT()
|
| + ON_WM_QUERYDRAGICON()
|
| + ON_WM_DESTROY()
|
| + ON_COMMAND(IDC_BUTTON1, OnEmbedChrome)
|
| + //}}AFX_MSG_MAP
|
| +END_MESSAGE_MAP()
|
| +
|
| +
|
| +// CclientDlg message handlers
|
| +
|
| +BOOL CclientDlg::OnInitDialog()
|
| +{
|
| + CDialog::OnInitDialog();
|
| +
|
| + // Set the icon for this dialog. The framework does this automatically
|
| + // when the application's main window is not a dialog
|
| + SetIcon(m_hIcon, TRUE); // Set big icon
|
| + SetIcon(m_hIcon, FALSE); // Set small icon
|
| +
|
| + // Build command-line arguments
|
| + CRect rect;
|
| + CWnd *pWnd = GetDlgItem(IDC_STATIC);
|
| + pWnd->GetWindowRect(&rect);
|
| +
|
| + CString str;
|
| + str.Format(_T("--embedded --embedded-settings=%d,%d,%d,%d,%d,http://www.google.com"),
|
| + m_hWnd, rect.left, rect.top, rect.Width(), rect.Height());
|
| + GetDlgItem(IDC_EDIT1)->SetWindowText(str);
|
| +
|
| + return TRUE; // return TRUE unless you set the focus to a control
|
| +}
|
| +
|
| +// If you add a minimize button to your dialog, you will need the code below
|
| +// to draw the icon. For MFC applications using the document/view model,
|
| +// this is automatically done for you by the framework.
|
| +
|
| +void CclientDlg::OnPaint()
|
| +{
|
| + if (IsIconic())
|
| + {
|
| + CPaintDC dc(this); // device context for painting
|
| +
|
| + SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
|
| +
|
| + // Center icon in client rectangle
|
| + int cxIcon = GetSystemMetrics(SM_CXICON);
|
| + int cyIcon = GetSystemMetrics(SM_CYICON);
|
| + CRect rect;
|
| + GetClientRect(&rect);
|
| + int x = (rect.Width() - cxIcon + 1) / 2;
|
| + int y = (rect.Height() - cyIcon + 1) / 2;
|
| +
|
| + // Draw the icon
|
| + dc.DrawIcon(x, y, m_hIcon);
|
| + }
|
| + else
|
| + {
|
| + CDialog::OnPaint();
|
| + }
|
| +}
|
| +
|
| +// The system calls this function to obtain the cursor to display while the user drags
|
| +// the minimized window.
|
| +HCURSOR CclientDlg::OnQueryDragIcon()
|
| +{
|
| + return static_cast<HCURSOR>(m_hIcon);
|
| +}
|
| +
|
| +void CclientDlg::OnDestroy()
|
| +{
|
| + if(m_hProc > 0)
|
| + ::TerminateProcess((HANDLE)m_hProc, 0);
|
| +}
|
| +
|
| +void CclientDlg::OnEmbedChrome()
|
| +{
|
| + CWnd *pWnd = GetDlgItem(IDC_BUTTON1);
|
| + pWnd->ModifyStyle(0, WS_DISABLED);
|
| + pWnd->Invalidate(FALSE);
|
| + ((CEdit*)GetDlgItem(IDC_EDIT1))->SetReadOnly();
|
| +
|
| + CString str;
|
| + GetDlgItem(IDC_EDIT1)->GetWindowText(str);
|
| +
|
| + CStringArray paramArray;
|
| +
|
| + wchar_t* tok = wcstok((LPTSTR)(LPCTSTR)str, L" ");
|
| + while(tok)
|
| + {
|
| + paramArray.Add(tok);
|
| + tok = wcstok(NULL, L" ");
|
| + }
|
| +
|
| + int ct = (int)paramArray.GetCount();
|
| + wchar_t **argv = new wchar_t*[ct+2];
|
| + argv[0] = _T("chrome.exe");
|
| + for(int i = 0; i < ct; i++)
|
| + argv[i+1] = (LPTSTR)(LPCTSTR)paramArray.GetAt(i);
|
| + argv[ct+1] = NULL;
|
| +
|
| + intptr_t res = _wspawnvp(_P_NOWAIT, _T("..\\Debug\\chrome.exe"), argv);
|
| + if(res == -1)
|
| + AfxMessageBox(_T("Server spawn failed"));
|
| + else
|
| + m_hProc = (HANDLE)res;
|
| +
|
| + delete [] argv;
|
| +}
|
|
|