// ffDlg.cpp : implementation file //我仿照的代码#include "stdafx.h" #include "ff.h" #include "ffDlg.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 AboutCStatusBarCtrl 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()///////////////////////////////////////////////////////////////////////////// // CFfDlg dialog CFfDlg::~CFfDlg() { delete this->m_pClient; delete this->m_pServer; } CFfDlg::CFfDlg(CWnd* pParent /*=NULL*/) : CDialog(CFfDlg::IDD, pParent) { //{{AFX_DATA_INIT(CFfDlg) // 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 CFfDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CFfDlg) DDX_Control(pDX, IDC_TAB, m_ctlTab); //}}AFX_DATA_MAP }BEGIN_MESSAGE_MAP(CFfDlg, CDialog) //{{AFX_MSG_MAP(CFfDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_SIZE() ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnSelchangeTab) //}}AFX_MSG_MAP END_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////// // CFfDlg message handlersBOOL CFfDlg::OnInitDialog() { //该void CFfDlg::OnSize(UINT nType, int cx, int cy) 在CFfDlg::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_ctlTab.InsertItem(PAGE_CLIENT,"Client"); this->m_ctlTab.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_ctlTab.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.right - 70)/2+70,(rect.right - rect.left),-1}; g_StatusBar.SetParts(4,wid); g_StatusBar.SetText("服务未启动",0,0); return TRUE; // return TRUE unless you set the focus to a control }void CFfDlg::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 CFfDlg::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 CFfDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; }void CFfDlg::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here int nIndex; nIndex = this->m_ctlTab.GetCurSel(); switch(nIndex) { case PAGE_CLIENT: this->m_pServer->ShowWindow(SW_HIDE); this->m_pClient->ShowWindow(SW_SHOW); this->m_pClient->UpdateData(); break; case PAGE_SERVER: this->m_pClient->ShowWindow(SW_HIDE); this->m_pServer->ShowWindow(SW_SHOW); this->m_pServer->UpdateData(); break; default: break; } *pResult = 0; }void CFfDlg::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy);
WM_INITDIALOG并不是像WM_CREATE一样的窗口回调消息是创建Dialog之后SendMessage的。你要么在OnInitDialog中再发一次WM_SIZE
onsize() 里处理可以这样;
if(某窗口/控件句柄!=0){处理;}ps:1分 , 你也太...........~~~~~~~~~~~~~
但按的之前运行,
//我仿照的代码#include "stdafx.h"
#include "ff.h"
#include "ffDlg.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 AboutCStatusBarCtrl 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()/////////////////////////////////////////////////////////////////////////////
// CFfDlg dialog
CFfDlg::~CFfDlg()
{
delete this->m_pClient;
delete this->m_pServer;
}
CFfDlg::CFfDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFfDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFfDlg)
// 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 CFfDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFfDlg)
DDX_Control(pDX, IDC_TAB, m_ctlTab);
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CFfDlg, CDialog)
//{{AFX_MSG_MAP(CFfDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_SIZE()
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnSelchangeTab)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CFfDlg message handlersBOOL CFfDlg::OnInitDialog()
{
//该void CFfDlg::OnSize(UINT nType, int cx, int cy) 在CFfDlg::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_ctlTab.InsertItem(PAGE_CLIENT,"Client");
this->m_ctlTab.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_ctlTab.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.right - 70)/2+70,(rect.right - rect.left),-1};
g_StatusBar.SetParts(4,wid);
g_StatusBar.SetText("服务未启动",0,0);
return TRUE; // return TRUE unless you set the focus to a control
}void CFfDlg::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 CFfDlg::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 CFfDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}void CFfDlg::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int nIndex;
nIndex = this->m_ctlTab.GetCurSel();
switch(nIndex)
{
case PAGE_CLIENT:
this->m_pServer->ShowWindow(SW_HIDE);
this->m_pClient->ShowWindow(SW_SHOW);
this->m_pClient->UpdateData();
break;
case PAGE_SERVER:
this->m_pClient->ShowWindow(SW_HIDE);
this->m_pServer->ShowWindow(SW_SHOW);
this->m_pServer->UpdateData();
break;
default:
break;
}
*pResult = 0;
}void CFfDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
RECT rect,rc1,rc2;
this->GetClientRect(&rect);
//以下代码注释,否则不能运行
//该OnSize 在BOOL CFfDlg::OnInitDialog() 之前运行 //g_StatusBar.GetRect(0,&rc2);
/*this->m_ctlTab.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_ctlTab.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);
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); int wid[4] = {70,(rect.right- rect.left -70)/2 + 70,(rect.right - rect.left),-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.GetText(s[0],0,0);
g_StatusBar.GetText(s[1],1,0);
g_StatusBar.GetText(s[2],2,0);*/
}