You can simulate the action of the mouse using the mouse_event function.

You can read pixels from the screen by first getting a DC to the screen (GetDC(NULL)), then using GetPixel. Don't forget to release the DC when you're done with it.