OLD | NEW |
(Empty) | |
| 1 // clientDlg.cpp : implementation file |
| 2 // |
| 3 |
| 4 #include "stdafx.h" |
| 5 #include "client.h" |
| 6 #include "clientDlg.h" |
| 7 #include <process.h> |
| 8 |
| 9 #ifdef _DEBUG |
| 10 #define new DEBUG_NEW |
| 11 #endif |
| 12 |
| 13 // CclientDlg dialog |
| 14 |
| 15 |
| 16 |
| 17 |
| 18 CclientDlg::CclientDlg(CWnd* pParent /*=NULL*/) |
| 19 : CDialog(CclientDlg::IDD, pParent) |
| 20 { |
| 21 m_hProc = 0; |
| 22 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); |
| 23 } |
| 24 |
| 25 void CclientDlg::DoDataExchange(CDataExchange* pDX) |
| 26 { |
| 27 CDialog::DoDataExchange(pDX); |
| 28 } |
| 29 |
| 30 BEGIN_MESSAGE_MAP(CclientDlg, CDialog) |
| 31 ON_WM_PAINT() |
| 32 ON_WM_QUERYDRAGICON() |
| 33 ON_WM_DESTROY() |
| 34 ON_COMMAND(IDC_BUTTON1, OnEmbedChrome) |
| 35 //}}AFX_MSG_MAP |
| 36 END_MESSAGE_MAP() |
| 37 |
| 38 |
| 39 // CclientDlg message handlers |
| 40 |
| 41 BOOL CclientDlg::OnInitDialog() |
| 42 { |
| 43 CDialog::OnInitDialog(); |
| 44 |
| 45 // Set the icon for this dialog. The framework does this automatically |
| 46 // when the application's main window is not a dialog |
| 47 SetIcon(m_hIcon, TRUE); // Set big icon |
| 48 SetIcon(m_hIcon, FALSE); // Set small icon |
| 49 |
| 50 // Build command-line arguments |
| 51 CRect rect; |
| 52 CWnd *pWnd = GetDlgItem(IDC_STATIC); |
| 53 pWnd->GetWindowRect(&rect); |
| 54 |
| 55 CString str; |
| 56 str.Format(_T("--embedded --embedded-settings=%d,%d,%d,%d,%d,http://www.
google.com"), |
| 57 m_hWnd, rect.left, rect.top, rect.Width(), rect.Height()); |
| 58 GetDlgItem(IDC_EDIT1)->SetWindowText(str); |
| 59 |
| 60 return TRUE; // return TRUE unless you set the focus to a control |
| 61 } |
| 62 |
| 63 // If you add a minimize button to your dialog, you will need the code below |
| 64 // to draw the icon. For MFC applications using the document/view model, |
| 65 // this is automatically done for you by the framework. |
| 66 |
| 67 void CclientDlg::OnPaint() |
| 68 { |
| 69 if (IsIconic()) |
| 70 { |
| 71 CPaintDC dc(this); // device context for painting |
| 72 |
| 73 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSa
feHdc()), 0); |
| 74 |
| 75 // Center icon in client rectangle |
| 76 int cxIcon = GetSystemMetrics(SM_CXICON); |
| 77 int cyIcon = GetSystemMetrics(SM_CYICON); |
| 78 CRect rect; |
| 79 GetClientRect(&rect); |
| 80 int x = (rect.Width() - cxIcon + 1) / 2; |
| 81 int y = (rect.Height() - cyIcon + 1) / 2; |
| 82 |
| 83 // Draw the icon |
| 84 dc.DrawIcon(x, y, m_hIcon); |
| 85 } |
| 86 else |
| 87 { |
| 88 CDialog::OnPaint(); |
| 89 } |
| 90 } |
| 91 |
| 92 // The system calls this function to obtain the cursor to display while the user
drags |
| 93 // the minimized window. |
| 94 HCURSOR CclientDlg::OnQueryDragIcon() |
| 95 { |
| 96 return static_cast<HCURSOR>(m_hIcon); |
| 97 } |
| 98 |
| 99 void CclientDlg::OnDestroy() |
| 100 { |
| 101 if(m_hProc > 0) |
| 102 ::TerminateProcess((HANDLE)m_hProc, 0); |
| 103 } |
| 104 |
| 105 void CclientDlg::OnEmbedChrome() |
| 106 { |
| 107 CWnd *pWnd = GetDlgItem(IDC_BUTTON1); |
| 108 pWnd->ModifyStyle(0, WS_DISABLED); |
| 109 pWnd->Invalidate(FALSE); |
| 110 ((CEdit*)GetDlgItem(IDC_EDIT1))->SetReadOnly(); |
| 111 |
| 112 CString str; |
| 113 GetDlgItem(IDC_EDIT1)->GetWindowText(str); |
| 114 |
| 115 CStringArray paramArray; |
| 116 |
| 117 wchar_t* tok = wcstok((LPTSTR)(LPCTSTR)str, L" "); |
| 118 while(tok) |
| 119 { |
| 120 paramArray.Add(tok); |
| 121 tok = wcstok(NULL, L" "); |
| 122 } |
| 123 |
| 124 int ct = (int)paramArray.GetCount(); |
| 125 wchar_t **argv = new wchar_t*[ct+2]; |
| 126 argv[0] = _T("chrome.exe"); |
| 127 for(int i = 0; i < ct; i++) |
| 128 argv[i+1] = (LPTSTR)(LPCTSTR)paramArray.GetAt(i); |
| 129 argv[ct+1] = NULL; |
| 130 |
| 131 intptr_t res = _wspawnvp(_P_NOWAIT, _T("..\\Debug\\chrome.exe"), argv); |
| 132 if(res == -1) |
| 133 AfxMessageBox(_T("Server spawn failed")); |
| 134 else |
| 135 m_hProc = (HANDLE)res; |
| 136 |
| 137 delete [] argv; |
| 138 } |
OLD | NEW |