Hi,

what ist the best way to read words under the mouse pointer (not only in edits/richedits...).
Can somebody help ?

Greetings,
Nordwind64
Posted on 2003-06-13 15:54:26 by Nordwind64
Hi,

In fact i have tried to implementing word sensitive F1 help add-in for AsmEdit for a while. But not very successful. Because AsmEdit was not ready to accept this. Btw, i did my best also. In fact inspired from AsmEdit sources(Thanks Ewayne). This is my implementation, only needs to selecting the keyword and F1. However you may wait the fat woman :)

;*******************************************


; Place the LIBRARY & EXPORTS in your Projects xxxx.def file.

;------------------
;LIBRARY (your Project name)
;EXPORTS DllProc
;------------------
title AddinT

.586
.model flat, stdcall
option casemap:none ; Case sensitive

include C:\Masm32V1\include\Windows.inc
include C:\Masm32\include\user32.inc
include C:\Masm32\include\kernel32.inc
include C:\Masm32\include\advapi32.inc
include C:\Masm32V1\include\DSPMACRO.asm
include masm32.inc

includelib C:\Masm32\lib\user32.lib
includelib C:\Masm32\lib\kernel32.lib
includelib C:\Masm32\lib\advapi32.lib
includelib masm32.lib

;===================================================
; PROTO, MACRO, and Data section
;===================================================
Initilize PROTO :DWORD
NewProject PROTO :DWORD
GetRegPaths PROTO :DWORD

FindTopic PROTO :DWORD,:DWORD
SearchKeyword proto :DWORD
GetKeyword proto

.const
; Messages sent to AsmEdit
IDM_GETDWORDS equ WM_USER+50
IDM_GETPROC equ WM_USER+51
IDM_GETDATA equ WM_USER+52

IDM_NEW equ 6001
IDM_OPEN equ 6002
IDM_CLOSE equ 6004
IDM_SAVEAS equ 6006
IDM_PRINT equ 6010

IDM_HELPF1 equ 492 ; wParam value

ADDINPROCS struct
lpGetWordFromPos dd 0 ;Handle of richedit, returns pointer to word
lpGetWord dd 0 ;lpWord, returns pointer to word
ADDINPROCS ends

; IDM_GETDWORDS returns a poiner to the following Handle & dword structure.
ASMDWORDS struct
hWnd dd 0 ; Handle of AsmEdit.
hMenu dd 0 ; Handle of AsmEdit Menu.
hToolBar dd 0 ; Handle of AsmEdit ToolBar.
hStatus dd 0 ; Handle of AsmEdit StatusBar.
hREdit dd 0 ; Handle of RichEdit window.
MenuID dd 0 ; Addin/Project menu item ID.
ProjType dd 0 ; Project type from create (.dll or .exe)
ASMDWORDS ends

; IDM_GETPROC returns a poiner to the following Procedure structure.
ASMEPROC struct
lpBaseAscii dd 0 ; Pointer to BaseAscii Proc.
lpAsciiBase dd 0 ; Pointer to AsciiBase Proc.
lpEnaDisMenu dd 0 ; Pointer to EnableDisableEditMenu Proc.
ASMEPROC ends

; IDM_GETDATA returns a poiner to the following Data structure.
ASMEDATA struct
lpRootDir dd 0 ; Pointer to root dir, ends with \.
lpPathName dd 0 ; Pointer to current full path.
lpFileName dd 0 ; Pointer to FileName.
lpProjectName dd 0 ; Pointer to Project Name.
lpProjectPath dd 0 ; Pointer to Project Path.
lpRegKey dd 0 ; AsmEdit registry key.
ASMEDATA ends

.data

AppName db 'ContextF1',0
szHelp db "C:\\Program Files\\Common Files\\Borland Shared\\MSHelp\\WIN32SDK.HLP",0

.data?
hInst dd ? ; AsmEdit's instance
hREdit dd ? ; Handle of RichEdit
dwHStruct dd ? ; Pointer to handles struct
dwPStruct dd ? ; Pointer to proc struct
dwDStruct dd ? ; Pointer to data struct

szKw db 51 dup (?)
lnKw dd ?
szFn db 256 dup (?)
buffer db 256 dup (?)
dOptions dd ?
lpHStruct dd ? ;Pointer to handles struct
lpPStruct dd ? ;Pointer to proc struct
lpDStruct dd ? ;Pointer to data struct
pDbPath dd ?
hHHwin dd ?

