With a C=O bond, the electrons that participate in the bond are closer to the oxygen than the carbon, which gives the oxygen a partial negative charge. As a result, the C has a partial positive charge, because electrons are further away from it. The reason Oxygen attracts these electrons is because it is more electronegative than carbon.
When a Hydrogen is bonded to something like Nitrogen, Oxygen, Chlorine or Fluorine, it will end up with a partial positive charge.
For example, if we had a H-N bond, the nitrogen would pull the electrons in that bond toward itself, resulting in it having a partial negative charge. Since the electrons in that bond spend less time near the Hydrogen and more time near the Nitrogen, the Hydrogen will have a partial positive charge.
Now say we have two separate compounds. One has a C=O bond, and the other has a H-N bond. Say we position these two compounds in such a way that the C=O bond is next to the H-N bond. As explained above, the O in the C=O has a partial negative charge, and the H in the H-N has a partial positive charge. We know that a negative charge is attracted to a positive charge, so we know that the O from the C=O and the H from the H-N will be attracted to each other, because they each carry opposite charges.
As a result, a Hydrogen bond will form between the O and the H of the two separate compounds.
I think what confused you is that you thought a Hydrogen bonded to a Nitrogen, Oxygen of Fluorine is itself a hydrogen bond. A H-F bond is not a Hydrogen bond, it is a covalent bond.
Hydrogen bonds are usually said to be intermolecular (between two separate molecules) while Covalent bonds are intramolecular (within the molecule itself)
Two different molecules or compounds will 'stick' together through a Hydrogen bond, and can be separated relatively easily. Covalent bonds on the other hand are much harder to break.