Page 1 of 3
Problem with catch events from EditorGadget() -->PB 3.7
Posted: Sat Jun 07, 2003 9:44 pm
by Thorsten
Hello
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
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
Possibly the beta tester from the update?
Posted: Sun Jun 08, 2003 6:06 am
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
Posted: Sun Jun 08, 2003 8:46 am
by Thorsten
Thank you very much El_Choni

Posted: Sun Jun 08, 2003 9:35 pm
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
Posted: Mon Jun 09, 2003 12:12 am
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
Posted: Mon Jun 09, 2003 2:15 am
by RJP Computing
Thanks
Works great!
Posted: Mon Jun 09, 2003 2:48 am
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.
Posted: Mon Jun 09, 2003 7:12 am
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
Posted: Mon Jun 09, 2003 12:39 pm
by RJP Computing
WOW 8O El_Choni
You know tons about RichEdits. Thanks Again.
Posted: Mon Jun 09, 2003 7:45 pm
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...

Posted: Tue Jun 10, 2003 4:31 am
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
Posted: Tue Jun 10, 2003 5:40 am
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?)
Posted: Tue Jun 10, 2003 6:17 am
by fsw
El_Choni wrote:BTW what does 'slick' mean?
deutsch -> geschickt
italiano -> destro
spanish -> maybe something like 'habilidad' or 'experto'...
Posted: Tue Jun 10, 2003 12:44 pm
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?
Posted: Tue Jun 10, 2003 3:07 pm
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.