473,809 Members | 2,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subclassing via NativeWindow

Hi everybody

I'm trying to subclass Winamp's main window in order to develop a
software which will interact with Winamp.
For testing, I'm trying to intercept the closing of this window via
WM_CLOSE, by showing a MessageBox, but it doesn't work althoug the code
seems to be correct. Do you notice a mistake ?
My test program contains a form with 2 buttons : one button to activate
subclassing, and the second button to desactivate it.

Here is my code. First, my class deriving from NativeWindow :

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Windows. Forms;
using System.Runtime. InteropServices ;

namespace WinampTest
{
public delegate void WAHandler(objec t sender, EventArgs e);

public class WAWindow : NativeWindow, IDisposable
{
bool disposed;
public event WAHandler WAEvent;
bool subclassed;

public bool Subclassed
{
get { return subclassed; }
set { subclassed = value; }
}

public WAWindow(IntPtr hwnd)
{
AssignHandle(hw nd);
}

protected override void WndProc(ref Message m)
{
if (subclassed)
{
if (m.Msg == 0x0010) // WM_CLOSE
WAEvent(this, null);
}
base.WndProc(re f m);
}

public void Dispose()
{
if (!disposed)
{
ReleaseHandle() ;
GC.SuppressFina lize(this);
disposed = true;
}
}

~WAWindow()
{
Dispose();
}
}
}

And my test program :

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;
using System.Runtime. InteropServices ;
using System.Threadin g;

namespace WinampTest
{
public partial class Form1 : Form
{
WAWindow w;
IntPtr hwnd;

const int WM_WA_IPC = 0x400;
[DllImport("user 32.dll", SetLastError = true)]
static extern IntPtr FindWindow(stri ng lpClassName, string
lpWindowName);

public Form1()
{
InitializeCompo nent();
hwnd = FindWindow("Win amp v1.x", null);
w = new WAWindow(hwnd);
w.WAEvent += new WAHandler(w_WAE vent);
}

void w_WAEvent(objec t sender, EventArgs e)
{
MessageBox.Show ("Coucou");
}

private void button1_Click(o bject sender, EventArgs e)
{
w.Subclassed = true;
}

private void button2_Click(o bject sender, EventArgs e)
{
w.Subclassed = false;
}
}
}

So, nothing seems to be strange. Where is my mistake ?

Thanks
Laura
Jul 23 '06 #1
2 6541
Stupid question.. but WinAmp is in the same process as your .NET components?

"Laura Martignas" <la********@lib ertysurf.frha scritto nel messaggio
news:Xn******** *************** ***@193.252.117 .183...
Hi everybody

I'm trying to subclass Winamp's main window in order to develop a
software which will interact with Winamp.
For testing, I'm trying to intercept the closing of this window via
WM_CLOSE, by showing a MessageBox, but it doesn't work althoug the code
seems to be correct. Do you notice a mistake ?
My test program contains a form with 2 buttons : one button to activate
subclassing, and the second button to desactivate it.

Here is my code. First, my class deriving from NativeWindow :

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Windows. Forms;
using System.Runtime. InteropServices ;

namespace WinampTest
{
public delegate void WAHandler(objec t sender, EventArgs e);

public class WAWindow : NativeWindow, IDisposable
{
bool disposed;
public event WAHandler WAEvent;
bool subclassed;

public bool Subclassed
{
get { return subclassed; }
set { subclassed = value; }
}

public WAWindow(IntPtr hwnd)
{
AssignHandle(hw nd);
}

protected override void WndProc(ref Message m)
{
if (subclassed)
{
if (m.Msg == 0x0010) // WM_CLOSE
WAEvent(this, null);
}
base.WndProc(re f m);
}

public void Dispose()
{
if (!disposed)
{
ReleaseHandle() ;
GC.SuppressFina lize(this);
disposed = true;
}
}

~WAWindow()
{
Dispose();
}
}
}

And my test program :

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;
using System.Runtime. InteropServices ;
using System.Threadin g;

