Qt的窗口消息处理函数是哪个
展开全部
重写窗体的nativeEvent事件,就可以了。
示例代码:
函数声明:
protected:
bool nativeEvent(const QByteArray &eventType, void *message, long *result);
函数定义:
bool GWSMainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
if (eventType == "windows_generic_MSG")
{
MSG* msg = reinterpret_cast<MSG*>(message);
switch (msg->message)
{
case WM_COPYDATA:
{
COPYDATASTRUCT *copyData = (COPYDATASTRUCT*)msg->lParam;
int nDataSize = copyData->cbData;
if(nDataSize > 0)
{
char* ch = new char[nDataSize];
memcpy(ch, copyData->lpData, nDataSize);
QString strMsg = QString::fromUtf8(ch);
delete [] ch;
m_msgList.append(strMsg);
int nIndex = m_msgList.count() - 1;
PostMessage((HWND)this->winId(), MYWM_HANDLECOPYDATA, copyData->dwData, nIndex);
}
return true;
}
case MYWM_HANDLECOPYDATA://自定义消息
{
return handleCopyDataMsg(msg->lParam, msg->wParam);
}
case MYWM_UPDATESOFTMGRICON:
{
int nCount = (int)msg->lParam;
m_pSysTitleWidget->updateSoftMgrIcon(nCount);
return true;
}
default:
return QWidget::nativeEvent(eventType, message, result);
}
}
else
return QWidget::nativeEvent(eventType, message, result);
}
示例代码:
函数声明:
protected:
bool nativeEvent(const QByteArray &eventType, void *message, long *result);
函数定义:
bool GWSMainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
if (eventType == "windows_generic_MSG")
{
MSG* msg = reinterpret_cast<MSG*>(message);
switch (msg->message)
{
case WM_COPYDATA:
{
COPYDATASTRUCT *copyData = (COPYDATASTRUCT*)msg->lParam;
int nDataSize = copyData->cbData;
if(nDataSize > 0)
{
char* ch = new char[nDataSize];
memcpy(ch, copyData->lpData, nDataSize);
QString strMsg = QString::fromUtf8(ch);
delete [] ch;
m_msgList.append(strMsg);
int nIndex = m_msgList.count() - 1;
PostMessage((HWND)this->winId(), MYWM_HANDLECOPYDATA, copyData->dwData, nIndex);
}
return true;
}
case MYWM_HANDLECOPYDATA://自定义消息
{
return handleCopyDataMsg(msg->lParam, msg->wParam);
}
case MYWM_UPDATESOFTMGRICON:
{
int nCount = (int)msg->lParam;
m_pSysTitleWidget->updateSoftMgrIcon(nCount);
return true;
}
default:
return QWidget::nativeEvent(eventType, message, result);
}
}
else
return QWidget::nativeEvent(eventType, message, result);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询