Mellor opened the scoring in the ninth minute with a curling effort which goalkeeper Jake Kean could only help into the net.
After Clinton Morrison had a shot saved by Kean, Mellor added a second in the 28th minute after getting on the end of a cross from Gary Teale.
Fabian Yantorno pulled a goal back for the visitors just before the break with a shot from around 20 yards which flew into the roof of the net.
Mellor completed his hat-trick from the penalty spot three minutes into the second-half after he was fouled by Gary Liddle.
Teale finished the scoring in the 55th minute when he lobbed the advancing Kean after finding himself in plenty of free space as Wednesday went through to the Northern area semi-finals.