📄 serverdlg.cpp
字号:
strThreadID.Format("%u", dwThreadID);
int nIndex = m_TraceList.InsertItem(m_TraceList.GetItemCount(), strThreadID);
m_TraceList.SetItemText(nIndex, 1, str);
}
catch(CMemoryException *e)
{
e->Delete();
}
catch(...)
{
// catch formating errors ...
}
}
/********************************************************************/
/* */
/* Function name : OnInitMenu */
/* Description : Update 'Start' & 'Stop' status */
/* */
/********************************************************************/
void CServerDlg::OnInitMenu(CMenu* pMenu)
{
CDialog::OnInitMenu(pMenu);
if (m_bRunning)
{
pMenu->EnableMenuItem(ID_SERVER_START, MF_GRAYED);
pMenu->EnableMenuItem(ID_SERVER_STOP, MF_ENABLED);
}
else
{
pMenu->EnableMenuItem(ID_SERVER_START, MF_ENABLED);
pMenu->EnableMenuItem(ID_SERVER_STOP, MF_GRAYED);
}
}
/********************************************************************/
/* */
/* Function name : OnClose */
/* Description : Close server */
/* */
/********************************************************************/
void CServerDlg::OnClose()
{
OnServerStop();
AfxGetApp()->WriteProfileString("Settings", "WebPages", m_strWebPages);
AfxGetApp()->WriteProfileString("Settings", "DefaultPage", m_strDefaultPage);
AfxGetApp()->WriteProfileInt("Settings", "AutoStart", m_bAutoStart);
AfxGetApp()->WriteProfileInt("Settings", "Port", m_nPort);
CDialog::OnCancel();
// CDialog::OnClose();
}
/********************************************************************/
/* */
/* Function name : OnAbout */
/* Description : Show aboutbox */
/* */
/********************************************************************/
void CServerDlg::OnAbout()
{
CAboutDlg dlg;
dlg.DoModal();
}
/********************************************************************/
/* */
/* Function name : OnStart */
/* Description : Start Web server */
/* */
/********************************************************************/
void CServerDlg::OnStart()
{
OnServerStart();
}
/********************************************************************/
/* */
/* Function name : OnStop */
/* Description : Stop Web server */
/* */
/********************************************************************/
void CServerDlg::OnStop()
{
OnServerStop();
}
/********************************************************************/
/* */
/* Function name : CreateBars */
/* Description : This function creates a toolbar and statusbar. */
/* */
/********************************************************************/
BOOL CServerDlg::CreateBars()
{
// create the toolbar
if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
{
TRACE0("Failed to create toolbar\n");
return FALSE;
}
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CCS_NODIVIDER | CBRS_TOOLTIPS | CBRS_FLYBY);
// make it flat.
m_wndToolBar.ModifyStyle(0, m_wndToolBar.GetStyle()|TBSTYLE_FLAT);
// create status bar at the bottom of the window
if (m_wndStatusBar.Create(this))
{
m_wndStatusBar.SetIndicators(auIDStatusBar, sizeof(auIDStatusBar)/sizeof(UINT));
m_wndStatusBar.SetPaneText(1, "", TRUE);
m_wndStatusBar.SetPaneInfo(0, m_wndStatusBar.GetItemID(0), SBPS_STRETCH, NULL );
}
// Set up hot bar image lists.
CImageList imageList;
CBitmap bitmap;
// Create and set the normal toolbar image list.
bitmap.LoadBitmap(IDB_TOOLBAR_COLD);
imageList.Create(24, 20, ILC_COLORDDB|ILC_MASK, 4, 1);
imageList.Add(&bitmap, RGB(255,0,255));
m_wndToolBar.SendMessage(TB_SETIMAGELIST, 0, (LPARAM)imageList.m_hImageList);
imageList.Detach();
bitmap.Detach();
// Create and set the normal toolbar image list.
bitmap.LoadBitmap(IDB_TOOLBAR_HOT);
imageList.Create(24, 20, ILC_COLORDDB|ILC_MASK, 4, 1);
imageList.Add(&bitmap, RGB(255,0,255));
m_wndToolBar.SendMessage(TB_SETHOTIMAGELIST, 0, (LPARAM)imageList.m_hImageList);
imageList.Detach();
bitmap.Detach();
// Set the text for each button
CToolBarCtrl& bar = m_wndToolBar.GetToolBarCtrl();
int nIndex = 0;
TBBUTTON tb;
for (nIndex = m_wndToolBar.GetToolBarCtrl().GetButtonCount() - 1; nIndex >= 0; nIndex--)
{
ZeroMemory(&tb, sizeof(TBBUTTON));
m_wndToolBar.GetToolBarCtrl().GetButton(nIndex, &tb);
// Do we have a separator?
if ((tb.fsStyle & TBSTYLE_SEP) == TBSTYLE_SEP)
continue;
// Have we got a valid command id?
if (tb.idCommand == 0)
continue;
// Get the resource string if there is one.
CString strText;
LPCTSTR lpszButtonText = NULL;
CString strButtonText("");
_TCHAR seps[] = "\n";
strText.LoadString(tb.idCommand);
if (!strText.IsEmpty())
{
lpszButtonText = _tcstok((LPTSTR)(LPCTSTR)strText, seps);
while(lpszButtonText)
{
strButtonText = lpszButtonText;
lpszButtonText = _tcstok(NULL, seps);
}
}
if (!strButtonText.IsEmpty())
m_wndToolBar.SetButtonText(nIndex, strButtonText);
}
// Resize the buttons so that the text will fit.
CRect rc(0, 0, 0, 0);
CSize sizeMax(0, 0);
for (nIndex = m_wndToolBar.GetToolBarCtrl().GetButtonCount() - 1; nIndex >= 0; nIndex--)
{
m_wndToolBar.GetToolBarCtrl().GetItemRect(nIndex, rc);
rc.NormalizeRect();
sizeMax.cx = __max(rc.Size().cx, sizeMax.cx);
sizeMax.cy = __max(rc.Size().cy, sizeMax.cy);
}
m_wndToolBar.SetSizes(sizeMax, CSize(20,20));
// resize the dialog to make room for control bars
CRect rcClientStart;
CRect rcClientNow;
GetClientRect(rcClientStart);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,
0, reposQuery, rcClientNow);
// move all the controls so they are in the same relative position within the remaining client area
// as they would be with no control bars.
CPoint ptOffset(rcClientNow.left - rcClientStart.left,
rcClientNow.top - rcClientStart.top);
CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD);
while (pwndChild)
{
pwndChild->GetWindowRect(rcChild);
ScreenToClient(rcChild);
rcChild.OffsetRect(ptOffset);
pwndChild->MoveWindow(rcChild, FALSE);
pwndChild = pwndChild->GetNextWindow();
}
// adjust the dialog window dimensions
CRect rcWindow;
GetWindowRect(rcWindow);
rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
MoveWindow(rcWindow, FALSE);
// position the control bars
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
return TRUE;
}
/********************************************************************/
/* */
/* Function name : CreateBars */
/* Description : This function creates a toolbar and statusbar. */
/* */
/********************************************************************/
void CServerDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if (!m_bInitialized)
return;
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
CRect rc, rcTrace;
GetClientRect(&rc);
m_TraceList.GetWindowRect(&rcTrace);
ScreenToClient(&rcTrace);
int l = rcTrace.left, t = rcTrace.top, r = rc.right - rcTrace.right, b = rc.bottom - rcTrace.bottom;
rc.DeflateRect(l,t,l,25);
m_TraceList.MoveWindow(&rc);
}
/********************************************************************/
/* */
/* Function name : OnSettings */
/* Description : Show settings dialog. */
/* */
/********************************************************************/
void CServerDlg::OnSettings()
{
CSettingsDlg dlg;
dlg.m_strWebPages = m_strWebPages;
dlg.m_strDefaultPage = m_strDefaultPage;
dlg.m_bAutoStart = m_bAutoStart;
dlg.m_nPort = m_nPort;
if (dlg.DoModal() == IDOK)
{
m_strWebPages = dlg.m_strWebPages;
m_strDefaultPage = dlg.m_strDefaultPage;
m_bAutoStart = dlg.m_bAutoStart;
m_nPort = dlg.m_nPort;
}
}
/********************************************************************/
/* */
/* Function name : OnSysCommand */
/* Description : Handle system commands */
/* */
/********************************************************************/
void CServerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
switch(nID)
{
case SC_MINIMIZE:
// do not minimize to the taskbar
ShowWindow(SW_HIDE);
break;
default:
CDialog::OnSysCommand(nID, lParam);
break;
}
}
/********************************************************************/
/* */
/* Function name : OnOK */
/* Description : Prevent 'Enter' from closing application */
/* */
/********************************************************************/
void CServerDlg::OnOK()
{
// CDialog::OnOK();
}
/********************************************************************/
/* */
/* Function name : OnCancel */
/* Description : Prevent 'Escape' from closing application */
/* */
/********************************************************************/
void CServerDlg::OnCancel()
{
// CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -