How do you create a POINT object in Win32?

I am trying to use the PtInRect function in Win32, which takes a POINT object. I have x and y coordinates, but I don’t know how I create a POINT from those. I tried looking it up, but could only find this documentation, which does not contain the information I want.

Thank you for your help.



You’re creating trouble for yourself because of attempting to dynamically allocate the POINT object with malloc. BTW you do not always need dynamic allocation and to initialize any struct you do not need to use malloc as you pointed in the comments, you can just create the object directly.


As tkausl pointed in the comments, POINT is created in the same way as any other struct.

Some examples on how creating a POINT:

int main()
    int someX = 100;
    int someY = 100;
    RECT testRect1 = {0,0,200,200};
    RECT testRect2 = {150,150,350,350};
    POINT p1{someX,someY};
    POINT p2 = {someX,someY};
    POINT p3;
    p3.x = someX;
    p3.y = someY;
    std::cout << (bool) PtInRect(&testRect1,p1) << std::endl;
    std::cout << (bool) PtInRect(&testRect1,p2) << std::endl;
    std::cout << (bool) PtInRect(&testRect1,p3) << std::endl;
    std::cout << (bool) PtInRect(&testRect1,{someX,someY}) << std::endl;
    std::cout << (bool) PtInRect(&testRect2,p1) << std::endl;
    std::cout << (bool) PtInRect(&testRect2,p2) << std::endl;
    std::cout << (bool) PtInRect(&testRect2,p3) << std::endl;
    std::cout << (bool) PtInRect(&testRect2,{someX,someY}) << std::endl;

Leave a Reply

Your email address will not be published. Required fields are marked *