Click here to Skip to main content
15,918,742 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to make an ATL Control redraw after a Property Change Pin
Paul Farry16-Nov-02 19:20
professionalPaul Farry16-Nov-02 19:20 
Questionhow many request per second ...? Pin
devvvy16-Nov-02 17:29
devvvy16-Nov-02 17:29 
AnswerRe: how many request per second ...? Pin
Christian Graus16-Nov-02 21:35
protectorChristian Graus16-Nov-02 21:35 
Generaldetecting SQL ALTER DATABASE Pin
devvvy16-Nov-02 17:24
devvvy16-Nov-02 17:24 
GeneralHELP - playback midi-notes (not files) Pin
trondb16-Nov-02 16:55
trondb16-Nov-02 16:55 
GeneralPredicting the rect of a dialog Pin
Wolfram Steinke16-Nov-02 16:41
Wolfram Steinke16-Nov-02 16:41 
GeneralRe: Predicting the rect of a dialog Pin
Gary R. Wheeler17-Nov-02 5:12
Gary R. Wheeler17-Nov-02 5:12 
GeneralPocket PC eVC and custom controls Pin
kati4216-Nov-02 16:24
kati4216-Nov-02 16:24 
I'm having difficulty with implementing a custom MFC control on an eVC Pocket PC dialog-type application. I create a custom control derived from CStatic following the methods of the CDoubleListPicker custom control example I found on this site, and when I run the program I can see the caption fine, but not the sub-controls that are created in my custon control.

Just to check on this problem, I took the CDoubleListPicker application and ported it to eVC, basically taking out things that aren't supported by the eVC environment, like the about box and resizing of the dialog. When I run this program, I have the same problem that none of the internal controls of CDoubleListPicker appear. I really made an effort to only take out the code that the compiler gave errors on, so I don't think I took out anything critical.

I will admit that I am only running this on the emulator, as my new device has not arrived yet, but I wanted to get a head start on programming...

Here's the class that I created, as well as what I think are the most critical functions.... Note that in the app I added a CStatic object to the dialog using the graphical dialog editor, and associated this control with the variable m_FileChooser of type CFileChooser (the custom control class).

Any help would be appreciated.

class CFileChooser : public CStatic
{
// Construction
public:
	CFileChooser();

// Attributes
public:
	#define ID_BASE_ID		((UINT)-1)
	enum { 
	  ID_DIR_DROP_BOX = (ID_BASE_ID - 1),	// current dir drop box control
	  ID_FILE_LIST_BOX = (ID_BASE_ID - 2),		// file list box control
	};

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CFileChooser)
	public:
	virtual BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
	protected:
	virtual void PreSubclassWindow();
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CFileChooser();

	// Generated message map functions
protected:
	void DoSizing();
	int CreateChildControls();
	CComboBox m_dirDropBox;
	CListBox m_fileListBox;
	//{{AFX_MSG(CFileChooser)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnSetFocus(CWnd* pOldWnd);
	afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
	afx_msg void OnEnable(BOOL bEnable);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

int CFileChooser::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CStatic::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (!CreateChildControls())
		return -1;

	return 0;
}

void CFileChooser::PreSubclassWindow() 
{
	CStatic::PreSubclassWindow();
	SetWindowText(_T("FileChooser"));

	// remove edges used to locate control in resource editor
	// remove or modify this line if you really want the control
	// to have client or static edges
	ModifyStyleEx(WS_EX_STATICEDGE, 0);

	CreateChildControls();

	DoSizing();
}

int CFileChooser::CreateChildControls()
{
	if (m_dirDropBox.GetSafeHwnd() != NULL)
		return TRUE;  // already created controls

	CWnd* pParent = GetParent();
	if (pParent == NULL)
		return FALSE;

	// create child controls
	CRect rc(0, 0, 0, 0);

	// create the drop down box that holds the path tree
	if (!m_dirDropBox.Create(DW_DROP_STYLE, rc, pParent, ID_DIR_DROP_BOX))
		return FALSE;

	// create the file list box
	if (!m_fileListBox.Create(LBS_MULTIPLESEL|DW_LIST_STYLE, rc, pParent, ID_FILE_LIST_BOX))
		return FALSE;

	// get information for setting visibility/enable
	BOOL bEnable = IsWindowEnabled();
	BOOL bShow = (GetStyle() & WS_VISIBLE);
	
	// configure the directory drop box
	m_dirDropBox.EnableWindow(bEnable);
	m_dirDropBox.ShowWindow(bShow ? SW_SHOW : SW_HIDE);

	// configure the file list box	
	m_fileListBox.EnableWindow(bEnable);
	m_fileListBox.ShowWindow(bShow ? SW_SHOW : SW_HIDE);

	return TRUE;
}

