How to access Windows device context (DC)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to access Windows device context (DC)

Andre Schnoor
Hi,

I need to access the device context (or HDC handle) for graphics API
development on Windows. Unfortunately, if I didn't miss something
important, VW uses disposable one-time host handles (not accessible from
inside the image).

Apart from that being a really annoying performance bottleneck
(especially on MacOS X), how can one get a valid HDC for using the
Windows API with DLLC?

VW is lacking so many basic graphics/UI functionality, using GDI as a
workaround is almost inevitable.

Andre

Reply | Threaded
Open this post in threaded view
|

Re: How to access Windows device context (DC)

Holger Kleinsorgen-4
> I need to access the device context (or HDC handle) for graphics API
> development on Windows. Unfortunately, if I didn't miss something
> important, VW uses disposable one-time host handles (not accessible from
> inside the image).
>
> Apart from that being a really annoying performance bottleneck
> (especially on MacOS X), how can one get a valid HDC for using the
> Windows API with DLLC?

Have a look at CairoGraphics, it extends class Window:

   cairoWin32HDC

     | winp |
     winp := CVoidType void pointerType newOfAddress: self windowHandle.
     ^ (OSSystemSupport concreteClass new GetDC: winp) datum.

However, in the long term, directly drawing on a window is IMHO not
sufficient, because it makes double buffering impossible. Getting the
HDC of a pixmap (used as a buffer) is a bit more tricky, look at package
WinGDIPlusInterface, method #hdcOfPixmap:do:



Reply | Threaded
Open this post in threaded view
|

RE: How to access Windows device context (DC)

Steven Kelly
In reply to this post by Andre Schnoor
Holger Kleinsorgen [mailto:[hidden email]] wrote:
> However, in the long term, directly drawing on a window is IMHO not
> sufficient, because it makes double buffering impossible. Getting the
> HDC of a pixmap (used as a buffer) is a bit more tricky, look at
package
> WinGDIPlusInterface, method #hdcOfPixmap:do:

Is there any way to create a WinGDIPlus bitmap or image from a VW image,
e.g. by using the VW pixmap HDC?

Thanks,
Steve

Reply | Threaded
Open this post in threaded view
|

Re: How to access Windows device context (DC)

Andre Schnoor
In reply to this post by Holger Kleinsorgen-4

Holger Kleinsorgen wrote:

>> I need to access the device context (or HDC handle) for graphics API
>> development on Windows. Unfortunately, if I didn't miss something
>> important, VW uses disposable one-time host handles (not accessible
>> from inside the image).
>>
>> Apart from that being a really annoying performance bottleneck
>> (especially on MacOS X), how can one get a valid HDC for using the
>> Windows API with DLLC?
>
> Have a look at CairoGraphics, it extends class Window:
>
>   cairoWin32HDC
>
>     | winp |
>     winp := CVoidType void pointerType newOfAddress: self windowHandle.
>     ^ (OSSystemSupport concreteClass new GetDC: winp) datum.

Thank you Holger, but this requires an open window. I was looking for a
method of querying the GDI about screen resolution and other properties.
This is needed prior to opening a window. I now resorted to this bad hack:

WinNTSystemSupport>>getScreenResolution
    | win winp hdc dpi |
    win := TransientWindow aPopUpIn: (0@0 extent: 10@10).
    winp := CVoidType void pointerType newOfAddress: win windowHandle.
    hdc := self GetDC: winp.
    dpi := [ (self GetDeviceCaps: hdc nIndex: 88) @ (self GetDeviceCaps:
hdc nIndex: 90) ]
        ensure: [ self ReleaseDC: winp with: hdc ].
    win close.  
    ^dpi


>
> However, in the long term, directly drawing on a window is IMHO not
> sufficient, because it makes double buffering impossible. Getting the
> HDC of a pixmap (used as a buffer) is a bit more tricky, look at
> package WinGDIPlusInterface, method #hdcOfPixmap:do:
>

I agree. I didn't want to draw directly (see above).

Andre

Reply | Threaded
Open this post in threaded view
|

Re: How to access Windows device context (DC)

Martin Huba
Hi Andre,

the easiest way is to use GetDC: 0 as documented in WinAPI reference...
Pixmap is really a bit more tricky, I remember that somehow I solved it once, but don't have access to my VW sources right now... Only on Windows though...
Once I get to it I can do a fileout for you, I remember we used this for a custom font display engine on VW5i4 where no Unicode was supported... The biggest problem were the pixmaps... But we did it somehow;-)
Martin



On 4/13/07, Andre Schnoor <[hidden email]> wrote:

Holger Kleinsorgen wrote:

