errr,

meant to put
if X > 0 Then Call Sendmessage(X, WM_Close, 0, 0)