Title: ih8saver
Description: my screensaver class-finaly done!
ih8censorship - June 18, 2004 08:54 PM (GMT)
well i got my screensaver class done all you really have to do is graphics and it supports several modes from a commandline argument:
/d - debug mode
/a - password change mode under windows 95,98, and ME
/c - change screensaver settings
/s - run normaly
anything else defaults to changeing the screensaver settings. anyway have a look i got a demo and the class and stuff at
http://www.angelfire.com/freak2/censored4u/ih8saver.zipits about 24k zipped. let me know what you think ^_^
MonkeyMan - June 19, 2004 04:46 AM (GMT)
It is about 1am so sorry if I don't make sense sometimes. Anyways at most it confused me. <_< It could be because I don't know how to inherent classes and stuff but also it doesn't seem to, well not sure how to word it. But also it looks really cool. Great Job.
dr voodoo - June 19, 2004 11:23 AM (GMT)
Not bad although I do have some critiques. Initialiatzion should happen in the Constructor, in case of an error throw an exception. Deinitialization should happen in the destructor.
So this would look like:
| CODE |
#include<windows.h> #include<stdexcep> class IH8SAVER{ //... public: IH8SAVER(int priority,LPCTSTR id,HINSTANCE thisinst,LPTSTR cmdln); virtual ~IH8SAVER();
void SS_Run(); virtual void SS_Graphics(); //... }; IH8SAVER::IH8SAVER(int priority,LPCTSTR id,HINSTANCE thisinst,LPTSTR cmdln){ //... if( /*invalid commandline*/ ) throw std::invalid_argument("Wrong commandline"); //... } IH8SAVER::~IH8SAVER(){ //... } void IH8SAVER::SS_Run(){ //... } void IH8SAVER::SS_Graphics(){ //... }
class MyScreenSaver:public IH8SAVER{ public: MyScreenSaver(int priority,LPCTSTR id,HINSTANCE thisinst,LPTSTR cmdln); ~MyScreenSaver(); void SS_Graphics(); }; MyScreenSaver::MyScreenSaver(int priority,LPCTSTR id,HINSTANCE thisinst,LPTSTR cmdln): IH8SAVER(priority,id,thisinst,cmdln){ //... } MyScreenSaver::~MyScreenSaver(){ //... } void MyScreenSaver::SS_Graphics(){ //... } int WINAPI WinMain(HINSTANCE ThisInst,HINSTANCE Thatinst,LPTSTR cmdln,int show) { try{ MyScreenSaver saver(THREAD_PRIORITY_LOWEST,"ih8saver demo 2",ThisInst,cmdln); saver.SS_Run(); }catch(std::invalid_argument&err){ MessageBox(0,err.what(),"Error",16); return 1; } return 0; }
|
PS: The Hungarian notation generaly makes C++ code less readable (or at least I have the feeling that it does). Only use prefixes if you need them SS_Run could as well be Run without any risque of name clashes. In C++ prefixes are generaly only useful in enums. ALSO IN C++ YOU (AT LEAST I) GENERALY ONLY USE BIG LETTERS FOR MACROS BECAUSE IF EVERYTHING IS BIG IT'S HARD TO READ AND ANNOYING TO ALWAYS HOLD SHIFT DOWN.
PPS: M$ is rarly a good example when it comes to makeing good C++ progs
Edit: I think the Googlebots have seen your post (look at the add at the top) :lol:
ih8censorship - June 20, 2004 12:04 AM (GMT)
Monkeyman- glad you liked it even though it confused ya :lol:
Dr voodoo- ARG i forgot about the destructor! ya that would have been a lot better way to clean things up, because then if the program for some un known reason quit it would still clean up after itself right? oh well ill fix it sometime when i feel like workin on screensavers again. i havent gotten much into exceptions, i skimmed a topic with a descussion about them a while back i should look for that. the reason i used the SS_ prefix was just kind of a personal preference of mine when looking through someone elses code, i see how a particular function is used and i want to do something similar and i have no idea where the function came from (like wheather its an api function or a C style function or a member function of some class), this way you knew it is screensaver specific and in the IH8SAVER class (was originaly called SCREENSAVER but i decided IH8SAVER was more appropriate :lol: ) about the caps and lowercases in the function names i think thats just a habit ive gotten into cause of typing tons of api functions <_<
anyways thanks for the comments guys ^_^
Rorie - June 22, 2004 01:50 AM (GMT)
okay i downloaded it, how do i insert bitmaps which is what i would like to do with my screen saver
ih8censorship - June 22, 2004 02:07 AM (GMT)
try this:
| CODE |
HBITMAP LoadBitmapFile(const TCHAR *filename) { return (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); }
//...
pic=LoadBitmapFile("hello.bmp"); if(!pic) MessageBox(0,"failed to load image","error",MB_ICONERROR|MB_OK); CreateWindowEx(0,"EDIT","",WS_CHILD|WS_VISIBLE,80,80,150,150,hwnd,(HMENU)NULL,0,0); hdc=GetDC(hwnd); comp=CreateCompatibleDC(hdc); SelectObject(comp,pic); SetTimer(hwnd,1,1,NULL); BitBlt(hdc,10,10,200,200,comp,0,0,SRCCOPY); ReleaseDC(hwnd,hdc); DeleteDC(comp); DeleteObject(pic);
|
thats the basic stuff to display a bitmap, im going to let you figure out where to put what in the class cause otherwise im making it for you and we dont belive in that around here (unless were being paid, then MAYBEY) ;)
if you dont know what any of those functions are look at
http://www.msdn.com
Danny - June 22, 2004 03:20 AM (GMT)
Rorie - June 22, 2004 04:14 AM (GMT)
| QUOTE |
HBITMAP LoadBitmapFile(const TCHAR *filename) { return (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); }
//...
pic=LoadBitmapFile("hello.bmp"); if(!pic) MessageBox(0,"failed to load image","error",MB_ICONERROR|MB_OK); CreateWindowEx(0,"EDIT","",WS_CHILD|WS_VISIBLE,80,80,150,150,hwnd,(HMENU)NULL,0,0); hdc=GetDC(hwnd); comp=CreateCompatibleDC(hdc); SelectObject(comp,pic); SetTimer(hwnd,1,1,NULL); BitBlt(hdc,10,10,200,200,comp,0,0,SRCCOPY); ReleaseDC(hwnd,hdc); DeleteDC(comp); DeleteObject(pic);
|
will that code work for every bitmap, btw where does it go?
| QUOTE |
im going to let you figure out where to put what in the class cause otherwise im making it for you and we dont belive in that around here (unless were being paid, then MAYBEY) ;)
|
don't worry i'll just use the examples
Rorie - July 1, 2004 04:12 AM (GMT)
| QUOTE (ih8censorship @ Jun 22 2004, 02:07 AM) |
try this:| CODE | HBITMAP LoadBitmapFile(const TCHAR *filename) { return (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); }
//...
pic=LoadBitmapFile("hello.bmp"); if(!pic) MessageBox(0,"failed to load image","error",MB_ICONERROR|MB_OK); CreateWindowEx(0,"EDIT","",WS_CHILD|WS_VISIBLE,80,80,150,150,hwnd,(HMENU)NULL,0,0); hdc=GetDC(hwnd); comp=CreateCompatibleDC(hdc); SelectObject(comp,pic); SetTimer(hwnd,1,1,NULL); BitBlt(hdc,10,10,200,200,comp,0,0,SRCCOPY); ReleaseDC(hwnd,hdc); DeleteDC(comp); DeleteObject(pic);
|
thats the basic stuff to display a bitmap, im going to let you figure out where to put what in the class cause otherwise im making it for you and we dont belive in that around here (unless were being paid, then MAYBEY) ;) if you dont know what any of those functions are look at http://www.msdn.com |
c'mon tell me where the code goes, that is all i am asking as i can't figure this out
Consumed - July 1, 2004 07:09 AM (GMT)
You can find out where to do that here:
http://winprog.org/tutorial/ It's under Graphics Device Interface(GDI).
Btw, great work ih8. I really love it. ^_^