Page 1 of 1

Add/Remove ClipboardFormatListener ?

Posted: Wed Sep 28, 2016 1:31 am
by vmars316
Add/Remove ClipboardFormatListener ?
In the code below
I added a RemoveClipboardFormatListener
and a GetClipboardText() .
The program runs fine with or without RemoveClipboardFormatListener .
Is it good programming to use it ?

Also , is it good programming to use GetClipnoardText()
with AddClipboardFormatListener . (oranges & apples)
It works great , but just wanted to check ?
Thanks

Code: Select all

; By netmaestro July 2016
; Demo monitoring clipboard changes
;
Global getStrText$

#WM_CLIPBOARDUPDATE     =         $031D

Declare Winproc(hwnd, msg, wParam, lParam)

OpenLibrary(0, "user32.dll")
Prototype AddClipboardFormatListener(hwnd)
Prototype RemoveClipboardFormatListener(hwnd)
Global AddClipboardFormatListener_.AddClipboardFormatListener = GetFunction(0, "AddClipboardFormatListener")
Global RemoveClipboardFormatListener_.RemoveClipboardFormatListener = GetFunction(0, "RemoveClipboardFormatListener")

OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ListViewGadget(0,10,10,200,200)
SetWindowCallback(@WinProc())
StickyWindow(0,1)
AddClipboardFormatListener_(WindowID(0))

Repeat
  EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow

RemoveClipboardFormatListener_(WindowID(0))

CloseLibrary(0)

;---------------------------------------------
;        End of Main Loop Code
;---------------------------------------------

Procedure WinProc(hwnd, msg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_CLIPBOARDUPDATE
      getStrText$ = GetClipboardText()
      AddGadgetItem(0, -1, getStrText$)
  EndSelect
  ProcedureReturn result
EndProcedure
__________________________________________________
Quote tags>Code tags
28.09.2016
RSBasic

Re: Add/Remove ClipboardFormatListener ?

Posted: Wed Sep 28, 2016 9:05 am
by netmaestro
I was going to answer this one with a bit of code but - it looks like I already did! :lol:

Re: Add/Remove ClipboardFormatListener ?

Posted: Wed Sep 28, 2016 6:26 pm
by Fred
:lol:

Re: Add/Remove ClipboardFormatListener ?

Posted: Thu Sep 29, 2016 3:32 am
by vmars316
More specifically
When i use

Code: Select all

AddClipboardFormatListener(hwnd)
and
[b]Purebasic's GetClipboardText()[/b]
what is Purebasic's GetClipboardText()
actually doing .
Is it essentially doing :

Code: Select all

OpenClipboard(NULL)
GetClipboardData(CF_TEXT)
GlobalLock()
GlobalUnlock()
CloseClipboard()
Or is PB using the older style clipboard processing ?

Thanks