3

I know it's a really old stuff, but I'm wrecking my brain over it. Does anyone know why this is happening?

Say, when the scrollbar mouse click notification is propagated through WM_NCHITTEST -> WM_NCLBUTTONDOWN -> WM_SYSCOMMAND -> WM_HSCROLL or WM_VSCROLL, all parameters in this chain seem to follow documentation, except SC_HSCROLL and SC_VSCROLL for WM_SYSCOMMAND. So if I do:

//From within WndProc
if(message == WM_SYSCOMMAND)
{
    UINT uiCmd = wParam & 0xFFF0;
    if(uiCmd == SC_HSCROLL)
    {
        TRACE(L"Horiz scroll\n");
    }
    else if(uiCmd == SC_VSCROLL)
    {
        TRACE(L"Vertical scroll\n");
    }
}

I seem to get vertical notification for horizontal and vice versa.

Here's the proof from Spy++. If I click this down arrow:

enter image description here

these are notifications that window receives:

enter image description here

All correct except SC_HSCROLL. WTF?

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • 1
    What is that control? Is that an ordinary Win32 ListBox, ListView, or something custom. Can you post an MVCE (minimal, complete,verifiable exampe). – selbie Apr 05 '19 at 05:17
  • Also, what you are really trying to do? As you can see, the WM_VSCROLL message comes in after the SYSCOMMAND. – selbie Apr 05 '19 at 05:18
  • @selbie/: It's a `richedit` – c00000fd Apr 05 '19 at 05:19

1 Answers1

1

if look for __int64 OnDwpNcLButtonDown(CThhemeWnd*, THEME_MSG*) under debugger visible next code:

enter image description here

wParam = HTVSCROLL != HitTest ? SC_VSCROLL : SC_HSCROLL;
SendMessage(*, WM_SYSCOMMAND, (wParam | HitTest), *)

the WM_SYSCOMMAND with SC_VSCROLL or SC_HSCROLL sent from this point, but obvious code contain logical error - the SC_VSCROLL and SC_HSCROLL confused.

correct code must be

wParam = HTVSCROLL == HitTest ? SC_VSCROLL : SC_HSCROLL;

also

In WM_SYSCOMMAND messages, the four low-order bits of the wParam parameter are used internally by the system. To obtain the correct result when testing the value of wParam, an application must combine the value 0xFFF0 with the wParam value by using the bitwise AND operator.

here visible that in place four low-order bits we have hit test code from WM_NCLBUTTONDOWN message, which is from WM_NCHITTEST message return

0xf087 - this is SC_HSCROLL | HTVSCROLL , when on hscroll we got 0xf076 which is SC_VSCROLL | HTHSCROLL

this is simply windows bug in uxtheme.OnDwpNcLButtonDown

RbMm
  • 31,280
  • 3
  • 35
  • 56
  • Interesting. And it's been there since, idk, Windows XP or so and nobody noticed it? Anyway, thanks for confirming it. I thought I was "seeing things" :) Although, if the bug is in `uxtheme.dll`, does this mean that if the process is not themed, `SC_VSCROLL` and `SC_HSCROLL` will be dispatched correctly? – c00000fd Apr 05 '19 at 17:00
  • @c00000fd - just look this ox xp - the [same error](https://i.imgur.com/7XMuOdM.png). – RbMm Apr 05 '19 at 17:09
  • @c00000fd - *if the process is not themed* - even not check.. simply need handle `WM_VSCROLL` and `WM_HSCROLL` i think. – RbMm Apr 05 '19 at 17:11