WM_LBUTTONDOWN和WM_KEYDOWN消息未在无模式对话框Win32中接收

时间:2017-05-27 14:40:28

标签: c++ windows winapi

我正在开发一个使用Windows Media Foundation捕获视频的Win32应用程序。我必须在透明的视频窗口上显示播放/暂停/停止位图图像。我创建了一个无模式对话框,并使用下面的代码在对话框中显示透明图像。

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ 
    int wmID;
    switch (unMessage)
    {
    case WM_COMMAND:
         switch(LOWORD(wParam))
         {
           case ID_BTN_VIDEOSTART:              
                 InitModelessDialog();
           break;
         }
         break;     
     }
     return CallWindowProc ( g_lpfnWndProc, hWnd, unMessage, wParam, lParam );
}

void InitModelessDialog()
{
     DIBSECTION ds;
     DWORD dwFlag = MID_EXT_STYLES | MID_CLR_KEY | MID_ALPHA_VAL;

     g_hWndVideoPause = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_DLG_VIDEORECORD), g_hwndPreview, DlgProc_VideoPause);

    g_hPauseBmp = (HBITMAP)LoadImage(g_hInstance, MAKEINTRESOURCE(IDB_BITMAP_PAUSE), IMAGE_BITMAP, 0, 0, 0);
    GetObject(g_hPauseBmp, sizeof(ds), &ds);

    g_hPauseDC = CreateCompatibleDC(NULL);
    SelectObject(g_hPauseDC, g_hPauseBmp);

    if(dwFlag & MID_EXT_STYLES)
      SetWindowLong(g_hWndVideoPause, GWL_EXSTYLE, GetWindowLong(g_hWndVideoPause, GWL_EXSTYLE) | (WS_EX_LAYERED | WS_EX_TRANSPARENT));

   if(dwFlag & (MID_CLR_KEY | MID_ALPHA_VAL))
   {
       DWORD dwTemp = 0;

       if(dwFlag & MID_ALPHA_VAL)
        dwTemp = LWA_ALPHA;

       if(dwFlag & MID_CLR_KEY)
        dwTemp |= LWA_COLORKEY;

       SetLayeredWindowAttributes(g_hWndVideoPause, UI_COLOR_KEY, (255 * UI_TRANSPARENCY_PERCENT) / 100, dwTemp);
   }

   SetParent(g_hWndVideoPause,g_hwndPreview);

   dlgWidth = ds.dsBm.bmWidth;
   dlgHeight = ds.dsBm.bmHeight;

   SetWindowPos(g_hWndVideoPause, HWND_TOP, 0, 0, ds.dsBm.bmWidth, ds.dsBm.bmHeight, SWP_SHOWWINDOW | SWP_NOMOVE);
   HDC hDlgDC = GetDC(g_hWndVideoPause);
   StretchBlt(hDlgDC, 0, 0, dlgWidth, dlgHeight, g_hPauseDC, 0, 0, ds.dsBm.bmWidth, ds.dsBm.bmHeight, SRCCOPY); 
   ReleaseDC(g_hWndVideoPause, hDlgDC);

   if(g_hPauseDC)
   {
      DeleteDC(g_hPauseDC);
      g_hPauseDC = NULL;
   }

   if(g_hPauseBmp)
   {
      DeleteObject(g_hPauseBmp);
      g_hPauseBmp = NULL;
  }
}

 INT_PTR CALLBACK DlgProc_VideoPause(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 {
    UNREFERENCED_PARAMETER(lParam);
    PAINTSTRUCT ps;
    switch (message)
    {
       case WM_INITDIALOG:
           return (INT_PTR)TRUE;
       case WM_PAINT:
        {
            HDC hDC = GetDC(hDlg);
            if(g_hPauseDC)
            {
                StretchBlt(hDC, 0, 0, dlgWidth, dlgHeight, g_hPauseDC, 0, 0, dlgWidth, dlgHeight, SRCCOPY);                         
            }
            ReleaseDC(hDlg, hDC);
        }
        break;
    case WM_ERASEBKGND:
    {
        return 1;
    }
    break;
    case WM_LBUTTONDOWN:
        OutputDebugString(L"DlgProc_VideoPause WM_LBUTTONDOWN pressed\r\n");
        break;
    case WM_KEYDOWN:
        OutputDebugString(L"DlgProc_VideoPause WM_KEYDOWN pressed\r\n");
        break;
    }
    return (INT_PTR)FALSE;
}

单击绘制的图像时,WM_KEYDOWN事件将转到父窗口。我想在对话框proc窗口中收到WM_LBUTTONDOWN和WM_KEYDOWN事件。在对话框proc中我需要做什么来接收这个通知?

我没有创建我的对话框作为子窗口,因为我无法对我的子对话框应用透明。所以我只创建一个无模式对话框。

我在这里遗漏了什么吗?请帮我解决这个问题。

提前致谢。

0 个答案:

没有答案