Help - Search - Members - Calendar
Full Version: Problems with WM_GETMINMAXINFO and on_size_limit_change
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
mixcherry
CODE
LRESULT playlists_dropdown::on_message(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg) {
.
.
case WM_CREATE:
{
m_tracker.initialize(this);
g_notify_list.add_item(wnd);

RECT rc;
GetClientRect(wnd, &rc);

m_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, WC_COMBOBOX,
0, CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_TABSTOP,
0, 0, rc.right, rc.bottom, wnd, HMENU(0), core_api::get_my_instance(), NULL);

g_update_all_sizes();
}
break;
.
.
case WM_GETMINMAXINFO:
{
MINMAXINFO * mmi;
mmi = (MINMAXINFO *) lp;
RECT rc;
GetWindowRect(m_hWnd, &rc);

/* DEBUG */
/* */ char buf[256];
/* */ sprintf(buf, "(%dx%d)", rc.right - rc.left, rc.bottom - rc.top);
/* */ console::info(buf);
/* DEBUG */

mmi->ptMinTrackSize.y = rc.bottom - rc.top;
}
break;
}
}


CODE
void playlists_dropdown::g_update_all_sizes()
{
unsigned n;
unsigned count = g_instances.get_count();
unsigned font_height = uGetFontHeight(g_font);

for (n = 0; n < count; n++) {
HWND wnd = g_instances[n]->m_hWnd;
if (wnd) {
SendMessage(wnd, CB_SETITEMHEIGHT, -1, font_height + cfg_padding);
SendMessage(wnd, CB_SETITEMHEIGHT, 0, font_height + cfg_padding);
}

/* DEBUG */
/* */ RECT rc;
/* */ GetWindowRect(wnd, &rc);
/* */ char buf[256];
/* */ sprintf(buf, "%d: (%dx%d)", n, rc.right - rc.left, rc.bottom - rc.top);
/* */ console::info(buf);
/* DEBUG */

g_instances[n]->get_host()->on_size_limit_change(g_notify_list[n], uie::size_limit_flag_t::size_limit_minimum_height);
}
}


Where:
  • m_hWnd is the window of my ComboBox.
  • g_instances (global variable) is the list of instances of my plugin (-> m_tracker is instance_tracker_client_t<playlists_dropdown,g_instances>).
  • g_notify_list (static field) is the list of of active windows.
The problem is with WM_GETMINMAXINFO. As you can see, after I create my ComboBox ("m_hWnd = CreateWindowEx(...)"), I call g_update_all_sizes() -- where I force (using on_size_limit_change()) my window to set its minimal height. But this doesn't work :/
The weird thing is that inside g_update_all_sizes, dimensions of my ComboBox are reported right (for example "248x41"). But when the WM_GETMINMAXINFO message is processed (after calling on_size_limit_change()), the dimensions of the same m_hWnd are reported to be "0x0"! How is this possible?

When I call g_update_all_sizes() some time *after* the window is created, for example from my Preferences Page, everything works OK.

EDIT: I forgot to mesnion, that I'm writing Columns UI extension, based on Console UIE example from Columns UI SDK.
musicmusic
The intitial size of your window may be (0,0). And you are probably creating the ComboBox with the same size.

I think the lesson is: dont set your minimum height equal to your current height! Because the min height is used to determine the height that is set.

Maybe this will help, at least its what I do:
CODE

//WM_CREATE handler:
[...]
        wnd_combo = CreateWindowEx(0, WC_COMBOBOX, 0, CBS_DROPDOWNLIST|CBS_SORT|WS_CHILD|WS_VISIBLE|WS_TABSTOP ,
            0,0,100,300, wnd, (HMENU)ID_ORDER, core_api::get_my_instance(), NULL);

[initialise and populate combobox]

            RECT rc;
            GetWindowRect(wnd_combo, &rc);
            height = rc.bottom - rc.top;

//WM_GETMINMAXINFO:
        mmi->ptMinTrackSize.y = height;
        mmi->ptMaxTrackSize.y = height;


IIRC the inital height of the combo is used to determine the size of the drop down. If you set the initial height to 0, you will probably end up with "1 pixel drop down" problem on Windows 2000 /
common controls 5.

BTW I don't think foo_uie_console is a good component is base another on, because it is quite specificially written for its purpose.
mixcherry
Thank you! That worked (at last smile.gif)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.