How to make image unmoveable in listview control? 
Author Message
 How to make image unmoveable in listview control?
All,

   I woud appreciate if you could let me know how to lock images in the
listview control.  I can add listitem in the listview and they show
images associated with it.  However I can use the mouse to drag the
image around.  I don't want it to do that.  I want to make a dialog
that shows list of icons like when we click new project menu item in
VB. Thank you very much.

Joseph

--== Sent via Deja.com http://www.*-*-*.com/
---Share what you know. Learn what you don't.---



Sat, 27 Oct 2001 03:00:00 GMT  
 How to make image unmoveable in listview control?
Hi Joseph.  There are currently two methods I know of that will accomplish
this.  The first method is somewhat extensive in comparison to the second in
that it requires subclassing and intercepting the LVN_BEGINDRAG message.
The other method was posted by somebody (sorry for not remembering who!) in
the winapi group, and it simply posts a WM_LBUTTONUP message in the
MouseDown event of the ListView.  Both methods are presented below:

'=======================
'SubClassing Method
'Begin Module Code

Option Explicit

Public Const WM_NOTIFY = &H4E
Public Const LVN_FIRST = -100&
Public Const LVN_BEGINDRAG = (LVN_FIRST - 9)

Public Declare Function CallWindowProc Lib "user32" Alias _
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Public Declare Function SetWindowLong Lib _
"user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Public Const GWL_WNDPROC = -4

Global lpPrevWndProc As Long
Global gHW As Long

Public Declare Sub MoveMemory Lib _
"kernel32" Alias "RtlMoveMemory" _
(pDest As Any, pSource As Any, _
ByVal dwLength As Long)

' The NMHDR structure contains information about a notification message. The
pointer
' to this structure is specified as the lParam member of the WM_NOTIFY
message.
Public Type NMHDR
hwndFrom As Long   ' Window handle of control sending message
idFrom As Long        ' Identifier of control sending message
code  As Long          ' Specifies the notification code
End Type

Public Sub Hook()
'Establish a hook to capture messages to this window
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
AddressOf WindowProc)
End Sub

Public Sub Unhook()
Dim temp As Long
'Reset the message handler for this window
temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
End Sub

Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Dim nmh As NMHDR

Select Case uMsg

    Case WM_NOTIFY

        ' Fill the NMHDR struct from the lParam pointer.
        ' (for any WM_NOTIFY msg, lParam always points to a struct which is
        '  either the NMHDR struct, or whose 1st member is the NMHDR struct)
        Call MoveMemory(nmh, ByVal lParam, Len(nmh))

        Select Case nmh.code

            Case LVN_BEGINDRAG
            'Notifies a list view control's
            'parent window that a drag-and-drop
            'operation involving the left
            'mouse button is being initiated.
            Debug.Print "LVN_BEGINDRAG"
            WindowProc = 1
            Exit Function

        End Select

End Select

'Pass message on to the original window message handler
WindowProc = CallWindowProc(lpPrevWndProc, hwnd, _
uMsg, wParam, lParam)
End Function

'End Module Code
'=======================
'Begin Form Code

Private Sub Form_Load()
'Store handle to this form's window
gHW = Me.hwnd
'Call procedure to begin capturing messages
Hook
End Sub

Private Sub Form_Unload(Cancel As Integer)
'Pressing the End button or selecting End from _
the Run menu without unhooking causes _
an Invalid Page Fault and closes Microsoft Visual Basic.
'Call procedure to stop intercepting the messages for this window
Unhook
End Sub

'End Form Code
'=======================

'Begin Other Method
'Form Code

Private Declare Function PostMessage Lib "User32" _
Alias "PostMessageA" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Private Const WM_LBUTTONUP = &H202

Private Sub ListView1_MouseDown(Button As Integer, _
Shift As Integer, x As Single, y As Single)
PostMessage ListView1.hWnd, WM_LBUTTONUP, 0&, 0&
End Sub

'End Other Method
'====================

'-------
galen



Sat, 27 Oct 2001 03:00:00 GMT  
 How to make image unmoveable in listview control?

Quote:

>All,

>   I woud appreciate if you could let me know how to lock images in the
>listview control.  I can add listitem in the listview and they show
>images associated with it.  However I can use the mouse to drag the
>image around.  I don't want it to do that.  I want to make a dialog
>that shows list of icons like when we click new project menu item in
>VB. Thank you very much.

>Joseph

Joseph,

Try setting the OLEDragMode property to ccOLEDragAutomatic (1).

Mattias

________________________________________________
Mattias "BeeZo" Sj?gren    Visual Basic f?r Alla



Sat, 27 Oct 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ActiveX image object makes image blury

2. Changing Image in a Listview control?

3. Change Checkbox Image in Listview Control

4. HOW TO: Display a background image in a ListView control

5. Listview Control and Image Lists

6. How to display images in listview control?

7. Show image in ListView control?

8. ListView Control (and background image)

9. Making the Form invisible but making the controls seen

10. Copy all contents in a listview control to another listview control

11. Image Control Supplied By Image List Control

12. Some Help Verr much Appreciated (Modal Dialog and unmoveable windows )

 

 
Powered by phpBB® Forum Software