views:

20

answers:

0

I have created a screen saver (C#, .NET 4.0 if that matters) but I have a couple of problems (on a more cosmetic level, though). These are probably easy to solve, but I have prettu much never used the Win32 API, so I can easily miss the obvious when it comes to that.

Q1: I set up the small preview window like this:

SetParent(Handle, hwndParent);
SetWindowLong(Handle, GWL_STYLE, new IntPtr(GetWindowLong(Handle, GWL_STYLE) | WS_CHILD));
Rectangle parentRect;
GetClientRect(hwndParent, out ParentRect);
Size = parentRect.Size;  

where hwndParent is parsed from the 2nd command argument. The problem here is that the preview window steals focus from the screen saver settings tab. As a naive attempt, I called SetFocus(hwndParent) but that didn't have any effect. What's the correct way of keeping the focus where it should be

Q2: If I open the configuration dialog in the "usual way" of creating a form, i.e.

Application.Run(new ConfigurationForm());

the dialog will not be modal to the Control Panel applet. How can this be achieved? I've understood that the HWND of the intended parent is provided with the command argument as "/c:nnnnnnnn" but thats as far I've gotten. (Using SetParent(hwndParent) just behaved weirdly so it is apparently not the correct function.)