Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Runtime.InteropServices
- Imports System.IO
- Imports System.Windows.Forms.OpenFileDialog
- Imports System.Windows.Forms.SaveFileDialog
- Public Class UnicodeEditor
- Private Const CLASS_NAME As String = "UED"
- Private Const APP_TITLE As String = "Unicode Editor"
- Private Const WS_CAPTION As Integer = &HC00000
- Private Const WS_MAXIMIZEBOX As Integer = &H10000
- Private Const WS_MINIMIZEBOX As Integer = &H20000
- Private Const WS_OVERLAPPED As Integer = &H0
- Private Const WS_SYSMENU As Integer = &H80000
- Private Const WS_THICKFRAME As Integer = &H40000
- Private Const WS_OVERLAPPEDWINDOW As Integer = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
- Private Const CS_HREDRAW As Integer = &H2
- Private Const CS_VREDRAW As Integer = &H1
- Private Const IDI_APPLICATION As Integer = 32512
- Private Const IDC_ARROW As Integer = 32512
- Private Const LTGRAY_BRUSH As Integer = 1
- Private Const SW_SHOWNORMAL As Integer = 1
- Private Const WM_USER = &H400
- Private Const WM_SIZE = &H5
- Private Const WM_COMMAND = &H111
- Private Const WM_DESTROY As Integer = &H2
- Private Const WM_LBUTTONDOWN As Integer = &H201
- Private Const WM_ACTIVATEAPP = &H1C
- Private Const WM_CLOSE = &H10
- Private Const WM_SETTEXT = &HC
- Private Const WM_GETTEXT = &HD
- Private Const WM_GETTEXTLENGTH = &HE
- Private Const WM_NOTIFY = &H4E
- Private Const WM_RBUTTONDOWN = &H204
- Private Const WM_PARENTNOTIFY = &H210
- Private Const WM_CONTEXTMENU As Long = &H7B
- Private Const WM_INITMENUPOPUP = &H117
- Private Const MB_OK As Integer = &H0
- Private Const EN_SETFOCUS = &H100
- Private Const EN_KILLFOCUS = &H200
- Private Const EN_CHANGE = &H300
- Private Const EN_UPDATE = &H400
- Private Const EN_ERRSPACE = &H500
- Private Const EN_MAXTEXT = &H501
- Private Const EN_HSCROLL = &H601
- Private Const EN_VSCROLL = &H602
- Private Const EN_SelChanged = &h702
- Private Const ENM_CHANGE = &h1
- Private Const ENM_SELCHANGE = &h80000
- Private Const ENM_MOUSEEVENTS = &h20000
- Private Const EC_LEFTMARGIN = &H1
- Private Const EC_RIGHTMARGIN = &H2
- Private Const EC_USEFONTINFO = &HFFFF
- Private Const EMSIS_COMPOSITIONSTRING = &H1
- Private Const EIMES_GETCOMPSTRATONCE = &H1
- Private Const EIMES_CANCELCOMPSTRINFOCUS = &H2
- Private Const EIMES_COMPLETECOMPSTRKILLFOCUS = &H4
- Private Const EM_AUTOURLDETECT = WM_USER + 91
- Private Const EM_GETAUTOURLDETECT = WM_USER + 92
- Private Const EM_GETSEL = &HB0
- Private Const EM_SETSEL = &HB1
- Private Const EM_GETRECT = &HB2
- Private Const EM_SETRECT = &HB3
- Private Const EM_SETRECTNP = &HB4
- Private Const EM_SCROLL = &HB5
- Private Const EM_LINESCROLL = &HB6
- Private Const EM_SCROLLCARET = &HB7
- Private Const EM_GETMODIFY = &HB8
- Private Const EM_SETMODIFY = &HB9
- Private Const EM_GETLINECOUNT = &HBA
- Private Const EM_LINEINDEX = &HBB
- Private Const EM_SETHANDLE = &HBC
- Private Const EM_GETHANDLE = &HBD
- Private Const EM_GETTHUMB = &HBE
- Private Const EM_LINELENGTH = &HC1
- Private Const EM_REPLACESEL = &HC2
- Private Const EM_GETLINE = &HC4
- Private Const EM_LIMITTEXT = &HC5
- Private Const EM_CANUNDO = &HC6
- Private Const EM_UNDO = &HC7
- Private Const EM_FMTLINES = &HC8
- Private Const EM_LINEFROMCHAR = &HC9
- Private Const EM_SETTABSTOPS = &HCB
- Private Const EM_SETPASSWORDCHAR = &HCC
- Private Const EM_EMPTYUNDOBUFFER = &HCD
- Private Const EM_GETFIRSTVISIBLELINE = &HCE
- Private Const EM_SETREADONLY = &HCF
- Private Const EM_SETWORDBREAKPROC = &HD0
- Private Const EM_GETWORDBREAKPROC = &HD1
- Private Const EM_GETPASSWORDCHAR = &HD2
- Private Const EM_SETMARGINS = &HD3
- Private Const EM_GETMARGINS = &HD4
- Private Const EM_GETLIMITTEXT = &HD5
- Private Const EM_POSFROMCHAR = &HD6
- Private Const EM_CHARFROMPOS = &HD7
- Private Const EM_SETIMESTATUS = &HD8
- Private Const EM_GETIMESTATUS = &HD9
- Private Const EM_SETOPTIONS = (&H400 + 77)
- Private Const EM_SETLANGOPTIONS = (&H400 + 120)
- Private Const EM_GETLANGOPTIONS = (&H400 + 121)
- Private Const EM_CANPASTE = (&H400 + 50)
- Private Const EM_EXLIMITTEXT = (&H400 + 53)
- Private Const EM_SETUNDOLIMIT = (&H400 + 82)
- Private Const EM_REDO = (&H400 + 84)
- Private Const EM_CANREDO = (&H400 + 85)
- Private Const EM_GETUNDONAME = (&H400 + 86)
- Private Const EM_GETREDONAME = (&H400 + 87)
- Private Const EM_STOPGROUPTYPING = (&H400 + 88)
- Private Const EM_PASTESPECIAL = (&H400 + 64)
- Private Const EM_GETOPTIONS = (&H400 + 78)
- Private Const EM_GETTEXTRANGE = &H400 + 75
- Private Const EM_GETOLEINTERFACE = (&H400 + 60)
- Private Const EM_SETTARGETDEVICE = (&H400 + 72)
- Private Const EM_SETEVENTMASK = (&H400 + 69)
- Private Const EM_GETEVENTMASK = (&H400 + 59)
- 'Extended edit style specific messages
- Private Const EM_SETEDITSTYLE = (&H400 + 204)
- Private Const EM_GETEDITSTYLE = (&H400 + 205)
- Private Const EM_SETTYPOGRAPHYOPTIONS = (&H400 + 202)
- Private Const EM_GETTYPOGRAPHYOPTIONS = (&H400 + 203)
- Private Const EM_GETCTFOPENSTATUS = (&H400 + 240)
- Private Const EM_SETCTFOPENSTATUS = (&H400 + 241)
- Private Const EM_SETZOOM = &h400 + 225
- ' Extended edit style masks
- Private Const SES_EMULATESYSEDIT = 1
- Private Const SES_BEEPONMAXTEXT = 2
- Private Const SES_EXTENDBACKCOLOR = 4
- Private Const SES_MAPCPS = 8 ' (obsolete)
- Private Const SES_EMULATE10 = 16 ' (obsolete)
- Private Const SES_USECRLF = 32 ' (obsolete)
- Private Const SES_NOXLTSYMBOLRANGE = 32
- Private Const SES_USEAIMM = 64
- Private Const SES_NOIME = 128
- Private Const SES_ALLOWBEEPS = 256
- Private Const SES_UPPERCASE = 512
- Private Const SES_LOWERCASE = 1024
- Private Const SES_NOINPUTSEQUENCECHK = 2048
- Private Const SES_BIDI = 4096
- Private Const SES_SCROLLONKILLFOCUS = 8192
- Private Const SES_XLTCRCRLFTOCR = 16384
- Private Const SES_DRAFTMODE = 32768
- Private Const SES_USECTF = &H10000
- Private Const SES_HIDEGRIDLINES = &H20000
- Private Const SES_USEATFONT = &H40000
- Private Const SES_CUSTOMLOOK = &H80000
- Private Const SES_LBSCROLLNOTIFY = &H100000
- Private Const SES_CTFALLOWEMBED = &H200000
- Private Const SES_CTFALLOWSMARTTAG = &H400000
- Private Const SES_CTFALLOWPROOFING = &H800000
- Private Const EM_SETTEXTMODE = (&H400 + 89)
- Private Const EM_GETTEXTMODE = (&H400 + 90)
- Private Const TM_PLAINTEXT = 1
- Private Const TM_RICHTEXT = 2
- Private Const TM_SINGLELEVELUNDO = 4
- Private Const TM_MULTILEVELUNDO = 8
- Private Const TM_SINGLECODEPAGE = 16
- Private Const TM_MULTICODEPAGE = 32
- Private Const ECO_AUTOWORDSELECTION = &H1
- Private Const ECO_AUTOVSCROLL = &H40
- Private Const ECO_AUTOHSCROLL = &H80
- Private Const ECO_NOHIDESEL = &H100
- Private Const ECO_READONLY = &H800
- Private Const ECO_WANTRETURN = &H1000
- Private Const ECO_SAVESEL = &H8000
- Private Const ECO_SELECTIONBAR = &H1000000
- Private Const ECOOP_SET = &H1
- Private Const ECOOP_OR = &H2
- Private Const ECOOP_AND = &H3
- Private Const ECOOP_XOR = &H4
- Private Const TO_ADVANCEDTYPOGRAPHY = 1
- Private Const TO_SIMPLELINEBREAK = 2
- Private Const TO_DISABLECUSTOMTEXTOUT = 4
- Private Const TO_ADVANCEDLAYOUT = 8
- Private Const TO_None = 0
- Private Const WB_LEFT = 0
- Private Const WB_RIGHT = 1
- Private Const WB_ISDELIMITER = 2
- Private Const WB_CLASSIFY = 3
- Private Const WB_MOVEWORDLEFT = 4
- Private Const WB_MOVEWORDRIGHT = 5
- Private Const WB_LEFTBREAK = 6
- Private Const WB_RIGHTBREAK = 7
- Private Const EM_FINDWORDBREAK = (&H400 + 76)
- Private Const WBF_ISWHITE = &H10
- Private Const WBF_BREAKLINE = &H20
- Private Const WBF_BREAKAFTER = &H40
- Private Const IMF_AUTOKEYBOARD = &H1
- Private Const IMF_AUTOFONT = &H2
- Private Const IMF_IMECANCELCOMPLETE = &H4 'High completes comp string when aborting, low cancels
- Private Const IMF_IMEALWAYSSENDNOTIFY = &H8
- Private Const IMF_AUTOFONTSIZEADJUST = &H10 '16
- Private Const IMF_UIFONTS = &H20 '32
- Private Const IMF_DUALFONT = &H80 '128
- Private Const IMF_None = &H0 '0
- Private Const IMF_SPELLCHECKING = &H800
- Private Const CP_ACP = 0 ' default to ANSI code page
- Private Const CP_OEMCP = 1 ' default to OEM code page
- Private Const CP_MACCP = 2 ' default to MAC code page
- Private Const CP_THREAD_ACP = 3 ' current thread's ANSI code page
- Private Const CP_SYMBOL = 42 ' SYMBOL translations
- Private Const CP_Unicode = 1200 ' Unicode
- Private Const CP_UTF7 = 65000 ' UTF-7 translation
- Private Const CP_UTF8 = 65001 ' UTF-8 translation
- Private Const ES_AUTOHSCROLL = &H80&
- Private Const ES_AUTOVSCROLL = &H40&
- Private Const ES_CENTER = &H1&
- Private Const ES_LEFT = &H0&
- Private Const ES_LOWERCASE = &H10&
- Private Const ES_MULTILINE = &H4&
- Private Const ES_NOHIDESEL = &H100&
- Private Const ES_OEMCONVERT = &H400&
- Private Const ES_PASSWORD = &H20&
- Private Const ES_READONLY = &H800&
- Private Const ES_RIGHT = &H2&
- Private Const ES_UPPERCASE = &H8&
- Private Const ES_WANTRETURN = &H1000&
- Private Const ES_NUMBER = &H2000
- Private Const WS_BORDER = &H800000
- Private Const WS_CHILD = &H40000000
- Private Const WS_CHILDWINDOW = (&H40000000)
- Private Const WS_CLIPCHILDREN = &H2000000
- Private Const WS_CLIPSIBLINGS = &H4000000
- Private Const WS_DISABLED = &H8000000
- Private Const WS_DLGFRAME = &H400000
- Private Const WS_EX_ACCEPTFILES = &H10&
- Private Const WS_EX_APPWINDOW = &H40000
- Private Const WS_EX_CLIENTEDGE = &H200
- Private Const WS_EX_COMPOSITED = &H2000000
- Private Const WS_EX_CONTEXTHELP = &H400
- Private Const WS_EX_CONTROLPARENT = &H10000
- Private Const WS_EX_DLGMODALFRAME = &H1
- Private Const WS_EX_LAYERED = &H80000
- Private Const WS_EX_LAYOUTRTL = &H400000 ' Right to left mirroring
- Private Const WS_EX_LEFT = &H0
- Private Const WS_EX_LEFTSCROLLBAR = &H4000
- Private Const WS_EX_LTRREADING = &H0
- Private Const WS_EX_MDICHILD = &H40
- Private Const WS_EX_NOACTIVATE = &H8000000
- Private Const WS_EX_NOINHERITLAYOUT = &H100000 ' Disable inheritence of mirroring by children
- Private Const WS_EX_NOPARENTNOTIFY = &H4
- ' Private Const WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE + WS_EX_CLIENTEDGE)
- ' Private Const WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE + WS_EX_TOOLWINDOW + WS_EX_TOPMOST)
- Private Const WS_EX_RIGHT = &H1000
- Private Const WS_EX_RIGHTSCROLLBAR = &H0
- Private Const WS_EX_RTLREADING = &H2000
- Private Const WS_EX_STATICEDGE = &H20000
- Private Const WS_EX_TOOLWINDOW = &H80
- Private Const WS_EX_TOPMOST = &H8
- Private Const WS_EX_TRANSPARENT = &H20&
- Private Const WS_EX_WINDOWEDGE = &H100
- Private Const WS_GROUP = &H20000
- Private Const WS_HSCROLL = &H100000
- Private Const WS_ICONIC = &H1000000
- Private Const WS_POPUP = &H80000000
- ' Private Const WS_POPUPWINDOW = (WS_POPUP + WS_B + DER + WS_SYSMENU)
- Private Const WS_SIZEBOX = &H40000
- Private Const WS_TABSTOP = &H10000
- Private Const WS_TILED = &H0&
- Private Const WS_TILEDWINDOW = (&H0& + &HC00000 + &H80000 + &H40000 + &H20000 + &H10000)
- Private Const WS_VISIBLE = &H10000000
- Private Const WS_VSCROLL = &H200000
- Private Const HWND_NOTOPMOST = -2
- Private Const SWP_SHOWWINDOW = &H40
- Private Const SWP_NOZORDER = &H4
- Private Const SWP_NOSIZE = &H1
- Private Const SWP_NOREPOSITION = &H200
- Private Const SWP_NOREDRAW = &H8
- Private Const SWP_NOOWNERZORDER = &H200 ' Don't do owner Z ordering
- Private Const SWP_NOMOVE = &H2
- Private Const SWP_NOCOPYBITS = &H100
- Private Const SWP_NOACTIVATE = &H10
- Private Const SWP_HIDEWINDOW = &H80
- Private Const SWP_FRAMECHANGED = &H20 ' The frame changed: send WM_NCCALCSIZE
- Private Const SWP_DRAWFRAME = &H20
- Private Const MF_POPUP = &H10
- Private Const MF_SEPARATOR = &H800
- Private Const TPM_RIGHTBUTTON = &H2
- Private Const TPM_LEFTALIGN = &H0
- Private Const TPM_NONOTIFY = &H80
- Private Const TPM_RETURNCMD = &H100
- Private Const MF_BYCOMMAND = &H0&
- Private Const MF_GRAYED = &H1&
- Private Const MF_ENABLED = &H0&
- Private Const MF_UNCHECKED = &H0&
- Private Const MF_CHECKED = &H8&
- Private Const CF_UNICODETEXT= 13
- Private Const OFN_READONLY = &H1
- Private Const OFN_OVERWRITEPROMPT = &H2
- Private Const OFN_HIDEREADONLY = &H4
- Private Const OFN_NOCHANGEDIR = &H8
- Private Const OFN_SHOWHELP = &H10
- Private Const OFN_ENABLEHOOK = &H20
- Private Const OFN_ENABLETEMPLATE = &H40
- Private Const OFN_ENABLETEMPLATEHANDLE = &H80
- Private Const OFN_NOVALIDATE = &H100
- Private Const OFN_ALLOWMULTISELECT = &H200
- Private Const OFN_EXTENSIONDIFFERENT = &H400
- Private Const OFN_PATHMUSTEXIST = &H800
- Private Const OFN_FILEMUSTEXIST = &H1000
- Private Const OFN_CREATEPROMPT = &H2000
- Private Const OFN_SHAREAWARE = &H4000
- Private Const OFN_NOREADONLYRETURN = &H8000
- Private Const OFN_NOTESTFILECREATE = &H10000
- Private Const OFN_NONETWORKBUTTON = &H20000
- Private Const OFN_NOLONGNAMES = &H40000 ' force no long names for 4.x modules
- Private Const OFN_EXPLORER = &H80000 ' new look commdlg
- Private Const OFN_NODEREFERENCELINKS = &H100000
- Private Const OFN_LONGNAMES = &H200000 ' force long names for 3.x modules
- Private Const OFN_SHAREFALLTHROUGH = 2
- Private Const OFN_SHARENOWARN = 1
- Private Const OFN_SHAREWARN = 0
- Private const OFN_FORCESHOWHIDDEN = &h10000000
- Private Const FVIRTKEY = True ' Assumed to be == TRUE
- Private Const FNOINVERT = &H2
- Private Const FSHIFT = &H4
- Private Const FCONTROL = &H8
- Private Const FALT = &H10
- Private Delegate Function WndProcDelgate(ByVal hWnd As IntPtr, ByVal Message As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
- <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
- Private Structure WNDCLASSEX
- Public cbSize As Integer ' Size in bytes of the WNDCLASSEX structure
- Public style As Integer ' Class style
- Public lpfnWndProc As WndProcDelgate ' Pointer to the classes Window Procedure
- Public cbClsExtra As Integer ' Number of extra bytes to allocate for class
- Public cbWndExtra As Integer ' Number of extra bytes to allocate for window
- Public hInstance As IntPtr ' Applications instance handle Class
- Public hIcon As IntPtr ' Handle to the classes icon
- Public hCursor As IntPtr ' Handle to the classes cursor
- Public hbrBackground As IntPtr ' Handle to the classes background brush
- Public lpszMenuName As String ' Resource name of class menu
- Public lpszClassName As String ' Name of the Window Class
- Public hIconSm As IntPtr ' Handle to the classes small icon
- End Structure
- <StructLayout(LayoutKind.Sequential)> _
- Private Structure POINTAPI
- Public x As Integer ' X-Coordinate in pixels
- Public y As Integer ' Y-Coordinate in pixels
- End Structure
- <StructLayout(LayoutKind.Sequential)> _
- Private Structure RECTL
- Public Left As Integer
- Public Top As Integer
- Public Right As Integer
- Public Bottom As Integer
- End Structure
- <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
- Private Structure MSG
- Public hWnd As IntPtr ' Window handle of the associated window
- Public Message As Integer ' Message identifier
- Public wParam As IntPtr ' Additional message info
- Public lParam As IntPtr ' Additional message info
- Public time As Integer ' Time message was posted
- Public pt As POINTAPI ' Cursor position when message was posted
- End Structure
- <StructLayout(LayoutKind.Sequential)> _
- Private Structure nmhdr
- Public hwndFrom As IntPtr
- Public idFrom As IntPtr
- Public code As IntPtr
- End Structure
- <StructLayout(LayoutKind.Sequential)> _
- Private Structure charrange
- Public cpMin As Integer
- Public cpMax As Integer
- End Structure
- <StructLayout(LayoutKind.Sequential)> _
- Private Structure selchange
- Public nmhdr As NMHDR
- Public chrg As CharRange
- Public seltyp As Short
- End Structure
- <StructLayout(LayoutKind.Sequential)> _
- Private Structure ACCEL
- Public fVirt As Byte
- Public key As Short
- Public cmd As Short
- End Structure
- Private Declare Function CreateAcceleratorTableW Lib "user32" (lpaccl As ACCEL, ByVal cEntries As Integer) As IntPtr
- Private Declare Function TranslateAcceleratorW Lib "user32" (ByVal hwnd As IntPtr, ByVal hAccTable As IntPtr, lpMsg As MSG) As Integer
- Private Declare Function DestroyAcceleratorTable Lib "user32" (ByVal haccel As IntPtr) As Integer
- Private Declare Auto Function LoadCursor Lib "user32" (ByVal hInstance As IntPtr, ByVal lpCursorName As IntPtr) As IntPtr
- Private Declare Auto Function LoadIcon Lib "user32" (ByVal hInstance As IntPtr, ByVal lpIconName As IntPtr) As IntPtr
- Private Declare Unicode Function LoadLibraryW Lib "kernel32" (ByVal lpLibFileName As String) As Integer
- Private Declare Unicode Function RegisterClassExW Lib "user32" (ByRef pcWndClassEx As WNDCLASSEX) As Integer
- Private Declare Unicode Function CreateWindowExW Lib "user32" (ByVal dwExStyle As Integer, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hWndParent As IntPtr, ByVal hMenu As IntPtr, ByVal hInstance As IntPtr, ByVal lpParam As IntPtr) As IntPtr
- Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
- Private Declare Function UpdateWindow Lib "user32" (ByVal hWnd As IntPtr) As Boolean
- Private Declare Auto Function GetMessage Lib "user32" (ByRef lpMsg As MSG, ByVal hWnd As IntPtr, ByVal wMsgFilterMin As Integer, ByVal wMsgFilterMax As Integer) As Boolean
- Private Declare Function TranslateMessage Lib "user32" (ByRef lpMsg As MSG) As Boolean
- Private Declare Auto Function DispatchMessage Lib "user32" (ByRef lpMsg As MSG) As IntPtr
- Private Declare Sub PostQuitMessage Lib "user32" (ByVal nExitCode As Integer)
- Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Integer) As IntPtr
- Private Declare Unicode Function MessageBoxW Lib "user32" (ByVal hWnd As IntPtr, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Integer) As Integer
- Private Declare Function SetFocus Lib "user32" (ByVal hWnd As IntPtr) As IntPtr
- Private Declare Auto Function DefWindowProc Lib "user32" (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
- Private Declare Auto Function SendMessageW Lib "user32" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Integer
- Private Declare Unicode Function SendMessageObj Lib "user32" alias "SendMessageW" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As IntPtr, <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.Interface)> ByRef lparam As Object) As Integer
- Private Declare Unicode Function SendMessageStr Lib "user32" alias "SendMessageW" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As IntPtr, ByVal lParam as String) As Integer
- Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
- Private Declare Unicode Function LoadMenuW Lib "user32" (ByVal hInstance As Integer, ByVal lpString As String) As Integer
- Private Declare Function SetMenu Lib "user32" Alias "SetMenu" (ByVal hwnd As Integer, ByVal hMenu As Integer) As Integer
- Private Declare Function CreateMenu Lib "user32" () As Integer
- Private Declare Function CreatePopupMenu Lib "user32" () As Integer
- Private Declare Function DrawMenuBar Lib "user32" (ByVal hMenuBar as Integer) As Integer
- Private Declare Unicode Function AppendMenuW Lib "user32" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal wIDNewItem As Integer, ByVal lpNewItem As String) As Integer
- Private Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Intptr, ByVal wFlags As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nReserved As Integer, ByVal hwnd As Intptr, ByVal ptrToNothing as intptr) As Integer
- Private Declare Function GetSubMenu Lib "user32" Alias "GetSubMenu" (ByVal hMenu As IntPtr, ByVal nPos As Integer) As IntPtr
- Private Declare Function DestroyMenu Lib "User32" (ByVal hMenu as Intptr) as Integer
- Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As Intptr, ByVal wIDEnableItem As Integer, ByVal wEnable As Integer) As Integer
- Private Declare Function CheckMenuItem Lib "user32" (ByVal hMenu As IntPtr, ByVal wIDEnableItem As Integer, ByVal wEnable As Integer) As Integer
- Private Declare Function CheckMenuRadioItem Lib "user32" (ByVal hMenu As IntPtr, ByVal un1 As Integer, ByVal un2 As Integer, ByVal un3 As Integer, ByVal un4 As Integer) As Integer
- ' Private Declare Function GetOpenFileNameW Lib "comdlg32.dll" (ByVal pOpenfilename As OPENFILENAME) As Integer
- ' Private Declare Function GetSaveFileNameW Lib "comdlg32.dll" (pOpenfilename As OPENFILENAME) As Integer
- ' Private Declare Function GetFileTitleW Lib "comdlg32.dll" (ByVal lpszFile As String, ByVal lpszTitle As String, ByVal cbBuf As Integer) As Short
- Private Declare Function GetDC Lib "user32" (ByVal hwnd As IntPtr) As IntPtr
- '==============================
- 'Global variables
- '===============================
- Public Dim Ret as Integer
- Public Dim gRTFHwnd as Intptr
- Public Dim RTFID as Integer
- Public Dim hWnd as Intptr
- Public Dim hInstance as IntPtr
- Public Dim TomDoc as Object
- Public Dim TomSel as Object
- Public Dim hMenuBar As Intptr
- Public Dim hFileMenu As Intptr
- Public Dim hFileSaveAsFormatMenu As Intptr
- Public Dim hHelpMenu As Intptr
- Public Dim hContextMenu as Intptr
- Public Dim hEditMenu as Intptr
- Public Dim hViewMenu as Intptr
- Public Dim gFileIsDirty as Boolean
- Public Dim gFileHasName as Boolean
- Public Dim WshShell as Object
- Public Dim FSO as Object
- '==============================
- 'Main program start called by sub main.
- '===============================
- Public Sub New()
- Dim wndClass As WNDCLASSEX
- Dim hWnd As IntPtr
- Dim Message As MSG
- hInstance = Marshal.GetHINSTANCE(GetType(UnicodeEditor).Module)
- '======================================
- 'Register and create the main window
- '------------------------------------------------
- With wndClass
- .style = CS_HREDRAW Or CS_VREDRAW
- .lpfnWndProc = New WndProcDelgate(AddressOf WndProc)
- .cbClsExtra = 0
- .cbWndExtra = 0
- .hInstance = hInstance
- .hIcon = LoadIcon(hInstance, New IntPtr(IDI_APPLICATION))
- .hIconSm = LoadIcon(hInstance, New IntPtr(IDI_APPLICATION))
- .hCursor = LoadCursor(hInstance, New IntPtr(IDC_ARROW))
- .hbrBackground = GetStockObject(LTGRAY_BRUSH)
- .lpszMenuName = Nothing
- .lpszClassName = CLASS_NAME
- .cbSize = Marshal.SizeOf(wndClass)
- End With
- RegisterClassExW (wndClass)
- hWnd = CreateWindowExW (0, CLASS_NAME, APP_TITLE, WS_OVERLAPPEDWINDOW, 300, 200, 640, 480, IntPtr.Zero, nothing , hInstance, IntPtr.Zero)
- '======================================
- 'Register and create the RTF window
- '------------------------------------------------
- Dim DLLModule as Integer
- Dim Flags as Integer
- DLLModule = LoadLibraryW("c:\windows\system32\MSFTEDIT.dll")
- If DLLModule = 0 Then MsgBox("Load Lib " & Err.LastDllError)
- Flags = WS_CHILD + WS_HSCROLL + WS_VSCROLL + WS_VISIBLE + ES_MULTILINE + ES_AUTOHSCROLL + ES_AUTOVSCROLL + ES_NOHIDESEL + ES_WANTRETURN
- Dim RTFClassName As String
- RTFID = &hff00
- RTFClassName = "RICHEDIT50W" & vbNullChar
- gRtfHwnd = CreateWindowExW(WS_EX_ACCEPTFILES + WS_EX_CLIENTEDGE, RTFClassName, "", Flags, 0, 0, 600, 400, hwnd, RTFID, DLLModule, IntPtr.Zero)
- '======================================
- 'Create Menus
- '------------------------------------------------
- hMenuBar = CreateMenu()
- 'SaveAs format Menu
- hFileSaveAsFormatMenu = CreatePopupMenu()
- If AppendMenuW(hFileSaveAsFormatMenu, 0, 190, "&Dos") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hFileSaveAsFormatMenu, 0, 191, "A&NSI") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hFileSaveAsFormatMenu, 0, 192, "&UTF8") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hFileSaveAsFormatMenu, 0, 193, "U&TF16") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hFileSaveAsFormatMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hFileSaveAsFormatMenu, 0, 194, "&Auto") = 0 then Msgbox("Append " & Err.LastDllError)
- Ret = CheckMenuRadioItem(hFileSaveAsFormatMenu, 190, 194, 191, mf_bycommand)
- 'File Menu
- hFileMenu = CreatePopupMenu()
- If AppendMenuW(hFileMenu, 0, 101, "&New" & vbtab & "Ctrl+N") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hFileMenu, 0, 102, "O&pen ..." & vbtab & "Ctrl+O") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hFileMenu, 0, 103, "S&ave" & vbtab & "Ctrl+S") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hFileMenu, 0, 104, "Save A&s ...") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hFileMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hFileMenu, MF_Popup, hFileSaveAsFormatMenu, "Save &Format") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hFileMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hFileMenu, 0, 105, "E&xit" & vbtab & "Alt+F4") = 0 then Msgbox("Append " & Err.LastDllError)
- 'Help Menu
- hHelpMenu = CreatePopupMenu()
- If AppendMenuW(hHelpMenu, 0, 901, "&Help" & vbtab & "F1") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hHelpMenu, 0, 902, "&Programming") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hHelpMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hHelpMenu, 0, 903, "&About") = 0 then Msgbox("Append " & Err.LastDllError)
- 'Edit Menu - this is almost the same as the context menu.
- hEditMenu = CreatePopupMenu()
- If AppendMenuW(hEditMenu, 0, 201, "&Undo" & vbtab & "Ctrl+Z") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hEditMenu, 0, 202, "&Redo" & vbtab & "Ctrl+Y") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hEditMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hEditMenu, 0, 203, "Cu&t" & vbtab & "Ctrl+X") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hEditMenu, 0, 204, "&Copy" & vbtab & "Ctrl+C") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hEditMenu, 0, 205, "&Paste" & vbtab & "Ctrl+V") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hEditMenu, 0, 206, "De&lete" & vbtab & "Del") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hEditMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hEditMenu, 0, 207, "Select &All" & vbtab & "Ctrl+A") = 0 then Msgbox("Append " & Err.LastDllError)
- 'Context Menu
- hContextMenu = CreatePopupMenu()
- If AppendMenuW(hContextMenu, 0, 201, "&Undo" & vbtab & "Ctrl+Z") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hContextMenu, 0, 202, "&Redo" & vbtab & "Ctrl+Y") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hContextMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hContextMenu, 0, 203, "Cu&t" & vbtab & "Ctrl+X") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hContextMenu, 0, 204, "&Copy" & vbtab & "Ctrl+C") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hContextMenu, 0, 205, "&Paste" & vbtab & "Ctrl+V") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hContextMenu, 0, 206, "De&lete" & vbtab & "Del") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hContextMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hContextMenu, 0, 207, "Select &All" & vbtab & "Ctrl+A") = 0 then Msgbox("Append " & Err.LastDllError)
- 'View Menu
- hViewMenu = CreatePopupMenu()
- If AppendMenuW(hViewMenu, 0, 301, "&Wordwrap") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hViewMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hViewMenu, 0, 302, "&Zoom 100%" & vbtab & "Ctrl+Wheel") = 0 then Msgbox("Append " & Err.LastDllError)
- 'MenuBar
- If SetMenu(hWnd, hMenuBar) = 0 then Msgbox("SetM " & Err.LastDllError)
- If AppendMenuW(hMenuBar, MF_Popup, hFileMenu, "&File") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hMenuBar, MF_Popup, hEditMenu, "&Edit") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hMenuBar, MF_Popup, hViewMenu, "&View") = 0 then Msgbox("Append " & Err.LastDllError)
- If AppendMenuW(hMenuBar, MF_Popup, hHelpMenu, "&Help") = 0 then Msgbox("Append " & Err.LastDllError)
- If DrawMenuBar(hWnd) = 0 then Msgbox(Err.LastDllError)
- '======================================
- 'Setting up Accelerator keys
- '------------------------------------------------
- Dim hAccTable as IntPtr
- Dim AccTable(1) as Accel
- With AccTable(0)
- .fvirt = fcontrol
- .key = &h4e
- .cmd = 101
- End With
- hAccTable = CreateAcceleratorTableW(AccTable(0), 1)
- console.writeline("hacctable = " & CStr(hAccTable))
- '======================================
- 'Setting editing options - there are probably over 100
- '------------------------------------------------
- Ret = SendMessageStr(gRtfHwnd, WM_SETTEXT, 0, "")
- Ret = SendMessageW(gRtfHwnd, EM_SETTEXTMODE, TM_MULTILEVELUNDO + TM_PLAINTEXT + TM_MULTICODEPAGE, 0)
- If GetTextMode(gRtfHwnd) <> 41 Then MsgBox("get Text mode = " & GetTextMode(gRtfHwnd))
- Ret = SendMessageW(gRtfHwnd, EM_SETEDITSTYLE, SES_ALLOWBEEPS + SES_USECRLF + SES_CTFALLOWPROOFING + SES_CTFALLOWSMARTTAG + SES_USECTF + SES_CTFALLOWEMBED, SES_ALLOWBEEPS + SES_USECRLF + SES_CTFALLOWPROOFING + SES_CTFALLOWSMARTTAG + SES_USECTF + SES_CTFALLOWEMBED)
- ' Uncomment to turn on spellchecking
- ' Ret = SendMessageW(gRtfHwnd, EM_SETLANGOPTIONS, IMF_SPELLCHECKING, IMF_SPELLCHECKING)
- If GetTextMode(gRtfHwnd) <> 41 Then MsgBox("get Text mode (2) = " & GetTextMode(gRtfHwnd))
- Ret = SendMessageW(gRtfHwnd, EM_SETTYPOGRAPHYOPTIONS, TO_None, TO_None)
- Ret = SendMessageW(gRtfHwnd, EM_SETOPTIONS, ECO_AUTOHSCROLL + ECO_AUTOVSCROLL + ECO_NOHIDESEL + ECO_WANTRETURN, ECOOP_OR)
- Ret = SendMessageW(gRtfHwnd, EM_EXLIMITTEXT, 0, 2000000)
- Ret = SendMessageW(gRTFhWnd, EM_SETOPTIONS, ECOOP_OR, ECO_SELECTIONBAR)
- Ret = SendMessageW(gRtfHwnd, EM_SetEventMask, 0, ENM_SelChange + ENM_Change)
- 'Getting TOM object
- Ret = SendMessageObj(gRtfHwnd, EM_GETOLEINTERFACE, 0, TomDoc)
- TomSel = TomDoc.Selection
- 'Showing the window
- ShowWindow(hWnd, SW_SHOWNORMAL)
- UpdateWindow (hWnd)
- ShowWindow(gRTFhWnd, SW_SHOWNORMAL)
- UpdateWindow (gRTFhWnd)
- SetFocus (gRTFhWnd)
- 'set initial global saved status
- gFileIsDirty = False
- gFileHasName = False
- console.writeline(System.Windows.Forms.Application.ExecutablePath)
- 'Create global utility objects wscript.shell for registry and shelling (eg help) and FSO for read support files
- WshShell = CreateObject("WScript.Shell")
- FSO = CreateObject("Scripting.FileSystemObject")
- Console.Writeline("Command line is: " & Command())
- If Command() <> "" then
- TomDoc.Open(Replace(Command(),"""", ""), &h442, 0)
- End If
- '======================================
- 'This is the program message loop. All further code is run in the window procedure till the window closes then this loop exits and the program exits.
- '------------------------------------------------
- Do While GetMessage(Message, IntPtr.Zero, 0, 0)
- TranslateAcceleratorW(hWnd, hAccTable, Message)
- ' TranslateMessage (Message)
- If TranslateAcceleratorW(hWnd, hAccTable, Message) <> 0 and err.lastdllerror = 0 then
- TranslateMessage (Message)
- End If
- DispatchMessage (Message)
- Loop
- Ret = DestroyMenu(hContextMenu)
- Ret = DestroyAcceleratorTable(hAccTable)
- 'This is pointless code so I get to see shutdown output before the console window disappears
- 'It is expoential to the number of spaces
- Dim i as intptr
- Do
- i = i + 1
- If Cint(i) > &h8fff then Exit Do
- RTFClassName = RTFClassName & " "
- Loop
- End Sub
- '======================================
- 'Main window procedure.
- '------------------------------------------------
- Private Function WndProc(ByVal hWnd As IntPtr, ByVal Message As Integer, ByVal wParam As Intptr, ByVal lParam As Intptr ) As IntPtr
- ' Console.WriteLine ("Message " & Message)
- ' Console.WriteLine ("Filestatus " & gFileIsDirty & " " & gFileHasName)
- Select Case Message
- Case WM_LBUTTONDOWN
- MessageBoxW(hWnd, "Left Mouse Button Pressed", APP_TITLE, MB_OK)
- WndProc = IntPtr.Zero
- Case WM_RBUTTONDOWN
- MessageBoxW(hWnd, "Right Mouse Button Pressed", APP_TITLE, MB_OK)
- WndProc = IntPtr.Zero
- Case WM_DESTROY
- PostQuitMessage (0)
- WndProc = IntPtr.Zero
- Case WM_SIZE
- Ret = SetWindowPos(gRtfHwnd, HWND_NOTOPMOST, 0, 0, CLng(LParam) AND &h0000ffff, CLng(LParam) >> 16, SWP_NOZORDER + SWP_NOOWNERZORDER)
- WndProc = IntPtr.Zero
- Case WM_COMMAND
- Console.WriteLine ("Command " & (CInt(wParam) >> 16) & " " & (CInt(wParam) and &Hffff) & " " & Cint(lparam))
- If (CInt(wParam) >> 16) > 1 Then
- ' console.Writeline("WmCommand " & (CInt(wParam) >> 16))
- If (CInt(wParam) >> 16) = EN_Change then Console.WriteLine("Edited")
- If (CInt(wParam) >> 16) = EN_Change then gFileIsDirty = True
- WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
- Else
- Dim MenuCommand as Integer
- MenuCommand = CInt(wParam) and &Hffff
- console.Writeline("Menu " & MenuCommand)
- Select Case MenuCommand
- Case 105 'Exit
- Ret = SendMessageW(Hwnd, WM_Close, 0, 0)
- WndProc = IntPtr.Zero
- Case 101 'New
- If gFileIsDirty = True Then
- console.writeline("saving")
- Ret = Msgbox("File has changed. Do you want to save?", vbyesnocancel, "Editor")
- If Ret = vbyes then
- Savefile()
- ElseIf Ret = vbno then
- Ret = SendMessageStr(gRtfHwnd, WM_SETTEXT, 0, "")
- gFileisDirty = False
- gFileHasName = False
- End If
- Else
- Ret = SendMessageStr(gRtfHwnd, WM_SETTEXT, 0, "")
- gFileisDirty = False
- gFileHasName = False
- End If
- WndProc = IntPtr.Zero
- Case 190 'Dos
- Ret = CheckMenuRadioItem(hFileSaveAsFormatMenu, 190, 194, 190, mf_bycommand)
- WndProc = IntPtr.Zero
- Case 191 'ANSI
- Ret = CheckMenuRadioItem(hFileSaveAsFormatMenu, 190, 194, 191, mf_bycommand)
- WndProc = IntPtr.Zero
- Case 192 'UTF8
- Ret = CheckMenuRadioItem(hFileSaveAsFormatMenu, 190, 194, 192, mf_bycommand)
- WndProc = IntPtr.Zero
- Case 193 'UTF16
- Ret = CheckMenuRadioItem(hFileSaveAsFormatMenu, 190, 194, 193, mf_bycommand)
- WndProc = IntPtr.Zero
- Case 194 'Auto
- Ret = CheckMenuRadioItem(hFileSaveAsFormatMenu, 190, 194, 194, mf_bycommand)
- WndProc = IntPtr.Zero
- Case 901 'Help
- WshShell.Run("""" & System.Windows.Forms.Application.StartupPath & "\Unicode Editor Help.hta""")
- WndProc = IntPtr.Zero
- Case 902 'Programming
- WshShell.Run("""" & System.Windows.Forms.Application.StartupPath & "\Unicode Editor.hta""")
- WndProc = IntPtr.Zero
- Case 903 'About
- Msgbox ("Unicode Editor" & vbcrlf & vbcrlf & "An editor built around Windows API calls." & vbcrlf & vbcrlf & "Created in Windows notepad and compiled with the built in to Windows Visual Basic .NET compiler." & vbcrlf & vbcrlf & "It is meant to be an easily changed program so people can experiment with, and as all the basic plumbing is already hooked up, won't need to spend months making the basics work right.", , "About Unicode Editor")
- WndProc = IntPtr.Zero
- Case 201 'undo
- If SendMessageW(grtfhwnd, em_canundo, 0, 0) <> 0 then
- Ret = SendMessageW(grtfhwnd, em_undo, 0, 0)
- End If
- WndProc = IntPtr.Zero
- Case 202 'redo
- If SendMessageW(grtfhwnd, em_canredo, 0, 0) <> 0 then
- Ret = SendMessageW(grtfhwnd, em_redo, 0, 0)
- End If
- WndProc = IntPtr.Zero
- Case 203
- If TomSel.Type = 2 then
- TomSel.Cut(vbnull)
- End If
- WndProc = IntPtr.Zero
- Case 204
- If TomSel.Type = 2 then
- TomSel.Copy(vbnull)
- End If
- WndProc = IntPtr.Zero
- Case 205
- If tomsel.canpaste(vbnull, CF_UNICODETEXT) = true
- tomsel.paste(vbnull, CF_UNICODETEXT)
- End If
- WndProc = IntPtr.Zero
- Case 206
- If TomSel.Type = 2 then
- Ret=TomSel.Delete(0, 0)
- End If
- WndProc = IntPtr.Zero
- Case 207 'select all
- Ret = tomsel.expand(6)
- WndProc = IntPtr.Zero
- Case 301 'Zoom 100%
- Ret = SendMessageW(gRtfHwnd, EM_SETTARGETDEVICE, GetDC(gRtfHwnd), -1800)
- WndProc = IntPtr.Zero
- Case 302 'Zoom 100%
- Ret = SendMessageW(grtfhwnd, em_setzoom, 0, 0)
- WndProc = IntPtr.Zero
- Case Else
- WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
- End Select
- End If
- Case WM_Notify
- Dim hdr As selchange = Marshal.PtrToStructure(lparam , GetType(selchange))
- If hdr.nmhdr.Code = En_SelChanged then
- Console.Writeline ("SelChanged")
- WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
- Else
- Console.Writeline ("Notify " & Cstr(hdr.nmhdr.Code))
- WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
- End If
- Case WM_ACTIVATEAPP
- WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
- Case WM_PARENTNOTIFY
- ' Console.WriteLine ("ParentNotify " & (CInt(wParam) >> 16) & " " & (CInt(wParam) and &Hffff) & " " & Cint(lparam))
- ' If (CInt(wParam) and &Hffff) = WM_RBUTTONDOWN Then Console.WriteLine ("Right button down")
- WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
- Case WM_CONTEXTMENU
- ' Console.WriteLine ("Context Menu " & (CInt(wParam) >> 16) & " " & (CInt(wParam) and &Hffff) & " " & Cint(lparam))
- If wParam = gRTFhWnd Then
- Console.WriteLine ("Edit Context Menu")
- Console.writeline(CStr(hcontextmenu))
- ' Dim hmenuTrackPopup as IntPtr
- ' hmenuTrackPopup = GetSubMenu(hContextMenu, 0)
- Ret = TrackPopupMenu(hContextMenu, TPM_RightButton, (CInt(lParam) and &Hffff), (CInt(lParam) >> 16), 0, hWnd, &h0)
- WndProc = 0
- Else
- Console.WriteLine ("Another Context Menu")
- WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
- End If
- Case WM_INITMENUPOPUP
- If wParam = hContextMenu Then
- ' Console.WriteLine ("Init Menu" & (CInt(wParam) >> 16) & " " & (CInt(wParam) and &Hffff) & " " & Cint(lparam))
- If SendMessageW(grtfhwnd, em_canundo, 0, 0) <> 0 then
- Ret = EnableMenuItem(hcontextmenu, 201, mf_bycommand + mf_enabled)
- Else
- Ret = EnableMenuItem(hcontextmenu, 201, mf_bycommand + mf_grayed)
- End If
- If SendMessageW(grtfhwnd, em_canredo, 0, 0) <> 0 then
- Ret = EnableMenuItem(hcontextmenu, 202, mf_bycommand + mf_enabled)
- Else
- Ret = EnableMenuItem(hcontextmenu, 202, mf_bycommand + mf_grayed)
- End If
- If tomsel.canpaste(vbnull, CF_UNICODETEXT) = true then
- Ret = EnableMenuItem(hcontextmenu, 205, mf_bycommand + mf_enabled)
- Else
- Ret = EnableMenuItem(hcontextmenu, 205, mf_bycommand + mf_grayed)
- End If
- If tomsel.type() = 1 then 'normal insertion
- Ret = EnableMenuItem(hcontextmenu, 203, mf_bycommand + mf_grayed)
- Ret = EnableMenuItem(hcontextmenu, 204, mf_bycommand + mf_grayed)
- Ret = EnableMenuItem(hcontextmenu, 206, mf_bycommand + mf_grayed)
- else
- Ret = EnableMenuItem(hcontextmenu, 203, mf_bycommand + mf_enabled)
- Ret = EnableMenuItem(hcontextmenu, 204, mf_bycommand + mf_enabled)
- Ret = EnableMenuItem(hcontextmenu, 206, mf_bycommand + mf_enabled)
- End If
- End If
- If wParam = hEditMenu Then
- ' Console.WriteLine ("Init Menu" & (CInt(wParam) >> 16) & " " & (CInt(wParam) and &Hffff) & " " & Cint(lparam))
- If SendMessageW(grtfhwnd, em_canundo, 0, 0) <> 0 then
- Ret = EnableMenuItem(heditmenu, 201, mf_bycommand + mf_enabled)
- Else
- Ret = EnableMenuItem(heditmenu, 201, mf_bycommand + mf_grayed)
- End If
- If SendMessageW(grtfhwnd, em_canredo, 0, 0) <> 0 then
- Ret = EnableMenuItem(heditmenu, 202, mf_bycommand + mf_enabled)
- Else
- Ret = EnableMenuItem(heditmenu, 202, mf_bycommand + mf_grayed)
- End If
- If tomsel.canpaste(vbnull, CF_UNICODETEXT) = true then
- Ret = EnableMenuItem(heditmenu, 205, mf_bycommand + mf_enabled)
- Else
- Ret = EnableMenuItem(heditmenu, 205, mf_bycommand + mf_grayed)
- End If
- If tomsel.type() = 1 then 'normal insertion
- Ret = EnableMenuItem(heditmenu, 203, mf_bycommand + mf_grayed)
- Ret = EnableMenuItem(heditmenu, 204, mf_bycommand + mf_grayed)
- Ret = EnableMenuItem(heditmenu, 206, mf_bycommand + mf_grayed)
- else
- Ret = EnableMenuItem(heditmenu, 203, mf_bycommand + mf_enabled)
- Ret = EnableMenuItem(heditmenu, 204, mf_bycommand + mf_enabled)
- Ret = EnableMenuItem(heditmenu, 206, mf_bycommand + mf_enabled)
- End If
- End If
- WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
- Case Else
- WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
- End Select
- End Function
- '======================================
- 'This is the starting sub. It calls the main sub New()
- '------------------------------------------------
- Public Shared Sub Main()
- Dim wnd As New UnicodeEditor
- End Sub
- '======================================
- 'Assorted functions
- '------------------------------------------------
- Public Function GetTextMode(lhwnd as IntPtr) As Integer
- Dim Ret As Integer
- Ret = SendMessageW(lhwnd, EM_GETTEXTMODE, 0, 0)
- GetTextMode = Ret
- End Function
- Private Sub OpenFile()
- Dim ofn as New System.Windows.Forms.OpenFileDialog
- With ofn
- .Filename = "*.*"
- .ShowDialog
- End With
- Console.writeline(ofn.filename)
- ' Ret = GetOpenFileNameW(ofn)
- ' Console.writeline(Len(ofn.file))
- ' Console.writeline(ofn.file)
- ' console.writeline("OFN " & Ret & " " & err.lastdllerror)
- End Sub
- Private Sub SaveFile()
- Dim ofn as New System.Windows.Forms.OpenFileDialog
- With ofn
- .Filename = "*.*"
- .ShowDialog
- End With
- Console.writeline(ofn.filename)
- ' Ret = GetOpenFileNameW(ofn)
- ' Console.writeline(Len(ofn.file))
- ' Console.writeline(ofn.file)
- ' console.writeline("OFN " & Ret & " " & err.lastdllerror)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement