为什么我的子窗口对鼠标事件无响应?

Ami*_*mit 5 c++ winapi visual-c++

我创建了一个自定义的静态窗口,该窗口显示位图图像,该窗口是其他窗口的子窗口。现在,我想捕获此窗口的鼠标事件,以便可以提供裁剪图像的功能。

但是问题是Mouse事件没有传递到此子窗口。...以下是该子窗口的代码段WndProc

WNDPROC origStatProc;
    // Variable which stores the handle of BITMAP image
HBITMAP hBitmap=NULL;
LRESULT CALLBACK dispWndProc(HWND hwnd,UINT msg, WPARAM wParam, LPARAM lParam)
{
    static HDC hdc;
    static PAINTSTRUCT paintSt;
    static RECT aRect;

    switch(msg)
    {
        case WM_PAINT:
        {
            hdc = BeginPaint(hwnd,&paintSt);
            GetClientRect(hwnd,&aRect);
            if(hBitmap!=NULL)
            {               
                HDC memDC = CreateCompatibleDC(hdc);
                if(memDC!=NULL)
                {
                    BITMAP bmp;
                    GetObject(hBitmap,sizeof(bmp),&bmp);
                    SelectObject(memDC,hBitmap);
                    SetStretchBltMode(hdc,HALFTONE);
                    StretchBlt(hdc,0,0,aRect.right,aRect.bottom,
                    memDC,0,0,bmp.bmWidth,bmp.bmHeight,
                    SRCCOPY);
                    DeleteObject(&bmp);
                    ReleaseDC(hwnd,memDC);
                }
            }           
            // the code for painting 
            EndPaint(hwnd,&paintSt);
        }
        break;
        case STM_SETIMAGE:
        {           
            InvalidateRect(hwnd,&aRect,true);           
        }
            break;  
        case WM_LBUTTONDOWN:
            {
                int xPos = GET_X_LPARAM(lParam);
                int yPos = GET_Y_LPARAM(lParam);
                char xstr[10];
                _itoa(xPos,xstr,10);
                MessageBox(NULL,xstr,"X Value ",MB_OK);
            }
            break;

        default:
            return origStatProc(hwnd,msg,wParam,lParam);

    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

谁能告诉我在此“子”窗口中还需要捕获鼠标事件的其他内容吗...

Mar*_*som 2

用于窗口的窗口类将确定窗口的某些默认行为。静态窗口类特别难以使用,因为 Windows 假设窗口永远不会更改其内容,并且不会以任何方式与用户交互。您可能会发现 WM_LBUTTONDOWN 被传递到父窗口。