Like say if I am running a webcam program and the iamges show up in a window, how would I grab those images and then put them into my program?

I'm thinking of finding a window with a certain name, then using some sort of capture method to where the iamge would be from the sides of the window.... but then if someone resized it, it would be ****ed up.