Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Convert a hDC to hWnd or vise versa

Credits go to 23yrold3yrold and ReyBrujo for helping out!
This thread is locked; no one can reply to it. rss feed Print
Convert a hDC to hWnd or vise versa
Archon
Member #4,195
January 2004
avatar

I am not sure how a hDC works (at all really), but ive got some API that rely on a hDC rather than a hWnd

Declare Function SetPixel Lib "gdi32" (ByVal hDC as Long....)

Yes its VB, anyway.
Is it possible to change a hWnd to a hDC or a hDC to a hWnd or if there are any VB API drawing functions that use a handle to window instead?

------ EDIT -------------
I wouldve used DirectX but if another DirectX program was running then it would crash. For this problem, is it possible to run 2 directX programs simultaneously (one window, one full screen?)?

ReyBrujo
Moderator
January 2001
avatar

Use the GetDC API, pass the HWND handle you have to get the DC handle.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

23yrold3yrold
Member #1,134
March 2001
avatar

An hDC is simply a handle (pointer) to a Device Context (IIRC), while a hWnd is a handle to an actual window. The two are not interchangable. You can get a handle to a window's device context for drawing though. But you can't convert between the two.

Do some reading up on how device contexts work.

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Archon
Member #4,195
January 2004
avatar

------ Posted too fast : Reading...------

ReyBrujo
Moderator
January 2001
avatar

Oh, you can read my reply above now. The problem was that I began the URL with [URL] and ended it with [/I], and no text was shown. Reporting that to Matthew.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Archon
Member #4,195
January 2004
avatar

OK, I hope GetDC is what I need... Thanks

ReyBrujo
Moderator
January 2001
avatar

X Archon said:

I wouldve used DirectX but if another DirectX program was running then it would crash. For this problem, is it possible to run 2 directX programs simultaneously (one window, one full screen?)?

Yes, you can usually run two or more Allegro games without problem... or at least that is what I think.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Archon
Member #4,195
January 2004
avatar

Can you set the hDC or hWND for drawing with Allegro?

ReyBrujo
Moderator
January 2001
avatar

If you register your own Windows Class, you can ask Allegro to create an instance of that class with win_set_window:

Allegro.txt said:

void win_set_window(HWND wnd);
Registers an user-created window to be used by Allegro. This function is
meant to be called before initialising the library with allegro_init()
or installing the autodetected system driver (SYSTEM_AUTODETECT). It
lets you attach Allegro to any already existing window and prevents the
library from creating its own, thus leaving you total control over the
window; in particular, you are responsible for processing the events as
usual (Allegro will automatically monitor a few of them, but will not
filter out any of them). You can then use every component of the library
(graphics, mouse, keyboard, sound, timers and so on), bearing in mind
that some Allegro functions are blocking (e.g. readkey() if the key buffer
is empty) and thus must be carefully manipulated by the window thread.

If you have a BITMAP, you can use win_get_dc to get its HDC:

Allegro.txt said:

HDC win_get_dc(BITMAP *bmp);
Retrieves a handle to the device context of a DirectX video or system
bitmap.

And you can draw to the HDC with draw_to_hdc, blit_to_hdc, stretch_blit_to_hdc, blit_from_hdc and stretch_blit_from_hdc. Check the Allegro documentation.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Archon
Member #4,195
January 2004
avatar

Thats alot of help, but I can only credit you once...

Another thing, are you suscribing to threads? Because if I copy the link in my hotmail to this thread, it asks for a username and password but they dont register with my own. Reasons?

ReyBrujo
Moderator
January 2001
avatar

No worries, in fact you are not forced to credit. Fair enough if the credit system bring faster and better answers than before.

And no, I don't suscribe. I am online enough to have all the light bulbs off. Which link you are trying to copy?

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Archon
Member #4,195
January 2004
avatar

this appears in my subscription email

http://lab.allegro.cc/forums/thread/381775#target

ReyBrujo
Moderator
January 2001
avatar

Ugh... Matthew is testing something, and it seems somewhat the new code mixed with the old one. Send a private message to him, with a link to this thread (and telling him the title). Explain him you tried to suscribe and it gave you that URL which asks you for a user and password.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Go to: