Melt butter in a heavy saucepan over low heat; whisk in flour and garlic powder. Cook, whisking constantly, 1 minute. Gradually whisk in milk; cook over medium heat, whisking until thickened. Add cheeses; cook over low heat, stirring until melted. Stir in corn and ham. Pour into a greased 2-quart baking dish.