MFC question, writing my own ComboBox like control

Hello

I am new to MFC programming and I want to do the following:

I want to create my own Combobox like control, however using a CEdit.

class CMyEdit : public CEdit
{
  CListBox m_lbHistory;
..
..
..
}

I override both OnCreate and Create() of CMyEdit in order to get 
notification when the control is created, afterwards I want to create the 
m_lbHistory control then hide it, then later show it when user presses DOWN.

1) Why aren't Oncreate() nor Create() being called?

2) What is the proper way to create the m_lbHistory control from CMyEdit ?

3) How can I handle the messages that will be passed to m_lbHistory from 
CMyEdit?
Or I have to subclass m_lbHistory's base class and allow it to talk with 
CMyEdit ?

Regards,
Elias 


0
lallous (134)
4/12/2006 7:22:47 AM
vc.mfc 33608 articles. 0 followers. Follow

7 Replies
808 Views

Similar Articles

[PageSpeed] 28

"lallous" <lallous@lgwm.org> wrote in message 
news:%23dmjqHgXGHA.3760@TK2MSFTNGP02.phx.gbl...
> Hello
>
> I am new to MFC programming and I want to do the following:
>
> I want to create my own Combobox like control, however using a CEdit.
>
> class CMyEdit : public CEdit
> {
>  CListBox m_lbHistory;
> .
> .
> .
> }
>
> I override both OnCreate and Create() of CMyEdit in order to get 
> notification when the control is created, afterwards I want to create the 
> m_lbHistory control then hide it, then later show it when user presses 
> DOWN.

What's the difference between this and a CBS_DROPDOWN extended ui combobox? 
The button?

>
> 1) Why aren't Oncreate() nor Create() being called?

Probably nobody is ever calling the Create member function.

>
> 2) What is the proper way to create the m_lbHistory control from CMyEdit ?
>

Call its Create or CreateEx member functions.

> 3) How can I handle the messages that will be passed to m_lbHistory from 
> CMyEdit?

Add the appropriate macros to your message map and implement the handler 
functions.

-- 
Jeff Partch [VC++ MVP]



0
jeffp (1712)
4/12/2006 7:54:35 AM
Hello Jeff,


"Jeff Partch [MVP]" <jeffp@mvps.org> wrote in message 
news:%23cMKZZgXGHA.1228@TK2MSFTNGP02.phx.gbl...
> "lallous" <lallous@lgwm.org> wrote in message 
> news:%23dmjqHgXGHA.3760@TK2MSFTNGP02.phx.gbl...
>> Hello
>>
>> I am new to MFC programming and I want to do the following:
>>
>> I want to create my own Combobox like control, however using a CEdit.
>>
>> class CMyEdit : public CEdit
>> {
>>  CListBox m_lbHistory;
>> .
>> .
>> .
>> }
>>
>> I override both OnCreate and Create() of CMyEdit in order to get 
>> notification when the control is created, afterwards I want to create the 
>> m_lbHistory control then hide it, then later show it when user presses 
>> DOWN.
>
> What's the difference between this and a CBS_DROPDOWN extended ui 
> combobox? The button?
>

For learning purposes, I am re-inventing the wheel.

>>
>> 1) Why aren't Oncreate() nor Create() being called?
>
> Probably nobody is ever calling the Create member function.
>
>
>>
>> 2) What is the proper way to create the m_lbHistory control from CMyEdit 
>> ?
>>
>
> Call its Create or CreateEx member functions.
>

The CMyEdit is a member variable of the dialog and is bound to a dialog 
control as well.
OnCreate, Create and PreCreatewindow are not being called at all.
So what is the place that will allow me to have the chance to create the 
listbox control when the CMyEdit is created?
(As said before CMyEdit is a member variable in the dialog).

I don't want to write any extra code in the dialog, the control should do 
all it needs by itself.

>> 3) How can I handle the messages that will be passed to m_lbHistory from 
>> CMyEdit?
>
> Add the appropriate macros to your message map and implement the handler 
> functions.
>

I know how to handle ON_LBN_xxx but will I be able to handle any sort of 
window messages that goes to that control?

Thanks,
Elias 


