ListBox

17/12/2003 - 20:24 por Rafael | Informe spam
Quiero redimendionar un ListBox que tengo en un FormView
y hago lo siguente:

- Derivo de una Clase CListBox
- Creo el evento PreCreateWindow

Pero el evento PreCreateWindow nunca se activa

No Quiero usar MoveWindow
 

Leer las respuestas

#1 Rodrigo Corral González
18/12/2003 - 12:47 | Informe spam
Debes hacerlo en la función PreSubclassWindow.

El porque lo tienes aquí:
http://msdn.microsoft.com/msdnmag/i...fault.aspx

Q I have a subclass of CListBox. In order for it to provide its specialized
behavior, the listbox must be owner-drawn. I overrode the virtual function
PreCreateWindow to force the LBS_OWNERDRAWFIXED style to be set. This works
fine if I create the listbox myself. If the listbox is part of a dialog
loaded from a resource, PreCreateWindow is never called. How do I ensure the
LBS_OWNERDRAWFIXED style is set in this case?

A The short answer is: use PreSubclassWindow.
The long answer follows. PreCreateWindow is a special CWnd virtual function
that MFC calls, as you might guess, just before creating a window. When you
call CWnd::Create or CWnd::CreateEx to create a window, MFC calls
CWnd::PreCreateWindow before invoking Windows® to actually create your
window for you.

BOOL CWnd::CreateEx(...)
{
CREATESTRUCT cs;
...
// init cs

if (!PreCreateWindow(cs)) {
PostNcDestroy();
return FALSE;
}
...
// create the window

return TRUE;
}
But dialogs aren't created in this fashion. Dialogs are created when you
call CDialog::DoModal, in which case MFC loads your dialog template using
::CreateDlgIndirect, which is roughly equivalent to ::DialogBox. Either way,
Windows creates the controls internally-CWnd::CreateEx is never invoked. So
your control's PreCreateWindow never gets called.
But when you connect your control to a CWnd-derived object instance, such as
your specialized listbox, you have to call SubclassDlgItem, which calls
SubclassWindow, and here MFC calls another specialized virtual function,
PreSubclassWindow. This is your big chance in life to do things like change
the style.

void CMyListBox::PreSubclassWindow()
{
// turn on owner-draw
ModifyStyle(0,LBS_OWNERDRAWFIXED);
}
In fact, PreSubclassWindow is the preferred place to do stuff like this
because MFC also calls PreSubclassWindow when you create a window with
CreateEx. In other words, PreSubclassWindow covers both cases-dialog or
standalone creation-so if you set the style in PreSubclassWindow, you don't
need to do it in PreCreateWindow, too.

Un saludo
Rodrigo Corral González


begin 666 indent.gif
M1TE&.#EA"@`$`(#_`-/0T ```"'Y! $`````+ `````*``0`0 (&A(^IRYT%
#`#L`
`
end

Preguntas similares