EditorGadget receive first clic and hide cursor [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

EditorGadget receive first clic and hide cursor [Resolved]

Post by Kwai chang caine »

Hello at all

I use an EditorGadget, but i see that the first click put the cursor into it, and sometime the second clic by random way detect the clic :(
I have try two method and it's the same thing :(

1/ Have you a tips for detect the first clic all the time ??? :roll:

2/ Have you another tips for hide cursor and stop the selection of the text inside ???
Because when i write this instruction, the cursor always appears :shock:

Code: Select all

SetGadgetAttribute(#Editor, #PB_Editor_ReadOnly, #true)
I can't use "DisableGadget()" because when an EditorGadget is Disable he loose his color and is all grey :(

Code: Select all

OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)  
EditorGadget(0, 8, 8, 306, 133) 

Repeat
 
 Event = WaitWindowEvent()
 
 If Event = #WM_LBUTTONDOWN
  MessageRequester("", "Hello WM")
 EndIf
  
 Select #PB_Event_Gadget
  
  Case #PB_EventType_LeftClick
  
   MessageRequester("", "Hello PB")
   
 EndSelect
   
Until Event = #PB_Event_CloseWindow 

Thanks and good day
Last edited by Kwai chang caine on Thu Feb 11, 2010 5:49 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: EditorGadget receive first clic and hide cursor

Post by netmaestro »

See if this behaves the way you want:

Code: Select all

Procedure EditProc(hwnd, msg, wparam, lparam)
  oldproc = GetProp_(hwnd, "oldproc")

  Select msg
    Case #WM_NCDESTROY
      RemoveProp_(hwnd, "oldproc")
    
    Case #WM_MOUSEMOVE
      If GetForegroundWindow_()<>WindowID(0)
        SetForegroundWindow_(WindowID(0))
      EndIf
      If GetActiveGadget()<>GetDlgCtrlID_(hwnd)
        SetActiveGadget(GetDlgCtrlID_(hwnd))
      EndIf
    
    Case #WM_KEYDOWN, #WM_KEYUP
      ProcedureReturn 0
    
  EndSelect   
  ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
EndProcedure

Procedure WinProc(hwnd, msg, wparam, lparam)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_COMMAND
      If lparam = GadgetID(0)
        If wparam>>16 = #EN_SETFOCUS
          HideCaret_(GadgetID(0))
        EndIf
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure

OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)  

hwnd = EditorGadget(0, 8, 8, 306, 133, #PB_Editor_ReadOnly) 
SetGadgetText(0,"Hello I'm an editor gadget")
SetProp_(hwnd, "oldproc", SetWindowLongPtr_(hwnd, #GWL_WNDPROC, @EditProc()))
SetWindowCallback(@WinProc())

Repeat

Event = WaitWindowEvent()

If Event = #WM_LBUTTONDOWN
  MessageRequester("", "Hello WM")
EndIf
  
Select #PB_Event_Gadget
  
  Case #PB_EventType_LeftClick
  
   MessageRequester("", "Hello PB")
   
EndSelect
   
Until Event = #PB_Event_CloseWindow 
BERESHEIT
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: EditorGadget receive first clic and hide cursor

Post by IdeasVacuum »

I'm 100% certain that netmaestro has given the best solution. An alternative would be to test the cursor x y position and hide/un-hide the cursor based on that result.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: EditorGadget receive first clic and hide cursor

Post by Kwai chang caine »

Thanks MASTER NETMAESTRO 8)

It's exactely what i want....
You are really my favorite frog :lol:
Perhaps a day ....i can give you, a little kiss on your splendid teeth, for thanks you to all your help at KCC :roll:
And you transform in prince, like in walt disney... :shock:
And even...i'm sure you transform in better that a prince ....in king of the programming 8)

I have try to modify your jewel...and with it ...KCC have make a ....vulgar stone code :oops:
Because i want can stop the effect of inactive Editor.

The top of the top, is a function like this

Code: Select all

EditorDisable(0, #true) 
I have again a problem, when the Edito to be active, i can write on it, but not Erase character :shock:

This is my shit :D

Code: Select all

Global ActiveEditor

Procedure EditorDisable(PbId, Value)

 If Value
  
  ActiveEditor = #False
  SetGadgetAttribute(0, #PB_Editor_ReadOnly, #True)
  
 Else
  
  ActiveEditor = #True
  ShowCaret_(GadgetID(0))
  SetGadgetAttribute(0, #PB_Editor_ReadOnly, #False)
 EndIf
 
EndProcedure

Procedure EditProc(hwnd, msg, wparam, lparam)

 oldproc = GetProp_(hwnd, "oldproc")
 
 Select msg
 
  Case #WM_NCDESTROY
   
   If Not ActiveEditor
    RemoveProp_(hwnd, "oldproc")
   EndIf
   
  Case #WM_MOUSEMOVE
  
   If Not ActiveEditor
   
    If GetForegroundWindow_()<>WindowID(0)
     SetForegroundWindow_(WindowID(0))
    EndIf
    If GetActiveGadget()<>GetDlgCtrlID_(hwnd)
     SetActiveGadget(GetDlgCtrlID_(hwnd))
    EndIf
    
    HideCaret_(GadgetID(0))
    
   EndIf
   
  Case #WM_KEYDOWN, #WM_KEYUP
  
   ProcedureReturn 0
      
  Case #WM_RBUTTONDOWN
        
   If Not ActiveEditor
    MessageRequester("", "Hello PB, 'im active now !!")
    EditorDisable(0, #False)
   Else
    MessageRequester("", "Hello PB, 'im inactive now !!")
    EditorDisable(0, #True)
   EndIf
       
 EndSelect   
   
 ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
 
EndProcedure

Procedure WinProc(hwnd, msg, wparam, lparam)
 
 result = #PB_ProcessPureBasicEvents
 
 If Not ActiveEditor
 
 Select msg
 
  Case #WM_COMMAND
      
   If lparam = GadgetID(0)
     
    If wparam>>16 = #EN_SETFOCUS
     HideCaret_(GadgetID(0))
    EndIf 
     
   EndIf
   
  EndSelect
  
 EndIf 
 
 ProcedureReturn result
 
EndProcedure

OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)  

hwnd = EditorGadget(0, 8, 8, 306, 133, #PB_Editor_ReadOnly) 
SetGadgetText(0,"Hello I'm an inactive editor gadget," + Chr(13) + "Right click To convert me in active editor !!!")
SetProp_(hwnd, "oldproc", SetWindowLongPtr_(hwnd, #GWL_WNDPROC, @EditProc()))
SetWindowCallback(@WinProc())
EditorDisable(0, #True)

Repeat

 Event = WaitWindowEvent()
   
Until Event = #PB_Event_CloseWindow 
ImageThe happiness is a road...
Not a destination
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Re: EditorGadget receive first clic and hide cursor

Post by Xombie »

KCC,

I might be missing the point of it but comment out the "ProcedureReturn 0" call here...

Code: Select all

  Case #WM_KEYDOWN, #WM_KEYUP
   
   ProcedureReturn 0
Again, perhaps it's in there for some other reason. I just looked quickly.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: EditorGadget receive first clic and hide cursor

Post by Kwai chang caine »

Hello XOMBIE glad to talk to you :D

You have right, i don't know why i have take off it ??? :roll:
So i have add this two lines, and i have always the same problem

I can't use delete or backspace for delete character ?? :roll:

Code: Select all

Global ActiveEditor

Procedure EditorDisable(PbId, Value)

If Value
  
  ActiveEditor = #False
  SetGadgetAttribute(0, #PB_Editor_ReadOnly, #True)
  
Else
  
  ActiveEditor = #True
  ShowCaret_(GadgetID(0))
  SetGadgetAttribute(0, #PB_Editor_ReadOnly, #False)
EndIf

EndProcedure

Procedure EditProc(hwnd, msg, wparam, lparam)

oldproc = GetProp_(hwnd, "oldproc")

Select msg

  Case #WM_NCDESTROY
   
   If Not ActiveEditor
    RemoveProp_(hwnd, "oldproc")
   EndIf
   
  Case #WM_MOUSEMOVE
  
   If Not ActiveEditor
   
    If GetForegroundWindow_()<>WindowID(0)
     SetForegroundWindow_(WindowID(0))
    EndIf
    If GetActiveGadget()<>GetDlgCtrlID_(hwnd)
     SetActiveGadget(GetDlgCtrlID_(hwnd))
    EndIf
    
    HideCaret_(GadgetID(0))
    
   EndIf
   
  Case #WM_KEYDOWN, #WM_KEYUP
  
   ProcedureReturn 0
      
  Case #WM_RBUTTONDOWN
        
   If Not ActiveEditor
    MessageRequester("", "Hello PB, 'im active now !!")
    EditorDisable(0, #False)
   Else
    MessageRequester("", "Hello PB, 'im inactive now !!")
    EditorDisable(0, #True)
   EndIf
  
  Case #WM_KEYDOWN, #WM_KEYUP
   
   ProcedureReturn 0
   
EndSelect   
   
ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)

EndProcedure

Procedure WinProc(hwnd, msg, wparam, lparam)

result = #PB_ProcessPureBasicEvents

If Not ActiveEditor

Select msg

  Case #WM_COMMAND
      
   If lparam = GadgetID(0)
     
    If wparam>>16 = #EN_SETFOCUS
     HideCaret_(GadgetID(0))
    EndIf 
     
   EndIf
   
  EndSelect
  
EndIf 

ProcedureReturn result

EndProcedure

OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)  

hwnd = EditorGadget(0, 8, 8, 306, 133, #PB_Editor_ReadOnly) 
SetGadgetText(0,"Hello I'm an inactive editor gadget," + Chr(13) + "Right click To convert me in active editor !!!")
SetProp_(hwnd, "oldproc", SetWindowLongPtr_(hwnd, #GWL_WNDPROC, @EditProc()))
SetWindowCallback(@WinProc())
EditorDisable(0, #True)

Repeat

Event = WaitWindowEvent()
   
Until Event = #PB_Event_CloseWindow 

ImageThe happiness is a road...
Not a destination
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Re: EditorGadget receive first clic and hide cursor

Post by Xombie »

Well, no. I meant if you comment out the line I mentioned then you will be able to use the backspace key.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: EditorGadget receive first clic and hide cursor

Post by Kwai chang caine »

Yeeeesss !!!!
You have right i'm a mule, that's works now :oops:
Master ZOMBIE wrote:I might be missing the point of .....
I have not understand what you say to me :roll:
I have read that i have missing the line

Code: Select all

Case #WM_KEYDOWN, #WM_KEYUP
      ProcedureReturn 0
So i have add a second time this two lines :lol:

If you see my code above, i have two time

Code: Select all

Case #WM_KEYDOWN, #WM_KEYUP
      ProcedureReturn 0
:oops:

Thanks XOMBIE for your precious help 8)
I wish you a very good day
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: EditorGadget receive first clic and hide cursor [Resolved]

Post by Kwai chang caine »

Is it possible to add at the code of NETMAESTRO, the disable of highlight of text in the editorgadget ???
ImageThe happiness is a road...
Not a destination
Post Reply