PDA

View Full Version : Windows screensaver



Darkstar
13th February 2006, 13:51
Hi!

I'm trying to write a Windows screensaver and I'm having trouble getting the preview mode to work.

In preview mode, the screensaver gets a window handle from the system which describes the window where the screensaver should run in. This is the small "monitor" widget in the screensaver setup dialog.

So I need my screensaver to not run fullscreen but inside this window. I found out that this should be possible by using QWidget::create() and passing the window handle as WId parameter. But everytime I try this I get the following output:

QWidget::create: Failed to set window procedure (Access denied)

What am I doing wrong here? Anyone know how this is supposed to work?

Thanks
--Michael

Cesar
13th February 2006, 16:30
I've found some info (http://www.esaro.se/savers/sshow.html). As far as I understood provided hWnd should be parent of your widget.

Darkstar
13th February 2006, 19:18
OK, I understand that.

So what I basically need to do is create a windows using Win32 API calls, which has the given hWnd as parent, and then pass that new window's hWnd over to QWidget::create(), right?

Complicated, but I'll try it and see if it works.

Darkstar
15th February 2006, 09:37
Okay, I changed my program a bit, but it still doesn't work right.

Here's what I do (in the constructor of my main Qt window) to setup the screensaver in preview mode (where window is the hWnd which is passed to the screensaver):

RECT rect;
HWND previewWindow;
GetClientRect(window, &rect);
printf("%d %d %d %d\n", rect.left, rect.top, rect.right, rect.bottom);
previewWindow = CreateWindow(L"Static", L"Preview", WS_VISIBLE | WS_CHILD, rect.left, rect.top, rect.right, rect.bottom, window, 0, 0, 0);
printf("new hWnd = %d\n", previewWindow);
create(previewWindow, false);
show();


This actually fills the preview-area black (my screensaver has a black background), but it seems that the screensaver now doesn't respond to any messages anymore. I.e. it doesn't repaint periodically, and when selecting a different screensaver in the dropdown-list, I have to manually kill my screensaver, otherwise the dialog window won't respond anymore, too (I guess it tries to send WM_QUIT to my saver which can't/won't respond)

Anyone have any ideas what's going wrong here?

andyp
21st October 2009, 10:44
Did you ever get anywhere with this ?
I am trying to do something similar (embedding a QMainWindow into an existing HWND) with QWidget::create.
I get the same error message, and the co-ordinates of my QMainWindow are offset by the position of my original HWND, and the QMainWindow is impervious to input events.