Re: User Control Problem
- From: Michael H <MichaelH@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 29 Jan 2008 01:07:00 -0800
Here the details:
I placed the custom control on the dialog. In the properties window of the
custom control I defined the class (ClassName: MyListBox - registered via
AfxRegisterClass). I created a member variable for the custom control (Type
CMyListBox). Via this member variable I can handle my custom list box. That's
all.
In the DLL DIalog it's the same
Everything works if I use the control only in the DLL. Everything works if I
use the control only in the app. If i use the control in both (app and DLL)
the control only works in the app (Class is registered first) but it doesn't
work in the DLL (Class is registered after the app has registered the class).
Have a look at the header file:
class CMyListBox : public CWnd
{
DECLARE_DYNAMIC(CMyListBox)
public:
CMyListBox();
virtual ~CMyListBox();
virtual BOOL PreTranslateMessage(MSG* pMsg);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
afx_msg UINT OnGetDlgCode();
afx_msg void OnSelchangeListBox( );
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
void Repaint();
// ListBox Functions
...
protected:
DECLARE_MESSAGE_MAP()
// to register the class, uses AfxRegisterClass
BOOL RegisterWindowClass();
// this function creates the buttons, the list box and the scroll bar if
needed
// on the custom control
virtual void PreSubclassWindow();
// ListBox Object
CListBox m_ListBox;
// Up/Down Buttons
int m_nBtHeight;
CButton m_BtUp;
CButton m_BtDown;
afx_msg void OnBtUpPressed();
afx_msg void OnBtDownPressed();
afx_msg void OnPaint();
...
};
I'm working with VisualStudio 2005.
Michael
"Joseph M. Newcomer" wrote:
How do you specify the class for the control to be created? There isn't nearly enough.
information here to deduce what is happening.
The issue with extension DLLs deals with how DLLs find their resources, and you don't have
nearly enough information in this description to tell us what is really going on.
joe
On Mon, 28 Jan 2008 07:50:01 -0800, Michael H <MichaelH@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Hi Joe,Joseph M. Newcomer [MVP]
Thanks for your answer. I wrote a class for the control. The cpp and h files
for this class are included in the project. I use this class for the MFC
custom control. Every time I use the control, I try to register the class. If
the class is already registred, the registration function is aborted. This
method workes fine if I only use the control in the main application. Now a
DLL is loaded from a dialog of the application. This DLL creates a Dialog
with the same custom list box the application uses. The sources (cpp and h)
are included in the DLL project file in the standard way.
If the DLL-Dialog is opened the control behaves in the described way
(buttons and scroll bar are visible but the listbox is not visible).
As I wrote I tried the way "Extension DLL" and everything work fine!
I know that the above described way is not the professional way but I'm
interested in the reasons for this behaviour.
Michael
"Joseph M. Newcomer" wrote:
I'm a bit confused.
Is the control defined by the DLL or by the App? That is, where is the code for the
control, in a DLL or the App? The control should be registered in the same module where
its code is.
I have no idea why use say it is not possible to use extended DLLs; this is one of the key
features that should be supported. If it doesn't work, you are doing something wrong, but
it is hard to tell from this description what you are trying to do.
joe
On Mon, 28 Jan 2008 01:55:00 -0800, Michael H <MichaelH@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Hi,Joseph M. Newcomer [MVP]
I programmed a user defined listbox. This control contains 2 user defined
buttons for scrolling up/down, a standard MFC Listbox object and a scroll bar
object.
In the App the class for this object is registered via the
RegisterWindowClass() Function.
In an application the control workes fine in different modal dialogs. If
this control is used in a DLL (the DLL generates a modal window) the control
is working fine if the DLL is the only instance which uses the control.
If the app has registered the Control class first, the control doesn't work
in the DLL window. Means the control only shows the buttons and the scroll
bar but not the list box.
If the control is included in the app and DLL via an extended MFC DLL
everything works fine. I cannot use the MFC included dynamic in the app -
therefor it is not possible to use extended DLLs.
Is somebody out there who can explain what happens there. Perhaps someone
has an idea how i can use this control in the app and an dll without loading
the control via DLL.
Thanks
Michael
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- Follow-Ups:
- Re: User Control Problem
- From: Joseph M . Newcomer
- Re: User Control Problem
- References:
- Re: User Control Problem
- From: Joseph M . Newcomer
- Re: User Control Problem
- From: Michael H
- Re: User Control Problem
- From: Joseph M . Newcomer
- Re: User Control Problem
- Prev by Date: Re: How to modify the caption text for a MDI-application.
- Next by Date: Threads
- Previous by thread: Re: User Control Problem
- Next by thread: Re: User Control Problem
- Index(es):