0
lallous (134)
4/12/2006 8:07:58 AM
"lallous" <lallous@lgwm.org> wrote in message 
news:OXSv4ggXGHA.4820@TK2MSFTNGP03.phx.gbl...
>>> I override both OnCreate and Create() of CMyEdit in order to get 
>>> notification when the control is created, afterwards I want to create 
>>> the m_lbHistory control then hide it, then later show it when user 
>>> presses DOWN.
>>
>> What's the difference between this and a CBS_DROPDOWN extended ui 
>> combobox? The button?
>>
>
> For learning purposes, I am re-inventing the wheel.
>

Okay, just keep in mind that the combobox is a very complicated 
implementation. :)

>
> The CMyEdit is a member variable of the dialog and is bound to a dialog 
> control as well.
> OnCreate, Create and PreCreatewindow are not being called at all.

No they wouldn't do. The dialog box and its controls are created by the OS 
as HWND windows and then subclassed and attached to their respective CWnd 
derivations afterward. In this secnario, nobody ever does call Create and 
the WM_CREATE message has long since come and gone.

> So what is the place that will allow me to have the chance to create the 
> listbox control when the CMyEdit is created?
> (As said before CMyEdit is a member variable in the dialog).
>
> I don't want to write any extra code in the dialog, the control should do 
> all it needs by itself.

What I do is override PreSubclassWindow, call the base class and then 
PostMessage myself a private "INTERNALCREATE" message then do the secondary 
window creation in its handler.

>
>>> 3) How can I handle the messages that will be passed to m_lbHistory from 
>>> CMyEdit?
>>
>> Add the appropriate macros to your message map and implement the handler 
>> functions.
>>
>
> I know how to handle ON_LBN_xxx but will I be able to handle any sort of 
> window messages that goes to that control?
>

If you mean messages to and for the constituent listbox, then what you'd 
need to do is implement a CListBox derived class and add message-map macros 
and handlers to that.

-- 
Jeff Partch [VC++ MVP]



0
jeffp (1712)
4/12/2006 8:33:28 AM
lallous wrote:

> Hello Jeff,
> 
> 
> "Jeff Partch [MVP]" <jeffp@mvps.org> wrote in message 
> news:%23cMKZZgXGHA.1228@TK2MSFTNGP02.phx.gbl...
> 
>>"lallous" <lallous@lgwm.org> wrote in message 
>>news:%23dmjqHgXGHA.3760@TK2MSFTNGP02.phx.gbl...
>>
>>>Hello
>>>
>>>I am new to MFC programming and I want to do the following:
>>>
>>>I want to create my own Combobox like control, however using a CEdit.
>>>
>>>class CMyEdit : public CEdit
>>>{
>>> CListBox m_lbHistory;
>>>.
>>>.
>>>.
>>>}
>>>
>>>I override both OnCreate and Create() of CMyEdit in order to get 
>>>notification when the control is created, afterwards I want to create the 
>>>m_lbHistory control then hide it, then later show it when user presses 
>>>DOWN.
>>
>>What's the difference between this and a CBS_DROPDOWN extended ui 
>>combobox? The button?
>>
> 
> 
> For learning purposes, I am re-inventing the wheel.
> 
> 
>>>1) Why aren't Oncreate() nor Create() being called?
>>
>>Probably nobody is ever calling the Create member function.
>>
>>
>>
>>>2) What is the proper way to create the m_lbHistory control from CMyEdit 
>>>?
>>>
>>
>>Call its Create or CreateEx member functions.
>>
> 
> 
> The CMyEdit is a member variable of the dialog and is bound to a dialog 
> control as well.
> OnCreate, Create and PreCreatewindow are not being called at all.
> So what is the place that will allow me to have the chance to create the 
> listbox control when the CMyEdit is created?
> (As said before CMyEdit is a member variable in the dialog).
> 
> I don't want to write any extra code in the dialog, the control should do 
> all it needs by itself.
> 
> 
>>>3) How can I handle the messages that will be passed to m_lbHistory from 
>>>CMyEdit?
>>
>>Add the appropriate macros to your message map and implement the handler 
>>functions.
>>
> 
> 
> I know how to handle ON_LBN_xxx but will I be able to handle any sort of 
> window messages that goes to that control?
> 
> Thanks,
> Elias 
> 
> 

