Announcement

Collapse
No announcement yet.

Unwanted select all

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

    Unwanted select all

    Can you help with a solution? See code below. Why is the full
    text selected initially even though a deselect command is sent
    to the textbox?. If you copy a small part to the clipboard and
    then paste to another program e.g. Word, then on returning to
    this program, the full text is automatically being selected again.
    Why? Can you help? Thanks in advance.

    Regards,
    Erik
    Code:
    #COMPILE EXE
    #REGISTER NONE
    #DIM ALL
    #INCLUDE "win32api.inc"
    #INCLUDE "commctrl.inc"
    %FORM1_TEXTRESULTS        = 100
    %Form1_TEXTCOPY           = 120
    DECLARE SUB ShowDialog_Form1(BYVAL hParent&)
    DECLARE CALLBACK FUNCTION Form1_DLGPROC
    GLOBAL hForm1&
    FUNCTION PBMAIN
        LOCAL Count&
        LOCAL CC1 AS INIT_COMMON_CONTROLSEX
        CC1.dwSize=SIZEOF(CC1)
        CC1.dwICC=%ICC_WIN95_CLASSES
        InitCommonControlsEX CC1
        ShowDialog_Form1 0
        DO
            DIALOG DOEVENTS TO Count&
        LOOP UNTIL Count&=0
    END FUNCTION
          
    SUB ShowDialog_Form1(BYVAL hParent&)
        LOCAL Style&, ExStyle& ,hCtl&
        LOCAL T$
        T$= REPEAT$(10,"The problem is that after pasting from clipboard to e.g. word and returning to this program, the total text is selected in this window! Why? How can this be avoided? Thanks for your help in solving this problem! "+$CRLF)
        Style& = %WS_POPUP OR %DS_MODALFRAME OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %DS_CENTER
        ExStyle& = 0
        DIALOG NEW hParent&, "Clipboard test", 0, 0,  300,  200, Style&, ExStyle& TO hForm1&
        CONTROL ADD TEXTBOX, hForm1&,  %FORM1_TEXTRESULTS,  T$, 1,1,295, 175, _
          %WS_CHILD OR %WS_VISIBLE OR %ES_MULTILINE OR %ES_WANTRETURN OR _
            %ES_LEFT OR %WS_VSCROLL OR %ES_AUTOVSCROLL OR %WS_TABSTOP, _
            %WS_EX_CLIENTEDGE
        CONTROL HANDLE hForm1&,%FORM1_TEXTRESULTS TO hCtl&
        SendMessage hCtl&,%EM_SETSEL,-1,0
    
        CONTROL ADD "Button", hForm1&,%Form1_TEXTCOPY,  "&Copy to clipboard ", 80, 184, 124, 12, _
            %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP
        DIALOG SHOW MODELESS hForm1& , CALL Form1_DLGPROC
    END SUB
    
    CALLBACK FUNCTION Form1_DLGPROC
        LOCAL hEdit AS LONG
        CONTROL HANDLE hForm1&,%FORM1_TEXTRESULTS TO hEdit
        ' copy selected text to clipboard
        IF CBCTL=%Form1_TEXTCOPY THEN SendMessage hEdit, %WM_COPY, 0, 0
    END FUNCTION


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

    #2
    Just for grins I modified your code to my clipboard routine, still dos it t hough.
    It's got something to do with the alt-tab/ Focus...not the copy command.


    Code:
    CallBack Function Form1_DLGPROC
        Local hEdit As Long
        Local sText As String
        Control Handle hForm1&,%FORM1_TEXTRESULTS To hEdit
        ' copy selected text to clipboard
    '    If CbCtl=%Form1_TEXTCOPY Then SendMessage hEdit, %WM_COPY, 0, 0
        If CbCtl=%Form1_TEXTCOPY Then
           Control Get Text CbHndl,hEdit To sText
           Clipboard_SetText sText
        End If
    
        If CbCtl = %EN_CHANGE Then GetFocus
    End Function
    '--------------------------------------------------------------------------------------------------------
    Sub Clipboard_SetText(ByVal Text As String)
    Local lpMem As Asciiz Ptr
    Local hMem  As Dword
        ' Allocate global memory block
        hMem  = GlobalAlloc(%GHND, Len(Text) + 1)
        ' lock it and get pointer to memory location
        lpMem = GlobalLock(hMem)
        ' copy text into memory object
        @lpMem = Text
        ' unlock the memory object
        GlobalUnlock hMem
        ' add text to the clipboard
        OpenClipboard 0
        EmptyClipboard
        SetClipboardData %CF_TEXT, hMem
        CloseClipboard
    End Sub
    ------------------
    Scott
    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


      #3
      Erik, this seems to work ok.

      Code:
      #COMPILE EXE
      #REGISTER NONE
      #DIM ALL
      #INCLUDE "win32api.inc"
      #INCLUDE "commctrl.inc"
      %FORM1_TEXTRESULTS        = 100
      %Form1_TEXTCOPY           = 120
      DECLARE SUB ShowDialog_Form1(BYVAL hParent&)
      DECLARE CALLBACK FUNCTION Form1_DLGPROC
      GLOBAL hForm1&, hCtl&
      FUNCTION PBMAIN
          LOCAL Count&
          LOCAL CC1 AS INIT_COMMON_CONTROLSEX
          CC1.dwSize=SIZEOF(CC1)
          CC1.dwICC=%ICC_WIN95_CLASSES
          InitCommonControlsEX CC1
          ShowDialog_Form1 0
          DO
              DIALOG DOEVENTS TO Count&
          LOOP UNTIL Count&=0
      END FUNCTION
      
      SUB ShowDialog_Form1(BYVAL hParent&)
          LOCAL Style&, ExStyle& ,hCtl&
          LOCAL T$
          T$= REPEAT$(10,"The problem is that after pasting from clipboard to e.g. word and returning to this program, the total text is selected in this window! Why? How can this be avoided? Thanks for your help in solving this problem! "+$CRLF)
          Style& = %WS_POPUP OR %DS_MODALFRAME OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %DS_CENTER
          ExStyle& = 0
          DIALOG NEW hParent&, "Clipboard test", 0, 0,  300,  200, Style&, ExStyle& TO hForm1&
          CONTROL ADD TEXTBOX, hForm1&,  %FORM1_TEXTRESULTS,  T$, 1,1,295, 175, _
              %WS_CHILD OR %WS_VISIBLE OR %ES_MULTILINE OR %ES_WANTRETURN OR _
              %ES_LEFT OR %WS_VSCROLL OR %ES_AUTOVSCROLL OR %WS_TABSTOP, _
              %WS_EX_CLIENTEDGE
          CONTROL ADD "Button", hForm1&,%Form1_TEXTCOPY,  "&Copy to clipboard ", 80, 184, 124, 12, _
              %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP
          DIALOG SHOW MODELESS hForm1& , CALL Form1_DLGPROC
      END SUB
      CALLBACK FUNCTION Form1_DLGPROC
         SELECT CASE CBMSG
         CASE %WM_INITDIALOG
            CONTROL HANDLE hForm1&,%FORM1_TEXTRESULTS TO hCtl&
         CASE %WM_PAINT
            SendMessage hCtl&, %EM_SETSEL,-1,0
         CASE %WM_COMMAND
            SELECT CASE CBCTL
            CASE %Form1_TEXTCOPY
               ' copy selected text to clipboard
               SendMessage hCtl&, %WM_COPY, 0, 0
            END SELECT
         END SELECT
      END FUNCTION

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

      Comment


        #4
        It is a focus problem, alright. The textbox is created first, so it
        will get focus on return from other dialogs. Several ways fix this
        properly, but I think one of the easiest is to change creation order,
        so button is created first, then textbox.

        That takes care of the auto-selection problem, but another arises,
        because now the button will gain focus on return. If this is ok,
        problem is fixed. If not ok and you want the textbox to gain focus,
        but without auto-selection, you can trap %WM_NCACTIVATE, and decide
        focus from there, like:
        Code:
        CALLBACK FUNCTION Form1_DLGPROC
           SELECT CASE CBMSG
             CASE %WM_NCACTIVATE
                IF CBWPARAM THEN CONTROL SET FOCUS CBHNDL, %FORM1_TEXTRESULTS
         
             CASE %WM_COMMAND
                SELECT CASE CBCTL
                   CASE %FORM1_TEXTRESULTS ' copy selected text to clipboard
                      CONTROL SEND CBHNDL, %FORM1_TEXTRESULTS, %WM_COPY, 0, 0
                END SELECT
          END SELECT
        END FUNCTION
        ------------------
        Forgot yo mention: If you add %ES_NOHIDESEL style to textbox, partial
        selections will be visible even when textbox loses focus, like when
        user presses the copy-button..


        [This message has been edited by Borje Hagsten (edited July 23, 2001).]

        Comment


          #5
          Hi Fellows,

          Thanks for your superb help. The problems have been solved
          completely. I am really learning a lot from this feed-back.
          Thanks!

          Many regards,

          Erik


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

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