Add guards around custom windows message handling