You can use the difference of B and A to narrow the intersection to one of the two edges in the direction of the vector. That is, on of 0 - B.x or width - B.x should have the same sign as B.x - A.x. Similarly for y. Then you just need to find one intersection, and see if it's at a valid window coordinate.

As for the second, I think you can sort your points by x, then y (or vice versa) to get them in order. If you add the appropriate corner, you should be able to get all the vertices you need.

On the other hand, I'm not a graphics expert, so I'm guessing there are established ways of calculating these things efficiently. Perhaps check game programming literature.