Results 1 to 9 of 9

Thread: classes....

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    classes....

    Im trying to remake my win32 graphics class. so far its works, if I put this as global:
    Code:
    	HDC hDC, hMemDC;
    	HBITMAP hBitmap;
    	BITMAP bm;
    	PAINTSTRUCT ps;
    	RECT rect;
                    HINSTANCE ghInst2;
    but I want to put it in my class....is this possible?

  2. #2
    Megatron
    Guest
    If you want 1 copy per class, rather than 1 copy per instance, then declare it as static.

    If that's not what you meant, please elabourate further (e.g: what objects do you want to be able to access it, and which ones do you not want to be able to access it).

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You might have to explain where and how you access those variables.

    Variables with global scope are accessible from anywhere, that's what makes them bad. If you put them in a class, you have to instantiate the class and have accessors for them, then access them by the object's name. This is not a good idea, because classes should be as independent as possible and protect it's data, so i have to ask you what you want with the variables.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Im using them to show a picture. I want 1 set per instance. But my graphic won't show (function) if I just put those in the class, the graphic only shows if they are global.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    how and where do you access them?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    through one of my classes functions. The function will be called in the WM_PAINT.

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    well I was expecting more scope related information.
    Anyways, you can do a false assertion in the accessor to track the access.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    *zoom* right over my head heres my class:

    Code:
    class graphics {
    public:
    
    ~graphics()  {
    }
    graphics()  {
    }
    	void ReDraw(int x, int y, HWND window)  {
    
    			hDC = BeginPaint(window, &ps) ;
    
    			GetClientRect(window, &rect) ;
    
    			hBitmap = LoadBitmap(ghInst, MAKEINTRESOURCE(IDB_BITMAP1));
    
    			GetObject(hBitmap, sizeof(BITMAP), &bm);
    
    			hMemDC = CreateCompatibleDC(hDC);
    			SelectObject(hMemDC, hBitmap);
    
    			BitBlt(hDC, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
    
    			DeleteDC(hMemDC);
    
    			EndPaint(window, &ps);
    			DeleteObject(hBitmap);
    
    	}
    };
    now I want this to be able to show a graphic without having to put all those variables seperate for each instance of the class. where should I put them? everywhere I try to put them in the class, the function doesn't work. If they're global it does

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Well that's not enough either, because I have no idea if you're accessing them or not. Easiest for you would be to zip it all up.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width