顺序问题2 述上铁

tdtdtdtdtd123 2006-07-29 02:51:50
onsize() 在OnInitDialog() 前运行 如何修改为onsize() 在OnInitDialog() 后运行 呢?
...全文
229 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
thesuper 2006-07-29
  • 打赏
  • 举报
回复
这么多,晕哦
tdtdtdtdtd123 2006-07-29
  • 打赏
  • 举报
回复
安不明白,同样的代码,为何产生了不同的执行顺序?
思危 2006-07-29
  • 打赏
  • 举报
回复
什么意思啊?
tdtdtdtdtd123 2006-07-29
  • 打赏
  • 举报
回复
if (hDialogTemplate != NULL) //在mfc\src\dlgcore.cpp hDialogTemplate=0x0060ce28
lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate);
...
if (CreateDlgIndirect(lpDialogTemplate,CWnd::FromHandle(hWndParent), hInst))
//分开
BOOL CALLBACK AfxDlgProc(HWND hWnd, UINT message, WPARAM, LPARAM)
{
if (message == WM_INITDIALOG)
{
// special case for WM_INITDIALOG
CDialog* pDlg = DYNAMIC_DOWNCAST(CDialog, CWnd::FromHandlePermanent(hWnd));
if (pDlg != NULL)
return pDlg->OnInitDialog();//粒子
else
return 1;
}
return 0;
}
//偶的访写 在mfc中变成了
if (CreateDlgIndirect(lpDialogTemplate,CWnd::FromHandle(hWndParent), hInst))
//lpDialogTemplate = 0x00607da0
hWnd = ::CreateDialogIndirect(hInst, lpDialogTemplate,
pParentWnd->GetSafeHwnd(), AfxDlgProc);
咋会这样呢?
tdtdtdtdtd123 2006-07-29
  • 打赏
  • 举报
回复
其实,我是对作例子敲的,但例子这样是行的 ,而我的偏偏不行呢?
郁闷
折腾_苏州 2006-07-29
  • 打赏
  • 举报
回复
我看了你的代码,OnSize()里面 在g_StatusBar调用时候,判断一下句柄是否存在就行了:
if(!g_StatusBar.GetSafeHud())
{
g_StatusBar.....
}
tdtdtdtdtd123 2006-07-29
  • 打赏
  • 举报
回复
// 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);
}
jasonshark 2006-07-29
  • 打赏
  • 举报
回复
声明一个全局的bool为false, OnInitDialog里置为true,
OnSize里根据这个值进行处理
syy64 2006-07-29
  • 打赏
  • 举报
回复
其实你可以用变量来控制对OnSize里的程序的调用。

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