IonicWind Software

IWBasic => General Questions => Topic started by: Andy on October 13, 2020, 10:03:07 AM

Title: SendMessage not working?
Post by: Andy on October 13, 2020, 10:03:07 AM
Hi,

Here a puzzle, I've gone back to looking at EM_HIDESELECTION.

The rich edit control is not receiving this message - why?

1. The rich edit is sub classed.

2. It receives all other messages.

Take a look:

SUB Rich_Edit_Handler(hwnd:int,uMsg:int,wParam:int,lParam:pointer),int

if uMsg = 177 'EM_SETSEL - Works!
print "SET SEL !!!! ",wParam,"  ",lParam
endif

if uMsg = 1087 'EM_HIDESELECTION - Does not Work ?????
  Finish() 'Exit program to check message received...
  print "################## ",wParam,"  ",lParam
endif

After loading a file I tried this:

SENDMESSAGE(rHandle,EM_SETSEL,0,10)
print "NOW #########################    ",EM_HIDESELECTION
SENDMESSAGE(w1.Hwnd,EM_HIDESELECTION,1,0)

The EM_HIDESELECTION value of 1087 is correct, but the rich edit control never receives it?

Help please any one...

Thanks,
Andy.
Title: Re: SendMessage not working?
Post by: Brian on October 13, 2020, 11:06:57 AM
Andy,

Just seen a post somewhere where they used the Windows API SendMessage instead of IWB's built-in SendMessage, and it worked

That's 043F Hex, 1087 Dec

Brian
Title: Re: SendMessage not working?
Post by: aurelCB on October 13, 2020, 02:03:29 PM
yes it should work or you can try 
RTHIDESEL      = 19
or 
EM_HIDESEL      = 19
which work in Creative basic

and yes it is 1087
Title: Re: SendMessage not working?
Post by: Andy on October 13, 2020, 11:58:48 PM
Spent a few more hours on this and this is what I have found:

Here is the IWBasic test code:

$INCLUDE "windowssdk.inc"
$INCLUDE "richedit.inc"
' Tried with & without richedit.inc.

openconsole

WINDOW w1
OPENWINDOW w1,0,0,500,400,@MINBOX|@MAXBOX|@SIZE|@CAPTION,0,"Window",&handler


'CONTROL w1,@RICHEDIT,"",0,0,500,400,0x50B010C4,1
CONTROL w1,@RICHEDIT,"",0,0,500,400,WS_BORDER|WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_LEFT|ES_MULTILINE|ES_AUTOVSCROLL,1
' Tried both styles just in case it was something to do with styles.

  SETFONT w1,"Arial",12,500,0,1
  setcontroltext(w1,1,"Hello" + CHR$(13) + CHR$ (10))
  int rHandle = getcontrolhandle(w1,1)

  setcaption w1,"RC Handle is " + str$(rHandle)

'================ - Here - =========================

const EM_HIDESEL = 0x13 ' 19 decimal  - tried 0x19 just in case...
const EM_HIDESELECTION = 0x43F ' 1087 decimal - (already defined in richedit.inc)

SubclassRichEdit(w1,1)
' Tried with sub classing the RE control as well as normal - sels not hidden.

SendMessage(rHandle,EM_SETSEL,0,5)
' Sets the selection okay.

setfocus w1,1
' Tried different combinations of SETFOCUS,
' e.g. Before selection, after selection, after hide selections - sels not hidden.

'OPTION 1:
'print SendMessageA(rHandle,EM_HIDESEL,1,0)
' Returns 1, leaves the highlight on, does not hide sels.

'OPTION 2:
print SendMessageA(rHandle,EM_HIDESELECTION,1,0)
' Returns 0, Destroys the highlight, does not hide sels.

' - Have also tried SendMessageW for options 1 & 2 - no difference.

'OPTION 3:
'print CONTROLCMD (w1,1,@rthidesel)
' Returns 0, Leaves the highlight on, does not hide sels.

setfocus w1,1
'=============================================

WAITUNTIL IsWindowClosed(w1)
closeconsole
end

SUB SubclassRichEdit(parent as WINDOW,id as INT)
    hEdit = GETCONTROLHANDLE(parent,id)
    lpfn = SetWindowLongA(hEdit,-4,&RichEditHandler)
    SetPropA(hEdit,"edit_handler",lpfn) 
RETURN
ENDSUB
SUB UnSubclassRichEdit(parent as WINDOW,id as INT)
    hEdit = GETCONTROLHANDLE(parent,id)
    SetWindowLongA(hEdit,-4,GetPropA(hEdit,"edit_handler"))
    RemovePropA(hEdit,"edit_handler")
RETURN
ENDSUB

SUB handler(),INT
 SELECT @MESSAGE
          CASE @IDCREATE
                CENTERWINDOW w1

          CASE @IDCLOSEWINDOW
                UnSubclassRichEdit(w1,1)
                CLOSEWINDOW w1

          CASE @IDCONTROL
                SELECT @CONTROLID
                endselect

    ENDSELECT
RETURN 0
ENDSUB

SUB RichEditHandler(hwnd:int,uMsg:int,wParam:int,lParam:pointer),int
    SELECT uMsg
          case EM_HIDESEL
                print "EM_HIDESEL Notify"
          case EM_HIDESELECTION
                print "EM_HIDESELELECTION Notify"

    ENDSELECT

RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
ENDSUB

And here is the Ebasic test code:


DECLARE IMPORT,SendMessageA(hWnd:uint, message:uint, wParam:int, lparam:uint),uint
DECLARE IMPORT,CallWindowProcA(lpPrevWndFunc:INT,hWnd:INT,Msg:INT,wParam:INT,lParam:INT),INT
DECLARE IMPORT,SetWindowLongA(hWnd:INT,nIndex:INT,dwNewLong:INT),INT
DECLARE IMPORT,SetPropA(hWnd:UINT,lpString:STRING,hData:UINT),INT
DECLARE IMPORT,GetPropA(hWnd:UINT,lpString:STRING),UINT
DECLARE IMPORT,RemovePropA(hWnd:UINT,lpString:STRING),UINT

openconsole

WINDOW w1
OPENWINDOW w1,0,0,500,400,@MINBOX|@MAXBOX|@SIZE|@CAPTION,0,"Window",&handler


CONTROL w1,@RICHEDIT,"",0,0,500,400,0x50B010C4,1
'CONTROL w1,@RICHEDIT,"",0,0,500,400,WS_BORDER|WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_LEFT|ES_MULTILINE|ES_AUTOVSCROLL,1
' Tried both styles.

  SETFONT w1,"Arial",12,500,0,1
  setcontroltext(w1,1,"Hello" + CHR$(13) + CHR$ (10))
  int rHandle
  rHandle = getcontrolhandle(w1,1)

  setcaption w1,"RC Handle is " + str$(rHandle)

'================ - Here - =========================
const EM_HIDESEL = 0x13 ' 19 decimal
const EM_HIDESELECTION = 0x43F ' 1087 decimal - (already defined in richedit.inc)

SubclassRichEdit(w1,1)
' Tried with sub classing the RE control as well as normal - sels not hidden.

'CONST EM_SETSEL = 0
'SendMessageA(rHandle,EM_SETSEL,0,5)
CONTROLCMD w1,1,@RTSETSELECTION,0,5



' Sets the selection okay.

setfocus w1,1
' Tried different combinations of SETFOCUS,
' e.g. Before selection, after selection, after hide selections - sels not hidden.

'OPTION 1:
'print SendMessageA(rHandle,EM_HIDESEL,1,0)
' Returns 1, leaves the highlight on, does not hide sels.

'OPTION 2:
'print SendMessageA(rHandle,EM_HIDESELECTION,1,0)
' Returns 0, Destroys the highlight, does not hide sels.

' - Have also tried SendMessageW for options 1 & 2 - no difference.

'OPTION 3:
print CONTROLCMD (w1,1,@rthidesel)
' Returns 0, Leaves the highlight on, does not hide sels.

setfocus w1,1
'=============================================

WAITUNTIL w1 = 0
closeconsole
end

SUB SubclassRichEdit(parent as WINDOW,id as INT)
    hEdit = GETCONTROLHANDLE(parent,id)
    lpfn = SetWindowLongA(hEdit,-4,&RichEditHandler)
    SetPropA(hEdit,"edit_handler",lpfn) 
RETURN
ENDSUB
SUB UnSubclassRichEdit(parent as WINDOW,id as INT)
    hEdit = GETCONTROLHANDLE(parent,id)
    SetWindowLongA(hEdit,-4,GetPropA(hEdit,"edit_handler"))
    RemovePropA(hEdit,"edit_handler")
RETURN
ENDSUB

