April 19, 2024, 09:19:14 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Popup listbox-how?

Started by sapero, October 23, 2006, 07:43:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sapero

Hello, I have small problem with listbox for property-grid control.
As you know, listbox (and any other control) placed on a window cannot stick out of the parent window.
But in combobox it can: the parent window of listbox is changed to desktop window, and windows styles are changed from WS_CHILD to WS_POPUP, so the listbox is always full visible.
I've tried this trick and it worked, but on the explorer task-switch toolbar, a new button has been added ???
I have removed this ugly button using extremal step: ITaskbarList::DeleteTab, but after minimizing main window the button was again visible.

Here is the snipped that demonstrates the floating listbox problem. I know, i can create extra window as parent for listbox, but any easier way?
import int SetParent(int hwndChid,int hwndParent);
import int SetWindowLongA(int hwnd,int index,int newlong);
import int GetDesktopWindow();
import int ClientToScreen(int hwnd,POINT *pt);
import int ScreenToClient(int hwnd,POINT *pt);
import int CoInitialize(int x);
import int CoUninitialize();
import int CoCreateInstance(GUID *cls,void *x,int ctl,GUID *iid,void *ppv);

#emit align 4
#emit $CLSID_TaskbarList dd 0x56FDF344, 0x11D0FD6D, 0x60008A95, 0x90A0C997
#emit $IID_ITaskbarList  dd 0x56FDF342, 0x11D0FD6D, 0x60008A95, 0x90A0C997
declare CLSID_TaskbarList();
declare IID_ITaskbarList();

#define LBS_DOCKED   0x50A00140 // WS_CHILD+
#define LBS_UNDOCKED 0x90A00140 // WS_POPUP+
#define GWL_STYLE    -16
#define IDC_DOCK     1000
#define IDC_TASKBAR  1001
#define IDC_LISTBOX  1002


interface ITaskbarList
{
declare virtual QueryInterface(GUID *iid,void *ppv);
declare virtual AddRef();
declare virtual Release();
declare virtual HrInit();
declare virtual AddTab(int hwnd);
declare virtual DeleteTab(int hwnd);
};


class CFloatingListbox : CDialog
{
CListbox *pLB;
declare Dock()
{
// set listbox parent to desktop
// and change style from child to popup
GetControl(IDC_DOCK)->SetText("Undock");
GetControl(IDC_TASKBAR)->Enable(FALSE);
RECT rc = pLB->GetWindowRect();
int w = rc.right - rc.left;
int h = rc.bottom - rc.top;
ScreenToClient(m_hwnd, &rc); // update left and top

SetParent(pLB->m_hwnd, m_hwnd);
pLB->SetSize(rc.left, rc.top, w,h);
SetWindowLongA(pLB->m_hwnd, GWL_STYLE, LBS_DOCKED);
}
declare Undock()
{
GetControl(IDC_DOCK)->SetText("Dock");
GetControl(IDC_TASKBAR)->Enable(TRUE);
RECT rc = pLB->GetWindowRect();
int w = rc.right - rc.left;
int h = rc.bottom - rc.top;
// ClientToScreen(m_hwnd, &rc); // update left and top

SetParent(pLB->m_hwnd, GetDesktopWindow());
pLB->SetSize(rc.left, rc.top, w,h);
SetWindowLongA(pLB->m_hwnd, GWL_STYLE, LBS_UNDOCKED);
}

declare virtual OnControl(int nID, int nNotifyCode, unsigned int hControl)
{
if (!nNotifyCode)
{
if (nID == IDC_DOCK)
{
if (GetControl(IDC_DOCK)->GetText() == "Undock")
Undock()
else
Dock();
}
else if (nID == IDC_TASKBAR)
{
ITaskbarList *itl;
CoInitialize(0);
if (!CoCreateInstance(&CLSID_TaskbarList,0,1,&IID_ITaskbarList,&itl))
{
itl->HrInit();
itl->DeleteTab(pLB->m_hwnd);
itl->Release();

//GetControl(IDC_TASKBAR)->Enable(FALSE);
// don't disable it: after minimizing the main window,
// the listbox adds its button to the taskbar again!
}
CoUninitialize();
}
}
}
declare virtual OnInitDialog() {pLB = GetControl(IDC_LISTBOX);}
}




sub main()
{
CFloatingListbox d1;
d1.Create(0,0,300,202,0x80CA0880,0,"Floating listbox test",0);
d1.AddControl(CTBUTTON,"Undock",15,14,116,47,0x50018000,0x0,IDC_DOCK);
d1.AddControl(CTBUTTON,"Remove from taskbar",159,14,116,47,0x58018000,0x0,IDC_TASKBAR);
d1.AddControl(CTLISTBOX,"Listbox",126,80,83,200,LBS_DOCKED,0,IDC_LISTBOX);
d1.AddControl(CTSTATIC,"click Undock, then click Remove from taskbar.\nMinimize main window and look at the taskbar!",7,83,95,107,0x50000100,0x0,4);
d1.Domodal();
return;
}


The floating listbox I need for this property grid: (based on RaGrid control)

Ionic Wind Support Team

A window can still have a parent and be a tool window.  I would leave the parent as the program window and change the extended style to WS_EX_TOOLWINDOW.

That way you don't get a new button on the taskbar.  A popup window of the desktop would always get a taskbar button.

Paul.

Ionic Wind Support Team

sapero

Toolwindow works like a charm, but with focus bug: the listbox will not accept any focus: SetFocus and any click on listbox holds the focus still on parent window ;D
I'll try other tricks.