Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.82 KB | None | 0 0
  1.  
  2. ' Text Editor using API calls not forms.
  3. 'File Save etc not implemented. Help requires other files.
  4. 'This one implement very basic macros, only 1. Requires editing registry for that function to work.
  5. 'Compile with C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc "%~dp0\Editor.vb" /win32manifest:"%~dp0\RunAsInvoker.manifest" /out:"%~dp0\Editor.exe" /target:exe /win32icon:"%~dp0\Editor.ico"
  6.  
  7.  
  8. Imports System.Runtime.InteropServices
  9. Imports System.IO
  10. Imports System.Windows.Forms.OpenFileDialog
  11. Imports System.Windows.Forms.SaveFileDialog
  12.  
  13. Public Class UnicodeEditor
  14.  
  15. Private Const CLASS_NAME As String = "UED"
  16. Private Const APP_TITLE As String = "Unicode Editor"
  17. Private Const WS_CAPTION As Integer = &HC00000
  18. Private Const WS_MAXIMIZEBOX As Integer = &H10000
  19. Private Const WS_MINIMIZEBOX As Integer = &H20000
  20. Private Const WS_OVERLAPPED As Integer = &H0
  21. Private Const WS_SYSMENU As Integer = &H80000
  22. Private Const WS_THICKFRAME As Integer = &H40000
  23. Private Const WS_OVERLAPPEDWINDOW As Integer = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
  24. Private Const CS_HREDRAW As Integer = &H2
  25. Private Const CS_VREDRAW As Integer = &H1
  26. Private Const IDI_APPLICATION As Integer = 32512
  27. Private Const IDC_ARROW As Integer = 32512
  28. Private Const LTGRAY_BRUSH As Integer = 1
  29. Private Const SW_SHOWNORMAL As Integer = 1
  30. Private Const WM_USER = &H400
  31. Private Const WM_SIZE = &H5
  32. Private Const WM_COMMAND = &H111
  33. Private Const WM_DESTROY As Integer = &H2
  34. Private Const WM_LBUTTONDOWN As Integer = &H201
  35. Private Const WM_ACTIVATEAPP = &H1C
  36. Private Const WM_CLOSE = &H10
  37. Private Const WM_SETTEXT = &HC
  38. Private Const WM_GETTEXT = &HD
  39. Private Const WM_GETTEXTLENGTH = &HE
  40. Private Const WM_NOTIFY = &H4E
  41. Private Const WM_RBUTTONDOWN = &H204
  42. Private Const WM_PARENTNOTIFY = &H210
  43. Private Const WM_CONTEXTMENU As Long = &H7B
  44. Private Const WM_INITMENUPOPUP = &H117
  45.  
  46. Private Const MB_OK As Integer = &H0
  47.  
  48. Private Const EN_SETFOCUS = &H100
  49. Private Const EN_KILLFOCUS = &H200
  50. Private Const EN_CHANGE = &H300
  51. Private Const EN_UPDATE = &H400
  52. Private Const EN_ERRSPACE = &H500
  53. Private Const EN_MAXTEXT = &H501
  54. Private Const EN_HSCROLL = &H601
  55. Private Const EN_VSCROLL = &H602
  56. Private Const EN_SelChanged = &h702
  57. Private Const ENM_CHANGE = &h1
  58. Private Const ENM_SELCHANGE = &h80000
  59. Private Const ENM_MOUSEEVENTS = &h20000
  60.  
  61. Private Const EC_LEFTMARGIN = &H1
  62. Private Const EC_RIGHTMARGIN = &H2
  63. Private Const EC_USEFONTINFO = &HFFFF
  64. Private Const EMSIS_COMPOSITIONSTRING = &H1
  65. Private Const EIMES_GETCOMPSTRATONCE = &H1
  66. Private Const EIMES_CANCELCOMPSTRINFOCUS = &H2
  67. Private Const EIMES_COMPLETECOMPSTRKILLFOCUS = &H4
  68. Private Const EM_AUTOURLDETECT = WM_USER + 91
  69. Private Const EM_GETAUTOURLDETECT = WM_USER + 92
  70.  
  71. Private Const EM_GETSEL = &HB0
  72. Private Const EM_SETSEL = &HB1
  73. Private Const EM_GETRECT = &HB2
  74. Private Const EM_SETRECT = &HB3
  75. Private Const EM_SETRECTNP = &HB4
  76. Private Const EM_SCROLL = &HB5
  77. Private Const EM_LINESCROLL = &HB6
  78. Private Const EM_SCROLLCARET = &HB7
  79. Private Const EM_GETMODIFY = &HB8
  80. Private Const EM_SETMODIFY = &HB9
  81. Private Const EM_GETLINECOUNT = &HBA
  82. Private Const EM_LINEINDEX = &HBB
  83. Private Const EM_SETHANDLE = &HBC
  84. Private Const EM_GETHANDLE = &HBD
  85. Private Const EM_GETTHUMB = &HBE
  86. Private Const EM_LINELENGTH = &HC1
  87. Private Const EM_REPLACESEL = &HC2
  88. Private Const EM_GETLINE = &HC4
  89. Private Const EM_LIMITTEXT = &HC5
  90. Private Const EM_CANUNDO = &HC6
  91. Private Const EM_UNDO = &HC7
  92. Private Const EM_FMTLINES = &HC8
  93. Private Const EM_LINEFROMCHAR = &HC9
  94. Private Const EM_SETTABSTOPS = &HCB
  95. Private Const EM_SETPASSWORDCHAR = &HCC
  96. Private Const EM_EMPTYUNDOBUFFER = &HCD
  97. Private Const EM_GETFIRSTVISIBLELINE = &HCE
  98. Private Const EM_SETREADONLY = &HCF
  99. Private Const EM_SETWORDBREAKPROC = &HD0
  100. Private Const EM_GETWORDBREAKPROC = &HD1
  101. Private Const EM_GETPASSWORDCHAR = &HD2
  102. Private Const EM_SETMARGINS = &HD3
  103. Private Const EM_GETMARGINS = &HD4
  104. Private Const EM_GETLIMITTEXT = &HD5
  105. Private Const EM_POSFROMCHAR = &HD6
  106. Private Const EM_CHARFROMPOS = &HD7
  107. Private Const EM_SETIMESTATUS = &HD8
  108. Private Const EM_GETIMESTATUS = &HD9
  109. Private Const EM_SETOPTIONS = (&H400 + 77)
  110. Private Const EM_SETLANGOPTIONS = (&H400 + 120)
  111. Private Const EM_GETLANGOPTIONS = (&H400 + 121)
  112.  
  113. Private Const EM_CANPASTE = (&H400 + 50)
  114. Private Const EM_EXLIMITTEXT = (&H400 + 53)
  115. Private Const EM_SETUNDOLIMIT = (&H400 + 82)
  116. Private Const EM_REDO = (&H400 + 84)
  117. Private Const EM_CANREDO = (&H400 + 85)
  118. Private Const EM_GETUNDONAME = (&H400 + 86)
  119. Private Const EM_GETREDONAME = (&H400 + 87)
  120. Private Const EM_STOPGROUPTYPING = (&H400 + 88)
  121. Private Const EM_PASTESPECIAL = (&H400 + 64)
  122. Private Const EM_GETOPTIONS = (&H400 + 78)
  123. Private Const EM_GETTEXTRANGE = &H400 + 75
  124. Private Const EM_GETOLEINTERFACE = (&H400 + 60)
  125. Private Const EM_SETTARGETDEVICE = (&H400 + 72)
  126. Private Const EM_SETEVENTMASK = (&H400 + 69)
  127. Private Const EM_GETEVENTMASK = (&H400 + 59)
  128.  
  129.  
  130. 'Extended edit style specific messages
  131. Private Const EM_SETEDITSTYLE = (&H400 + 204)
  132. Private Const EM_GETEDITSTYLE = (&H400 + 205)
  133. Private Const EM_SETTYPOGRAPHYOPTIONS = (&H400 + 202)
  134. Private Const EM_GETTYPOGRAPHYOPTIONS = (&H400 + 203)
  135. Private Const EM_GETCTFOPENSTATUS = (&H400 + 240)
  136. Private Const EM_SETCTFOPENSTATUS = (&H400 + 241)
  137. Private Const EM_SETZOOM = &h400 + 225
  138.  
  139. ' Extended edit style masks
  140. Private Const SES_EMULATESYSEDIT = 1
  141. Private Const SES_BEEPONMAXTEXT = 2
  142. Private Const SES_EXTENDBACKCOLOR = 4
  143. Private Const SES_MAPCPS = 8 ' (obsolete)
  144. Private Const SES_EMULATE10 = 16 ' (obsolete)
  145. Private Const SES_USECRLF = 32 ' (obsolete)
  146. Private Const SES_NOXLTSYMBOLRANGE = 32
  147. Private Const SES_USEAIMM = 64
  148. Private Const SES_NOIME = 128
  149. Private Const SES_ALLOWBEEPS = 256
  150. Private Const SES_UPPERCASE = 512
  151. Private Const SES_LOWERCASE = 1024
  152. Private Const SES_NOINPUTSEQUENCECHK = 2048
  153. Private Const SES_BIDI = 4096
  154. Private Const SES_SCROLLONKILLFOCUS = 8192
  155. Private Const SES_XLTCRCRLFTOCR = 16384
  156. Private Const SES_DRAFTMODE = 32768
  157. Private Const SES_USECTF = &H10000
  158. Private Const SES_HIDEGRIDLINES = &H20000
  159. Private Const SES_USEATFONT = &H40000
  160. Private Const SES_CUSTOMLOOK = &H80000
  161. Private Const SES_LBSCROLLNOTIFY = &H100000
  162. Private Const SES_CTFALLOWEMBED = &H200000
  163. Private Const SES_CTFALLOWSMARTTAG = &H400000
  164. Private Const SES_CTFALLOWPROOFING = &H800000
  165.  
  166. Private Const EM_SETTEXTMODE = (&H400 + 89)
  167. Private Const EM_GETTEXTMODE = (&H400 + 90)
  168. Private Const TM_PLAINTEXT = 1
  169. Private Const TM_RICHTEXT = 2
  170. Private Const TM_SINGLELEVELUNDO = 4
  171. Private Const TM_MULTILEVELUNDO = 8
  172. Private Const TM_SINGLECODEPAGE = 16
  173. Private Const TM_MULTICODEPAGE = 32
  174.  
  175. Private Const ECO_AUTOWORDSELECTION = &H1
  176. Private Const ECO_AUTOVSCROLL = &H40
  177. Private Const ECO_AUTOHSCROLL = &H80
  178. Private Const ECO_NOHIDESEL = &H100
  179. Private Const ECO_READONLY = &H800
  180. Private Const ECO_WANTRETURN = &H1000
  181. Private Const ECO_SAVESEL = &H8000
  182. Private Const ECO_SELECTIONBAR = &H1000000
  183. Private Const ECOOP_SET = &H1
  184. Private Const ECOOP_OR = &H2
  185. Private Const ECOOP_AND = &H3
  186. Private Const ECOOP_XOR = &H4
  187.  
  188. Private Const TO_ADVANCEDTYPOGRAPHY = 1
  189. Private Const TO_SIMPLELINEBREAK = 2
  190. Private Const TO_DISABLECUSTOMTEXTOUT = 4
  191. Private Const TO_ADVANCEDLAYOUT = 8
  192. Private Const TO_None = 0
  193.  
  194. Private Const WB_LEFT = 0
  195. Private Const WB_RIGHT = 1
  196. Private Const WB_ISDELIMITER = 2
  197. Private Const WB_CLASSIFY = 3
  198. Private Const WB_MOVEWORDLEFT = 4
  199. Private Const WB_MOVEWORDRIGHT = 5
  200. Private Const WB_LEFTBREAK = 6
  201. Private Const WB_RIGHTBREAK = 7
  202. Private Const EM_FINDWORDBREAK = (&H400 + 76)
  203. Private Const WBF_ISWHITE = &H10
  204. Private Const WBF_BREAKLINE = &H20
  205. Private Const WBF_BREAKAFTER = &H40
  206.  
  207. Private Const IMF_AUTOKEYBOARD = &H1
  208. Private Const IMF_AUTOFONT = &H2
  209. Private Const IMF_IMECANCELCOMPLETE = &H4 'High completes comp string when aborting, low cancels
  210. Private Const IMF_IMEALWAYSSENDNOTIFY = &H8
  211. Private Const IMF_AUTOFONTSIZEADJUST = &H10 '16
  212. Private Const IMF_UIFONTS = &H20 '32
  213. Private Const IMF_DUALFONT = &H80 '128
  214. Private Const IMF_None = &H0 '0
  215. Private Const IMF_SPELLCHECKING = &H800
  216. Private Const CP_ACP = 0 ' default to ANSI code page
  217. Private Const CP_OEMCP = 1 ' default to OEM code page
  218. Private Const CP_MACCP = 2 ' default to MAC code page
  219. Private Const CP_THREAD_ACP = 3 ' current thread's ANSI code page
  220. Private Const CP_SYMBOL = 42 ' SYMBOL translations
  221. Private Const CP_Unicode = 1200 ' Unicode
  222. Private Const CP_UTF7 = 65000 ' UTF-7 translation
  223. Private Const CP_UTF8 = 65001 ' UTF-8 translation
  224. Private Const ES_AUTOHSCROLL = &H80&
  225. Private Const ES_AUTOVSCROLL = &H40&
  226. Private Const ES_CENTER = &H1&
  227. Private Const ES_LEFT = &H0&
  228. Private Const ES_LOWERCASE = &H10&
  229. Private Const ES_MULTILINE = &H4&
  230. Private Const ES_NOHIDESEL = &H100&
  231. Private Const ES_OEMCONVERT = &H400&
  232. Private Const ES_PASSWORD = &H20&
  233. Private Const ES_READONLY = &H800&
  234. Private Const ES_RIGHT = &H2&
  235. Private Const ES_UPPERCASE = &H8&
  236. Private Const ES_WANTRETURN = &H1000&
  237. Private Const ES_NUMBER = &H2000
  238.  
  239. Private Const WS_BORDER = &H800000
  240. Private Const WS_CHILD = &H40000000
  241. Private Const WS_CHILDWINDOW = (&H40000000)
  242. Private Const WS_CLIPCHILDREN = &H2000000
  243. Private Const WS_CLIPSIBLINGS = &H4000000
  244. Private Const WS_DISABLED = &H8000000
  245. Private Const WS_DLGFRAME = &H400000
  246. Private Const WS_EX_ACCEPTFILES = &H10&
  247. Private Const WS_EX_APPWINDOW = &H40000
  248. Private Const WS_EX_CLIENTEDGE = &H200
  249. Private Const WS_EX_COMPOSITED = &H2000000
  250. Private Const WS_EX_CONTEXTHELP = &H400
  251. Private Const WS_EX_CONTROLPARENT = &H10000
  252. Private Const WS_EX_DLGMODALFRAME = &H1
  253. Private Const WS_EX_LAYERED = &H80000
  254. Private Const WS_EX_LAYOUTRTL = &H400000 ' Right to left mirroring
  255. Private Const WS_EX_LEFT = &H0
  256. Private Const WS_EX_LEFTSCROLLBAR = &H4000
  257. Private Const WS_EX_LTRREADING = &H0
  258. Private Const WS_EX_MDICHILD = &H40
  259. Private Const WS_EX_NOACTIVATE = &H8000000
  260. Private Const WS_EX_NOINHERITLAYOUT = &H100000 ' Disable inheritence of mirroring by children
  261. Private Const WS_EX_NOPARENTNOTIFY = &H4
  262. ' Private Const WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE + WS_EX_CLIENTEDGE)
  263. ' Private Const WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE + WS_EX_TOOLWINDOW + WS_EX_TOPMOST)
  264. Private Const WS_EX_RIGHT = &H1000
  265. Private Const WS_EX_RIGHTSCROLLBAR = &H0
  266. Private Const WS_EX_RTLREADING = &H2000
  267. Private Const WS_EX_STATICEDGE = &H20000
  268. Private Const WS_EX_TOOLWINDOW = &H80
  269. Private Const WS_EX_TOPMOST = &H8
  270. Private Const WS_EX_TRANSPARENT = &H20&
  271. Private Const WS_EX_WINDOWEDGE = &H100
  272. Private Const WS_GROUP = &H20000
  273. Private Const WS_HSCROLL = &H100000
  274. Private Const WS_ICONIC = &H1000000
  275. Private Const WS_POPUP = &H80000000
  276. ' Private Const WS_POPUPWINDOW = (WS_POPUP + WS_B + DER + WS_SYSMENU)
  277. Private Const WS_SIZEBOX = &H40000
  278. Private Const WS_TABSTOP = &H10000
  279. Private Const WS_TILED = &H0&
  280. Private Const WS_TILEDWINDOW = (&H0& + &HC00000 + &H80000 + &H40000 + &H20000 + &H10000)
  281. Private Const WS_VISIBLE = &H10000000
  282. Private Const WS_VSCROLL = &H200000
  283. Private Const HWND_NOTOPMOST = -2
  284. Private Const SWP_SHOWWINDOW = &H40
  285. Private Const SWP_NOZORDER = &H4
  286. Private Const SWP_NOSIZE = &H1
  287. Private Const SWP_NOREPOSITION = &H200
  288. Private Const SWP_NOREDRAW = &H8
  289. Private Const SWP_NOOWNERZORDER = &H200 ' Don't do owner Z ordering
  290. Private Const SWP_NOMOVE = &H2
  291. Private Const SWP_NOCOPYBITS = &H100
  292. Private Const SWP_NOACTIVATE = &H10
  293. Private Const SWP_HIDEWINDOW = &H80
  294. Private Const SWP_FRAMECHANGED = &H20 ' The frame changed: send WM_NCCALCSIZE
  295. Private Const SWP_DRAWFRAME = &H20
  296. Private Const MF_POPUP = &H10
  297. Private Const MF_SEPARATOR = &H800
  298. Private Const TPM_RIGHTBUTTON = &H2
  299. Private Const TPM_LEFTALIGN = &H0
  300. Private Const TPM_NONOTIFY = &H80
  301. Private Const TPM_RETURNCMD = &H100
  302.  
  303. Private Const MF_BYCOMMAND = &H0&
  304. Private Const MF_GRAYED = &H1&
  305. Private Const MF_ENABLED = &H0&
  306. Private Const MF_UNCHECKED = &H0&
  307. Private Const MF_CHECKED = &H8&
  308.  
  309. Private Const CF_UNICODETEXT= 13
  310.  
  311. Private Const OFN_READONLY = &H1
  312. Private Const OFN_OVERWRITEPROMPT = &H2
  313. Private Const OFN_HIDEREADONLY = &H4
  314. Private Const OFN_NOCHANGEDIR = &H8
  315. Private Const OFN_SHOWHELP = &H10
  316. Private Const OFN_ENABLEHOOK = &H20
  317. Private Const OFN_ENABLETEMPLATE = &H40
  318. Private Const OFN_ENABLETEMPLATEHANDLE = &H80
  319. Private Const OFN_NOVALIDATE = &H100
  320. Private Const OFN_ALLOWMULTISELECT = &H200
  321. Private Const OFN_EXTENSIONDIFFERENT = &H400
  322. Private Const OFN_PATHMUSTEXIST = &H800
  323. Private Const OFN_FILEMUSTEXIST = &H1000
  324. Private Const OFN_CREATEPROMPT = &H2000
  325. Private Const OFN_SHAREAWARE = &H4000
  326. Private Const OFN_NOREADONLYRETURN = &H8000
  327. Private Const OFN_NOTESTFILECREATE = &H10000
  328. Private Const OFN_NONETWORKBUTTON = &H20000
  329. Private Const OFN_NOLONGNAMES = &H40000 ' force no long names for 4.x modules
  330. Private Const OFN_EXPLORER = &H80000 ' new look commdlg
  331. Private Const OFN_NODEREFERENCELINKS = &H100000
  332. Private Const OFN_LONGNAMES = &H200000 ' force long names for 3.x modules
  333. Private Const OFN_SHAREFALLTHROUGH = 2
  334. Private Const OFN_SHARENOWARN = 1
  335. Private Const OFN_SHAREWARN = 0
  336. Private const OFN_FORCESHOWHIDDEN = &h10000000
  337.  
  338. Private Const FVIRTKEY = &h1 ' Assumed to be == TRUE
  339. Private Const FNOINVERT = &H2
  340. Private Const FSHIFT = &H4
  341. Private Const FCONTROL = &H8
  342. Private Const FALT = &H10
  343.  
  344. Public Const tomCharacter = 1
  345. Public Const tomWord = 2
  346. Public Const tomSentence = 3
  347. Public Const tomParagraph = 4
  348. Public Const tomLine = 5
  349. Public Const tomStory = 6
  350. Public Const tomScreen = 7
  351. Public Const tomSection = 8
  352. Public Const tomColumn = 9
  353. Public Const tomRow = 10
  354. Public Const tomWindow = 11
  355. Public Const tomCell = 12
  356. Public Const tomCharFormat = 13
  357. Public Const tomParaFormat = 14
  358. Public Const tomTable = 15
  359. Public Const tomObject = 16
  360.  
  361. Private Delegate Function WndProcDelgate(ByVal hWnd As IntPtr, ByVal Message As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
  362.  
  363. <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
  364. Private Structure WNDCLASSEX
  365. Public cbSize As Integer ' Size in bytes of the WNDCLASSEX structure
  366. Public style As Integer ' Class style
  367. Public lpfnWndProc As WndProcDelgate ' Pointer to the classes Window Procedure
  368. Public cbClsExtra As Integer ' Number of extra bytes to allocate for class
  369. Public cbWndExtra As Integer ' Number of extra bytes to allocate for window
  370. Public hInstance As IntPtr ' Applications instance handle Class
  371. Public hIcon As IntPtr ' Handle to the classes icon
  372. Public hCursor As IntPtr ' Handle to the classes cursor
  373. Public hbrBackground As IntPtr ' Handle to the classes background brush
  374. Public lpszMenuName As String ' Resource name of class menu
  375. Public lpszClassName As String ' Name of the Window Class
  376. Public hIconSm As IntPtr ' Handle to the classes small icon
  377. End Structure
  378.  
  379. <StructLayout(LayoutKind.Sequential)> _
  380. Private Structure POINTAPI
  381. Public x As Integer ' X-Coordinate in pixels
  382. Public y As Integer ' Y-Coordinate in pixels
  383. End Structure
  384.  
  385. <StructLayout(LayoutKind.Sequential)> _
  386. Private Structure RECTL
  387. Public Left As Integer
  388. Public Top As Integer
  389. Public Right As Integer
  390. Public Bottom As Integer
  391. End Structure
  392.  
  393. <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
  394. Private Structure MSG
  395. Public hWnd As IntPtr ' Window handle of the associated window
  396. Public Message As Integer ' Message identifier
  397. Public wParam As IntPtr ' Additional message info
  398. Public lParam As IntPtr ' Additional message info
  399. Public time As Integer ' Time message was posted
  400. Public pt As POINTAPI ' Cursor position when message was posted
  401. End Structure
  402.  
  403. <StructLayout(LayoutKind.Sequential)> _
  404. Private Structure nmhdr
  405. Public hwndFrom As IntPtr
  406. Public idFrom As IntPtr
  407. Public code As IntPtr
  408. End Structure
  409.  
  410. <StructLayout(LayoutKind.Sequential)> _
  411. Private Structure charrange
  412. Public cpMin As Integer
  413. Public cpMax As Integer
  414. End Structure
  415.  
  416. <StructLayout(LayoutKind.Sequential)> _
  417. Private Structure selchange
  418. Public nmhdr As NMHDR
  419. Public chrg As CharRange
  420. Public seltyp As Short
  421. End Structure
  422.  
  423. <StructLayout(LayoutKind.Sequential)> _
  424. Private Structure ACCEL
  425. Public fVirt As Byte
  426. Public key As UShort
  427. Public cmd As UShort
  428. End Structure
  429.  
  430. Private Declare Function CreateAcceleratorTableW Lib "user32" (lpaccl As ACCEL(), ByVal cEntries As Integer) As IntPtr
  431. Private Declare Function TranslateAcceleratorW Lib "user32" (ByVal hwnd As IntPtr, ByVal hAccTable As IntPtr, lpMsg As MSG) As Integer
  432. Private Declare Function DestroyAcceleratorTable Lib "user32" (ByVal haccel As IntPtr) As Integer
  433. Private Declare Auto Function LoadCursor Lib "user32" (ByVal hInstance As IntPtr, ByVal lpCursorName As IntPtr) As IntPtr
  434. Private Declare Auto Function LoadIcon Lib "user32" (ByVal hInstance As IntPtr, ByVal lpIconName As IntPtr) As IntPtr
  435. Private Declare Unicode Function LoadLibraryW Lib "kernel32" (ByVal lpLibFileName As String) As Integer
  436. Private Declare Unicode Function RegisterClassExW Lib "user32" (ByRef pcWndClassEx As WNDCLASSEX) As Integer
  437. 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
  438. Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
  439. Private Declare Function UpdateWindow Lib "user32" (ByVal hWnd As IntPtr) As Boolean
  440. 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
  441. Private Declare Function TranslateMessage Lib "user32" (ByRef lpMsg As MSG) As Boolean
  442. Private Declare Auto Function DispatchMessage Lib "user32" (ByRef lpMsg As MSG) As IntPtr
  443. Private Declare Sub PostQuitMessage Lib "user32" (ByVal nExitCode As Integer)
  444. Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Integer) As IntPtr
  445. 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
  446. Private Declare Function SetFocus Lib "user32" (ByVal hWnd As IntPtr) As IntPtr
  447. 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
  448. 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
  449. 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
  450. 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
  451. 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
  452. Private Declare Unicode Function LoadMenuW Lib "user32" (ByVal hInstance As Integer, ByVal lpString As String) As Integer
  453. Private Declare Function SetMenu Lib "user32" Alias "SetMenu" (ByVal hwnd As Integer, ByVal hMenu As Integer) As Integer
  454. Private Declare Function CreateMenu Lib "user32" () As Integer
  455. Private Declare Function CreatePopupMenu Lib "user32" () As Integer
  456. Private Declare Function DrawMenuBar Lib "user32" (ByVal hMenuBar as Integer) As Integer
  457. 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
  458. 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
  459. Private Declare Function GetSubMenu Lib "user32" Alias "GetSubMenu" (ByVal hMenu As IntPtr, ByVal nPos As Integer) As IntPtr
  460. Private Declare Function DestroyMenu Lib "User32" (ByVal hMenu as Intptr) as Integer
  461. Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As Intptr, ByVal wIDEnableItem As Integer, ByVal wEnable As Integer) As Integer
  462. Private Declare Function CheckMenuItem Lib "user32" (ByVal hMenu As IntPtr, ByVal wIDEnableItem As Integer, ByVal wEnable As Integer) As Integer
  463. 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
  464. Private Declare Function GetMenuState Lib "user32" (ByVal hMenu As IntPtr, ByVal wID As Integer, ByVal wFlags As Integer) As Integer
  465. Private Declare Function GetDC Lib "user32" (ByVal hwnd As IntPtr) As IntPtr
  466.  
  467. '==============================
  468. 'Global variables
  469. '===============================
  470.  
  471. Public Dim Ret as Integer
  472. Public Dim gRTFHwnd as Intptr
  473. Public Dim RTFID as Integer
  474. Public Dim hWnd as Intptr
  475. Public Dim hInstance as IntPtr
  476.  
  477. Public Dim TomDoc as Object
  478. Public Dim TomSel as Object
  479.  
  480. Public Dim hMenuBar As Intptr
  481. Public Dim hFileMenu As Intptr
  482. Public Dim hFileSaveAsFormatMenu As Intptr
  483. Public Dim hHelpMenu As Intptr
  484. Public Dim hContextMenu as Intptr
  485. Public Dim hEditMenu as Intptr
  486. Public Dim hViewMenu as Intptr
  487. Public Dim hInsertMenu as Intptr
  488. Public Dim hToolsMenu as Intptr
  489.  
  490. Public Dim gFileIsDirty as Boolean
  491. Public Dim gFileHasName as Boolean
  492.  
  493. Public Dim WshShell as Object
  494. Public Dim FSO as Object
  495.  
  496. Public Dim ScriptControl1 as Object
  497.  
  498. '==============================
  499. 'Main program start called by sub main.
  500. '===============================
  501.  
  502. Public Sub New()
  503. Dim wndClass As WNDCLASSEX
  504. Dim hWnd As IntPtr
  505. Dim Message As MSG
  506.  
  507. hInstance = Marshal.GetHINSTANCE(GetType(UnicodeEditor).Module)
  508.  
  509. '======================================
  510. 'Register and create the main window
  511. '------------------------------------------------
  512. With wndClass
  513. .style = CS_HREDRAW Or CS_VREDRAW
  514. .lpfnWndProc = New WndProcDelgate(AddressOf WndProc)
  515. .cbClsExtra = 0
  516. .cbWndExtra = 0
  517. .hInstance = hInstance
  518. .hIcon = LoadIcon(hInstance, New IntPtr(IDI_APPLICATION))
  519. .hIconSm = LoadIcon(hInstance, New IntPtr(IDI_APPLICATION))
  520. .hCursor = LoadCursor(hInstance, New IntPtr(IDC_ARROW))
  521. .hbrBackground = GetStockObject(LTGRAY_BRUSH)
  522. .lpszMenuName = Nothing
  523. .lpszClassName = CLASS_NAME
  524. .cbSize = Marshal.SizeOf(wndClass)
  525. End With
  526.  
  527. RegisterClassExW (wndClass)
  528. hWnd = CreateWindowExW (0, CLASS_NAME, APP_TITLE, WS_OVERLAPPEDWINDOW, 300, 200, 640, 480, IntPtr.Zero, nothing , hInstance, IntPtr.Zero)
  529.  
  530. '======================================
  531. 'Register and create the RTF window
  532. '------------------------------------------------
  533. Dim DLLModule as Integer
  534. Dim Flags as Integer
  535. DLLModule = LoadLibraryW("c:\windows\system32\MSFTEDIT.dll")
  536. If DLLModule = 0 Then MsgBox("Load Lib " & Err.LastDllError)
  537. Flags = WS_CHILD + WS_HSCROLL + WS_VSCROLL + WS_VISIBLE + ES_MULTILINE + ES_AUTOHSCROLL + ES_AUTOVSCROLL + ES_NOHIDESEL + ES_WANTRETURN
  538. Dim RTFClassName As String
  539. RTFID = &hff00
  540. RTFClassName = "RICHEDIT50W" & vbNullChar
  541. gRtfHwnd = CreateWindowExW(WS_EX_ACCEPTFILES + WS_EX_CLIENTEDGE, RTFClassName, "", Flags, 0, 0, 600, 400, hwnd, RTFID, DLLModule, IntPtr.Zero)
  542.  
  543. '======================================
  544. 'Create Menus
  545. '------------------------------------------------
  546. hMenuBar = CreateMenu()
  547.  
  548. 'SaveAs format Menu
  549. hFileSaveAsFormatMenu = CreatePopupMenu()
  550. If AppendMenuW(hFileSaveAsFormatMenu, 0, 190, "&Dos") = 0 then Msgbox("Append " & Err.LastDllError)
  551. If AppendMenuW(hFileSaveAsFormatMenu, 0, 191, "&ANSI") = 0 then Msgbox("Append " & Err.LastDllError)
  552. If AppendMenuW(hFileSaveAsFormatMenu, 0, 192, "&UTF8") = 0 then Msgbox("Append " & Err.LastDllError)
  553. If AppendMenuW(hFileSaveAsFormatMenu, 0, 193, "U&TF16") = 0 then Msgbox("Append " & Err.LastDllError)
  554. If AppendMenuW(hFileSaveAsFormatMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
  555. If AppendMenuW(hFileSaveAsFormatMenu, 0, 194, "&Auto") = 0 then Msgbox("Append " & Err.LastDllError)
  556. Ret = CheckMenuRadioItem(hFileSaveAsFormatMenu, 190, 194, 191, mf_bycommand)
  557.  
  558. 'File Menu
  559. hFileMenu = CreatePopupMenu()
  560. If AppendMenuW(hFileMenu, 0, 101, "&New" & vbtab & "Ctrl+N") = 0 then Msgbox("Append " & Err.LastDllError)
  561. If AppendMenuW(hFileMenu, 0, 102, "O&pen ..." & vbtab & "Ctrl+O") = 0 then Msgbox("Append " & Err.LastDllError)
  562. If AppendMenuW(hFileMenu, 0, 103, "S&ave" & vbtab & "Ctrl+S") = 0 then Msgbox("Append " & Err.LastDllError)
  563. If AppendMenuW(hFileMenu, 0, 104, "Save A&s ...") = 0 then Msgbox("Append " & Err.LastDllError)
  564. If AppendMenuW(hFileMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
  565. If AppendMenuW(hFileMenu, MF_Popup, hFileSaveAsFormatMenu, "Save &Format") = 0 then Msgbox("Append " & Err.LastDllError)
  566. If AppendMenuW(hFileMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
  567. If AppendMenuW(hFileMenu, 0, 105, "E&xit" & vbtab & "Alt+F4") = 0 then Msgbox("Append " & Err.LastDllError)
  568.  
  569.  
  570.  
  571. 'Help Menu
  572. hHelpMenu = CreatePopupMenu()
  573. If AppendMenuW(hHelpMenu, 0, 901, "&Help" & vbtab & "F1") = 0 then Msgbox("Append " & Err.LastDllError)
  574. If AppendMenuW(hHelpMenu, 0, 902, "&Programming") = 0 then Msgbox("Append " & Err.LastDllError)
  575. If AppendMenuW(hHelpMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
  576. If AppendMenuW(hHelpMenu, 0, 903, "&About") = 0 then Msgbox("Append " & Err.LastDllError)
  577.  
  578.  
  579. 'Edit Menu - this is almost the same as the context menu.
  580. hEditMenu = CreatePopupMenu()
  581. If AppendMenuW(hEditMenu, 0, 201, "&Undo" & vbtab & "Ctrl+Z") = 0 then Msgbox("Append " & Err.LastDllError)
  582. If AppendMenuW(hEditMenu, 0, 202, "&Redo" & vbtab & "Ctrl+Y") = 0 then Msgbox("Append " & Err.LastDllError)
  583. If AppendMenuW(hEditMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
  584. If AppendMenuW(hEditMenu, 0, 203, "Cu&t" & vbtab & "Ctrl+X") = 0 then Msgbox("Append " & Err.LastDllError)
  585. If AppendMenuW(hEditMenu, 0, 204, "&Copy" & vbtab & "Ctrl+C") = 0 then Msgbox("Append " & Err.LastDllError)
  586. If AppendMenuW(hEditMenu, 0, 205, "&Paste" & vbtab & "Ctrl+V") = 0 then Msgbox("Append " & Err.LastDllError)
  587. If AppendMenuW(hEditMenu, 0, 206, "De&lete" & vbtab & "Del") = 0 then Msgbox("Append " & Err.LastDllError)
  588. If AppendMenuW(hEditMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
  589. If AppendMenuW(hEditMenu, 0, 207, "Select &All" & vbtab & "Ctrl+A") = 0 then Msgbox("Append " & Err.LastDllError)
  590.  
  591. 'Context Menu
  592. hContextMenu = CreatePopupMenu()
  593. If AppendMenuW(hContextMenu, 0, 201, "&Undo" & vbtab & "Ctrl+Z") = 0 then Msgbox("Append " & Err.LastDllError)
  594. If AppendMenuW(hContextMenu, 0, 202, "&Redo" & vbtab & "Ctrl+Y") = 0 then Msgbox("Append " & Err.LastDllError)
  595. If AppendMenuW(hContextMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
  596. If AppendMenuW(hContextMenu, 0, 203, "Cu&t" & vbtab & "Ctrl+X") = 0 then Msgbox("Append " & Err.LastDllError)
  597. If AppendMenuW(hContextMenu, 0, 204, "&Copy" & vbtab & "Ctrl+C") = 0 then Msgbox("Append " & Err.LastDllError)
  598. If AppendMenuW(hContextMenu, 0, 205, "&Paste" & vbtab & "Ctrl+V") = 0 then Msgbox("Append " & Err.LastDllError)
  599. If AppendMenuW(hContextMenu, 0, 206, "De&lete" & vbtab & "Del") = 0 then Msgbox("Append " & Err.LastDllError)
  600. If AppendMenuW(hContextMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
  601. If AppendMenuW(hContextMenu, 0, 207, "Select &All" & vbtab & "Ctrl+A") = 0 then Msgbox("Append " & Err.LastDllError)
  602.  
  603. 'View Menu
  604. hViewMenu = CreatePopupMenu()
  605. If AppendMenuW(hViewMenu, 0, 301, "&Wordwrap") = 0 then Msgbox("Append " & Err.LastDllError)
  606. If AppendMenuW(hViewMenu, MF_Separator, 999, "") = 0 then Msgbox("Append " & Err.LastDllError)
  607. If AppendMenuW(hViewMenu, 0, 302, "&Zoom 100%" & vbtab & "Ctrl+Wheel") = 0 then Msgbox("Append " & Err.LastDllError)
  608.  
  609. 'Insert Menu
  610. hInsertMenu = CreatePopupMenu()
  611. If AppendMenuW(hInsertMenu, 0, 401, "&Date/Time" & vbtab & "F5") = 0 then Msgbox("Append " & Err.LastDllError)
  612.  
  613. 'Tools Menu
  614. hToolsMenu = CreatePopupMenu()
  615. If AppendMenuW(hToolsMenu, 0, 701, "&Word Count") = 0 then Msgbox("Append " & Err.LastDllError)
  616. If AppendMenuW(hToolsMenu, 0, 702, "&Macro") = 0 then Msgbox("Append " & Err.LastDllError)
  617.  
  618. 'MenuBar
  619. If SetMenu(hWnd, hMenuBar) = 0 then Msgbox("SetM " & Err.LastDllError)
  620. If AppendMenuW(hMenuBar, MF_Popup, hFileMenu, "&File") = 0 then Msgbox("Append " & Err.LastDllError)
  621. If AppendMenuW(hMenuBar, MF_Popup, hEditMenu, "&Edit") = 0 then Msgbox("Append " & Err.LastDllError)
  622. If AppendMenuW(hMenuBar, MF_Popup, hViewMenu, "&View") = 0 then Msgbox("Append " & Err.LastDllError)
  623. If AppendMenuW(hMenuBar, MF_Popup, hInsertMenu, "&Insert") = 0 then Msgbox("Append " & Err.LastDllError)
  624. If AppendMenuW(hMenuBar, MF_Popup, hToolsMenu, "&Tools") = 0 then Msgbox("Append " & Err.LastDllError)
  625. If AppendMenuW(hMenuBar, MF_Popup, hHelpMenu, "&Help") = 0 then Msgbox("Append " & Err.LastDllError)
  626. If DrawMenuBar(hWnd) = 0 then Msgbox(Err.LastDllError)
  627.  
  628.  
  629. '======================================
  630. 'Setting up Accelerator keys
  631. '------------------------------------------------
  632.  
  633. Dim hAccTable as IntPtr
  634. Dim AccTable(6) as Accel
  635. With AccTable(0) 'Ctrl + N
  636. .fvirt = fcontrol + fVirtKey
  637. .key = &h4e
  638. .cmd = 101
  639. End With
  640. With AccTable(1) 'Ctrl + O
  641. .fvirt = fcontrol + fVirtKey
  642. .key = &h4f
  643. .cmd = 102
  644. End With
  645. With AccTable(2) 'Ctrl + S
  646. .fvirt = fcontrol + fVirtKey
  647. .key = &h53
  648. .cmd = 103
  649. End With
  650. With AccTable(3) 'F1
  651. .fvirt = fVirtKey
  652. .key = &h70
  653. .cmd = 901
  654. End With
  655. With AccTable(4) 'F5
  656. .fvirt = fVirtKey
  657. .key = &h74
  658. .cmd = 401
  659. End With
  660. With AccTable(5) 'Shift+F10
  661. .fvirt = fVirtKey + fShift
  662. .key = &h79
  663. .cmd = 998
  664. End With
  665. hAccTable = CreateAcceleratorTableW(AccTable, 6)
  666.  
  667. '======================================
  668. 'Setting editing options - there are probably over 100
  669. '------------------------------------------------
  670. Ret = SendMessageStr(gRtfHwnd, WM_SETTEXT, 0, "")
  671. Ret = SendMessageW(gRtfHwnd, EM_SETTEXTMODE, TM_MULTILEVELUNDO + TM_PLAINTEXT + TM_MULTICODEPAGE, 0)
  672. If GetTextMode(gRtfHwnd) <> 41 Then MsgBox("get Text mode = " & GetTextMode(gRtfHwnd))
  673. 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)
  674. ' Uncomment to turn on spellchecking
  675. ' Ret = SendMessageW(gRtfHwnd, EM_SETLANGOPTIONS, IMF_SPELLCHECKING, IMF_SPELLCHECKING)
  676. If GetTextMode(gRtfHwnd) <> 41 Then MsgBox("get Text mode (2) = " & GetTextMode(gRtfHwnd))
  677. Ret = SendMessageW(gRtfHwnd, EM_SETTYPOGRAPHYOPTIONS, TO_None, TO_None)
  678. Ret = SendMessageW(gRtfHwnd, EM_SETOPTIONS, ECO_AUTOHSCROLL + ECO_AUTOVSCROLL + ECO_NOHIDESEL + ECO_WANTRETURN, ECOOP_OR)
  679. Ret = SendMessageW(gRtfHwnd, EM_EXLIMITTEXT, 0, 2000000)
  680. Ret = SendMessageW(gRTFhWnd, EM_SETOPTIONS, ECOOP_OR, ECO_SELECTIONBAR)
  681. Ret = SendMessageW(gRtfHwnd, EM_SetEventMask, 0, ENM_SelChange + ENM_Change)
  682.  
  683. 'Getting TOM object
  684. Ret = SendMessageObj(gRtfHwnd, EM_GETOLEINTERFACE, 0, TomDoc)
  685. TomSel = TomDoc.Selection
  686.  
  687.  
  688. 'Showing the window
  689. ShowWindow(hWnd, SW_SHOWNORMAL)
  690. UpdateWindow (hWnd)
  691. ShowWindow(gRTFhWnd, SW_SHOWNORMAL)
  692. UpdateWindow (gRTFhWnd)
  693. SetFocus (gRTFhWnd)
  694.  
  695. 'set initial global saved status
  696. gFileIsDirty = False
  697. gFileHasName = False
  698.  
  699. console.writeline(System.Windows.Forms.Application.ExecutablePath)
  700.  
  701. 'Create global utility objects wscript.shell for registry and shelling (eg help) and FSO for read support files
  702. WshShell = CreateObject("WScript.Shell")
  703. FSO = CreateObject("Scripting.FileSystemObject")
  704.  
  705. Console.Writeline("Command line is: " & Command())
  706. If Command() <> "" then
  707. TomDoc.Open(Replace(Command(),"""", ""), &h442, 0)
  708. gFileIsDirty = False
  709. gFileHasName = True
  710. End If
  711.  
  712. '======================================
  713. 'This is the program message loop. All further interesting code is run in the window procedure till the window closes then this loop exits and the program exits.
  714. '------------------------------------------------
  715. Do While GetMessage(Message, IntPtr.Zero, 0, 0)
  716. TranslateAcceleratorW(hWnd, hAccTable, Message)
  717. If TranslateAcceleratorW(hWnd, hAccTable, Message) <> 0 and err.lastdllerror = 0 then
  718. TranslateMessage (Message)
  719. End If
  720. DispatchMessage (Message)
  721. Loop
  722. Ret = DestroyMenu(hContextMenu)
  723. Ret = DestroyAcceleratorTable(hAccTable)
  724. 'This is pointless code so I get to see shutdown output before the console window disappears
  725. 'It is expoential to the number of spaces
  726. Dim i as intptr
  727. Do
  728. i = i + 1
  729. If Cint(i) > &h8fff then Exit Do
  730. RTFClassName = RTFClassName & " "
  731. Loop
  732. End Sub
  733.  
  734. '======================================
  735. 'Main window procedure.
  736. '------------------------------------------------
  737. Private Function WndProc(ByVal hWnd As IntPtr, ByVal Message As Integer, ByVal wParam As Intptr, ByVal lParam As Intptr ) As IntPtr
  738. ' Console.WriteLine ("Message " & Message)
  739. ' Console.WriteLine ("Filestatus " & gFileIsDirty & " " & gFileHasName)
  740. Select Case Message
  741. Case WM_LBUTTONDOWN
  742. MessageBoxW(hWnd, "Left Mouse Button Pressed", APP_TITLE, MB_OK)
  743. WndProc = IntPtr.Zero
  744. Case WM_RBUTTONDOWN
  745. MessageBoxW(hWnd, "Right Mouse Button Pressed", APP_TITLE, MB_OK)
  746. WndProc = IntPtr.Zero
  747. Case WM_DESTROY
  748. PostQuitMessage (0)
  749. WndProc = IntPtr.Zero
  750. Case WM_SIZE
  751. Ret = SetWindowPos(gRtfHwnd, HWND_NOTOPMOST, 0, 0, CLng(LParam) AND &h0000ffff, CLng(LParam) >> 16, SWP_NOZORDER + SWP_NOOWNERZORDER)
  752. WndProc = IntPtr.Zero
  753. Case WM_COMMAND
  754. Console.WriteLine ("Command " & (CInt(wParam) >> 16) & " " & (CInt(wParam) and &Hffff) & " " & Cint(lparam))
  755. If (CInt(wParam) >> 16) > 1 Then
  756. ' console.Writeline("WmCommand " & (CInt(wParam) >> 16))
  757. If (CInt(wParam) >> 16) = EN_Change then Console.WriteLine("Edited")
  758. If (CInt(wParam) >> 16) = EN_Change then gFileIsDirty = True
  759. WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
  760. Else
  761. Dim MenuCommand as Integer
  762. MenuCommand = CInt(wParam) and &Hffff
  763. console.Writeline("Menu " & MenuCommand)
  764. Select Case MenuCommand
  765. Case 105 'Exit
  766. Ret = SendMessageW(Hwnd, WM_Close, 0, 0)
  767. WndProc = IntPtr.Zero
  768. Case 101 'New
  769. If gFileIsDirty = True Then
  770. console.writeline("saving")
  771. Ret = Msgbox("File has changed. Do you want to save?", vbyesnocancel, "Editor")
  772. If Ret = vbyes then
  773. Savefile()
  774. ElseIf Ret = vbno then
  775. Ret = SendMessageStr(gRtfHwnd, WM_SETTEXT, 0, "")
  776. gFileisDirty = False
  777. gFileHasName = False
  778. End If
  779. Else
  780. Ret = SendMessageStr(gRtfHwnd, WM_SETTEXT, 0, "")
  781. gFileisDirty = False
  782. gFileHasName = False
  783. End If
  784. WndProc = IntPtr.Zero
  785. Case 190 'Dos
  786. Ret = CheckMenuRadioItem(hFileSaveAsFormatMenu, 190, 194, 190, mf_bycommand)
  787. WndProc = IntPtr.Zero
  788. Case 191 'ANSI
  789. Ret = CheckMenuRadioItem(hFileSaveAsFormatMenu, 190, 194, 191, mf_bycommand)
  790. WndProc = IntPtr.Zero
  791. Case 192 'UTF8
  792. Ret = CheckMenuRadioItem(hFileSaveAsFormatMenu, 190, 194, 192, mf_bycommand)
  793. WndProc = IntPtr.Zero
  794. Case 193 'UTF16
  795. Ret = CheckMenuRadioItem(hFileSaveAsFormatMenu, 190, 194, 193, mf_bycommand)
  796. WndProc = IntPtr.Zero
  797. Case 194 'Auto
  798. Ret = CheckMenuRadioItem(hFileSaveAsFormatMenu, 190, 194, 194, mf_bycommand)
  799. WndProc = IntPtr.Zero
  800. Case 901 'Help
  801. WshShell.Run("""" & System.Windows.Forms.Application.StartupPath & "\Unicode Editor Help.hta""")
  802. WndProc = IntPtr.Zero
  803. Case 902 'Programming
  804. WshShell.Run("""" & System.Windows.Forms.Application.StartupPath & "\Unicode Editor.hta""")
  805. WndProc = IntPtr.Zero
  806. Case 903 'About
  807. 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")
  808. WndProc = IntPtr.Zero
  809. Case 201 'undo
  810. If SendMessageW(grtfhwnd, em_canundo, 0, 0) <> 0 then
  811. Ret = SendMessageW(grtfhwnd, em_undo, 0, 0)
  812. End If
  813. WndProc = IntPtr.Zero
  814. Case 202 'redo
  815. If SendMessageW(grtfhwnd, em_canredo, 0, 0) <> 0 then
  816. Ret = SendMessageW(grtfhwnd, em_redo, 0, 0)
  817. End If
  818. WndProc = IntPtr.Zero
  819. Case 203
  820. If TomSel.Type = 2 then
  821. TomSel.Cut(vbnull)
  822. End If
  823. WndProc = IntPtr.Zero
  824. Case 204
  825. If TomSel.Type = 2 then
  826. TomSel.Copy(vbnull)
  827. End If
  828. WndProc = IntPtr.Zero
  829. Case 205
  830. If tomsel.canpaste(vbnull, CF_UNICODETEXT) = true
  831. tomsel.paste(vbnull, CF_UNICODETEXT)
  832. End If
  833. WndProc = IntPtr.Zero
  834. Case 206
  835. If TomSel.Type = 2 then
  836. Ret=TomSel.Delete(0, 0)
  837. End If
  838. WndProc = IntPtr.Zero
  839. Case 207 'select all
  840. Ret = tomsel.expand(6)
  841. WndProc = IntPtr.Zero
  842. Case 301 'Wordwrap
  843. If GetMenuState(hViewMenu, 301, MF_ByCommand) = 0 then
  844. Console.writeline("GetMenuState " & Ret)
  845. Ret = SendMessageW(gRtfHwnd, EM_SETTARGETDEVICE, GetDC(gRtfHwnd), -1800)
  846. CheckMenuItem(hViewMenu, 301, MF_ByCommand + MF_Checked)
  847. Else
  848. Console.writeline("GetMenuState " & Ret)
  849. Ret = SendMessageW(gRtfHwnd, EM_SETTARGETDEVICE, GetDC(gRtfHwnd), 20000000)
  850. CheckMenuItem(hViewMenu, 301, MF_ByCommand + MF_UnChecked)
  851. End If
  852. WndProc = IntPtr.Zero
  853. Case 302 'Zoom 100%
  854. Ret = SendMessageW(grtfhwnd, em_setzoom, 0, 0)
  855. WndProc = IntPtr.Zero
  856. Case 401 'Insert Date/Time
  857. TomSel.TypeText(FormatDateTime(Now(), 0) & " ")
  858. WndProc = IntPtr.Zero
  859. Case 998 'Context menu from keyboard
  860. Ret = TrackPopupMenu(hContextMenu, TPM_RightButton, (CInt(lParam) and &Hffff), (CInt(lParam) >> 16), 0, hWnd, &h0)
  861. WndProc = 0
  862. Case 702 'Macro 1
  863. ' On Error Resume Next
  864. ScriptControl1 = createObject("MSScriptControl.ScriptControl")
  865. With ScriptControl1
  866. .Language = "VBScript"
  867. .UseSafeSubset = False
  868. .AllowUI = True
  869. .AddObject("TomDoc", TomDoc, True)
  870. .AddObject("TomSel", TomSel, True)
  871. ScriptControl1.addcode("Msgbox TomSel.Text")
  872. End With
  873. ScriptControl1 = nothing
  874. SetFocus (gRTFhWnd)
  875. WndProc = 0
  876. On Error Goto 0
  877. Case 701 'Word Count
  878. Dim R As Object
  879. Dim R2 As Object
  880. Dim Str As String
  881. If TomSel.Start = TomSel.End And TomSel.StoryLength <> 0 Then
  882. R = TomDoc.Range(TomSel.StoryLength, TomSel.StoryLength)
  883. Str = "Document Word Count" & vbCrLf & vbCrLf
  884. Str = Str & "Characters" & vbTab & R.GetIndex(tomCharacter) - 1 & vbCrLf
  885. Str = Str & "Words" & vbTab & vbTab & R.GetIndex(tomWord) - 1 & vbCrLf
  886. Str = Str & "Sentences" & vbTab & R.GetIndex(tomSentence) - 1 & vbCrLf
  887. Str = Str & "Screen Lines" & vbTab & R.GetIndex(tomLine) & vbCrLf
  888. Str = Str & "Lines" & vbTab & vbTab & R.GetIndex(tomParagraph) & vbCrLf
  889. MsgBox(Str)
  890. ElseIf TomSel.StoryLength <> 0 Then
  891. R = TomDoc.Range(TomSel.End, TomSel.End)
  892. R2 = TomDoc.Range(TomSel.Start, TomSel.Start)
  893. Str = "Selection Word Count" & vbCrLf & vbCrLf
  894. Str = Str & "Characters" & vbTab & R.GetIndex(tomCharacter) - R2.GetIndex(tomCharacter) & vbCrLf
  895. Str = Str & "Words" & vbTab & vbTab & R.GetIndex(tomWord) - R2.GetIndex(tomWord) & vbCrLf
  896. Str = Str & "Sentences" & vbTab & R.GetIndex(tomSentence) - R2.GetIndex(tomSentence) & vbCrLf
  897. Str = Str & "Screen Lines" & vbTab & R.GetIndex(tomLine) - R2.GetIndex(tomLine) & vbCrLf
  898. Str = Str & "Lines" & vbTab & vbTab & R.GetIndex(tomParagraph) - R2.GetIndex(tomParagraph) & vbCrLf
  899. MsgBox(Str)
  900. Else
  901. MsgBox("There is no text to count.")
  902. End If
  903. TomSel.Select
  904. WndProc = IntPtr.Zero
  905. Case Else
  906. WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
  907. End Select
  908. End If
  909. Case WM_Notify
  910. Dim hdr As selchange = Marshal.PtrToStructure(lparam , GetType(selchange))
  911. If hdr.nmhdr.Code = En_SelChanged then
  912. Console.Writeline ("SelChanged")
  913. WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
  914. Else
  915. Console.Writeline ("Notify " & Cstr(hdr.nmhdr.Code))
  916. WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
  917. End If
  918. Case WM_ACTIVATEAPP
  919. WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
  920. Case WM_PARENTNOTIFY
  921. ' Console.WriteLine ("ParentNotify " & (CInt(wParam) >> 16) & " " & (CInt(wParam) and &Hffff) & " " & Cint(lparam))
  922. ' If (CInt(wParam) and &Hffff) = WM_RBUTTONDOWN Then Console.WriteLine ("Right button down")
  923. WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
  924. Case WM_CONTEXTMENU
  925. ' Console.WriteLine ("Context Menu " & (CInt(wParam) >> 16) & " " & (CInt(wParam) and &Hffff) & " " & Cint(lparam))
  926. If wParam = gRTFhWnd Then
  927. Console.WriteLine ("Edit Context Menu")
  928. Console.writeline(CStr(hcontextmenu))
  929. Ret = TrackPopupMenu(hContextMenu, TPM_RightButton, (CInt(lParam) and &Hffff), (CInt(lParam) >> 16), 0, hWnd, &h0)
  930. WndProc = 0
  931. Else
  932. Console.WriteLine ("Another Context Menu")
  933. WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
  934. End If
  935. Case WM_INITMENUPOPUP
  936. If wParam = hContextMenu Then
  937. ' Console.WriteLine ("Init Menu" & (CInt(wParam) >> 16) & " " & (CInt(wParam) and &Hffff) & " " & Cint(lparam))
  938. If SendMessageW(grtfhwnd, em_canundo, 0, 0) <> 0 then
  939. Ret = EnableMenuItem(hcontextmenu, 201, mf_bycommand + mf_enabled)
  940. Else
  941. Ret = EnableMenuItem(hcontextmenu, 201, mf_bycommand + mf_grayed)
  942. End If
  943. If SendMessageW(grtfhwnd, em_canredo, 0, 0) <> 0 then
  944. Ret = EnableMenuItem(hcontextmenu, 202, mf_bycommand + mf_enabled)
  945. Else
  946. Ret = EnableMenuItem(hcontextmenu, 202, mf_bycommand + mf_grayed)
  947. End If
  948. If tomsel.canpaste(vbnull, CF_UNICODETEXT) = true then
  949. Ret = EnableMenuItem(hcontextmenu, 205, mf_bycommand + mf_enabled)
  950. Else
  951. Ret = EnableMenuItem(hcontextmenu, 205, mf_bycommand + mf_grayed)
  952. End If
  953. If tomsel.type() = 1 then 'normal insertion
  954. Ret = EnableMenuItem(hcontextmenu, 203, mf_bycommand + mf_grayed)
  955. Ret = EnableMenuItem(hcontextmenu, 204, mf_bycommand + mf_grayed)
  956. Ret = EnableMenuItem(hcontextmenu, 206, mf_bycommand + mf_grayed)
  957. else
  958. Ret = EnableMenuItem(hcontextmenu, 203, mf_bycommand + mf_enabled)
  959. Ret = EnableMenuItem(hcontextmenu, 204, mf_bycommand + mf_enabled)
  960. Ret = EnableMenuItem(hcontextmenu, 206, mf_bycommand + mf_enabled)
  961. End If
  962. End If
  963. If wParam = hEditMenu Then
  964. ' Console.WriteLine ("Init Menu" & (CInt(wParam) >> 16) & " " & (CInt(wParam) and &Hffff) & " " & Cint(lparam))
  965. If SendMessageW(grtfhwnd, em_canundo, 0, 0) <> 0 then
  966. Ret = EnableMenuItem(heditmenu, 201, mf_bycommand + mf_enabled)
  967. Else
  968. Ret = EnableMenuItem(heditmenu, 201, mf_bycommand + mf_grayed)
  969. End If
  970. If SendMessageW(grtfhwnd, em_canredo, 0, 0) <> 0 then
  971. Ret = EnableMenuItem(heditmenu, 202, mf_bycommand + mf_enabled)
  972. Else
  973. Ret = EnableMenuItem(heditmenu, 202, mf_bycommand + mf_grayed)
  974. End If
  975. If tomsel.canpaste(vbnull, CF_UNICODETEXT) = true then
  976. Ret = EnableMenuItem(heditmenu, 205, mf_bycommand + mf_enabled)
  977. Else
  978. Ret = EnableMenuItem(heditmenu, 205, mf_bycommand + mf_grayed)
  979. End If
  980. If tomsel.type() = 1 then 'normal insertion
  981. Ret = EnableMenuItem(heditmenu, 203, mf_bycommand + mf_grayed)
  982. Ret = EnableMenuItem(heditmenu, 204, mf_bycommand + mf_grayed)
  983. Ret = EnableMenuItem(heditmenu, 206, mf_bycommand + mf_grayed)
  984. else
  985. Ret = EnableMenuItem(heditmenu, 203, mf_bycommand + mf_enabled)
  986. Ret = EnableMenuItem(heditmenu, 204, mf_bycommand + mf_enabled)
  987. Ret = EnableMenuItem(heditmenu, 206, mf_bycommand + mf_enabled)
  988. End If
  989. End If
  990. WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
  991. Case Else
  992. WndProc = DefWindowProc(hWnd, Message, wParam, lParam)
  993. End Select
  994. End Function
  995.  
  996. '======================================
  997. 'This is the starting sub. It calls the main sub New()
  998. '------------------------------------------------
  999.  
  1000. Public Shared Sub Main()
  1001. Dim wnd As New UnicodeEditor
  1002. End Sub
  1003.  
  1004. '======================================
  1005. 'Assorted functions
  1006. '------------------------------------------------
  1007.  
  1008. Public Function GetTextMode(lhwnd as IntPtr) As Integer
  1009. Dim Ret As Integer
  1010. Ret = SendMessageW(lhwnd, EM_GETTEXTMODE, 0, 0)
  1011. GetTextMode = Ret
  1012. End Function
  1013.  
  1014. Private Sub OpenFile()
  1015. Dim ofn as New System.Windows.Forms.OpenFileDialog
  1016. With ofn
  1017. .Filename = "*.*"
  1018. .ShowDialog
  1019. End With
  1020. Console.writeline(ofn.filename)
  1021. ' Ret = GetOpenFileNameW(ofn)
  1022. ' Console.writeline(Len(ofn.file))
  1023. ' Console.writeline(ofn.file)
  1024. ' console.writeline("OFN " & Ret & " " & err.lastdllerror)
  1025. End Sub
  1026.  
  1027.  
  1028. Private Sub SaveFile()
  1029. Dim ofn as New System.Windows.Forms.OpenFileDialog
  1030. With ofn
  1031. .Filename = "*.*"
  1032. .ShowDialog
  1033. End With
  1034. Console.writeline(ofn.filename)
  1035. ' Ret = GetOpenFileNameW(ofn)
  1036. ' Console.writeline(Len(ofn.file))
  1037. ' Console.writeline(ofn.file)
  1038. ' console.writeline("OFN " & Ret & " " & err.lastdllerror)
  1039. End Sub
  1040.  
  1041. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement