After a return to power and expansion, Hungary slowly grew until 1396 when they were overrun by the Ottoman Turks, but by 1456 they had defeated the Turks and established a large and well trained army. However all this fighting left the local Magyar people neglected and soon both the nobles and the peasants were fighting the king as the pendulum swung the other direction in 1541 when the Turks returned and took the then Austrian-controlled Budapest (at the time two separate cities: Buda and Pest).
Until 1686, Hungary was divided by Turkish, Hungarian, and Austrian control, at which point the Polish armies defeated the Turks, but the Magyars didn't gain independence since the Hapsburgs came in and took over the land previously controlled by the Turks. The relationship was inconsistent over time as independence movements came and went as the Hapsburg power declined and eventually created the dual monarchy of the Austrian-Hungarian Empire in 1867.
During much of early Austrian rule (prior to the dual monarchy) the countries experiences wars, in particular the counter-reformation, the Thirty Years War, and further battles with the Turks. The 1700s were much the same as Austria got involved in wars with the Russians, Swedes, Prussians, and French among others.
The 1800s began with further wars with the French as Napoleon swept across Europe. In his wake he left various revolutionary ideas behind, including rule by the people and greater power by the people to determine their own destiny. This led to Hungarian revolts and in 1867 Austria united with Hungary in a dual monarchy to overpower these thoughts and movements. This union created a government in which the two countries operated fairly independently of each other, only sharing a few governmental branches.