主题:在CMainFrame的toolbar中的ComboBox窗口怎么没句柄
// ComboToolBar.cpp : implementation file
//
#include "stdafx.h"
#include "CToobarDemo.h"
#include "ComboToolBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CComboToolBar
CComboToolBar::CComboToolBar()
{
}
CComboToolBar::~CComboToolBar()
{
}
BOOL CComboToolBar::CreateCombo( DWORD dwStyle, CComboBox *pComboBox, UINT nID,
int nWidth, int nHeight )
{
// set the size of combo-control
CRect pRect(-nWidth, -nHeight, 0, 0);
pRect.right -= 2;
// make the button, that is selected to be the combo-control,
// a separator and resize that separator
ASSERT(CommandToIndex(nID) >= 0); // make sure the id is valid
SetButtonInfo( CommandToIndex( nID ), nID, TBBS_SEPARATOR, nWidth );
// create the combo-control itself, reposition it in the
// client-area and show it
if (!pComboBox->Create( dwStyle, pRect, this, nID ))
{
TRACE("Failed to create the combo-box %p .\n", nID);
return FALSE;
}
GetItemRect( CommandToIndex(nID), &pRect );
pRect.left += 2;
pRect.right = pRect.left + nWidth;
[color=C0C0C0]pComboBox->SetWindowPos(0, pRect.left, pRect.top, 0, 0,
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOCOPYBITS );[/color]// pComboBox->SetFont( &m_GuiFont );
pComboBox->ShowWindow( SW_SHOW );
return TRUE;
}
BEGIN_MESSAGE_MAP(CComboToolBar, CToolBar)
//{{AFX_MSG_MAP(CComboToolBar)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CComboToolBar message handlers
我声明了一个从CToolBar继承的类CComboToolBar(至于CreateCombo是我手工加上去的),同时在CMainFrame声明了CComboBox m_pcombo,便于在CMainFrame的OnCreate调用m_wndToolBar(已经改为CComboToolBar类型)中调用CreateCombo时利用该参数,我不接的是当执行到SetWindowPos时(为何其第一个句柄参数为0,难道m_pcombo窗口没创建句柄。不解....
请高手指点迷津,小弟在此谢过~
//
#include "stdafx.h"
#include "CToobarDemo.h"
#include "ComboToolBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CComboToolBar
CComboToolBar::CComboToolBar()
{
}
CComboToolBar::~CComboToolBar()
{
}
BOOL CComboToolBar::CreateCombo( DWORD dwStyle, CComboBox *pComboBox, UINT nID,
int nWidth, int nHeight )
{
// set the size of combo-control
CRect pRect(-nWidth, -nHeight, 0, 0);
pRect.right -= 2;
// make the button, that is selected to be the combo-control,
// a separator and resize that separator
ASSERT(CommandToIndex(nID) >= 0); // make sure the id is valid
SetButtonInfo( CommandToIndex( nID ), nID, TBBS_SEPARATOR, nWidth );
// create the combo-control itself, reposition it in the
// client-area and show it
if (!pComboBox->Create( dwStyle, pRect, this, nID ))
{
TRACE("Failed to create the combo-box %p .\n", nID);
return FALSE;
}
GetItemRect( CommandToIndex(nID), &pRect );
pRect.left += 2;
pRect.right = pRect.left + nWidth;
[color=C0C0C0]pComboBox->SetWindowPos(0, pRect.left, pRect.top, 0, 0,
SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOCOPYBITS );[/color]// pComboBox->SetFont( &m_GuiFont );
pComboBox->ShowWindow( SW_SHOW );
return TRUE;
}
BEGIN_MESSAGE_MAP(CComboToolBar, CToolBar)
//{{AFX_MSG_MAP(CComboToolBar)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CComboToolBar message handlers
我声明了一个从CToolBar继承的类CComboToolBar(至于CreateCombo是我手工加上去的),同时在CMainFrame声明了CComboBox m_pcombo,便于在CMainFrame的OnCreate调用m_wndToolBar(已经改为CComboToolBar类型)中调用CreateCombo时利用该参数,我不接的是当执行到SetWindowPos时(为何其第一个句柄参数为0,难道m_pcombo窗口没创建句柄。不解....
请高手指点迷津,小弟在此谢过~