Problem with catch events from EditorGadget() -->PB 3.7

Everything else that doesn't fall into one of the other PB categories.
Thorsten
User
User
Posts: 28
Joined: Sun Apr 27, 2003 2:55 pm
Location: Germany
Contact:

Problem with catch events from EditorGadget() -->PB 3.7

Post by Thorsten »

Hello :D

I have test the new EditorGadget() and have it modified with:

Read only + word selection:
SendMessage_(GadgetID(#Message), #EM_SETOPTIONS, #ECOOP_SET, #ECO_READONLY|#ECO_AUTOWORDSELECTION)

Background color:
SendMessage_(GadgetID(#Message), #EM_SETBKGNDCOLOR, #Null, RGB($95,$DD,$7A))

Text mode:
SendMessage_(GadgetID(#Message), #EM_SETTEXTMODE, #TM_PLAINTEXT, #Null)

Event mask:
SendMessage_(GadgetID(#Message), #EM_SETEVENTMASK, #Null, #ENM_LINK)

automatic URLs:
SendMessage_(GadgetID(#Message), #EM_AUTOURLDETECT, #True, #Null)

My problem is that I wan't to catch the click on a URL :wink:
I have the whole day with a lot of methods - without any success :(

Here is a VisualBasic example, that I have found:
http://www.visualbasicforum.com/t73845.html

Any idea :?: :D Possibly the beta tester from the update?
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Code: Select all

Declare WndProc(hWnd, uMsg, wParam, lParam)

Structure ENLINK
  nmhdr.NMHDR
  msg.l
  wParam.l
  lParam.l
  chrg.CHARRANGE
EndStructure

#EN_LINK = $70b
#ENM_LINK = $4000000

Procedure WndProc(hWnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY
      *el.ENLINK = lParam
      If *el\nmhdr\code=#EN_LINK
        If *el\msg=#WM_LBUTTONDOWN
          StringBuffer = AllocateMemory(512)
          txt.TEXTRANGE
          txt\chrg\cpMin = *el\chrg\cpMin
          txt\chrg\cpMax = *el\chrg\cpMax
          txt\lpstrText = StringBuffer
          SendMessage_(GadgetID(0), #EM_GETTEXTRANGE, 0, txt)
          Debug PeekS(StringBuffer)
          FreeMemory(StringBuffer)
        EndIf
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 100, 200, 195, 260, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget, "PureBasic Window")=0:End:EndIf
If CreateGadgetList(WindowID())=0:End:EndIf
EditorGadget(0, 0, 0, WindowWidth(), WindowHeight())
SendMessage_(GadgetID(0), #EM_SETEVENTMASK, 0, #ENM_LINK|SendMessage_(GadgetID(0), #EM_GETEVENTMASK, 0, 0))
SendMessage_(GadgetID(0), #EM_AUTOURLDETECT, #TRUE, 0)
SetGadgetText(0, "http://www.purebasic.com"+Chr(10))
SetWindowCallback(@WndProc())
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
End
Last edited by El_Choni on Sun Apr 18, 2004 3:07 pm, edited 1 time in total.
El_Choni
Thorsten
User
User
Posts: 28
Joined: Sun Apr 27, 2003 2:55 pm
Location: Germany
Contact:

Post by Thorsten »

Thank you very much El_Choni :D
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

I have another question about the editor gadget. How can I get to accept dropped files and then load them into the editor? I can get this to work with a text gadget but I am loosing the dropped files message in the editor gadget. Please help.

Thanks
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Code: Select all

DisableDebugger
Procedure WndProc(hWnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY
      *edp.ENDROPFILES = lParam
      If *edp\nmhdr\code=#EN_DROPFILES
        FileNameBuffer = AllocateMemory(0, #MAX_PATH)
        While DragQueryFile_(*edp\hDrop, fileIndex, FileNameBuffer, #MAX_PATH)
          fileIndex+1
          AddGadgetItem(0, -1, PeekS(FileNameBuffer))
        Wend
        DragFinish_(*edp\hDrop)
        FreeMemory(0)
        result = 0
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure
EnableDebugger

If OpenWindow(0, 100, 200, 195, 260, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget, "PureBasic Window")=0:End:EndIf
If CreateGadgetList(WindowID())=0:End:EndIf
EditorGadget(0, 0, 0, WindowWidth(), WindowHeight())
DragAcceptFiles_(GadgetID(0), #TRUE)
SendMessage_(GadgetID(0), #EM_SETEVENTMASK, 0, #ENM_DROPFILES|SendMessage_(GadgetID(0), #EM_GETEVENTMASK, 0, 0))
SetWindowCallback(@WndProc())
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
End
El_Choni
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

Thanks :lol:

Works great!
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

Hi i am now having a problem loading the file to the richedit. Can somebody help. Here is the code. It works great for small files but if I try to load a file of 400K it fails.

Code: Select all

Procedure loadFile(pFilePath.s)
  If ReadFile(0, pFilePath)
    fileBuffer = AllocateMemory(0,Lof())            
    ReadData(fileBuffer, Lof())
    CloseFile(0)            
    SetGadgetText(0, PeekS(fileBuffer))
  Else
    MessageRequester("Error", "Error Occured While Opening File", #PB_MessageRequester_Ok)
  EndIf
  FreeMemory(0)
EndProcedure

DisableDebugger 
Procedure WndProc(hWnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents 
  Select uMsg 
    Case #WM_NOTIFY
      *edp.ENDROPFILES = lParam 
      If *edp\nmhdr\code=#EN_DROPFILES 
        FileNameBuffer = AllocateMemory(0, #MAX_PATH)
         
        ;While DragQueryFile_(*edp\hDrop, fileIndex, FileNameBuffer, #MAX_PATH) 
          ;fileIndex+1 
          ;AddGadgetItem(0, 0, PeekS(FileNameBuffer))
        While DragQueryFile_(*edp\hDrop, fileIndex, FileNameBuffer, #MAX_PATH)
          fileIndex + 1
          loadFile(PeekS(FileNameBuffer))
        Wend 
        DragFinish_(*edp\hDrop) 
        FreeMemory(0)
        result = 0 
      EndIf 
  EndSelect 
  ProcedureReturn result 
EndProcedure 
EnableDebugger 

If OpenWindow(0, 200, 50, 700, 780, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget, "Untitled - RJPad Lite v0.1")=0:End:EndIf 
  If CreateGadgetList(WindowID())=0:End:EndIf 
    EditorGadget(0, 0, 0, WindowWidth(), WindowHeight()) 
    DragAcceptFiles_(GadgetID(0), #TRUE) 
    SendMessage_(GadgetID(0), #EM_SETEVENTMASK, 0, #ENM_DROPFILES | SendMessage_(GadgetID(0), #EM_GETEVENTMASK, 0, 0)) 
    SetWindowCallback(@WndProc()) 
  Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow 
End
Thanks in advance.
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Code: Select all

Procedure StreamFileInCallback(hFile, pbBuff, cb, pcb)
  ProcedureReturn ReadFile_(hFile, pbBuff, cb, pcb, 0)!1
EndProcedure

Procedure loadFile(pFilePath.s)
  If ReadFile(0, pFilePath)
    If GetExtensionPart(pFilePath)="rtf"
      uFormat = #SF_RTF
    Else
      uFormat = #SF_TEXT
    EndIf
    edstr.EDITSTREAM
    edstr\dwCookie = UseFile(0)
    edstr\dwError = 0
    edstr\pfnCallback = @StreamFileInCallback()
    SendMessage_(GadgetID(0), #EM_STREAMIN, uFormat, edstr)
    CloseFile(0)
  Else 
    MessageRequester("Error", "Error Occured While Opening File", #PB_MessageRequester_Ok) 
  EndIf 
EndProcedure 

DisableDebugger 
Procedure WndProc(hWnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY
      *edp.ENDROPFILES = lParam
      If *edp\nmhdr\code=#EN_DROPFILES
        FileNameBuffer = AllocateMemory(0, #MAX_PATH)
        While DragQueryFile_(*edp\hDrop, fileIndex, FileNameBuffer, #MAX_PATH)
          fileIndex+1
          loadFile(PeekS(FileNameBuffer))
        Wend
        DragFinish_(*edp\hDrop)
        FreeMemory(0)
        result = 0
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure
EnableDebugger

If OpenWindow(0, 200, 50, 700, 780, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget,"Untitled - RJPad Lite v0.1")=0:End:EndIf 
  If CreateGadgetList(WindowID())=0:End:EndIf 
    EditorGadget(0, 0, 0, WindowWidth(), WindowHeight())
    SendMessage_(GadgetID(0), #EM_LIMITTEXT, -1, 0)
    DragAcceptFiles_(GadgetID(0), #TRUE)
    SendMessage_(GadgetID(0), #EM_SETEVENTMASK, 0, #ENM_DROPFILES|SendMessage_(GadgetID(0), #EM_GETEVENTMASK, 0, 0))
    SetWindowCallback(@WndProc()) 
  Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow 
End
El_Choni
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

WOW 8O El_Choni
You know tons about RichEdits. Thanks Again.
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Post by Andre »

RJP Computing wrote:WOW 8O El_Choni
You know tons about RichEdits. Thanks Again.
Don't wonder. El Choni is the author of the RichEdit user library... 8)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

Got another one for you, just because it was so slick how you load the file. Is there a slick 'sendmessage' way to save the text loaded in the editor gadget, or will getgadgettext work?

Thanks
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Yes, GetGadgetText should work (as SetGadgetText). However, there is another 'slick' message to do it ;)

Code: Select all

Procedure StreamFileOutCallback(hFile, pbBuff, cb, pcb)
  ProcedureReturn WriteFile_(hFile, pbBuff, cb, pcb, 0)!1
EndProcedure

Procedure saveFile(pFilePath.s)
  If OpenFile(0, pFilePath)
    If GetExtensionPart(pFilePath)="rtf"
      uFormat = #SF_RTF
    Else
      uFormat = #SF_TEXT
    EndIf
    edstr.EDITSTREAM
    edstr\dwCookie = UseFile(0)
    edstr\dwError = 0
    edstr\pfnCallback = @StreamFileOutCallback()
    SendMessage_(GadgetID(0), #EM_STREAMOUT, uFormat, edstr)
    CloseFile(0)
  Else 
    MessageRequester("Error", "Error Occured While Saving File", #PB_MessageRequester_Ok) 
  EndIf 
EndProcedure 

If OpenWindow(0, 200, 50, 700, 780, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget,"Untitled - RJPad Lite v0.1")=0:End:EndIf
If CreateMenu(0, WindowID())=0:End:EndIf
  MenuTitle("&File")
    MenuItem(0, "&Save")
If CreateGadgetList(WindowID())=0:End:EndIf 
EditorGadget(0, 0, 0, WindowWidth(), WindowHeight())
SendMessage_(GadgetID(0), #EM_LIMITTEXT, -1, 0)
AddKeyboardShortcut(0, #PB_Shortcut_Control|#PB_Shortcut_S, 0)
Repeat
  EventID = WaitWindowEvent()
  If EventID=#PB_EventMenu And EventMenuID()=0
    FileName$ = SaveFileRequester("", "", "All files|(*.*)", 0)
    If FileName$
      saveFile(FileName$)
    EndIf
  EndIf
Until EventID=#PB_Event_CloseWindow
End
(BTW what does 'slick' mean?)
El_Choni
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

El_Choni wrote:BTW what does 'slick' mean?
deutsch -> geschickt
italiano -> destro

spanish -> maybe something like 'habilidad' or 'experto'...

I am to provide the public with beneficial shocks.
Alfred Hitshock
RJP Computing
Enthusiast
Enthusiast
Posts: 202
Joined: Sun Apr 27, 2003 4:44 am
Location: Michigan, USA
Contact:

Post by RJP Computing »

Thanks fsw.

Thanks El_Choni again. You answered that perfectly. Were can I go to find out the information that you are helping with?
-Ryan
RJP Computing

Ubuntu 8.10/WinXP, AMD Athlon 64 3000+, 1000MB RAM, AC 97 Audio, nVidia GeForce 7600GT 512MB
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

In the PureBasic resources site:

http://www.reelmediaproductions.com/pb

You'll find a link to download the WIN32.HLP file, which is an old Windows API reference, but still valid and useful. And in:

http://msdn.microsoft.com/library/default.asp

Where you'll find much more info. I recommend you to order (or download, if you have enough bandwidth) the Windows Platform SDK from there (it's 16$ or so). It has help for every aspect or function of Windows, from Windows 95 to XP, and is up to date.
El_Choni
Post Reply