Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WIN32 Messages Handle Doubt 4 for LuckyLuke

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Lucky

Yes I am trying to get the messages between that range these are

nLoadMsg = RegisterWindowMessage("CCSLoad")
nQueryMsg = RegisterWindowMessage("CCSQuery")

nLoadRspMsg = RegisterWindowMessage("CNCLoadResponse")
nStartedMsg = RegisterWindowMessage("CNCStarted")
nInterruptedMsg = RegisterWindowMessage("CNCInterrupted")
nResumedMsg = RegisterWindowMessage("CNCResumed")
nFinishedMsg = RegisterWindowMessage("CNCFinished")
nStatusMsg = RegisterWindowMessage("CNCStatus")

So i think I need to give some parameters to windowproc, am i right?


Public Sub Subclass(hWnd As Long)

m_hWnd = hWnd

lpPrevProc = SetWindowLong(m_hWnd, GWL_WNDPROC, AddressOf WindowProc '(->Here)' )


End Sub


I also changed the select sentence to


Public Function WindowProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Select Case wParam
.
.
.

When I run my application it just disapears when it runs the function Subclass

Thanks




 
Basically you've got a mismatch in the declaration of CallWindowProc and your WindowProc. So, when you subclass (and AddressOf does no checking for this sort of thing at all) and the first message arrival actually causes an error. Unfortunately, once you hook the message queue of a window like this the IDE cannot be used to debug, and indeed will crash back to the desktop as you have found.

To eliminate this problem change your declaration of CallWindowProc to:

Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

 
Public Function WindowProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Select Case wMsg
Case Is = nLoadMsg
Select Case wParam
-

'etc, etc, etc...

'you shouldn't forget though, to add this line to the WindowProc function, else you program crashes:

WindowProc = CallWindowProc(lpPrevProc, hWnd, wMsg, wParam, lParam)
End Function

Try doing it like this, or perhaps you could try to change the Select Case wMsg statement in:

If wMsg < MinMsg and wMsg > MaxMsg Then...

Hope this helps,

LuCkY
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top