Announcement

Collapse
No announcement yet.

Prevent Paste

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Prevent Paste

    Hello,
    I wonder if someone got some sample code of how to prevent a user
    from using any Paste functions (Shift-Ins, Ctrl-V, and menu-selected Paste)
    in another app (for example Notepad with a specific file open)

    I guess this involves some use of SetWindowsHookEx ++, and have looked at
    some of the code in these forums, but not been able to modify it to serve
    my needs.

    any help appreciated

    TIA
    -p


    ------------------

  • #2
    You'll need to subclass the box and catch WM_PASTE.
    Then exit function..


    ------------------
    [email protected]
    hellobasic

    Comment


    • #3
      I really hope subclassing isn't the only way....
      anyone else ?
      -p

      ------------------

      Comment


      • #4
        Which difficult is in subclassing ?!

        Code:
           #Compile Exe
           #Dim All
           #Register None
           #Include "Win32Api.Inc"
           Global ProcOr As Long
        
           CallBack Function Proc
              Select Case CbMsg
                 Case %WM_PASTE: MsgBox "Tomorrow": Exit Function
                 Case %WM_DESTROY: SetWindowLong CbHndl, %GWL_WNDPROC, ProcOr: Exit Function
              End Select
              Function = CallWindowProc(ProcOr, CbHndl, CbMsg, CbWparam, CbLparam)
           End Function
        
           CallBack Function DlgProc
              Select Case CbMsg
                 Case %WM_INITDIALOG
                    Control Add TextBox, CbHndl, 102, "", 10, 5, 180, 15
                    ProcOr = SetWindowLong(GetDlgItem(CbHndl, 102), %GWL_WNDPROC, CodePtr(Proc))
              End Select
           End Function
        
           Function PbMain
              Local hDlg As Long
              Dialog New 0 ,"Test",,, 200, 30, %WS_SYSMENU Or %WS_CAPTION Or %WS_MINIMIZEBOX To hDlg
              Dialog Show Modal hDlg, Call DlgProc
           End Function

        ------------------
        E-MAIL: [email protected]

        Comment


        • #5
          To be more spesific,

          background:
          A gouvernment authoroty demands users handling sensitive personal
          information to have a separate network login to use their e-mail unless we
          prevent them from beeing able to paste information into e-mail messages.

          One alternative is to use Terminal server and Citrix, but I hoped it
          would be possible to build a solution trapping when the user tried to
          do a paste and stop the command from beeing processed.

          Semen, if Your sample can be enhanced to solve this I'll be more than glad...,
          I can't see how to do it

          -p



          ------------------

          Comment


          • #6
            Per --
            Because I don't exactly understand, what you want to do, I can suggest two another (global) methods.
            1) SetClipboardViewer (I posted yesterday a skeleton).
            Allows to detect any clipboard change (you can simply delete a content).
            2) Global (low-level) keyboard hook (I also posted samples).
            In hook it possible to lock transfer a key combination to app.

            Because first variant is better I modified a code, which I posted before.
            At least under Win2000 (I beleive) it works.
            Note that you can cancel this app through Task Manager only.

            Code:
              #Compile Exe
               #Dim All
               #Register None
               #Include "Win32Api.Inc"
               
               CallBack Function DlgProc
                  Static hwndNextViewer As Long
                  Select Case CbMsg
                     Case %WM_INITDIALOG
                        OpenClipBoard 0: EmptyClipboard: CloseClipboard
                        hwndNextViewer = SetClipboardViewer(CbHndl)
                     Case %WM_SIZE: ShowWindow CbHndl, 0
                     Case %WM_CHANGECBCHAIN
                        If CbWparam = hwndNextViewer Then hwndNextViewer = CbLparam Else _
                        If hwndNextViewer <> 0 Then SendMessage hwndNextViewer, CbMsg, CbWparam, CbLparam
                     Case %WM_DESTROY
                        ChangeClipboardChain CbHndl, hwndNextViewer
                     Case %WM_DRAWCLIPBOARD
                        OpenClipBoard 0: EmptyClipboard: CloseClipboard
                        SendMessage hwndNextViewer, CbMsg, CbWparam, CbLparam
                  End Select
              End Function
              
              Function PbMain
                 Local hDlg As Long
                 Dialog New 0, "Test", ,, 100, 100, %WS_CAPTION Or %WS_SYSMENU, %WS_EX_TOOLWINDOW To hDlg
                 Dialog Show Modal hDlg Call DlgProc
              End Function

            ------------------
            E-MAIL: [email protected]

            [This message has been edited by Semen Matusovski (edited October 10, 2000).]

            Comment


            • #7
              Why not just add this?

              %ES_READONLY Prevents the user from typing or editing text in the control.

              Woops, I just saw the "In another app".

              You need to catch their window and control, and how to do that is waaaay beyond me.
              I saw a program that did it once, modified a programs menus and such, was pretty slick...

              Scott

              ------------------
              Scott
              mailto:[email protected][email protected]</A>

              [This message has been edited by Scott Turchin (edited October 10, 2000).]
              Scott Turchin
              MCSE, MCP+I
              http://www.tngbbs.com
              ----------------------
              True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

              Comment


              • #8
                Semen,
                I think I'll try to enhance Your Clipboard sample,
                The sample stops all Copy/Paste for all apps but it should be possible
                to use a timer to detect when the actual window is in foreground and then
                disable Clipboard until it is not in foreground anymore.

                Thank You very much!
                -p


                ------------------

                Comment

                Working...
                X