以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [原创]全局代码报错  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=108934)

--  作者:天一生水
--  发布时间:2017/11/1 9:36:00
--  [原创]全局代码报错

嵌入exe程序到当前窗口的全局代码,原封不动的复制进项目,保存时报错:

 


此主题相关图片如下:2017-11-1.jpg
按此在新窗口浏览图片

 

全局代码:


 

<DllImport("user32.dll", EntryPoint := "FindWindow")> _
Public Function FindWindow(lpClassName As String, lpWindowName As String) As Integer
End Function

<DllImport("user32.dll", EntryPoint := "SetParent")> _
Public Function SetParent(hWndChild As Integer, hWndNewParent As Integer) As Integer
End Function

Public Declare Function MoveWindow Lib "user32" (ByVal hwnd As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Integer) As Integer
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer
Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String) As Integer

Public  Declare Function GetWindow Lib "user32" (ByVal hwnd As Integer, ByVal wCmd As Integer) As Integer
Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Integer
Public Declare Function ShowWindow Lib "user32" (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As EnumWindowsProc, ByVal lParam As Integer) As Integer
Public Delegate Function   EnumWindowsProc(ByVal   hwnd   As   Integer,   ByVal   lParam   As   Integer)   As   Boolean
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Integer) As Integer
Public Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Integer
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Integer) As Integer
Public Const WM_CLOSE = &H10

<DllImport("user32.dll", SetLastError:=True)> _
Public Function GetForegroundWindow() As IntPtr
End Function


<DllImport("user32.dll")> _
Public Function GetWindowTextLength(hWnd As Integer) As Integer
End Function

Public Function EnumWindowsProcCallBack(ByVal   hwnd   As   Integer,   ByVal   lParam   As   Integer)   As   Boolean
      Return Functions.Execute("EnumWindowsProcCallBack", hwnd, lparam)
End   Function

Public Const GW_HWNDFIRST =0
Public Const GW_HWNDLAST = 1
Public Const GW_HWNDNEXT = 2
Public Const GW_HWNDPREV = 3
Public Const GW_OWNER = 4

Public jbs As new List (of String)


--  作者:有点甜
--  发布时间:2017/11/1 9:48:00
--  

 代码没有问题,你应该在全局代码,还写有了类似的相同的代码,比如,下面的代码,如果写了两次,就有问题

 

<DllImport("user32.dll", EntryPoint := "FindWindow")> _
Public Function FindWindow(lpClassName As String, lpWindowName As String) As Integer
End Function

 

<DllImport("user32.dll", EntryPoint := "FindWindow")> _
Public Function FindWindow(lpClassName As String, lpWindowName As String) As Integer
End Function


--  作者:天一生水
--  发布时间:2017/11/1 14:42:00
--  

谢谢田老师!

还剩下一句代码有冲突,去掉哪一边都不行,合在一起也不行,改不了:

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Integer) As Integer

这句与“无边框可移动”的一句全局代码有冲突:

Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer,ByVal wMsg As Integer, ByVal
wParam As Integer, lParam As Integer) As Integer
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Public Sub Panel_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs)
If e.Button=MouseButtons.Left Then
    ReleaseCapture()
    SendMessage(sender.Parent.Handle.ToInt32, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End If
End Sub


--  作者:有点甜
--  发布时间:2017/11/1 15:50:00
--  

删掉这句

 

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer,ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Integer) As Integer