Thanks, zeckensack. I solved the problem as you said.
There is a problem that if the viewport is larger than the windows size(I have to fix the viewport for my application), the glReadPixels return the frame-buffer in windows size, which means Values for pixels that lie outside the window connected to the current OpenGL context are undefined.
is there a way I can read the whole viewport pixels ignoring the size of windows(MFC windows)?
please help me out.