PDA

Click to See Complete Forum and Search --> : Simple Subclassing (in VB maybe).


Vlatko
Aug 31st, 2000, 10:47 AM
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.

Aug 31st, 2000, 01:11 PM
I am not very good in C++. but I'll try :D



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)

Aug 31st, 2000, 01:47 PM
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.

LRESULT CALLBACK WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);


Regarding MessageBox arguments:

int nRes = MessageBox("MessageBox Text", "MyProgram", MB_OK | MB_ICONEXCLAMATION);

parksie
Aug 31st, 2000, 01:58 PM
Megatron - you missed the first argument to MessageBox...

int MessageBox(HWND hWndOwner, LPCTSTR lpszText, LPCTSTR lpszTitle, UINT nFlags);

Aug 31st, 2000, 03:04 PM
Strange. The one I use is:

MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption, UNIT nType)

CthulhuDragon
Aug 31st, 2000, 03:12 PM
The MFC version doesnt need an HWND, the regular API one does. At least that is how I understand it.

parksie
Aug 31st, 2000, 03:19 PM
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:

int CWnd::MessageBox(LPCTSTR lpszText, LPCTSTR lpszCaption, UINT nFlags) {
return ::MessageBox(m_hWnd, lpszTest, lpszCaption, nFlags);
}