请教个问题
void CSuperEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
TCHAR ch[20];
GetWindowText(ch,20);
if (strlen(ch) == 1 && (nChar <= 'C' && nChar >= 'A'))
return;
if (nChar != 'A'
&& nChar != 'B'
&& nChar != 'C'
)
return;
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
-----------------------
我想问一下, 这里最后一句 CEdit::OnChar(nChar, nRepCnt, nFlags); 应该是把其他消息给默认的处理过程了, 但CSuperEdit::OnChar 不需要返回吗?而且 CEdit::OnChar(nChar, nRepCnt, nFlags) 能把消息传给 默认的过程 DefWindowProc (hwnd, message, wParam, lParam) 吗?BOOL C****Dlg::PreTranslateMessage(MSG* pMsg)
{ if( pMsg->message == WM_KEYDOWN )
{
switch( pMsg->wParam )
{
case VK_RETURN:
pMsg->wParam=VK_TAB; }
}
return CDialog::PreTranslateMessage(pMsg);
} 这个函数,这么不是 LRESULT 类型的呀? 因为 回调函数都是 LRESULT 类型的呀?
--------------------------------------------------------------------------------
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_CREATE:
PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
return 0 ; case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}-----------------------------------------------------------请高手指导
void CSuperEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
TCHAR ch[20];
GetWindowText(ch,20);
if (strlen(ch) == 1 && (nChar <= 'C' && nChar >= 'A'))
return;
if (nChar != 'A'
&& nChar != 'B'
&& nChar != 'C'
)
return;
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
-----------------------
我想问一下, 这里最后一句 CEdit::OnChar(nChar, nRepCnt, nFlags); 应该是把其他消息给默认的处理过程了, 但CSuperEdit::OnChar 不需要返回吗?而且 CEdit::OnChar(nChar, nRepCnt, nFlags) 能把消息传给 默认的过程 DefWindowProc (hwnd, message, wParam, lParam) 吗?BOOL C****Dlg::PreTranslateMessage(MSG* pMsg)
{ if( pMsg->message == WM_KEYDOWN )
{
switch( pMsg->wParam )
{
case VK_RETURN:
pMsg->wParam=VK_TAB; }
}
return CDialog::PreTranslateMessage(pMsg);
} 这个函数,这么不是 LRESULT 类型的呀? 因为 回调函数都是 LRESULT 类型的呀?
--------------------------------------------------------------------------------
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_CREATE:
PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
return 0 ; case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}-----------------------------------------------------------请高手指导
wtypes.h中的定义:
typedef long BOOL;
typedef LONG HRESULT;
PreTranslateMessage是用于预处理消息的,在进入窗口过程之前就会被调用,不是被窗口过程调用的,所以不需要返回LRESULT,只需要返回TRUE/FALSE表示消息是否已经被处理了。while(GetMessage(...))
{
if (!PreTranslateMessage(...)) // ---> 只有PreTranslateMessage没有处理这个消息才会调用窗口过程
{
TranslateMessage(...);
DispatchMessage(...); // ---> 这个调用才会进入窗口过程
}
}
这个函数,这么不是 LRESULT 类型的呀? 因为 回调函数都是 LRESULT 类型的呀? -------Nonzero if the message was translated and should not be dispatched; 0 if the message was not translated and should be dispatched.
最终会调用Default()将该消息传递给DefWindowProc 进行处理。当消息返回void时,会使用默认的返回值0.
typedef LONG HRESULT;
typedef BOOL HRESULT; 哪不二义了呀?
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (hwnd, &ps) ;
return 0 ; ----------
为什么这里要返回呀?-------Nonzero if the message was translated and should not be dispatched; 0 if the message was not translated and should be dispatched. 消息被解释并没有分发是非0,消息没有被解释并应该进行分发是0?TranslateMessage(...);
DispatchMessage(...); // ---> 这个调用才会进入窗口过程 消息不都被解释和分发吗?