ModNotepad PInvoke自动选择X86 与X64

Imports System.IO
Imports System.Runtime.InteropServices
Module ModNotepad
    Public intPtr As IntPtr '第三方应用窗口的句柄
    Private Const DLL_FILE_NAME As String = "Notepad2.dll"
    Public Function GetModulePath() As String
        Dim strPath As String = Path.Combine(Path.Combine(Path.Combine(If(IntPtr.Size = 4, "x86", "x64"))), DLL_FILE_NAME)
        If File.Exists(strPath) Then
            strPath = strPath
        End If
        Dim csIntPtr As IntPtr = LoadLibraryA(strPath)
        Return strPath
    End Function

    ''' <summary>
    ''' 调整第三方应用窗体大小
    ''' </summary>
    Public Sub ResizeWindow()
        ShowWindow(intPtr, 0) '先将窗口隐藏
        ShowWindow(intPtr, 3) '再将窗口最大化,可以让第三方窗口自适应容器的大小
    End Sub
    ''' <summary>
    ''' 将第三方窗体嵌入到容器内
    ''' </summary>
    ''' <param name="hWndNewParent">父容器句柄</param>
    Public Sub SetParent(ByVal hWndNewParent As IntPtr)
        SetParent(intPtr, hWndNewParent) '将第三方窗体嵌入父容器
        ShowWindow(intPtr, 3) '让第三方窗体在容器中最大化显示
    End Sub
    Public Delegate Sub NotificationCallback(ByVal message As String)



    <DllImport(DLL_FILE_NAME, CallingConvention:=CallingConvention.Cdecl)>
    Public Sub RegisterCallback(ByVal callback As NotificationCallback)
    End Sub




    <DllImport(DLL_FILE_NAME, CallingConvention:=CallingConvention.Cdecl)>
    Public Function GetHWND() As Integer
    End Function


    <DllImport(DLL_FILE_NAME, CallingConvention:=CallingConvention.Cdecl)>
    Public Sub AddText(bolClear As Boolean, message As String)
    End Sub


    <DllImport(DLL_FILE_NAME, CallingConvention:=CallingConvention.Cdecl)>
    Public Function GetMain_HWND() As IntPtr
    End Function



    <DllImport(DLL_FILE_NAME, CallingConvention:=CallingConvention.Cdecl)>
    Public Sub CloseExe()
    End Sub


    <DllImport(DLL_FILE_NAME, CallingConvention:=CallingConvention.Cdecl)>
    Public Sub Style_Loadvb()
    End Sub






    <DllImport(DLL_FILE_NAME, CallingConvention:=CallingConvention.Cdecl)>
    Public Function GetTextL2() As IntPtr
    End Function






    <DllImport(DLL_FILE_NAME, CallingConvention:=CallingConvention.Cdecl)>
    Public Function wWinMainDLL(ByVal lpCmdLine As String, ByVal nShowCmd As Integer) As Integer
    End Function


    <DllImport("user32.dll ", EntryPoint:="SetParent")>
    Private Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr '将外部窗体嵌入程序
    End Function
    <DllImport("user32.dll", EntryPoint:="ShowWindow", CharSet:=CharSet.Auto)>
    Public Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As Integer) As Integer '设置窗体属性
    End Function
    <DllImport("kernel32")>
    Private Function LoadLibraryA(<MarshalAs(UnmanagedType.LPStr)> ByVal fileName As String) As IntPtr
    End Function

End Module

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值