Im trying to remake my win32 graphics class. so far its works, if I put this as global:
but I want to put it in my class....is this possible?:confused:Code:HDC hDC, hMemDC;
HBITMAP hBitmap;
BITMAP bm;
PAINTSTRUCT ps;
RECT rect;
HINSTANCE ghInst2;
Printable View
Im trying to remake my win32 graphics class. so far its works, if I put this as global:
but I want to put it in my class....is this possible?:confused:Code:HDC hDC, hMemDC;
HBITMAP hBitmap;
BITMAP bm;
PAINTSTRUCT ps;
RECT rect;
HINSTANCE ghInst2;
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).
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.
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.
how and where do you access them?
through one of my classes functions. The function will be called in the WM_PAINT.
well I was expecting more scope related information.
Anyways, you can do a false assertion in the accessor to track the access.
*zoom* right over my head :p heres my class:
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 :(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);
}
};
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.