Controling ordinary dc motor

My project is home automation, my problem is to control a dc motor to open and close a small window in details,i need a code to control this motor in both diction's,how i can do this?