#include<windows.h>
#include<string>
using namespace std;
bool gameover = false;
int mousex;
int mousey;
int colortrack = 1;
HBRUSH brush = CreateSolidBrush(RGB(255,0,0));
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam);
class MyBitmap{
private:
HWND window;
HDC hdc;
HDC imagedc;
HBITMAP image;
HBITMAP oldimage;
int height;
int width;
public:
MyBitmap(HWND hwnd, char* file,int xwidth,int yheight){
hdc = GetDC(hwnd);
imagedc = CreateCompatibleDC(hdc);
image = (HBITMAP)LoadImage(NULL,"mypic.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
width = xwidth;
height = yheight;
window = hwnd;
}
void Draw(int x, int y){
SelectObject(imagedc,image);
BitBlt(hdc,x,y,width,height,imagedc,0,0,SRCCOPY);
}
void Cleanup(){
oldimage = (HBITMAP)SelectObject(imagedc,image);
DeleteObject(oldimage);
DeleteDC(imagedc);
ReleaseDC(window, hdc);
}
};
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hpInstance,PSTR cmdline,int iCmd){
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = "class";
wc.lpszMenuName = NULL;
wc.style = CS_VREDRAW|CS_HREDRAW;
RegisterClass(&wc);
HWND hwnd = CreateWindow("class","My Window",WS_OVERLAPPEDWINDOW,0,0,800,600,NULL,NULL,hInstance,NULL);
MSG msg;
MyBitmap mybitmap(hwnd,"mypic.bmp",10,10);
ShowWindow(hwnd,iCmd);
UpdateWindow(hwnd);
while(!gameover){
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else{
mybitmap.Draw(mousex,mousey);
}
}
mybitmap.Cleanup();
return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam){
switch(iMsg){
case WM_DESTROY:
PostQuitMessage(0);
gameover = true;
break;
case WM_LBUTTONDOWN:
mousex = LOWORD(lParam);
mousey = HIWORD(lParam);
break;
case WM_RBUTTONDOWN:
break;
}
return DefWindowProc(hwnd,iMsg,wParam,lParam);
}
Cheap Ripoff of Paint plz help
How Do I make it so that when the person clicks and drags it paints all of the parts they have dragged over. I can only make it draw in places. ALSO A NOTE i'm using bitmaps because i'm trying to learn more abotu using them. Thats why I use them instead of fillrect. heres my source so far:
Thanks,
Well I think maybe I should say click and drag like in paint how you use the pencil to draw lines and stuff. Maybe its a little more clear now. [smile]
Thanks again,(sorry for double post)
Thanks again,(sorry for double post)
Try this:
(lbd is a global bool set to false initially).
Anyway, hope this makes sense...
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam){ switch(iMsg){ case WM_DESTROY: PostQuitMessage(0); gameover = true; break; case WM_LBUTTONDOWN: mousex = LOWORD(lParam); mousey = HIWORD(lParam); lbd=true; break; case WM_LBUTTONUP: lbd=false; break; case WM_MOUSEMOVE: if(lbd){ mousex = LOWORD(lParam); mousey = HIWORD(lParam); } break; case WM_RBUTTONDOWN: break; } return DefWindowProc(hwnd,iMsg,wParam,lParam);}
(lbd is a global bool set to false initially).
Anyway, hope this makes sense...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement