473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

ListView and overrided WndProc

Hello

from example from web i did a little code to avoiding columnHeader resize.
this code seems to work well,
but when I put a 'normal' ListView on the same Form than my overrided ListView
it seems to stop working.

if I'm resizing 'normal' ListView ColumnHeaders, then I can resizing ColumnHeaders of my overrided ListView.
If I don't resizing 'normal' ListView ColumnHeaders, then resizing of my overrided ListView ColumnHeaders is disabled.

Here is the code.
To test, create a Form, put on it a ListView and one MyListView.

To test, move the mouse on MyListView columnHeaders and you can see that resizing is disabled.
Then resize ListView columnsHeaders, then you will be able to resize MyListView columnHeaders.

It's looking like loosing the NativeWindow Handle ;o{{
cyrille

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Diagnostics ;

using System.Runtime.InteropServices ; // DllImport, StructLayoutAttribute

namespace MyListView
{
/// <summary>
/// Description résumée de MyListView.
/// </summary>
public class MyListView : ListView
{

#region Code généré par le Concepteur de composants

/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
private System.ComponentModel.Container components = null;

/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}

#endregion

public MyListView()
{
// Cet appel est requis par le Concepteur de formulaires Windows.Forms.
InitializeComponent();

// TODO*: ajoutez les initialisations après l'appel à InitComponent

}

/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

[DllImport("User32.dll")]
static extern int SendMessage(IntPtr hWnd, int uMsg, IntPtr wParam, IntPtr lParam);

//************* Win32 messages constants, structs and functions **************
const int LVM_FIRST = 0x1000;
const int LVM_GETHEADER = LVM_FIRST + 31 ;

const int HDM_FIRST = 0x1200;
const int HDM_HITTEST = HDM_FIRST + 6 ;

const int HHT_ONDIVIDER = 0x0004 ;

const int WM_SETCURSOR = 0x0020 ;
const int WM_LBUTTONDOWN = 0x0201 ;

[StructLayout(LayoutKind.Sequential)]
struct HDHITTESTINFO
{
public Point pt;
public int flags;
public int iItem;
}

protected override void OnHandleCreated(EventArgs e)
{
Debug.WriteLine( "OnHandleCreated() " + e.ToString() );

base.OnHandleCreated( e );

/*
lResult = SendMessage( // returns LRESULT in lResult
(HWND) hWndControl, // handle to destination control
(UINT) LVM_GETHEADER, // message ID
(WPARAM) wParam, // = 0; not used, must be zero
(LPARAM) lParam // = 0; not used, must be zero );
*/
IntPtr hHeader = (IntPtr)SendMessage( Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero);

HeaderNativeWindow nativeWindow = new HeaderNativeWindow( hHeader );

}

class HeaderNativeWindow : NativeWindow
{
public HeaderNativeWindow(IntPtr hHeader)
{
Debug.WriteLine( "HeaderNativeWindow() " + hHeader );

AssignHandle( hHeader );
}

protected override void WndProc(ref Message m)
{
Debug.WriteLine( "WndProc() m.Msg = " + m.Msg);

switch(m.Msg)
{
case WM_SETCURSOR:
// do not allow change cursor to "resizable"
return;

case WM_LBUTTONDOWN:

Debug.WriteLine( "WndProc() WM_LBUTTONDOWN" );

//Get cursor position(in client coordinates)
Int16 x = (Int16)m.LParam;
Int16 y = (Int16)((int)m.LParam >> 16);
Point cursorPosition = new Point(x, y);

//sending HDM_HITTEST message for determination further actions
HDHITTESTINFO hitInfo = new HDHITTESTINFO();
hitInfo.pt = cursorPosition ;
IntPtr buffer = Marshal.AllocHGlobal(Marshal.SizeOf(hitInfo));
Marshal.StructureToPtr(hitInfo, buffer, true);

SendMessage(m.HWnd, HDM_HITTEST, IntPtr.Zero, buffer);

hitInfo = (HDHITTESTINFO)Marshal.PtrToStructure(buffer, typeof(HDHITTESTINFO));
Marshal.FreeHGlobal(buffer);

if( hitInfo.flags == HHT_ONDIVIDER )
{
//do not allow handling WM_LBUTTONDOWN (mouse was pressed for column resizing)
return ;
}
//allow handling WM_LBUTTONDOWN
break;
}
base.WndProc(ref m);
}
}

/* ListView WndProc
*
protected override void WndProc(ref Message m)
{
if (m.Msg==WM_NOTIFY )
{
NMHDR nm =(NMHDR) m.GetLParam(typeof(NMHDR));
if (nm.code==HDN_ITEMCHANGEDW)
{
int right=0;
int left=0;
TOOLINFO ti=new TOOLINFO();
ti.cbSize=Marshal.SizeOf(ti);
ti.uFlags=TTF_SUBCLASS;
ti.hWnd=headerHandle;
for (int i=0; i<this.Columns.Count; i++)
{
if (i<this.Columns.Count)
right+=this.Columns[i].Width;
else
right=this.Width;
ti.uID=i;
if (i<this.Columns.Count)
ti.pszText=this.Columns[i].Text;
else
ti.pszText="";
Rectangle rect= new System.Drawing.Rectangle(left,0,right,20);
ti.rect=rect;
// SendMessage(toolTipHandle, TTM_DELTOOLW, 0, ref ti);
SendMessage(toolTipHandle, TTM_ADDTOOLW, 0, ref ti);
left=right;
}
}
}
base.WndProc (ref m);
}
*/

}
}

Nov 16 '05 #1
0 4463

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Anushya | last post by:
Hi I am using Listview and inherited listview control overriding WndProc & PreProcessMessage in ListView. I need this to customize listview to display only the page the user scrolls to. Since i...
0
by: Anushya | last post by:
Hi I am using Listview and inherited listview control overriding WndProc & PreProcessMessage in ListView. I need this to customize listview to display only the page the user scrolls to. Since i...
1
by: SlantyOD | last post by:
Hi All, I'm trying to tie two ListViews together so that when the user scrolls one, the other stays 'in sync'. Since there are no OnScroll events, and the scroll bar position is unavailable,...
2
by: Anushya devi | last post by:
Hi All I used listview and tried to update it by using Addrange. When the number of items is less, it works fine.. But I need to update nearly 200,000 items and it hangs. Also i need to add...
1
by: Cyrille Giquello | last post by:
the code is the one at page http://www.gotdotnet.com/Community/MessageBoard/Thread.aspx?id=96378&Page=1#96674 Hello from example from web i did a little code to avoiding columnHeader resize....
1
by: Tim | last post by:
I have successfully captured the scroll event of the listview control by creating a class that inherits the list view control then overriding the wndproc procedure. I have two questions though....
5
by: jtalbot_vizible | last post by:
I was looking at the code on codeproject to solve my listview flickering issue. All the references to functions in the rest of my post refer to that code. It's available at...
11
by: rb | last post by:
Hi All, Is there a property or method to keep the headercolumns from being resized by the user for a listview? I am using Visual Basic in Visual Studio . net 2005 Thank you.
1
by: Michael M. | last post by:
HI all, When I add items to a Listview control, then clearing the items and adding more items my program seems to allocate a few KB of data and then not free the Memory. I noticed this about...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.