KIS Systems, Inc - Contract Programming for Unix/Windows/Web in C++/C#/PHP/Qt/.NET and other technologies.

KIS Technoblog

Technical ruminations from our chief codemeister – Rick Berger

Archive for September, 2006

Win32 API – Can’t Get Away

Posted by admin on 27th September 2006

Ran into a window controlling problem with C#/.NET – a couple of things in the API aren’t exposed. The first is (are, really), the messages WM_NC* (used to detect non-client mouse hits, etc.) The second is the ability to set window settings via the SystemParametersInfo call. In this case, I want to use SPI_{SET/GET}DRAGFULLWINDOWS. C#/.NET exposes the GET functionality, but not the SET.

The first case is handled relatively painlessly – simply a matter of putting a message filter on the app and then watching for the hwnd and WM_ message of interest. You don’t want to get too carried away with message filters – every message that goes through the message pump is forwarded to the filter, first, once installed. So, you install it only when you need it, and remove it when you don’t. And just do minimal processing, while you’re in there.

The second problem requires an interop call to the user32 dll and getting that all set up properly. Not terrifically taxing, but not perfectly straightforward, either. It’s unfortunate the named constants for the SPI_, WM_, etc values aren’t available in the toolkit. You have to redeclare them in your code, somewhere (don’t want to use raw numbers, for sure.)

On one hand it points out the shortcomings of a kit like C#/.NET – on the other, it’s always nice to know I can get under the cover/lift the hood when I need to.

rickb

Posted in .NET, Programming, Win32 API, Windows, software | No Comments »

The ‘new’ keyword – an oddity in C#

Posted by admin on 17th September 2006

Here’s something different: The ‘new’ keyword can have different semantics in C#, depending on the context:

  • As an instantiator – the normal context you would think of, ie:

    'new String'

    .

  • As an explicit member hider – a different context, ie:

    'new public func(int iarg)'

    where ‘func’ is something that is defined in a base class and may or may not be overrideable.

It’s no big deal, just an oddity. I’m trying to think of another language where a keyword has completely different semantics depending on context. I can’t think of any, of the top of my head.

The former definition and usage is something that’s familiar to anyone versed in OOP methodology and languages: instantiate me an object of the named type.

The latter is something that is basically a tell to the compiler – your saying, in effect, “Yes, I am hiding a member and I’m doing it intentionally, and please don’t bug me with any more warnings about it,” and the compiler acknowledges the usage and doesn’t say anything more about it.

You wonder if, during the design hammer sessions deep in the bowels of MS, whether anyone balked at this and proposed a different keyword to fit the different semantic: ‘hider’ or ‘cover’ or some such thing.

Only the MS insiders know. Meanwhile, we’ll ‘new’ a class for an instance, and ‘new’ a member we intentionally want to hide in that class and move on, happily.

rickb

Posted in .NET, CSharp, Programming | No Comments »