Hello again. sorry for all the dumb questions but hey im learning
well here is a little background on what i am doing.
i am trying to familiarize myself with windows api. so I made a class called line that makes a line at a specified location with a specified thickness. you can access the variables to change the size and location.
so I am making a bacic win32 app with a half second timer. every time WM_TIMER comes around I want to change the values of my line objects members randomly and then draw it to the hdc. For some reason It is not working from within the message loop.
here are the source files.
lines.h
#include <math.h>
class Line
{
private:
HWND Hwnd;
public:
double sx,sy,ex,ey,T;
Line(HWND, double, double, double, double, double, bool);
int draw(HWND);
};
Line::Line(HWND lHwnd, double lsx, double lsy, double lex, double ley, double lT, bool drw) :
sx(lsx), sy(lsy), ex(lex), ey(ley), T(lT), Hwnd(lHwnd)
{
if(drw)
draw(Hwnd);
}
int Line::draw(HWND Hwnd)
{
bool virt = false;
int start[] = {(int) sx, (int) sy};
int end[] = {(int) ex, (int) ey};
if (start[1] == end [1])
virt = true;
double hT = (T / 2);
HDC hDC;
//PAINTSTRUCT ps;
hDC = GetDC(Line::Hwnd);
MoveToEx(hDC, end[0], end[1], NULL);
LineTo(hDC, start[0], start[1]);
for(int c = 0; c < hT; c++)
{
//if(T > 1)
//{
start[0]--;
start[1]++;
end[0]--;
end[1]++;
MoveToEx(hDC, end[0], end[1], NULL);
LineTo(hDC, start[0], start[1]);
//}
}
start[0] = (int) sx;
start[1] = (int) sy;
end[0] = (int) ex;
end[1] = (int) ey;
for(int c = 0; c < hT; c++)
{
//if(T > 1)
//{
start[0]++;
start[1]--;
end[0]++;
end[1]--;
MoveToEx(hDC, end[0], end[1], NULL);
LineTo(hDC, start[0], start[1]);
//}
}
ReleaseDC(Hwnd,hDC);
return 0;
}
I have cut all of the window creation code out for your viewing pleasure.
main.cpp
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
Line dude(hwnd, 0, 0, 544, 375, 20, false);
//if i uncomment the next commented section of code it will work fine.
/* dude.sx = (double) (rand() % 375 + 1);
dude.sy = (double) (rand() % 544 + 1);
dude.ex = (double) (rand() % 375 + 1);
dude.sy = (double) (rand() % 544 + 1);
dude.draw(hwnd);
RECT txtrct;
txtrct.bottom = 375;
txtrct.top = 0;
txtrct.left = 0;
txtrct.right = 544;
HDC hDC;
hDC = GetDC(hwnd);
HBRUSH brush;
brush = (HBRUSH)SelectObject(hDC, GetStockObject(WHITE_BRUSH));
FillRect(hDC, &txtrct, brush);
ReleaseDC(hwnd, hDC);*/
switch (message) /* handle the messages */
{
case WM_CREATE:
SetTimer(hwnd, 1, 500, NULL);
srand(time(0));
break;
case WM_TIMER:
// this does not produce any lines when i run it. :(
//Line dude(hwnd, 0, 0, 544, 375, 20, false);
dude.sx = (double) (rand() % 544 + 1);
dude.sy = (double) (rand() % 375 + 1);
dude.ex = (double) (rand() % 544 + 1);
dude.sy = (double) (rand() % 375 + 1);
dude.draw(hwnd);
break;
case WM_PAINT:
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
so there it is can anyone catch any errors in the code?
thanks
EDIT:
I know my file structure is messed up, Ill try fixing that real quick.