SetWindowOrgEx, SetViewPortOrgEx, SetWindowExtEx, SetViewPortExtEx

This is a discussion on SetWindowOrgEx, SetViewPortOrgEx, SetWindowExtEx, SetViewPortExtEx within the Windows Programming forums, part of the Platform Specific Boards category; These functions are confusing me. Can somebody explain them? There implementations and what they are used for? Thanks... --Garfield...

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    SetWindowOrgEx, SetViewPortOrgEx, SetWindowExtEx, SetViewPortExtEx

    These functions are confusing me. Can somebody explain them? There implementations and what they are used for? Thanks...

    --Garfield
    1978 Silver Anniversary Corvette

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Their names are pretty self-explanatory They allow you to move the origin and the extent of the viewport and window around, and enable you to set the extents as a logical scale rather than a pixel one. You might use them to display graphs or graphics, where changing the origin would make the calculations easier (such as using a Cartesian co-ordinate system).

    Petzold goes into quite a bit of detail about them, what exactly is confusing you?
    zen

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    I just wasn't sure about what the differences were. What exactly is the "viewport"? That's what I don't understand. Thanks, zen...

    --Garfield
    1978 Silver Anniversary Corvette

  4. #4
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    The viewport sets the origin and extent of the client area in pixels (or based on the size in pixels) and the window is the origin and extent of the client area in logical units (which can be a user defined scale). The window co-ordinates will then be converted to viewport co-ordinates for display.

    The default mapping mode treats window units as viewport units with the origin at the top left, so all painting to the client area is based on the pixels where the painting is to be done.
    zen

  5. #5
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    So what is the difference between SetWindowOrgEx and SetViewPortOrgEx? I don't really understand the difference between the ViewPort and the Window. Thanks, zen, I really appreciate it!!!
    1978 Silver Anniversary Corvette

  6. #6
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    An example -

    Code:
    				SetMapMode(hdc,MM_ANISOTROPIC);
    				SetWindowOrgEx(hdc,0,0,0);
    				SetWindowExtEx(hdc,2000,2000,0);
    				SetViewportOrgEx(hdc,0,0,0);
    				SetViewportExtEx(hdc,100,100,0);
    				TextOut(hdc,2000,2000,"Hello, World!",13);
    First of all I'm setting the logical units to be used to draw to the window to 2000 by 2000, and then making these units relate to 100 by 100 pixels. So my text will be outputted at 100 pixels across and 100 pixels down in my client area. If I changed the TextOut call to paint at 1000,1000 then the text will be drawn at 50,50 and changing it to 4000,4000 will draw at 200,200.

    If I do something like -

    Code:
    				SetMapMode(hdc,MM_ANISOTROPIC);
    				SetWindowOrgEx(hdc,-1000,-1000,0);
    				SetWindowExtEx(hdc,2000,2000,0);
    				SetViewportOrgEx(hdc,0,0,0);
    				SetViewportExtEx(hdc,100,100,0);
    				TextOut(hdc,0,0,"Hello, World!",13);
    The the origin of the window now starts at -1000,-1000, so now when I paint the text at 0,0 this translates to 50 pixels across and 50 pixels down (as 0,0 is 1000 logical units from the left and 1000 logical units from the top).

    Alternatively I can adjust where the text is painted by altering the viewport origin -

    Code:
    				SetMapMode(hdc,MM_ANISOTROPIC);
    				SetWindowOrgEx(hdc,0,0,0);
    				SetWindowExtEx(hdc,2000,2000,0);
    				SetViewportOrgEx(hdc,50,50,0);
    				SetViewportExtEx(hdc,100,100,0);
    				TextOut(hdc,0,0,"Hello, World!",13);
    The origin 0,0 has been transformed 50 pixels across the top and 50 pixels down.

    There's probably not much point altering the window orgin and the viewport orgin, you'd alter one and stick with it. However you may want to alter the extent of both so that differing amount of pixels represent a differerent amount of logical units.

    If you're not sure take the code and stick it in a WM_PAINT message and have a play around with it.
    zen

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Thanks, zen. I'm still a little confused, but I'm sure reading your example over and Petzold, I'll get it. Thanks again...
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21