Elias:

I have never used it, but I think you may need CWnd::PreSubclassWindow().

David Wilkinson
0
no-reply8010 (1791)
4/12/2006 8:34:58 AM
Thank you Jeff and David,

Along with this article:

http://www.flounder.com/presubclasswindow.htm

It seems PreSubclassWindow is the way to go.

Thanks
--
Elias
"Jeff Partch [MVP]" <jeffp@mvps.org> wrote in message 
news:Oq$YHvgXGHA.1084@TK2MSFTNGP04.phx.gbl...
> "lallous" <lallous@lgwm.org> wrote in message 
> news:OXSv4ggXGHA.4820@TK2MSFTNGP03.phx.gbl...
>>>> I override both OnCreate and Create() of CMyEdit in order to get 
>>>> notification when the control is created, afterwards I want to create 
>>>> the m_lbHistory control then hide it, then later show it when user 
>>>> presses DOWN.
>>>
>>> What's the difference between this and a CBS_DROPDOWN extended ui 
>>> combobox? The button?
>>>
>>
>> For learning purposes, I am re-inventing the wheel.
>>
>
> Okay, just keep in mind that the combobox is a very complicated 
> implementation. :)
>
>>
>> The CMyEdit is a member variable of the dialog and is bound to a dialog 
>> control as well.
>> OnCreate, Create and PreCreatewindow are not being called at all.
>
> No they wouldn't do. The dialog box and its controls are created by the OS 
> as HWND windows and then subclassed and attached to their respective CWnd 
> derivations afterward. In this secnario, nobody ever does call Create and 
> the WM_CREATE message has long since come and gone.
>
>> So what is the place that will allow me to have the chance to create the 
>> listbox control when the CMyEdit is created?
>> (As said before CMyEdit is a member variable in the dialog).
>>
>> I don't want to write any extra code in the dialog, the control should do 
>> all it needs by itself.
>
> What I do is override PreSubclassWindow, call the base class and then 
> PostMessage myself a private "INTERNALCREATE" message then do the 
> secondary window creation in its handler.
>
>>
>>>> 3) How can I handle the messages that will be passed to m_lbHistory 
>>>> from CMyEdit?
>>>
>>> Add the appropriate macros to your message map and implement the handler 
>>> functions.
>>>
>>
>> I know how to handle ON_LBN_xxx but will I be able to handle any sort of 
>> window messages that goes to that control?
>>
>
> If you mean messages to and for the constituent listbox, then what you'd 
> need to do is implement a CListBox derived class and add message-map 
> macros and handlers to that.
>
> -- 
> Jeff Partch [VC++ MVP]
>
>
> 


0
lallous (134)
4/12/2006 8:42:13 AM
"lallous" <lallous@lgwm.org> wrote in message 
news:%23qA1B0gXGHA.3936@TK2MSFTNGP05.phx.gbl...
> Thank you Jeff and David,
>
> It seems PreSubclassWindow is the way to go.
>

Good. Just in case I elided it a bit too much: one of the things you should 
not do in PreSubclassWindow is directly create secondary CWnd windows --  
thus my PostMessage suggestion. When called in the context of a Create[Ex] 
call, PreSubclassWindow is executed during a WH_CBT/CREATEWND hook.
-- 
Jeff Partch [VC++ MVP]


0
jeffp (1712)
4/12/2006 8:55:28 AM
This article has some stuff that might be useful to you:

http://www.codeproject.com/combobox/colorpicker.asp

Tom

