-
This is VB(like tou didn't know).
Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
WindowProc = CallWindowProc(PrevProc, hwnd, uMsg, wParam, lParam)
If uMsg = WM_RBUTTONDOWN Then
MsgBox "Ok..."
End If
End Function
PrevProc = SetWindowLong(F.hwnd, GWL_WNDPROC, AddressOf WindowProc)
How do i do this in VC++?
To subclass a window, to make that msg pop on some WM.
-
I am not very good in C++. but I'll try :D
Code:
LONG WindowProc(HWND hwnd,LONG uMsg,LONG wParam,LONG lParam)
WindowProc = CallWindowProc(PrevProc, hwnd, uMsg, wParam, lParam);
If (uMsg == WM_RBUTTONDOWN) {
MessageBox()//I am not sure of the Arg's of MessageBox right now
}
}
PrevProc = SetWindowLong(F.hwnd, GWL_WNDPROC,&WindowProc)
-
Keep in mind that C++ datatypes are different from VB. In VB, we would declare almost everything as Long but here we can be more specific.
Code:
LRESULT CALLBACK WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
Regarding MessageBox arguments:
Code:
int nRes = MessageBox("MessageBox Text", "MyProgram", MB_OK | MB_ICONEXCLAMATION);
-
Megatron - you missed the first argument to MessageBox...
Code:
int MessageBox(HWND hWndOwner, LPCTSTR lpszText, LPCTSTR lpszTitle, UINT nFlags);
-
Strange. The one I use is:
Code:
MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption, UNIT nType)
-
The MFC version doesnt need an HWND, the regular API one does. At least that is how I understand it.
-
In MFC, the function without an HWND is a member function of CWnd. Since CWnd has a member variable m_hwnd - it doesn't bother you with having to type it in. I think it expands to something like:
Code:
int CWnd::MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption, UINT nFlags) {
return ::MessageBox(m_hWnd, lpszTest, lpszCaption, nFlags);
}