ICE 3.4.2
[php5-ice-freebsdport.git] / cpp / demo / Ice / MFC / server / HelloServerDlg.cpp
blob58acc9b04bd83e68dcdcccd7427a67150be093a6
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
8 // **********************************************************************
10 #include "stdafx.h"
11 #include "HelloServer.h"
12 #include "HelloServerDlg.h"
14 #ifdef _DEBUG
15 #define new DEBUG_NEW
16 #endif
19 CHelloServerDlg::CHelloServerDlg(const Ice::CommunicatorPtr& communicator, const LogIPtr& log,
20 CWnd* pParent /*=NULL*/) :
21 CDialog(CHelloServerDlg::IDD, pParent), _communicator(communicator), _log(log)
23 _hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
26 void
27 CHelloServerDlg::DoDataExchange(CDataExchange* pDX)
29 CDialog::DoDataExchange(pDX);
32 BEGIN_MESSAGE_MAP(CHelloServerDlg, CDialog)
33 ON_WM_PAINT()
34 ON_WM_QUERYDRAGICON()
35 //}}AFX_MSG_MAP
36 ON_BN_CLICKED(IDC_SHUTDOWN, OnShutdown)
37 ON_BN_CLICKED(IDC_CLEAR, OnClear)
38 ON_MESSAGE(WM_USER, OnLog)
39 END_MESSAGE_MAP()
41 BOOL
42 CHelloServerDlg::OnInitDialog()
44 CDialog::OnInitDialog();
46 // Set the icon for this dialog. The framework does this automatically
47 // when the application's main window is not a dialog
48 SetIcon(_hIcon, TRUE); // Set big icon
49 SetIcon(_hIcon, FALSE); // Set small icon
52 // Retrieve the edit control.
54 _edit = (CEdit*)GetDlgItem(IDC_LOG);
55 _log->setHandle(m_hWnd);
58 // Set the focus to the shutdown button, so that the text in the log
59 // is not initially highlighted.
61 ((CButton*)GetDlgItem(IDC_SHUTDOWN))->SetFocus();
63 return FALSE; // return FALSE because we explicitly set the focus
66 void
67 CHelloServerDlg::OnCancel()
69 _log->setHandle(0);
70 CDialog::OnCancel();
73 // If you add a minimize button to your dialog, you will need the code below
74 // to draw the icon. For MFC applications using the document/view model,
75 // this is automatically done for you by the framework.
77 void
78 CHelloServerDlg::OnPaint()
80 if (IsIconic())
82 CPaintDC dc(this); // device context for painting
84 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
86 // Center icon in client rectangle
87 int cxIcon = GetSystemMetrics(SM_CXICON);
88 int cyIcon = GetSystemMetrics(SM_CYICON);
89 CRect rect;
90 GetClientRect(&rect);
91 int x = (rect.Width() - cxIcon + 1) / 2;
92 int y = (rect.Height() - cyIcon + 1) / 2;
94 // Draw the icon
95 dc.DrawIcon(x, y, _hIcon);
97 else
99 CDialog::OnPaint();
103 // The system calls this function to obtain the cursor to display while the user drags
104 // the minimized window.
105 HCURSOR
106 CHelloServerDlg::OnQueryDragIcon()
108 return static_cast<HCURSOR>(_hIcon);
111 void
112 CHelloServerDlg::OnShutdown()
114 EndDialog(0);
117 void
118 CHelloServerDlg::OnClear()
120 _edit->SetWindowText(CString(""));
123 LRESULT
124 CHelloServerDlg::OnLog(WPARAM wParam, LPARAM lParam)
126 char* text = (char*)lParam;
128 _edit->SetSel(-1, -1);
129 _edit->ReplaceSel(CString(text));
131 delete[] text;
133 return 0;