I am trying to understand the map from window coordinate axis (origin top-left) to OpenGL
coordinate axis (origin left-bottom) when using the mouse function. In
What book are you referring to? The origin in NDC-space is the center of the viewport (0,0 is the center; -1,-1 is the bottom-left; 1,1 is the top-right). Any other coordinate space is defined by your projection matrix.
I believe what the book is trying to teach you is that NDC-1,-1 is the bottom-left corner of your viewport and NDC1,1 is the top-right corner.
NDCX = (2.0 * (ScreenX - ViewportX) / ViewportW) - 1.0;
NDCY = (2.0 * (ScreenY - ViewportY) / ViewportH) - 1.0;
You of course have one additional step necessary since the Y-axis runs the opposite direction in your mouse coordinate system. That is why you see the Y-axis flipped in your mapping h-y