"lallous" <lallous@lgwm.org> wrote in message 
news:%23dmjqHgXGHA.3760@TK2MSFTNGP02.phx.gbl...
> Hello
>
> I am new to MFC programming and I want to do the following:
>
> I want to create my own Combobox like control, however using a CEdit.
>
> class CMyEdit : public CEdit
> {
>  CListBox m_lbHistory;
> .
> 


0
tserface (3860)
4/12/2006 2:13:27 PM
Reply:

Similar Artilces:

Question related to modal dialogs
This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C600A8.61759780 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, Le't consider the following simplified example: 1. I have 3 dialog classes: CMainDlg, CFirstDlg, CSecondDlg, all derived = from CDialog. 2. In the CMainDlg::OnOK() I want to display the CFirstDlg, so the = function looks like: void CMainDlg::OnOK()=20 { CFirstDlg dlg; dlg.DoModal(); =20 CDialog::OnOK(); } 3. In the CFirstDlg::OnInitDialog method I ne...

A strange problem with MFC
Hi, Rencently I met a strange problem. The code like below: CWinThread* pThread = AfxBeginThread(ThreadFunc, (LPVOID)this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); if(pThread->m_hThread != NULL){ pThread->m_bAutodelete = FALSE; pThread->ResumeThread(); } After the statement "pThread->m_bAutodelete = FALSE" executed, I found the value of pThread->m_hThread is 0. While pThread->m_bAutodelete is still 1! The code section located in a win32 static library, with /Md option.The host application(exe) is a win32 console application, with /Md option. There...

String formatting question
Hello, I don't know where the appropriate place is to ask this question but I am hoping someone can help me in this forum. I have latitude and longitude for county borders for over 500 counties. For each county I have anywhere from a few hundred to thousands of coordinates, I have a need to have all the coordinates in a(horizontal)line in this format: Lat(space)Long,(space)Lat(space)Long, and so on....... I must stress that Iam looking for the lat/long to be in horizontal. I guess that means no carriage return. not sure if that is the appropriate term. I have the list of...

an initialization question
Hi, I have a user-defined structure shown below. typedef struct D { int x; CString s1; } DD; I don't know why the compiler doesn't like the following line. DD d[] = {{1, s2}, {2, s3}}; In contrast, the following code gets passed by the compiler: CString s1, s2; CString ss[] = {s1, s2}; Do you have any idea? Please help me out. Thanks. Tony ps. The error message from the compiler is shown below: :\tmp\test22\test22Dlg.cpp(249) : error C2440: 'initializing' : cannot convert from 'const int' to 'struct CTest22Dlg::OnCheck1::D' No construct...

return int value to OS in MFC App
Hi, Everybody. I have to make A MFC app to return int value to Operatiing System.. if i could use WinMain() function, this is not matter. but MFC does not reveal WinMain().... How can i solve this problem? Can Anybody help me with this problem? <flybluewing@bcline.com> wrote in message news:1189386249.923483.59250@y42g2000hsy.googlegroups.com... > Hi, Everybody. > > I have to make A MFC app to return int value to Operatiing System.. > > if i could use WinMain() function, this is not matter. > but MFC does not reveal WinMain().... > How can i solve this problem?...

How do I change control colors
I create a dialog based MFC application in VC++ 6.0 and add some controls like edit boxes and buttons. I would like to change the defaultcolors of the controls. Is there no simple way to do this? I havn't found the answer in the docs. The only thing I have found is a SetBkColor method but that won't work. I have only succeded in changing the background color of the main dialog window with SetDialogBkColor. >I create a dialog based MFC application in VC++ 6.0 and add some controls >like edit boxes and buttons. >I would like to change the defaultcolors of the controls. Is...

Write to XML
Hello everybody I am making an application in vb.net. I keep my app settings in an xml file. What I am trying to do is to change the data of a node according to the application user preferences. All documents and example I ve found on the internet are about creating and saving a whole xml document at the disc. Does anybody know if I can just change the data of a node instead of recreating the whole document? Thank you in advance Diomatas wrote: > What I am trying to do is to change the data of a node according to the > application user preferences. > > All documents and...

Unicode in MFC
Hi, I am new to MFC programming and I have a problem: when I try to write the caption of a button or something else in my own language(Farsi), in the design mode it shows the correct string but when I compile it it shows a '?' instead of every character. Can anyone please help me with that. > I am new to MFC programming and I have a problem: > when I try to write the caption of a button or something else in my > own language(Farsi), in the design mode it shows the correct string > but when I compile it it shows a '?' instead of every character. Can > anyone ple...

Easy Forms Questions
I have a form that I setfocus to a text box upon opening the form. Is there a way to force the user to update that field before I allow them to navaigate away from it? If the field is empty when opening the form: Yes, OnLostFocus event to go back to that textbox if it is Null or "" (depending on the format). You can also add a message to alert the user that they cannot leave the field until it is updated. If not empty, what are you storing in it?. This will help with further suggestions. "AJ" <AJ@discussions.microsoft.com> wrote in message news:9A98F9DB-7408-...

mfc and IE activeX
I'm using VS 2003 and trying to use Internet Explorer in my MFC application but encountering problems If I built a very simple test dialog-application and drop in the IE it works exactly as expected. However, when I create a similar dialog box in my MFC application and call the ...DoModal() nothing appears at all - not even the dialog box itself. It's as if my application does not want to use ActiveX components - I also tried a couple of other Microsoft ActiveX controls and they have the same problem. I must be missing something obvious - any one with any ideas will be much ...

Barcodes / Label printing question
Does the function "Serialization" in RMS, affect or perform any validation of the Item Lookup Code length, and that Items corresponding or selected barcode? We use 128-A, and use Retail Realms Fashion Bundle to create UPC numbers. In RMS Serialization is Off. RMS manual states barcodes must be 12 digits and no letters, however, it allows more digits, and letters, to be used as an Item Lookup, and doesnt display any error when selecting barcode 128-A and printing. It seems it will print anything, but the actual printed barcode may not really be the complete Item Lookup code, if ...

Simple Exchange Question
Let me start by saying that I know almost nothing about Exchange Server or how to set anything up. All I really know is how to go into Active Directory Users and Groups and review information and add SMTP addresses. I'm not a networking guy at all. We're a small three man company and we're in the middle of switching our IT support, so I figured I'd ask this question here because I'm hoping it's very simple. I want to set up email addresses that get forwarded to multiple people. For instance, I want to set up support@mydomain.com. Whenever an email is sent to that...

Money 2004 Bills and Deposits Question
After submitting a transaction via the Bills and Deposits screen, Money places focus on the next instance of the transaction (i.e., for a recurring transaction). Is there anyway to prevent this? I would prefer that focus be placed on the next transaction in the list. No, there doesn't appear to be a way to fix that. I suggest reporting it to MS via the MSWish site. Or reporting it as a bug at their support site. -- Semper Fi Kevin Campbell "With freedom goes responsibility. Sir Winston Churchill once said you can have 10,000 regulations and still not have respect for the...

several simple questions
Hi - I am a long time Win user who just happily switched to the Mac and Entourage and if you would be so kind, here are some very beginner questions. I know that Entourage and Outlok are not identical in features. 1. I created and saved a signature. I select Messsgae-Signature and select the one I want to use, but isn;t there a way to automatically have it inserted as the default? 2. Speaking of defaults, is there no option to use a color with text in creating Entourage messages? 3. As far as I can tel, there is no Autotext option in Entourage - nor is there an insert menu. Is there a way to i...

Newbie Question...
I'm using Excel 2003. I can create columns, rows, data, new worksheets, etc., so I have a very basic knowledge of using Excel. With that said, here is what I'm trying to accomplish: First of all, I'm the manager of several apartment complexes. We have seperate worksheets for each complex. Each worksheet contains unit #, move-in date, lease expiration, etc. Just general information. There are also columns we mark 'R' for when we have requested that trash, paint, maintenance, cleaning and carpet cleaning be performed. We then update the 'R' to 'X' when...

Question about Pivot Tables..why is that
WordXP I created the pivot table successfully and am up to dragging the field and putting them in the column. Why is it that sometimes I put the field in the column and it fills out the entire column with the info (ex. putting the "serial #" field in the column produces all the serial numbers to show up in each cell underneath) and other times I put the field in the column and all it shows is the sum amount. What is happening? Thank you. ~D~ There are four 'areas' in a pivot table , row fields, column fields, page fields and values. The value area is where the pivot ...

Chart Question 04-19-10
I have a column chart that is working. I have the value of the column shown in the series. On some of the column bars there is a value underlined with an arrow pointing either up or down. Does anyone know what this is and how can I turn it off? I am using RS2008 with SQL Server 2005. Thanks in advance ...

Need Help with MFC!!
Hi all, need help esp. with Graphic part. When you right click on any drive on your machine and click properties, you get a tabbed dialog. I want to know how can I embed graphic image (pie chart) into my MFC Dialog? I have written code which displays the Disk Usage right now but don't know how to display that info as a PIE CHART!!!!!! besides what type of MFC Dialog application should I look fwd to build? I want exactly as the DRIVE properties. TIA -- ======== Regards Vai ======== Have you looked at the CDC::Pie method? joe On Wed, 12 May 2004 23:07:11 -0400, "Vai2000"...

MFC to Console.
Hello Group. I need to convert the code of WiniNet Async Demo from microsoft samples from MFC to a console function.. Someone can help me with the changes.. The code is posted here Regards /* Microsoft Corporation Copyright 1999-2002 */ /******************************************************************** ProjectName : AsyncDemo Purpose : This sample demonstrates how to submit two WinInet requests, using InternentOpenUrl, asynchronously. Notes : This sample does not handle any authentication. To properly handle authentication, the functions that handle specific protocols (like Ht...

XML and MFC
Hello guys, What source of knowledge would you point me to if you were about to integrate XML with MFC? Of course if there's any Microsoft documentation anywhere, please post me a link to it. Thank you in advance! :-) Yea, I wanna know it too. Who would give a hand? > What source of knowledge would you point me to if you were about to > integrate XML with MFC? Of course if there's any Microsoft documentation > anywhere, please post me a link to it. After digging left and right, I remained with two main options: - MSXML - MS, proprietary, COM, with all the implications:...

A Question about CTreeCntrl
I'm writing an application from an example that uses a CTreeCtrl. I'm don't understand the usage of the InsertItem methods and its parameters. HTREEITEM InsertItem( LPTVINSERTSTRUCT lpInsertStruct ); HTREEITEM InsertItem( UINT nMask, LPCTSTR lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam, HTREEITEM hParent, HTREEITEM hInsertAfter ); HTREEITEM InsertItem( LPCTSTR lpszItem, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST ); HTREEITEM InsertItem( LPCTSTR lpszItem, int nImage, int nS...

Question on "Monthly Income and Expenses" report
I decided I wanted to generate a quarterly report by category showing monthly income and expenses. I was able to get it to work, but try as I might, I can not find a way to show transfers from my checking account to my savings account. I know that I do not want to show transfers to the credit card account. But the choices on the show transfers does not result in the transfers to savings or the purchase of CD's as showing up in the report. I am running Money Plus Delux. Without chasing the specifics just yet, understand that "Income and Expenses" are everything Transfe...

Question about WM_SIZEPARENT
I have a CWnd derived class which is in control of some tabbed CView objects. The first view which is AFX_IDW_PANE_FIRST controls sizing of the views when it receives the WM_SIZEPARENT message. The problem is that it doesn't always get the message. I've traced into CWnd::RepositionBars(...) and found the following code: for (HWND hWndChild = ::GetTopWindow(m_hWnd); hWndChild != NULL; hWndChild = ::GetNextWindow(hWndChild, GW_HWNDNEXT)) { UINT nIDC = _AfxGetDlgCtrlID(hWndChild); CWnd* pWnd = CWnd::FromHandlePermanent(hWndChild); if (nIDC == nIDLeftOver) hWndLeftOver = hWnd...

Sending Window Messages from an MFC app to a Windows Firm tray application
Hello, I have an MFC MDI application and a Windows Forms (2.0) Tray Icon application. I want to run a command on the tray application via my MFC application. There is a "Register" context menu command on the tray icon application. I want to call the Register command from my MFC MDI application. I thought of a windows message. How do I do it? Is there any other better mechanism to do so? Thanks, Janiv Ratson. If you know the class of the window on the tray application you can use FindWindow() to get the window for the class. Then you can use either PostMessage() or SendMessag...

dynamically managing of layout in MFC + GridBagLayout in MFC or C++
Hi, can anybody tell me how can I make or find a function in MFC to manage layout of a dialog that dynamically has been create and also the controls in the dialog? I am new in MFC, what I am lokking for is something like GridBagLayout in java? is there something like this in C++ MFC ? any idea plz? Thank u There is nothing like GridBagLayout in MFC. However, you can achieve the same functionality thru various means. You have to move the controls manually on resize of the dialog or window. Please see the following examples: http://www.codeproject.com/dialog/easysize.asp http://www.codepr...