IonicWind Software

IWBasic => General Questions => Topic started by: Andy on June 19, 2020, 12:03:58 AM

Title: Notification / messages
Post by: Andy on June 19, 2020, 12:03:58 AM
Well, I can see some sort of finishing line to my editor program now, but as always I have another question...

I read somewhere about message queues - let me explain a little more...

The colouring of text is working well, and on the whole you don't see the program colouring the text on screen, however you do see it briefly when pressing the page up / down keys.

It's not a major thing but can I / is there a way to detect these two key presses before the rich edit control actually scrolls a page up / down?

If so, I would like to try colouring the next / previous page before it appears.

Any one any ideas please?

Andy.
Title: Re: Notification / messages
Post by: Andy on June 21, 2020, 04:03:31 AM
Can anyone help with this please?

Thanks,
Andy.
Title: Re: Notification / messages
Post by: fasecero on June 21, 2020, 06:25:04 PM
You could give it a try by subclassing the richedit and catching WM_KEYDOWN. If it works -> perform the colouring and handle the scrolling by yourself and return 0 (zero) to cancel the message.
Title: Re: Notification / messages
Post by: Andy on June 22, 2020, 04:01:27 AM
Fasecero,

What a hero you are!

It just shows that you are never too old to learn something.

My rich edit control was already sub classed, and I was already detecting WM_KEYDOWN, just didn't know you could cancel a control's message (once sub classed by returning zero for wParam) like this:

if wParam = 34 'Page down
   int StoreTopLine = SendMessage(rHandle,EM_GETFIRSTVISIBLELINE,0,0)
   ScrollDownPage() '<------- My sub to colour the next set of lines (not visable yet)
   int NewTopLine = StoreTopLine + 29
   setcontroltext(w1,EDIT_1,ltrim$(str$(NewTopLine))) '<----- This moves the scroll position to the line I want
   Offset = SendMessage(rHandle,EM_LINEINDEX,(sRange.Low / 16) + 28,0)
   SendMessage(rHandle,EM_SETSEL,Offset,Offset)
   setfocus w1,1
   RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,0,lParam) '<----- This line here ***
endif

Thank you so much, in just a couple of hours, I have managed to sort out all the colouring issues!

Andy.
 :)
Title: Re: Notification / messages
Post by: fasecero on June 22, 2020, 10:55:02 AM
Nice. The standard way to cancel a message is to avoid CallWindowProcA, so just call

RETURN 0
instead of

RETURN CallWindowProcA(GetPropA(hwnd,"edit_handler"),hwnd,uMsg,0,lParam) '<----- This line here ***
Title: Re: Notification / messages
Post by: Brian on June 22, 2020, 11:34:51 AM
Gabriel,

I have some code to allow only numerics, full point and hyphen in an edit box. So I can replace this line RETURN CallWindowProcA(GetPropA(hWnd,"edit_handler"),hWnd,uMsg,wParam,lParam) with just RETURN 0?

Sounds too easy!

'========================================
SUB NumEditSubclass(parent:WINDOW,id:INT) 'Allow nums, full stop and minus
'========================================
'Sub-class stuff
   hEdit=GETCONTROLHANDLE(parent,id)
   lpFn=SetWindowLongA(hEdit,-4,&NumEditHandler)
'Save the old handler as a property in the edit control, this way we don't need any global variables
   SetPropA(hEdit,"edit_handler",lpFn)
ENDSUB

'==================================================================
SUB NumEditHandler(hWnd:INT,uMsg:INT,wParam:INT,lParam:POINTER),INT 'Allow minus
'==================================================================
   SELECT uMsg
CASE @IDCHAR
IF ((wParam<0x30) OR (wParam>0x39)) AND (wParam<>ASC(".")) AND (wParam<>ASC("-")) AND (wParam<>0x08) THEN RETURN 1
ENDSELECT
RETURN CallWindowProcA(GetPropA(hWnd,"edit_handler"),hWnd,uMsg,wParam,lParam)
ENDSUB

Brian
Title: Re: Notification / messages
Post by: fasecero on June 22, 2020, 01:55:35 PM
It should be, just remember we are talking specifically about WM_KEYDOWN

https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-keydown

QuoteReturn value
An application should return zero if it processes this message.