void CFileChooser::DoSizing()
{
	// put child controls in the correct places
	if (m_dirDropBox.GetSafeHwnd() == NULL)
		return; // controls not yet created

	if (GetParent() == NULL)
		return;

	// get the size and position of this control
	CRect rc;
	GetWindowRect(&rc);
	GetParent()->ScreenToClient(&rc);

	// size the directory drop box
	m_dirDropBox.ShowWindow(GetStyle() & WS_VISIBLE ? SW_SHOW : SW_HIDE);
	m_dirDropBox.MoveWindow(rc.left, rc.top, rc.Width(), DROP_BOX_SIZE);

	// adjust the rect object rc to no longer include the area with
	// the drop box and the gap between the drop box and the list box
	rc.top += BOX_CTRL_GAP + DROP_BOX_SIZE;

	// put lists one either side beside buttons
	m_fileListBox.MoveWindow(rc.left, rc.top, rc.Width(), rc.Height());

	// redraw self and the controls
	RedrawWindow();
	m_dirDropBox.RedrawWindow();
	m_fileListBox.RedrawWindow();
}


- Kati
GeneralDynamically resizing an edit control Pin
georgiek5016-Nov-02 15:59
georgiek5016-Nov-02 15:59 
GeneralRe: Dynamically resizing an edit control Pin
Christian Graus16-Nov-02 16:19
protectorChristian Graus16-Nov-02 16:19 
GeneralRe: Dynamically resizing an edit control Pin
georgiek5016-Nov-02 17:24
georgiek5016-Nov-02 17:24 
GeneralMFC Custom Control Pin
s o v a n n16-Nov-02 15:51
s o v a n n16-Nov-02 15:51 
GeneralRe: MFC Custom Control Pin
Anna :)18-Nov-02 2:14
Anna :)18-Nov-02 2:14 
GeneralUsing DLLs Pin
d.f16-Nov-02 15:22
d.f16-Nov-02 15:22 
GeneralRe: Using DLLs Pin
dabs17-Nov-02 3:18
dabs17-Nov-02 3:18 
GeneralCListCtrl List Style :: MFC Pin
valikac16-Nov-02 14:51
valikac16-Nov-02 14:51 
GeneralRe: CListCtrl List Style :: MFC Pin
kati4216-Nov-02 16:04
kati4216-Nov-02 16:04 
GeneralRe: CListCtrl List Style :: MFC Pin
Atlantys16-Nov-02 17:45
Atlantys16-Nov-02 17:45 
GeneralRe: CListCtrl List Style :: MFC Pin
valikac16-Nov-02 19:04
valikac16-Nov-02 19:04 
GeneralRe: CListCtrl List Style :: MFC Pin
sunj17-Nov-02 18:41
sunj17-Nov-02 18:41 
GeneralDetect LButton Hold (like key hold) When Mouse Not Moving in MFC Pin
s o v a n n16-Nov-02 14:46
s o v a n n16-Nov-02 14:46 
GeneralRe: Detect LButton Hold When Mouse Not Moving Pin
Christian Graus16-Nov-02 14:55
protectorChristian Graus16-Nov-02 14:55 
GeneralRe: Detect LButton Hold (like key hold) When Mouse Not Moving in MFC Pin
dabs17-Nov-02 3:22
dabs17-Nov-02 3:22 
GeneralOptimizing re-draw focus rect Pin
peterchen16-Nov-02 11:17
peterchen16-Nov-02 11:17 
GeneralRe: Optimizing re-draw focus rect Pin
Chris Richardson16-Nov-02 11:31
Chris Richardson16-Nov-02 11:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.