📄 filesharedlg.cpp
字号:
// FileShareDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FileShare.h"
#include "FileShareDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define PAGE_CLIENT 0
#define PAGE_SERVER 1
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
CStatusBarCtrl g_StatusBar;
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileShareDlg dialog
CFileShareDlg::CFileShareDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFileShareDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFileShareDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFileShareDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileShareDlg)
DDX_Control(pDX, IDC_TAB, m_ctrlTab);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFileShareDlg, CDialog)
//{{AFX_MSG_MAP(CFileShareDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_SIZE()
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnSelchangeTab)
ON_COMMAND(IDM_EXIT, OnExit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileShareDlg message handlers
BOOL CFileShareDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
RECT rect;
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
// TODO: Add extra initialization here
g_StatusBar.Create(WS_CHILD|WS_VISIBLE|CCS_BOTTOM|SBARS_SIZEGRIP,
CRect(0,0,0,0), this, IDC_STATUS_BAR);
this->m_ctrlTab.InsertItem(PAGE_CLIENT,"Client");
this->m_ctrlTab.InsertItem(PAGE_SERVER,"Server");
this->m_pClient = new CClientDlg(this);
this->m_pServer = new CServerDlg(this);
this->m_pClient->Create(IDD_CLIENT,this);
this->m_pServer->Create(IDD_SERVER,this);
this->m_ctrlTab.SetCurSel(PAGE_CLIENT);
this->m_pServer->ShowWindow(SW_HIDE);
this->m_pClient->ShowWindow(SW_SHOW);
this->m_pClient->UpdateWindow();
this->GetClientRect(&rect);
int wid[4]={70,(rect.right-rect.left-70)/2+70,(rect.right-rect.left),-1};//{rect.right-300, rect.right-200, rect.right-100,-1};
g_StatusBar.SetParts(4,wid);
g_StatusBar.SetText("服务未启动",0,0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CFileShareDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CFileShareDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (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 to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFileShareDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFileShareDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
// HWND h = GetDlgItem(IDC_TAB)->GetSafeHwnd();
// ::SetWindowPos(h,NULL,0,0,cx,cy,SWP_SHOWWINDOW);
// this->m_ctrlTab.MoveWindow(0,0,cx,cy,TRUE);
RECT rect,rc1,rc2;
this->GetClientRect(&rect);
// this->m_ctrlTab.AdjustRect(FALSE,&rect);
// this->m_ctrlTab.MoveWindow(&rect,TRUE);
g_StatusBar.GetRect(0,&rc2);
this->m_ctrlTab.SetWindowPos(NULL,0,0,cx,cy-(rc2.bottom-rc2.top),SWP_SHOWWINDOW);
g_StatusBar.GetRect(0,&rc2);
g_StatusBar.SetWindowPos(NULL,rect.left,rect.bottom-(rc2.bottom-rc2.top),cx,rc2.bottom-rc2.top,SWP_SHOWWINDOW);
this->m_ctrlTab.GetItemRect(0,&rc1);
m_pClient->SetWindowPos(NULL,rect.left,rect.top+(rc1.bottom-rc1.top),rect.right-rect.left,(rect.bottom-rect.top)-(rc2.bottom-rc2.top)-14,0);//SWP_SHOWWINDOW);
m_pServer->SetWindowPos(NULL,rect.left,rect.top+(rc1.bottom-rc1.top),rect.right-rect.left,(rect.bottom-rect.top)-(rc2.bottom-rc2.top)-14,0);//SWP_SHOWWINDOW);
// this->GetClientRect(&rect);
int wid[4]={70,(rect.right-rect.left-70)/2+70,(rect.right-rect.left),-1};//{rect.right-300, rect.right-200, rect.right-100,-1};
g_StatusBar.SetParts(4,wid);
char s[3][256];
g_StatusBar.GetText(s[0],0,NULL);
g_StatusBar.GetText(s[1],1,NULL);
g_StatusBar.GetText(s[2],2,NULL);
g_StatusBar.SetText(s[0],0,0);
g_StatusBar.SetText(s[1],1,0);
g_StatusBar.SetText(s[2],2,0);
/*
int wid[4];
wid[0]=60;
wid[1]=((cy)-wid[0])/2;
wid[2]=wid[1];
wid[3]=-1;
g_StatusBar.SetParts(4,wid);
g_StatusBar.SetText("服务未启动",0,0);
*/
// this->m_ctrlTab.SetItemSize(CSize(cx,cy));
// this->m_ctrlTab.GetClientRect(&rect);
// this->m_pClient->ShowWindow(SW_SHOW);
// this->m_pClient->UpdateWindow();
}
void CFileShareDlg::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int nIndex;
nIndex=this->m_ctrlTab.GetCurSel();
switch(nIndex)
{
case PAGE_CLIENT:
this->m_pServer->ShowWindow(SW_HIDE);
this->m_pClient->ShowWindow(SW_SHOW);
this->m_pClient->UpdateWindow();
break;
case PAGE_SERVER:
this->m_pClient->ShowWindow(SW_HIDE);
this->m_pServer->ShowWindow(SW_SHOW);
this->m_pServer->UpdateWindow();
break;
default:
break;
}
*pResult = 0;
}
CFileShareDlg::~CFileShareDlg()
{
delete this->m_pClient;
delete this->m_pServer;
}
void CFileShareDlg::OnExit()
{
SendMessage(WM_CLOSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -