Author Topic: EM_EXSETSEL problem...  (Read 26202 times)

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: EM_EXSETSEL problem...
« Reply #15 on: September 23, 2012, 03:35:14 AM »
Normally in such a case I would construct the simplest setup that shows these symptoms.
Anyway: Have you tried PostMessage?

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #16 on: September 23, 2012, 10:50:23 PM »
a'right, here's an update... tried to use PostMessage... so it claims that is succeeds (eax == 01) LastError == ERROR_SUCCESS (0)... but still no text is actually being selected inside the richedit box...

MarkFoundString PROC rvaFound:DWORD
LOCAL dwTemp:DWORD
LOCAL rChar:CHARRANGE
int 3
    invoke szLen, addr srchString
    mov edx, txtAddr
    mov ecx, rvaFound
    sub ecx, edx ; getting offsets...
    mov rChar.cpMin, ecx
    add eax, ecx
    mov rChar.cpMax, eax
    ;invoke SendMessage, hTxt, EM_EXSETSEL, 0, addr rChar
    invoke PostMessage, hTxt, EM_EXSETSEL, 0, addr rChar
    ret
MarkFoundString ENDP

 :dazzled:

PS: i just tried to eventually work around that, using SendDlgItemMessage like that: invokeSendDlgItemMessage, hWnd, ID_CTEXT, EM_EXSETSEL, 0, addr rChar (instead of postmessage/sendmessage...) -> returns eax == 00000005h/LastError ERROR_ACCESS_DENIED (00000005h)...  :icon_eek: still no text selection marked... hWnd is a GLOBAL variable, containing the MAIN window's handle...

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #17 on: September 23, 2012, 11:45:51 PM »
What's the probability of that being kinda related to me not bothering to embed a manifest inside the executable?! :icon_rolleyes: i'm going way too short on options on that problem already, so just wild guess...   :redface:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: EM_EXSETSEL problem...
« Reply #18 on: September 23, 2012, 11:58:37 PM »
You can test that out by using an external manifest file but I doubt thats the problem. I pointed you at the masm32 example for a reason, it WORKS correctly. If you use a riched 2 or later version, you can search both forwards and backwards with whole word and case options. Just do this the standard Microsoft way and you can do all of these things without having to guess what is happening.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #19 on: September 24, 2012, 12:05:53 AM »
i'm using the most primitive/old school/whatever variant - "Riched32.dll", so it's not 2.0 or sth... finally, i may have to give up on the riched32 option and use 2.0 or sth, if it's working... but i still try to preserve backwards compatibility on this...

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #20 on: September 24, 2012, 12:17:53 AM »
@ hutch-- : btw the example 06 seems to also fail the SendMessage EM_EXSETSEL... return values: eax == 0000000Bh/LastError == ERROR_INVALID_HANDLE... string searched inside the buffer == "asdf"

PS: though the text actually get's selected... ?! ::)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: EM_EXSETSEL problem...
« Reply #21 on: September 24, 2012, 12:43:17 AM »
Richedit 1 worked fine in win9x but it is emulated in Win2000 onwards in the later DLL. The series of riched went up to about 3 then it changes to another version that I have avoided as I hear it has problems.

This is the Winhelp on the message EM_EXSETSEL.


The EM_EXSETSEL message selects a range of characters and/or OLE objects in a rich edit control.

EM_EXSETSEL 
wParam = 0;
lParam = (LPARAM) (CHARRANGE FAR *) ichCharRange;
 

Parameters

ichCharRange

Zero-based index of the character.

 

Return Values

Returns the zero-based index of the line.


You would check if the LastError value should be applied to a richedit message.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: EM_EXSETSEL problem...
« Reply #22 on: September 24, 2012, 12:51:27 AM »
a'right, here's an update... tried to use PostMessage... so it claims that is succeeds (eax == 01) LastError == ERROR_SUCCESS (0)... but still no text is actually being selected inside the richedit box...

Try something simple like
    ; edit contains "This is a test with Richedit"
    mov rChar.cpMin, 10
    mov rChar.cpMax, 14
with SendMessage, PostMessage, Riched20, ....

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #23 on: September 24, 2012, 12:53:04 AM »
i've read the official documentationi only wasn't sure about if i should set rva's (inside the memory buffer) or offsets... now i know, it's about offsets, so that calculated correctly... but when using SendMessage, yeah, the getlasterror is the way to check if everything went fine, and it gives me ERROR_ACCESS_DENIED (that applies to SendDlgItemText and PostMessage as well)... i'm sure it's something really tiny, but i still can't think of something, that could be possibly wrong with my current 'setup'... except probably this could be OS specific, since devel environment is Windows Embedded 2009 POSReady, updated to CURRENT... since the last update my 'axe hex editor (v3.0)' stopped actually displaying it's main window... except inside the taskbar... but that seems kinda odd, the updates i applied @ that time were only some stuff about ActiveX rollup (or something similar) and the ms malware remover for september...  :dazzled:

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #24 on: September 24, 2012, 01:00:31 AM »
@ jj2007: mate, just tried it with static values: cpMin == 04h, cpMax == 08h, using SendDlgItemMessage... again no text's being actually selected, eax == 08h (that would be cpMax i suppose)/LastError == ERROR_ACCESS_DENIED (00000005h)... the last error is actually being set from the SendDlgItemMessage... pretty sure, that plain old SendMessage gives the same result...

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #25 on: September 24, 2012, 01:38:52 AM »
allright... seems u must EXPLICITLY call SetFocus on the richedit control... how could i work it out, since i actually have to find it in 2 separate richedit's (they can't have the window focus concurrently...)?

TouEnMasm

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: EM_EXSETSEL problem...
« Reply #26 on: September 24, 2012, 01:45:50 AM »

Only one window could have the focus.If you want to write two differents richedit and you have need of setfocus with riched32.dll,invoke setfocus and then send message to the richedit.The two functions must used the same handle.
Fa is a musical note to play with CL

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #27 on: September 24, 2012, 01:49:07 AM »
@ ToutEnMasm : cool, mate, that's quite similar to what i had in mind, since i've two riched's that must have 'concurrent' view... it's something similar to a hex editor, but still not exactly... damn, what a mess for a first richedit project...  :t

P.S.: btw what riched window message could i use to scroll it down to the found position?

TouEnMasm

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: EM_EXSETSEL problem...
« Reply #28 on: September 24, 2012, 01:57:30 AM »

You made a scroll  with a richedit giving it the style  XX_scroll something.
Use msdn or any help file to have the exact name of the style to use.The style can be up-down  or left-right.
Fa is a musical note to play with CL

PsYcHoCoDe

  • Guest
Re: EM_EXSETSEL problem...
« Reply #29 on: September 24, 2012, 02:00:52 AM »
@ ToutEnMasm : styles are both ES_AUTOVSCROLL/ES_AUTOVHORIZONTAL and WS_VSCROLL/WS_HSCROLL currently... and it still doesn't seem to do the AUTO part...  :icon_rolleyes:

 P.S.: no problem to paste the whole rsrc.rc, if needed?