ON_WM_ACTIVATE()

本文介绍了一个Windows应用程序如何处理窗口获得和失去焦点的消息。通过ON_WM_ACTIVATE()响应函数,可以根据不同情况(如激活方式和最小化状态)进行特定操作。
失去焦点和得到焦点响应的是:ON_WM_ACTIVATE()
对应的处理是:afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
nState有三种状态:
WA_INACTIVE The window is being deactivated.
WA_ACTIVE The window is being activated through some method other than a mouse click (for example, by use of the keyboard interface to select the window).
WA_CLICKACTIVE The window is being activated by a mouse click.
当窗口得到或失去焦点时,会触发这个消息.
我们接收到这个消息后,可以判断到底是哪一种状态.

C/C++ code
    
void CXXXDlg::OnActivate( UINT nState, CWnd* pWndOther, BOOL bMinimized ) { CDialog::OnActivate(nState, pWndOther, bMinimized); if (WA_ACTIVE == nState) { ...... } else if (WA_INACTIVE == nState) { ...... } else { ...... } }
WM_HWIN WM_CreateWindowAsChild( int x0, int y0, int width, int height ,WM_HWIN hParent, U32 Style, WM_CALLBACK * cb ,int NumExtraBytes) { WM_Obj * pWin; WM_Obj * pParent; WM_HWIN hWin; //WM_ASSERT_NOT_IN_PAINT(); // May be included again in later versions to avoid application errors WM_LOCK(); Style |= WM__CreateFlags; // // Default parent is Desktop 0 // if (!hParent) { if (WM__NumWindows) { #if GUI_NUM_LAYERS == 1 hParent = WM__ahDesktopWin[0]; #else hParent = WM__ahDesktopWin[GUI_pContext->SelLayer]; #endif } } if (hParent == WM_UNATTACHED) { hParent = WM_HWIN_NULL; } if (hParent) { pParent = WM_LOCK_H(hParent); x0 += pParent->Rect.x0; y0 += pParent->Rect.y0; if (width==0) { width = pParent->Rect.x1 - pParent->Rect.x0+1; } if (height==0) { height = pParent->Rect.y1 - pParent->Rect.y0+1; } GUI_UNLOCK_H(pParent); } if ((hWin = (WM_HWIN) GUI_ALLOC_AllocZero(NumExtraBytes + sizeof(WM_Obj))) == 0) { GUI_DEBUG_ERROROUT("WM.c:\nNo memory to create window in WM_CreateWindowAsChild()"); } else { WM__NumWindows++; pWin = WM_LOCK_H(hWin); pWin->Rect.x0 = x0; pWin->Rect.y0 = y0; pWin->Rect.x1 = x0 + width - 1; pWin->Rect.y1 = y0 + height - 1; pWin->cb = cb; // // Copy the flags which can simply be accepted // pWin->Status |= (Style & (U32)(WM_CF_SHOW | WM_SF_MEMDEV | WM_CF_MEMDEV_ON_REDRAW | WM_SF_STAYONTOP | WM_CF_DISABLED | WM_SF_CONST_OUTLINE | WM_SF_HASTRANS | WM_CF_ANCHOR_RIGHT | WM_CF_ANCHOR_BOTTOM | WM_CF_ANCHOR_LEFT | WM_CF_ANCHOR_TOP | WM_CF_LATE_CLIP | WM_CF_STATIC | WM_CF_MOTION_X | WM_CF_MOTION_Y | WM_CF_GESTURE | WM_CF_MOTION_R | WM_CF_ZOOM)); GUI_UNLOCK_H(pWin); // // Add to linked lists // _AddToLinList(hWin); WM__InsertWindowIntoList(hWin, hParent); // // Activate window if WM_CF_ACTIVATE is specified // if (Style & WM_CF_ACTIVATE) { WM_SelectWindow(hWin); // This is not needed if callbacks are being used, but it does not cost a lot and makes life easier ... } // // Handle the Style flags, one at a time // #if WM_SUPPORT_TRANSPARENCY if (Style & WM_SF_HASTRANS) { WM__TransWindowCnt++; // Increment counter for transparency windows } #endif if (Style & WM_CF_BGND) { WM_BringToBottom(hWin); } if (Style & WM_CF_SHOW) { pWin = WM_LOCK_H(hWin); pWin->Status |= WM_SF_ISVIS; // Set Visibility flag GUI_UNLOCK_H(pWin); WM_InvalidateWindow(hWin); // Mark content as invalid } #if WM_SUPPORT_NOTIFY_VIS_CHANGED if (hParent) { WM__SendMsgNoData(hParent, WM_NOTIFY_VIS_CHANGED); // Notify window that visibility may have changed } #endif WM__SendMsgNoData(hWin, WM_CREATE); } WM_UNLOCK(); return hWin; }
03-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值