Guest_imported
New member
- Jan 1, 1970
- 0
Hi, Lucky
Thanks a lot for all your support
I already did what you told me before but I do not get anything, I am sending you the code that I have in my application, please could you tell me if I am missing some parameters.
I really appreciate your help
Thanks
THis is what I have in my module
'''''
Public Type POINTAPI
x As Long
y As Long
End Type
Public Type msg
hWnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Public Declare Function InitAtomTable Lib "kernel32" (ByVal nSize As Long) As Long
Public Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Public Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Integer
Public Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal nAtom As Integer) As Integer
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Public Declare Function GlobalGetAtomName Lib "kernel32" Alias "GlobalGetAtomNameA" (ByVal nAtom As Long, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Const HWND_BROADCAST = &HFFFF&
Public xMsg As msg
Public nLoadMsg, nQueryMsg, nLoadRspMsg, nInterruptedMsg, nStartedMsg, nResumedMsg, nFinishedMsg, nStatusMsg
Public MinMsg As Long, MaxMsg As Long
Public x, y
Public aString As String * 256
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_WNPROC = -4
Private lpPrevProc As Long
Private m_hWnd As Long
Public Sub Subclass(hWnd As Long)
m_hWnd = hWnd
lpPrevProc = SetWindowLong(m_hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnSubClass()
Call SetWindowLong(m_hWnd, GWL_WNDPROC, lpPrevProc)
End Sub
Public Function WindowProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case wMsg.wParam
Case 0
lblStatus.Caption = "No Program Loaded"
lblInterrupt.Caption = ""
Case 1
'dummy = GlobalGetAtomName(xMsg.lParam, aString, 256)
lblStatus.Caption = "Program Loaded and Ready to Run - " & aString
lblInterrupt.Caption = ""
Case 2
'dummy = GlobalGetAtomName(xMsg.lParam, aString, 256)
lblStatus.Caption = "Program Running - " & aString
lblInterrupt.Caption = ""
Case 3
'dummy = GlobalGetAtomName(xMsg.lParam, aString, 256)
lblStatus.Caption = "Program Stopped - " & aString
lblInterrupt.Caption = ""
Select Case Interrupt
Case 0
lblInterrupt.Caption = "Operator pressed Cycle Stop"
Case 1
lblInterrupt.Caption = "E-Stop pressed"
Case 2
lblInterrupt.Caption = "Safety mat tripped"
Case 3
lblInterrupt.Caption = "Machine fault"
Case 4
lblInterrupt.Caption = "Program stopped because of M00 or M01 in program"
End Select
Case 4
dummy = GlobalGetAtomName(xMsg.lParam, aString, 256)
lblStatus.Caption = "Program Finished - " & aString
lblInterrupt.Caption = ""
cmdLoad.Enabled = True
End Select
WindowProc = CallWindowProc(lpPrevProc, hWnd, wMsg, wParam, lParam)
End Function
Public Function RegisterMessages() As Variant
nLoadMsg = RegisterWindowMessage("CCSLoad"
nQueryMsg = RegisterWindowMessage("CCSQuery"
nLoadRspMsg = RegisterWindowMessage("CNCLoadResponse"
nStartedMsg = RegisterWindowMessage("CNCStarted"
nInterruptedMsg = RegisterWindowMessage("CNCInterrupted"
nResumedMsg = RegisterWindowMessage("CNCResumed"
nFinishedMsg = RegisterWindowMessage("CNCFinished"
nStatusMsg = RegisterWindowMessage("CNCStatus"
End Function
'''''''''
THis is the main form
Private Sub cmdLoad_Click()
If m_LoadAtom <> 0 Then
dummy = GlobalDeleteAtom(m_LoadAtom)
m_LoadAtom = 0
End If
m_LoadAtom = GlobalAddAtom(Trim(txtProg.Text))
x = FindWindow(vbNullString, "CNCSim"
y = Me.hWnd
dummy = PostMessage(x, nLoadMsg, m_LoadAtom, y)
If GetMessage(xMsg, Me.hWnd, MinMsg, MaxMsg) Then
lblMsgID.Caption = xMsg.message
lblLParam.Caption = xMsg.lParam
lblWParam.Caption = xMsg.wParam
End If
Select Case xMsg.wParam
Case 0
lblStatus.Caption = "Program Loaded OK"
cmdLoad.Enabled = False
Case 1
lblStatus.Caption = "Program File Not Found"
Case 2
lblStatus.Caption = "Error Opening File"
Case 3
lblStatus.Caption = "Machine is not stopped, cannot load program"
Case 4
lblStatus.Caption = "Program contains errors (see Laser Control display for details)"
End Select
End Sub
Private Sub Form_Load()
dummy = RegisterMessages()
Call Subclass(Me.hWnd)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call UnSubClass
End Sub
Thanks a lot for all your support
I already did what you told me before but I do not get anything, I am sending you the code that I have in my application, please could you tell me if I am missing some parameters.
I really appreciate your help
Thanks
THis is what I have in my module
'''''
Public Type POINTAPI
x As Long
y As Long
End Type
Public Type msg
hWnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Public Declare Function InitAtomTable Lib "kernel32" (ByVal nSize As Long) As Long
Public Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Public Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Integer
Public Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal nAtom As Integer) As Integer
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Public Declare Function GlobalGetAtomName Lib "kernel32" Alias "GlobalGetAtomNameA" (ByVal nAtom As Long, ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Const HWND_BROADCAST = &HFFFF&
Public xMsg As msg
Public nLoadMsg, nQueryMsg, nLoadRspMsg, nInterruptedMsg, nStartedMsg, nResumedMsg, nFinishedMsg, nStatusMsg
Public MinMsg As Long, MaxMsg As Long
Public x, y
Public aString As String * 256
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_WNPROC = -4
Private lpPrevProc As Long
Private m_hWnd As Long
Public Sub Subclass(hWnd As Long)
m_hWnd = hWnd
lpPrevProc = SetWindowLong(m_hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnSubClass()
Call SetWindowLong(m_hWnd, GWL_WNDPROC, lpPrevProc)
End Sub
Public Function WindowProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case wMsg.wParam
Case 0
lblStatus.Caption = "No Program Loaded"
lblInterrupt.Caption = ""
Case 1
'dummy = GlobalGetAtomName(xMsg.lParam, aString, 256)
lblStatus.Caption = "Program Loaded and Ready to Run - " & aString
lblInterrupt.Caption = ""
Case 2
'dummy = GlobalGetAtomName(xMsg.lParam, aString, 256)
lblStatus.Caption = "Program Running - " & aString
lblInterrupt.Caption = ""
Case 3
'dummy = GlobalGetAtomName(xMsg.lParam, aString, 256)
lblStatus.Caption = "Program Stopped - " & aString
lblInterrupt.Caption = ""
Select Case Interrupt
Case 0
lblInterrupt.Caption = "Operator pressed Cycle Stop"
Case 1
lblInterrupt.Caption = "E-Stop pressed"
Case 2
lblInterrupt.Caption = "Safety mat tripped"
Case 3
lblInterrupt.Caption = "Machine fault"
Case 4
lblInterrupt.Caption = "Program stopped because of M00 or M01 in program"
End Select
Case 4
dummy = GlobalGetAtomName(xMsg.lParam, aString, 256)
lblStatus.Caption = "Program Finished - " & aString
lblInterrupt.Caption = ""
cmdLoad.Enabled = True
End Select
WindowProc = CallWindowProc(lpPrevProc, hWnd, wMsg, wParam, lParam)
End Function
Public Function RegisterMessages() As Variant
nLoadMsg = RegisterWindowMessage("CCSLoad"
nQueryMsg = RegisterWindowMessage("CCSQuery"
nLoadRspMsg = RegisterWindowMessage("CNCLoadResponse"
nStartedMsg = RegisterWindowMessage("CNCStarted"
nInterruptedMsg = RegisterWindowMessage("CNCInterrupted"
nResumedMsg = RegisterWindowMessage("CNCResumed"
nFinishedMsg = RegisterWindowMessage("CNCFinished"
nStatusMsg = RegisterWindowMessage("CNCStatus"
End Function
'''''''''
THis is the main form
Private Sub cmdLoad_Click()
If m_LoadAtom <> 0 Then
dummy = GlobalDeleteAtom(m_LoadAtom)
m_LoadAtom = 0
End If
m_LoadAtom = GlobalAddAtom(Trim(txtProg.Text))
x = FindWindow(vbNullString, "CNCSim"
y = Me.hWnd
dummy = PostMessage(x, nLoadMsg, m_LoadAtom, y)
If GetMessage(xMsg, Me.hWnd, MinMsg, MaxMsg) Then
lblMsgID.Caption = xMsg.message
lblLParam.Caption = xMsg.lParam
lblWParam.Caption = xMsg.wParam
End If
Select Case xMsg.wParam
Case 0
lblStatus.Caption = "Program Loaded OK"
cmdLoad.Enabled = False
Case 1
lblStatus.Caption = "Program File Not Found"
Case 2
lblStatus.Caption = "Error Opening File"
Case 3
lblStatus.Caption = "Machine is not stopped, cannot load program"
Case 4
lblStatus.Caption = "Program contains errors (see Laser Control display for details)"
End Select
End Sub
Private Sub Form_Load()
dummy = RegisterMessages()
Call Subclass(Me.hWnd)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call UnSubClass
End Sub