There are various theories on dreams. They appear to originate from the subconscious mind, reflecting a mix of past experiences, desires, expectations, and emotional tendencies. The ability to influence dreams can be developed through various means. This hub might help.
You dream throughout sleep, but the dreams you remember are during your REM sleep, which is when you form memories. Your dreams are your mind recalling things you've seen and heard, which as the other person said, come out as either a nightmare or good dream.
You can help the HubPages community highlight top quality content by ranking this answer up or down.