News | Articles | Libraries | Developer Tools | Books | Forum Links | Search   
Sections:
 

QA: Where are the MoveTo and LineTo methods?

By Joao Paulo Figueira, June 8, 2003.
Print version

Question

The MoveTo and LineTo HDC methods are not supported. How can I implement them?

Answer

Assuming that you are doing straight API development with the GDI, you will not find these methods. They are not natively supported by the GDI, and are simulated in MFC 3.0. The solution lies on the Polyline function. This function takes as parameters a handle to the device context, a POINT array and the size of the array.

Here is how you might implement a simple Line function:

BOOL Line(HDC hDC, int x0, int y0, int x1, int y1) { POINT points[2] = {{x0,y0}, {x1,y1}}; return Polyline(hDC, points, 2); }

To simulate the MoveTo and LineTo functions, you will need to store the initial point set by MoveTo in a variable and then, in the LineTo function, use an approach similar to the one used above. The drawback of this method is that the initial point set by MoveTo is independent of the HDC. A better approach would be to encapsulate the DC handle in a C++ class, and store there the initial point. This way, you would have a connection between HDC and initial point.

Related resources:

Discuss

Discuss this article. Here you can write your comments and read comments of other developers.
Rate this article:     Poor Excellent    
 12345 
© 2001-2005 Pocket PC Developer Network, a division of Spb Software House