SUB handler(),INT
 SELECT @MESSAGE
          CASE @IDCREATE
                CENTERWINDOW w1

          CASE @IDCLOSEWINDOW
                UnSubclassRichEdit(w1,1)
                CLOSEWINDOW w1

          CASE @IDCONTROL
                SELECT @CONTROLID
                endselect

    ENDSELECT
RETURN 0
ENDSUB

SUB RichEditHandler(hwnd:int,uMsg:int,wParam:int,lParam:pointer),int
    SELECT uMsg
          case EM_HIDESEL
                print "Notify"
    ENDSELECT

RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
ENDSUB
 

Both IWB & EB versions don't work, so what ever Creative Basic is doing, it's not doing it here.

Andy.
Title: Re: SendMessage not working?
Post by: LarryMc on October 14, 2020, 04:26:22 PM
Andy
hideselection is another word for unseleclet  or unhilite
I modified your code and took out all the extra stuff (I could have taken out the subclass but I just left it there but it isn't needed in the example)

$INCLUDE "windowssdk.inc"
$INCLUDE "richedit.inc"
' Tried with & without richedit.inc.

openconsole
int toggle

WINDOW w1
OPENWINDOW w1,0,0,900,600,@MINBOX|@MAXBOX|@SIZE|@CAPTION,0,"Window",&handler


CONTROL w1,@RICHEDIT,"",0,0,900,400,WS_BORDER|WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_LEFT|ES_MULTILINE|ES_AUTOVSCROLL,1

  SETFONT w1,"Arial",12,500,0,1
  setcontroltext(w1,1,"Mary had a little lamb. It's fleece was white as snow. And every where that Mary went the lamb was sure to go." + CHR$(13) + CHR$ (10))
  int rHandle = getcontrolhandle(w1,1)

CONTROL w1,@BUTTON,"Pick Selected Text",100,500,200,25,0,2
CONTROL w1,@BUTTON,"Toggle Selection ON/OFF",600,500,200,25,0,3
  setcaption w1,"RC Handle is " + str$(rHandle)

'================ - Here - =========================

const EM_HIDESELECTION = 0x43F ' 1087 decimal - (already defined in richedit.inc)

SubclassRichEdit(w1,1)

setfocus w1,1

WAITUNTIL IsWindowClosed(w1)
closeconsole
end

SUB SubclassRichEdit(parent as WINDOW,id as INT)
    hEdit = GETCONTROLHANDLE(parent,id)
    lpfn = SetWindowLongA(hEdit,-4,&RichEditHandler)
    SetPropA(hEdit,"edit_handler",lpfn)
RETURN
ENDSUB
SUB UnSubclassRichEdit(parent as WINDOW,id as INT)
    hEdit = GETCONTROLHANDLE(parent,id)
    SetWindowLongA(hEdit,-4,GetPropA(hEdit,"edit_handler"))
    RemovePropA(hEdit,"edit_handler")
RETURN
ENDSUB

SUB handler(),INT
 SELECT @MESSAGE
          CASE @IDCREATE
                CENTERWINDOW w1

          CASE @IDCLOSEWINDOW
                UnSubclassRichEdit(w1,1)
                CLOSEWINDOW w1

          CASE @IDCONTROL
                SELECT @CONTROLID
case 2
if @BN_CLICKED=0
int seltxt=int(rnd(0,95))
setfocus w1,1
SendMessageA(rHandle,EM_SETSEL,seltxt,seltxt+5)
endif
case 3
if @BN_CLICKED=0
if toggle=0 then
toggle=1
SendMessage(rHandle,EM_HIDESELECTION,toggle,0)
else
toggle=0
SendMessage(rHandle,EM_HIDESELECTION,toggle,0)
endif
endif
                endselect

    ENDSELECT
RETURN 0
ENDSUB

SUB RichEditHandler(hwnd:int,uMsg:int,wParam:int,lParam:pointer),int
    SELECT uMsg

    ENDSELECT

RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,wParam,lParam)
ENDSUB
Title: Re: SendMessage not working?
Post by: Andy on October 14, 2020, 08:19:20 PM
Thanks Larry for clarifying the wording.

Me stupid!

I guess it's all down to my misinterpretation of the wParam explanation of EM_HIDESELECTION...

"Otherwise, the selection is hidden"

I took that to mean it would hide text, not remove the highlight.

Perhaps it should say:

"Otherwise, the highlight of the selection is removed" ?

Thanks for clearing it up in a way that my two brain cells can understand, and thanks again to Brian & Aurel who clearly understood it from the beginning.

Me stupid!

Andy.