topicBuffer db 256 dup (?)

.code

;===============================================================
; DLL Entry
;===============================================================
DllEntry PROC hInstance:DWORD, reason, reserved1

.if reason == DLL_PROCESS_ATTACH ; When the dll is loaded
push hInstance
pop hInst
mov eax, TRUE
.endif
ret

DllEntry ENDP

;===============================================================
; Initilize Proc loads pointers for various handles, and
; data areas. Is called from the DllProc
;===============================================================
Initilize PROC hWnd:DWORD

INVOKE SendMessage, hWnd, IDM_GETDWORDS, 0, 0
mov dwHStruct, eax
INVOKE SendMessage, hWnd, IDM_GETPROC, 0, 0
mov dwPStruct, eax
INVOKE SendMessage, hWnd, IDM_GETDATA, 0, 0
mov dwDStruct, eax
ret

Initilize ENDP

;===============================================================
; DllProc Receives WM_COMMAND messages from AsmEdit
;===============================================================
DllProc PROC uses edi hWnd:DWORD, wMsg, wParam, lParam

.if wMsg == WM_COMMAND

.if !dwHStruct ; Check if Initilize has been run
INVOKE Initilize, hWnd
.endif
mov eax, wParam
cwde
mov wParam, eax

; NOTE! The wParam & lParam value will be whatever you specified in the menu command.

;---------- [New Tab] ----------
.if ax == IDM_HELPF1
invoke GetKeyword ; Get the current word
.if eax
invoke WinHelp,hREdit,addr szHelp,HELP_KEY, eax
.endif
jmp Ret1
.endif

;---------- [AsmEdit closing down] ----------
.elseif wMsg == WM_CLOSE
; Do cleanup work
jmp Ret0
.endif

Ret0:
xor eax, eax
ret

Ret1:
mov eax, TRUE
ret

DllProc ENDP

;----------------------------------------------------------------------------------
GetKeyword proc

LOCAL trg:TEXTRANGE
LOCAL chr:byte
LOCAL hEdt:dword
LOCAL pKeyword:dword


;Clear buffer
mov buffer,0
mov pKeyword, offset buffer

mov eax, dwHStruct
mov eax,(ASMDWORDS ptr [eax]).hREdit

.if eax
mov hREdit, eax
mov hEdt,eax
.endif

;Get selection
invoke SendMessage, hEdt, EM_EXGETSEL, 0, addr trg.chrg
;Get size
mov eax, trg.chrg.cpMax
sub eax, trg.chrg.cpMin
.if eax
;There is a selection in the edit window
;If more than 255 chars in selection, dont bother
.if eax<256
invoke SendMessage,hEdt,EM_GETSELTEXT,0,addr buffer
.endif
.else
;No selection, let RadASM get word under caret
; push hEdt
; mov eax,[lpPStruct]
; mov eax,(ADDINPROCS ptr [eax]).lpGetWordFromPos
; call eax
; mov pKeyword,eax
;On return eax contains pointer to word
;The word will be a null string if caret is on white space
;Check character before keyword
; Get start of word
inc trg.chrg.cpMin ; Hack to fix when the caret is just after the "."
invoke SendMessage,hEdt,EM_FINDWORDBREAK,WB_MOVEWORDLEFT,trg.chrg.cpMin
; Set up the textrange
mov trg.chrg.cpMax,eax
dec eax
mov trg.chrg.cpMin,eax
lea edx,chr
mov trg.lpstrText,edx
; Get the character
invoke SendMessage,hEdt,EM_GETTEXTRANGE,0,addr trg
.if chr=="."
mov esi,pKeyword
mov edi,offset buffer+1
mov byte ptr [edi-1],"."
@@:
lodsb
stosb
or al,al
jnz @B
mov pKeyword,offset buffer
.endif
.endif

mov pKeyword, offset buffer
invoke ltrim,pKeyword,pKeyword
mov eax,pKeyword
.if byte ptr [eax]==0
xor eax,eax
.endif
ret

GetKeyword endp
;----------------------------------------------------------------------------------

End DllEntry
Posted on 2003-06-13 16:52:46 by cakmak
I usually move the mouse pointer off the text to see it, and then read it from left to right. :grin:

Try the EM_CHARFROMPOS message. :alright:
Posted on 2003-06-13 16:52:46 by iblis
Hi,

thanks a lot !!!

Greetings,
Nordwind64
Posted on 2003-06-15 06:58:55 by Nordwind64