Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a device context (DC) in DLL

Status
Not open for further replies.

MarkOtero

Programmer
Jul 25, 2001
1
US
How do you create a device context (DC) in a DLL?

I know that a DC requires a windows handle, however, if a dll has no window how does a DC get created?

I am creating a dll function that returns the width of a string of characters in pixels.

e.g. int GetTextWidth(char* strFontFaceName, int iFontSize, char* strText)

Any suggestions? Or is this possible?

Thanks!
 
I don't think is possible to have a DC without a HWND(or handle) to a window. You could get a handle to an active window, but this is not a good method.

The best solution it apears to me is to add another parameter to your function : HDC hDc, verify it if is valit on the function start and make all the calculation based on it.
You will pass this parameter at runtime. This way I think your function will be more flexible.
To get a handle to the DC you can use GetDC(), in MFC CClientDC dc(this) or something else.
Also inside your function you will be able to get an HWND with the WindowFromDC API function, if you will nedd it

Hope this helps, s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top