user32.dllのGetForegroundWindowとGetWindowTextをDllImportして使う。
HWNDにIntPtr、LPTSTRにStringBuilderを使っとけばおk

詳しいやりかたはぐぐれ