>> I need to access the device context (or HDC handle) for graphics API
>> development on Windows. Unfortunately, if I didn't miss something
>> important, VW uses disposable one-time host handles (not accessible
>> from inside the image).
>>
>> Apart from that being a really annoying performance bottleneck
>> (especially on MacOS X), how can one get a valid HDC for using the
>> Windows API with DLLC?
>
> Have a look at CairoGraphics, it extends class Window:
>
>   cairoWin32HDC
>
>     | winp |
>     winp := CVoidType void pointerType newOfAddress: self windowHandle.
>     ^ (OSSystemSupport concreteClass new GetDC: winp) datum.

Thank you Holger, but this requires an open window. I was looking for a
method of querying the GDI about screen resolution and other properties.
This is needed prior to opening a window. I now resorted to this bad hack:

WinNTSystemSupport>>getScreenResolution
    | win winp hdc dpi |
    win := TransientWindow aPopUpIn: (0@0 extent: 10@10).
    winp := CVoidType void pointerType newOfAddress: win windowHandle.
    hdc := self GetDC: winp.
    dpi := [ (self GetDeviceCaps: hdc nIndex: 88) @ (self GetDeviceCaps:
hdc nIndex: 90) ]
        ensure: [ self ReleaseDC: winp with: hdc ].
    win close.
    ^dpi


>
> However, in the long term, directly drawing on a window is IMHO not
> sufficient, because it makes double buffering impossible. Getting the
> HDC of a pixmap (used as a buffer) is a bit more tricky, look at
> package WinGDIPlusInterface, method #hdcOfPixmap:do:
>

I agree. I didn't want to draw directly (see above).

Andre




--
Wisdom is what's left after we've run out of personal opinions.
Cullen Hightower
Reply | Threaded
Open this post in threaded view
|

Re: How to access Windows device context (DC)

Mark Pirogovsky-3
In reply to this post by Andre Schnoor
On windows platform you can use MFC functions GetSystemMetrics and
SystemParametersInfo, Which can provide you all needed infromation and
then some, even can tell you if you are running in the Terminal Services
environment (like in citrix).

http://msdn2.microsoft.com/en-us/library/ms724385.aspx

here are examples of the use:


GetSystemMetrics: nIndex
        <C: int GetSystemMetrics(int nIndex)>
                ^self externalAccessFailedWith: _errorCode

SystemParametersInfouiAction: uiAction uiParam: uiParam pvParam: pvParam
fWinIni: fWinIni
        <C: BOOL SystemParametersInfoA(UINT uiAction, UINT uiParam, PVOID
pvParam, UINT fWinIni)>


windowDecorationRectangle
        "Win32SystemSupport new windowDecorationRectangle"
        "The inset to a normal window client area caused by the window caption
and resize frame borders"

        | sm_cycaption sm_cxframe sm_cyframe |
        sm_cycaption := Win32SystemSupport new GetSystemMetrics: 4.
        sm_cxframe := Win32SystemSupport new GetSystemMetrics: 32.
        sm_cyframe := Win32SystemSupport new GetSystemMetrics: 33.
        ^sm_cxframe@(sm_cyframe + sm_cycaption)
                corner: sm_cxframe@sm_cyframe

Andre Schnoor wrote:

>
> Holger Kleinsorgen wrote:
>
>>> I need to access the device context (or HDC handle) for graphics API
>>> development on Windows. Unfortunately, if I didn't miss something
>>> important, VW uses disposable one-time host handles (not accessible
>>> from inside the image).
>>>
>>> Apart from that being a really annoying performance bottleneck
>>> (especially on MacOS X), how can one get a valid HDC for using the
>>> Windows API with DLLC?
>>
>>
>> Have a look at CairoGraphics, it extends class Window:
>>
>>   cairoWin32HDC
>>
>>     | winp |
>>     winp := CVoidType void pointerType newOfAddress: self windowHandle.
>>     ^ (OSSystemSupport concreteClass new GetDC: winp) datum.
>
>
> Thank you Holger, but this requires an open window. I was looking for a
> method of querying the GDI about screen resolution and other properties.
> This is needed prior to opening a window. I now resorted to this bad hack:
>
> WinNTSystemSupport>>getScreenResolution
>    | win winp hdc dpi |
>    win := TransientWindow aPopUpIn: (0@0 extent: 10@10).
>    winp := CVoidType void pointerType newOfAddress: win windowHandle.
>    hdc := self GetDC: winp.
>    dpi := [ (self GetDeviceCaps: hdc nIndex: 88) @ (self GetDeviceCaps:
> hdc nIndex: 90) ]
>        ensure: [ self ReleaseDC: winp with: hdc ].
>    win close.      ^dpi
>
>
>>
>> However, in the long term, directly drawing on a window is IMHO not
>> sufficient, because it makes double buffering impossible. Getting the
>> HDC of a pixmap (used as a buffer) is a bit more tricky, look at
>> package WinGDIPlusInterface, method #hdcOfPixmap:do:
>>
>
> I agree. I didn't want to draw directly (see above).
>
> Andre
>
>
>