Editorgadget: Notification about caretmovement

Just starting out? Need help? Post your questions and find answers here.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Editorgadget: Notification about cursormovement

Post by srod »

netmaestro wrote:
btw : I've never seen #WM_KEYFIRST used in that way before
hehe. It's incorrect but it works fine because WM_KEYDOWN is the first key message and therefore has the same value (256) as WM_KEYFIRST.
Ah, a happy coincidence! :)
I may look like a mule, but I'm not a complete ass.
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 670
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: Editorgadget: Notification about cursormovement

Post by Kurzer »

srod wrote:PostMessage_() should be fine.
Okay, thanks for confirmation
srod wrote:A strange way of structuring the program for sure. Rather than post a message I would just call a separate function in your code.
I want to keep the Callback as "tansparent" as possible to the main code.
In the final Version the old GadgetProc adress should pass via SetProp_() and GetProp_() or something similar to the callback. Then the callback procedure is independent from global variables. And I can use it in different projects.

Sending messages... a small taste of OOP
srod wrote:btw : I've never seen #WM_KEYFIRST used in that way before! I though it was for use with GetMessage_() or PeekMessage_() etc.
:? I have no idea what #WM_KEYFIRST usually is for.

The truth is, #WM_KEYDOWN together with #VK_RETURN genareted two messages instead one message like #WM_KEYDOWN and #VK_UP... VK_DOWN and so on.
So I tried some other message constance at random. :oops: (hey, I'm not an API crack ;) )
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 670
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: Editorgadget: Notification about cursormovement

Post by Kurzer »

netmaestro wrote:
btw : I've never seen #WM_KEYFIRST used in that way before
hehe. It's incorrect but it works fine because WM_KEYDOWN is the first key message and therefore has the same value (256) as WM_KEYFIRST.
Ah, Netmaestro... thank you. Another secret is disclosed.

At my first tests I used WM_KEYUP together with VK_RETURN... but I got two messsges each time I pressed RETURN.
With WM_KEYFIRST I got only one message. But now I tried WM_KEYDOWN and lo... RETURN gives me only one message. Heureka...

So if you change WM_KEYFIRST with WM_KEYDOWN in my code all went okay and looks okay (I hope). :lol:

There is a german saying: "Muehsam ernaehrt sich das Eichhoernchen."
I don't know the english pendant. Maybe "slowly but surely" :lol:

EDIT: Here is the final version with SetProp_() and GetProp_()

Code: Select all

EnableExplicit

Global Event
#CURSORCHANGE = #WM_USER + 1

Procedure.i EditGadgetProc(hWnd, uMsg, wParam, lParam)
	Protected hParentWindow.i = GetParent_(hWnd)
	
	Select uMsg
		Case #WM_KEYDOWN
			If wParam = #VK_UP
       	PostMessage_(hParentWindow, #CURSORCHANGE, 0, 0)
			ElseIf wParam = #VK_DOWN
       	PostMessage_(hParentWindow, #CURSORCHANGE, 0, 0)
			ElseIf wParam = #VK_LEFT
       	PostMessage_(hParentWindow, #CURSORCHANGE, 0, 0)
			ElseIf wParam = #VK_RIGHT
       	PostMessage_(hParentWindow, #CURSORCHANGE, 0, 0)
			ElseIf wParam = #VK_PRIOR
       	PostMessage_(hParentWindow, #CURSORCHANGE, 0, 0)
			ElseIf wParam = #VK_NEXT
       	PostMessage_(hParentWindow, #CURSORCHANGE, 0, 0)
			ElseIf wParam = #VK_RETURN
       	PostMessage_(hParentWindow, #CURSORCHANGE, 0, 0)
			EndIf
		Case #WM_LBUTTONUP
     	PostMessage_(hParentWindow, #CURSORCHANGE, 0, 0)
		Default
	EndSelect
	
	ProcedureReturn CallWindowProc_(GetProp_(hWnd, "OLDPROC"), hWnd, uMsg, wParam, lParam)
	
EndProcedure

If OpenWindow(0, 100, 200, 300, 100, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	EditorGadget(0, 10, 10, 280, 80)
	SetProp_(GadgetID(0), "OLDPROC", SetWindowLong_(GadgetID(0), #GWL_WNDPROC, @EditGadgetProc()))
	
	Repeat 
		Event = WaitWindowEvent()
		If Event = #CURSORCHANGE
			SetWindowTitle(0, "Caret in Line: " + Str(SendMessage_(GadgetID(0), #EM_LINEFROMCHAR, SendMessage_(GadgetID(0), #EM_LINEINDEX,-1,0), 0)))
		EndIf
		
	Until Event = #PB_Event_CloseWindow
EndIf
EDIT2: Damn, PAGE UP/DOWN does not work. :?
EDIT3: Ah, it's VK_PRIOR and VK_NEXT... I completed the code above.

A big Thank you to all who gave me hints! :thumbsup:
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 670
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: Editorgadget: Notification about cursormovement

Post by Kurzer »

netmaestro wrote:You can subclass the editorgadget and look for #wm_mousemove,..
Uh! Netmaestro, only at this moment I realize that I used the wrong term.

Cursor = Mousecursor
Caret = "Textmarker" within the editorgadget.

Its the caret, what I meant. I will correct the subject of this topic now.

(There is another german saying: "Alt wie eine Kuh und man lernt immer noch dazu" - sorry I don't know the english translation. Hmm, maybe this: "Old as a cow, but you always learn something new". Okay, but in english it does not rhyme. :lol:)
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
Post Reply