I'm surprised that Britain needed to win a war against China to get Hong Kong while the Portuguese had Macao all this time. And I've never heard of a Chinese-Portuguese war. Why was it so easy for Portugal to get a piece of Chinese territory, but not for the Brtiish ?
I'll try to give you a partial answer about Portuguese Macau. Firstly, you need to understand there are roughly 300 years between the initial arrival of the Portuguese in Macau (1553) and the British occupation of Hong Kong (1841). During their voyages to the East, the Portuguese established a trade post close to the rich Pearl River Delta and this trade post would soon develop into the modern city of Macau. It's important to highlight that they did it with the consent of local mandarins and payed tributes to them. Given its strategic position, throughout most of the early modern age Macau was the main center of commerce between China and the rest of the world (and for some time the sole port where foreigners were allowed).
As said, the British occupation began in a very different world for China. Then, the Chinese approach towards Western commerce lost its efficiency and started affecting China's internal politics: Hong Kong's occupation is one of the several consequences of the Opium Wars.
/r/airessa gave the gist of the answer, so I'll just add a bit more context. Even though it was comparatively easier for the Portuguese to acquire Macau than the British did for Hong Kong, Sino-Portuguese relations wasn't all that rosy. They certainly fought: the first naval battles between the Chinese and the Europeans involved the Ming Chinese and the Portuguese in 1521 and 1522 (in the waters of Hong Kong too, for good measure). Despite their initial advantages in ship design and cannonry, the Portuguese were driven away and did not come back to the waters near Hong Kong and Macau until 1554.
The Portuguese had gotten themselves a bad name prior to the conflict: they had conquered Malacca, which was a tributary to the Ming empire; and when they landed in China, they were building recklessly building forts and collecting tariffs like they owned the place; they were even buying children as slaves, which got them the reputation as child-eating cannibals! (there's even a graphic Chinese record about how the Portuguese would cook the children) In 1554, instead of trying to clear their name, the Portuguese just said they weren't the same people as the "Folangji" (Franks) who came before - they were a new people called "Pudulijia" (assumed to be the Chinese transcription of Portugal). This and a few bribes to "grease the wheels" were enough to convince the local authorities.
At the same time the Ming dynasty was beset by the worst pirate raids during its existence, the Jiajing wokou raids. Initially, the Portuguese traders were included in this category of pirates by the authorities due to their earlier activities, but by the 1550s, the Cantonese authorities noticed the Portuguese were attacking the pirates in their waters with superior firepower, and in a few instances even sought their help to repel the pirates. As thanks for this, the Portuguese were allowed to settle in Macau for an annual fee (bribe). Until recently, Chinese historians reject the story of Portuguese assistance against the pirates, saying Macau was gotten through trickery and bribes, but more and more contemporary sources seem to confirm this "foundation myth".
Still, even when the Portuguese were allowed to develop Macau as a trading post, they were under no illusion who Macau really belongs to. Other than the fact that they had to pay rent to keep Macau, the Ming Chinese controlled a gate situated at a choke point into Macau - if the Portuguese were found to be doing anything untoward like building unauthorized fortifications, the Chinese could starve Macau by closing the gate. Usually the threat of that was enough to force the Portuguese to sing to their tune. This situation did not change until 1887, when Portugal forced China to cede Macau. This was after Hong Kong was ceded to the British and the Western Powers were scrambling to carve China into their spheres of influence.