Announcement

Collapse
No announcement yet.

Q: How to send a double click to a ListView control

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

  • Q: How to send a double click to a ListView control

    I have an owner drawn ListView control that loads a file into a text editor when the user double clicks on the desired ListView entry. The owner draw stuff highlights the entry selected by the user. This works. But now I need to be able to simulate the double click event as I will be loading files from an INI file too.

    The problem is not loading the file(s), but getting the ListView owner draw stuff to accurately reflect the files currently loaded in the editor. I'm assuming that I need to send the %WM_NOTIFY message to the ListView callback along with lParam variable as a pointer to a NM_LISTVIEW structure. I guess I'm asking if the NM_LISTVIEW structure can be faked in order to send the information I need and how to do that?
    Later...

    JR

    "When governments fear the people there is liberty. When people fear the government there is tyranny." - Thomas Jefferson

  • #2
    Originally posted by John R. Heathcote View Post
    I need to send the %WM_NOTIFY message to the ListView callback along with lParam variable as a pointer to a NM_LISTVIEW structure.
    why not use a user message instead (%WM_USER + nnn), generating spoof WM_NOTIFY and WM_COMMAND messages can be troublesome and is generally advised against.

    Comment


    • #3
      WM_NOTIFY should only be sent by the control. You can use GOTO, a custom message (as Chris mentions), or call a shared function (this would be my preferred choice).
      kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

      Comment


      • #4
        But the problem still remains, I want to be able to color certain cells in the ListView control to show by highlight the selections the user has made so far.

        Here is the custom draw portion of the callback (which works):

        Code:
                    CASE %NM_CUSTOMDRAW
                      lpLvCd = CB.LPARAM
        
                      SELECT CASE @lplvcd.nmcd.dwDrawStage
                        CASE %CDDS_PREPAINT, %CDDS_ITEMPREPAINT
                          FUNCTION = %CDRF_NOTIFYSUBITEMDRAW
        
                        CASE %CDDS_ITEMPREPAINT OR %CDDS_SUBITEM
                          'Get the selected ListView row and checkbox status
                          nRow = @lpLvCd.nmcd.dwItemSpec
                          '#DEBUG PRINT "@lpLvCd.nmcd.dwItemSpec =" + STR$(nRow)
                          nCol = @lpLvCd.iSubItem
                          nLVchk = ListView_GetCheckState(hLV, nRow)
                          '#DEBUG PRINT "  ListView checked =" + STR$(nLVchk)
        
                          'Define the normal and bold fonts we need
                          hNFont = PBFormsMakeFont("MS Sans Serif", 8, %FW_NORMAL, %FALSE, %FALSE, %FALSE, %DEFAULT_CHARSET)
                          hBFont = PBFormsMakeFont("MS Sans Serif", 8, %FW_BOLD, %FALSE, %FALSE, %FALSE, %DEFAULT_CHARSET)
        
                          SELECT CASE nLVchk
                            CASE 0            'Row NOT checked?
                              SELECT CASE nCol
                                CASE 0        'Column 0 - CheckBox
        '                          @lpLvCd.clrTextBk = IFE_WHITE
        '                           @lpLvCd.clrText   = IFE_BLACK
        '                          'Specify Normal Font
        '                          SelectObject @lpLvCd.nmcd.hdc, hNFont
        
                                CASE 1 TO 3   'Cols 1 to 3 - VB text items
                                  'Draw items cells with "normal" text colors and font
                                  @lpLvCd.clrTextBk = IFE_WHITE
                                  @lpLvCd.clrText   = IFE_BLACK
                                  'Specify Normal Font
                                  SelectObject @lpLvCd.nmcd.hdc, hNFont
                                  ListView_SetColumnWidth hLV, nCol, %LVSCW_AUTOSIZE
        
                              END SELECT
        
                            CASE -1           'Row IS checked?
                              SELECT CASE @lpLvCd.iSubItem
                                CASE 0        'Column 0 - CheckBox
        '                          @lpLvCd.clrTextBk = IFE_WHITE
        '                          @lpLvCd.clrText   = IFE_BLUE
        '                          'Specify Normal Ffont
        '                          SelectObject @lpLvCd.nmcd.hdc, hNFont
        
                                CASE 1        'Column 1 - Key
                                  @lpLvCd.clrTextBk = IFE_WHITE
                                  @lpLvCd.clrText   = IFE_BLACK
                                  'Specify Normal Font
                                  SelectObject @lpLvCd.nmcd.hdc, hNFont
        
                                CASE 2, 3     'Cols 2 & 3 - VB data
                                  @lpLvCd.clrTextBk = IFE_DKGREEN
                                  @lpLvCd.clrText   = IFE_WHITE
                                  'Specify Bold font
                                  SelectObject @lpLvCd.nmcd.hdc, hBFont
                                  ListView_SetColumnWidth hLV, nCol, %LVSCW_AUTOSIZE_USEHEADER
                              END SELECT
        
                          END SELECT
        
                          DeleteObject hNFont
                          DeleteObject hBFont
        
                          FUNCTION = %CDRF_NEWFONT
        Yes it is a ListView control with checkboxes, but highlighting the cells is so much more effective.
        Later...

        JR

        "When governments fear the people there is liberty. When people fear the government there is tyranny." - Thomas Jefferson

        Comment


        • #5
          Try LVN_ITEMCHANGED to track changes to the ListView item states. If you need to update/redraw an item upon the double-click event, send LVM_REDRAWITEMS to the ListView from NM_DBLCLK.
          kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

          Comment

          Working...
          X