/ Forside / Teknologi / Udvikling / VB/Basic / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
VB/Basic
#NavnPoint
berpox 2425
pete 1435
CADmageren 1251
gibson 1230
Phylock 887
gandalf 836
AntonV 790
strarup 750
Benjamin... 700
10  tom.kise 610
Kommunikationsproblemer mellem .bas og .cl~
Fra : janprog


Dato : 09-08-02 09:40

Hej

Jeg har lavet et .bas-modul som gør at beskeder fra andre programmer kan
modtages i min egen messagehandler (windowsproc) og derefter kalde en
procedure i hovedprogrammets form. Dette virker fint.

Nu har jeg prøvet at lave en ocx (usercontrol) som bare skal puttes ind i
formen og så skulle den have indbygget messagehandlingen. Dette kan jeg ikke
få til at virke...

Mit problem består (muligvis) i at jeg ikke kan kalde usercontrol-modulet
(.ctl) fra .bas modulet på samme måde som jeg kalder en form. f.eks.

minForm.besked() <- Virker
minUserControl.besked() <- Virker ikke. Compileren siger: Variabel
"minUserControl" is not defined.

Hvis jeg definerer:

dim mUS minUserControl

og kalder mUS.besked() kompilerer programmet fint, men programmet går ned.
(i XP med mulighed for at sende fejlen til MS)

På den anden side *skal* WindowProc() placeres i et .bas module...
Hvordan skal det gøres ordentlig. Det ville være lækkert at kunne komme det
hele ind i en usercontrol.

JanProg


Min program ser sådan ud:

*********************** usercontrol
(.ctl)************************************************************
' i CtlBesked.ctl - Name=CtlBesked



Public Event BeskedAnkommet(parm1 As Long, Parm2 As Long)


Public Sub besked(wParam As Long, lParam As Long)
RaiseEvent BeskedAnkommet(wParam, lParam)
End Sub

Public Sub HookBeskeder(hWindow As Long)
HSE hWindow
End Sub

************************ Module (.bas)
***********************************************************
' i MessageHandler.bas

' dim CB CtlBesked

Private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long


Private 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


' The SetWindowLong function is used to change the window procedure
associated with a
' particular window. This will cause the system to call your own application
defined
' window procedure (WindowProc).

' You should call the CallWindowProc because an application must pass any
messages not
' processed by your own window procedure to the previous window procedure.

' Then some helpful declarations:


Private lpPrevWndProc As Long ' To hold the address of the initial
' window procedure
Private Const GWL_WNDPROC = -4 ' As defined in WinUser.h
Private Const MSG_ID = &H8067& ' The message ID defined according to the
' registry key

' Now we tell windows to pass messages to our own function "WindowProc".
' It would be reasonable to put a call to "HookBeskeder()" in Form_Load()
' and a call to "UnHookBeskeder()" in the Form_Unload().

Public Sub HookBeskeder(hWindow As Long)
lpPrevWndProc = SetWindowLong(hWindow, GWL_WNDPROC, AddressOf WindowProc)
' lpPrevWndProc should now contain the
' address of the previous window procedure
End Sub

Public Sub UnhookBeskeder(hWindow As Long)
SetWindowLong hWindow, GWL_WNDPROC, lpPrevWndProc
' Use the initial window procedure
End Sub

' Then in the function WindowProc(), receive all messages to grap the
message
' identified the msgid value. All other messages should be passed over to
the previous WindowProc.

Function WindowProc(ByVal HW As Long, ByVal uMsg As Long, ByVal wParam As
Long, ByVal lParam As Long) As Long
If uMsg = MSG_ID Then
ctlBesked.Besked wParam, lParam '<<<<---- Variabel "ctlBesked" is not
defined.
CB.Besked WParam, lParam '<<<<---- Giver Runtime Fejl.
Else
WindowProc = CallWindowProc(lpPrevWndProc, HW, uMsg, wParam, lParam)
End If

End Function

Public Sub HSE(hWindow As Long)
lpPrevWndProc = SetWindowLong(hWindow, GWL_WNDPROC, AddressOf WindowProc)
' lpPrevWndProc should now contain the
' address of the previous window procedure
End Sub


*************************Form module (.frm)
**********************************************************
' i Client.frm
' CtlBesked indsat på formen og navngivet aBeskedCtl.

Private Sub aBeskedCtl_BeskedAnkommet(parm1 As Long, parm2 As Long)
MsgBox parm1 & " " & parm2
End Sub

Private Sub Form_Load()
aBeskedCtl.HookBeskeder Me.hWnd
End Sub





 
 
Søg
Reklame
Statistik
Spørgsmål : 177552
Tips : 31968
Nyheder : 719565
Indlæg : 6408847
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste