|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| Screensaver Template |
|
![]() Wampus Member since: 4/26/2004 |
||||
|
|
||||
| Does anyone know of any good blank template projects or wizards for a DirectX screensaver? I have the Moire sample from the 8.1 SDK, which I'm sure I could pull from for a project of my own. I just thought I'd ask before I started on that as a blank project would save some time. Thanks for any info. |
||||
|
||||
![]() Moe Member since: 1/24/2000 From: Calgary, Canada |
||||
|
|
||||
| You can go ahead and try this... it comes from Windows 98 Programming from the Ground up... (I am pretty much just typing it out of the book, so I haven't tried it...) //Code for a minimal screensaver // #include <windows.h> #include <scrnsave.h> char str[80] = "Windows 98 Screensaver"; int delay = 200; LRESULT WINAPI ScreenSaverProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HDC hdc; static unsigned int timer; static RECT srcdim; static SIZE size; static int X = 0, Y = 0; static HBRUSH hBlkBrush; static TEXTMETRIC tm; switch(message) { case WM_CREATE: timer = SetTimer(hwnd, 1, delay, NULL); hBlkBrush = (HBRUSH) GetStockObject(BLACK_BRUSH); break; case WM_ERASEBKGND: hdc = GetDC(hwnd); //get coordinates of the screen GetClientRect(hwnd, &scrdim); //erase the screen SelectObject(hdc, hBlkBrush); PatBlt(hdc, 0, 0, scrdim.right, scrdim.bottom, PATCOPY); //get and save height and length of string GetTextMetrics(hdc, &tm); GetTextExtentPoint32(hdc, str, strlen(str), &size); ReleaseDC(hwnd, hdc); break; case WM_TIMER: hdc = GetDC(hwnd); //erase previous output SelectObject(hdc, hBlkBrush); PatBlt(hdc, X, Y, X + size.cx, Y + size.cy, PATCOPY); //move the string to a new location X += 10; Y += 10; if(X > scrdim.right) X = 0 if(Y > scrdim.bottom) Y = 0 //output string SetBkColor(hdc, RGB(0,0,0)); SetTextColor(hdc, RGB(0,255,255)); TextOut(hdc, X, Y, str, strlen(str)); ReleaseDC(hwnd, hdc); break; case WM_DESTROY: KillTimer(hwnd, timer); break; default: return DefScreenSaverProc(hwnd, message, wParam, lParam); } return 0; } //placeholder dialog box function BOOL WINAPI ScreenSaverCofigureDialog(HWND, hdwnd, UNIT message, WPARAM wParam, LPARAM lParam) { return 0; } //no class to register BOOL WINAPI RegisterDialogClasses(HANDLE hInst) { return 1; } //it requires the following resource file: /* #include <windows.h> #include <scnsave.h> ID_APP ICON SCRICON.ICO STRINGTABLE { IDS_DESCRIPTION "My Screen Saver #1" } */ Like I said, I haven't tried compiling it, so I have no idea if it works... |
||||
|
||||
![]() Muhammad Haggag Moderator Member since: 9/22/2000 From: Redmond, WA, United States |
||||
|
|
||||
| A screensaver is a normal windows application that's invoked with some specific command-line parameters. I can't remember them off the top of my head, but things like "yourscreensaver /p window-handle" when the user is previewing it, and you're supposed to render into the window with the given handle. You get the idea. A google for "screensaver tutorial" would give you some good results. As soon as you know the command-line parameters needed, just add code to handle them in your own application-framework and you've got a screensaver. Please read the DirectX FAQ, it answers a lot of common technical questions | NeXe | Journal #259850 |
||||
|
||||
![]() Wampus Member since: 4/26/2004 |
||||
|
|
||||
| Well, I gave it a shot, but its giving me some link errors. saver.obj : error LNK2019: unresolved external symbol _DefScreenSaverProc@16 referenced in function _ScreenSaverProc@16 I think I'll just work backwards from the Moire project. |
||||
|
||||
![]() Moe Member since: 1/24/2000 From: Calgary, Canada |
||||
|
|
||||
Quote: Can you possibly post the code from the Moire project? |
||||
|
||||
![]() ReaVeR-Andrey Member since: 7/15/2005 From: Moscow, Russian Federation |
||||
|
|
||||
Yes, Moe's screensaver works, after a few corrections:#include <windows.h> #include <scrnsave.h> char str[80] = "Windows Screensaver"; int delay = 200; #pragma comment ( lib, "scrnsave.lib" ) #pragma comment ( lib, "comctl32.lib" ) LRESULT WINAPI ScreenSaverProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HDC hdc; static unsigned int timer; static RECT scrdim; static SIZE size; static int X = 0, Y = 0; static HBRUSH hBlkBrush; static TEXTMETRIC tm; switch(message) { case WM_CREATE: timer = (UINT) SetTimer(hwnd, 1, delay, NULL); hBlkBrush = (HBRUSH) GetStockObject(BLACK_BRUSH); break; case WM_ERASEBKGND: hdc = GetDC(hwnd); //get coordinates of the screen GetClientRect(hwnd, &scrdim); //erase the screen SelectObject(hdc, hBlkBrush); PatBlt(hdc, 0, 0, scrdim.right, scrdim.bottom, PATCOPY); //get and save height and length of string GetTextMetrics(hdc, &tm); GetTextExtentPoint32(hdc, str, (int) strlen(str), &size); ReleaseDC(hwnd, hdc); break; case WM_TIMER: hdc = GetDC(hwnd); //erase previous output SelectObject(hdc, hBlkBrush); PatBlt(hdc, X, Y, X + size.cx, Y + size.cy, PATCOPY); //move the string to a new location X += 10; Y += 10; if(X > scrdim.right) X = 0; if(Y > scrdim.bottom) Y = 0; //output string SetBkColor(hdc, RGB(0,0,0)); SetTextColor(hdc, RGB(0,255,255)); TextOut(hdc, X, Y, str, (int) strlen(str)); ReleaseDC(hwnd, hdc); break; case WM_DESTROY: KillTimer(hwnd, timer); break; default: return DefScreenSaverProc(hwnd, message, wParam, lParam); } return 0; } //placeholder dialog box function BOOL WINAPI ScreenSaverConfigureDialog(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { return 0; } //no class to register BOOL WINAPI RegisterDialogClasses(HANDLE hInst) { return 1; } ... and resource.rc ... #include <windows.h> #include <scrnsave.h> ID_APP ICON SCRICON.ICO STRINGTABLE { IDS_DESCRIPTION "My Screen Saver #1" } ... and don't forget to put scricon.ico into the project's directory. |
||||
|
||||
![]() ReaVeR-Andrey Member since: 7/15/2005 From: Moscow, Russian Federation |
||||
|
|
||||
| Hmm. How to use Direct3D along with screensavers? The program fails if I try to create Direct3D device. I mean the device creates ok, but the program quits. |
||||
|
||||
![]() Muhammad Haggag Moderator Member since: 9/22/2000 From: Redmond, WA, United States |
||||
|
|
||||
Quote: Interesting. Do you mean it quits when set as a screensaver? Please read the DirectX FAQ, it answers a lot of common technical questions | NeXe | Journal #259850 |
||||
|
||||
![]() Moe Member since: 1/24/2000 From: Calgary, Canada |
||||
|
|
||||
Quote: Excellent! I think I might have to try playing around with it some time... (when I have time). |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|