namespace WinampTest
{
public partial class Form1 : Form
{
WAWindow w;
IntPtr hwnd;

const int WM_WA_IPC = 0x400;
[DllImport("user 32.dll", SetLastError = true)]
static extern IntPtr FindWindow(stri ng lpClassName, string
lpWindowName);

public Form1()
{
InitializeCompo nent();
hwnd = FindWindow("Win amp v1.x", null);
w = new WAWindow(hwnd);
w.WAEvent += new WAHandler(w_WAE vent);
}

void w_WAEvent(objec t sender, EventArgs e)
{
MessageBox.Show ("Coucou");
}

private void button1_Click(o bject sender, EventArgs e)
{
w.Subclassed = true;
}

private void button2_Click(o bject sender, EventArgs e)
{
w.Subclassed = false;
}
}
}

So, nothing seems to be strange. Where is my mistake ?

Thanks
Laura

Jul 24 '06 #2
"Laura T" <laura.t@_yahoo .comwrote in
news:eC******** *****@TK2MSFTNG P03.phx.gbl:
Stupid question.. but WinAmp is in the same process as your .NET
components?

No.. I just realized it today ! I have to program a system wide hook if I
want to access Winamp from my app... Stupid am I :)

Jul 24 '06 #3

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

Similar topics

2
5166
by: BJörn Lindqvist | last post by:
A problem I have occured recently is that I want to subclass builtin types. Especially subclassing list is very troublesome to me. But I can't find the right syntax to use. Take for example this class which is supposed to be a representation of a genome: class Genome(list): def __init__(self): list.__init__(self) self = ....
0
2190
by: Marco Segurini | last post by:
Hi, I am trying to dynamically install/deinstall a message handler to a System.Windows.Forms.Form using NativeWindow. I do not use IMessageFilter derived class because it intercept only the PostMessage messages. My problem is that when I install the message handler the second time a "Fatal stack overflow error" occurs.
3
4268
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint of a subclassed DataGridTextBoxColum dos not seem like a practical way to do it. I have subclassed a DataGrid and overridden the OnPaint as such:
0
1495
by: Gianluca | last post by:
Anyone knows if the bug in NativeWindow.RegisterClass and the class names list being case sensitive is scheduled to be fixed or already fixed? In short, NativeWindow.RegisterClass keeps a list of registered classes that is case sensitive, but Windows itself is not. So you want to use a class that is already registered by the .NET framework you have to guess the correct case or you get a 'class already registered" exception. That's...
2
3014
by: Alexander Wehrli | last post by:
Hi, I need to write a functionality to catch all Windows Messages from any Window (like spy++ does). I thought that would be possible by subclassing the window. So I wrote a class that inherts from NativeWindow, Assigned a Handle from another window and overrode the WndProc method. BUT, I never catch any message EXCEPT if I assign the handle of my own
0
1622
by: edx | last post by:
Hi, I have the following lines of code: WNDCLASS wc; memset (&wc, 0, sizeof (wc)); wc.hbrBackground = GetSysColorBrush (COLOR_WINDOW); wc.hInstance = GetModuleHandle (NULL); wc.lpfnWndProc = (WNDPROC)e3dxgine::Window::WndProc; wc.lpszClassName = "__e3dxgine_Wnd";
3
1766
by: Andrius B. | last post by:
Hi all. Could smb provide an Internet site or smth explaining how to use function SetWindowSubclass in vb.net? All examples found by me are in C++ :( Thanks.
0
1003
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Hello, I followed the MS instructions to subclass Windows using C#.net (http://support.microsoft.com/kb/815775) as the follows. I then opened several Excel files, and selected anyone of them as foreground window. I was expecting to see windows message, saying WM_ACTIVATE, or something like that, however, to my surprise, I saw NO windows message when I randomly selected those Excel windows, (although I could see other window messages,...
3
3535
by: tomko | last post by:
Hi, What is the right way to dispose of a NativeWindow? I guess the NativeWindow is managed code and will be cleared by the GC, but the window handle it is holding is a native handle! I'm using the standard dispose code: NativeWindow nativeWindow;
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10120
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7662
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.