farshizzo
asked on
pop-up listbox in MDI application
Hi
I'm trying to create an IDE with support for autocompletion similar to Visual C++. It's an MDI application that uses CRichEditView. I created my own class CComplete that inherits from CListBox. I'm able to popup the listbox and fill it with the appropriate words but I have a couple problems. First off, my CComplete class does not respond to the Escape key. I handle the WM_KEYDOWN message and it responds to every key except for VK_ESCAPE. Second, if I set the CRichEditView as the parent of CComplete then the listbox will only be drawn inside the view and will be cutoff if it goes outside the views frame. I fixed this by setting the main window as the parent, but then the list box wouldn't respond to mouse clicks. Any ideas?
I'm trying to create an IDE with support for autocompletion similar to Visual C++. It's an MDI application that uses CRichEditView. I created my own class CComplete that inherits from CListBox. I'm able to popup the listbox and fill it with the appropriate words but I have a couple problems. First off, my CComplete class does not respond to the Escape key. I handle the WM_KEYDOWN message and it responds to every key except for VK_ESCAPE. Second, if I set the CRichEditView as the parent of CComplete then the listbox will only be drawn inside the view and will be cutoff if it goes outside the views frame. I fixed this by setting the main window as the parent, but then the list box wouldn't respond to mouse clicks. Any ideas?
ASKER
william, your escape key solution worked, but only if I set the CRichEditView as the parent. If I set the main window as the parent does that mean I have to handle the PreTranslateMessage in the main window and pass it on?
Also, when I SetCapture() in my CComplete class the mouse arrow would disappear.
Also, when I SetCapture() in my CComplete class the mouse arrow would disappear.
ASKER
I forgot to mention something. When I set the main window as the parent the list box doesn't respond to mouse clicks, but it does respond to the mouse wheel.
I think it's the same problem the MainFrame is taking the mouse messages try forwarding these to the Listbox also.
It seems to me that the list should be a popup window not a child window so that it is not clipped (even to the main window). However, a listbox must be a child window. Have you considered creating a popup window and putting the listbox within that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks nass, that worked great
ASKER
aphillip, how would I go about putting the listbox within a popup window?
(Sorry I didn't reply earlier but I somehow missed getting email that said there had been followups in this thread.)
> how would I go about putting the listbox within a popup window?
You can create a popup window using CreateEx with style WS_POPUP. In MFC I would just derive a class from CWnd (use "generic CWnd" as the base class in Class Wizard) and call CreateEx in the contructor.
Then create a CListBox using the above popup window as the parent passed to CListBox::Create(). Make it the same size as the popup window.
There may be example code on CodeGuru or CodeProject to do this. There should at least be code that shows how to create a popup window.
> how would I go about putting the listbox within a popup window?
You can create a popup window using CreateEx with style WS_POPUP. In MFC I would just derive a class from CWnd (use "generic CWnd" as the base class in Class Wizard) and call CreateEx in the contructor.
Then create a CListBox using the above popup window as the parent passed to CListBox::Create(). Make it the same size as the popup window.
There may be example code on CodeGuru or CodeProject to do this. There should at least be code that shows how to create a popup window.
ASKER
aphillip, I tried the popup window and it works perfectly, I'll make sure to get you some points for you answer. thanks a lot!
> I tried the popup window and it works perfectly ...
glad I could help
> I'll make sure to get you some points for you answer
Don't worry about it. I don't do it for the points.
glad I could help
> I'll make sure to get you some points for you answer
Don't worry about it. I don't do it for the points.
Try overiding ... CRichEdit's PreTranslateMessage(MSG* pMsg) (see Class Wizard)
If a VK_ESCAPE comes in check if your Listbox is active and pass it over
m_listMyListBox->SendMessa
or simply close the listbox.
For the second part when you listbox is active try
m_listMyListBox->SetCaptur