Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2005

Tip: Looking for answers? Try searching our database.

GetDC question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mark - 12 Jul 2005 17:20 GMT
I need to use GetDC but I don't know how to find a parameter to pas to the
function. This is the GetDc from MSVC help:

**********
GetDC

The GetDC function retrieves a handle to a display device context for the
client area of a specified window or for the entire screen. You can use the
returned handle in subsequent GDI functions to draw in the device context.

The GetDCEx function is an extension to GetDC, which gives an application
more control over how and whether clipping occurs in the client area.

HDC GetDC(
 HWND hWnd   // handle to a window
);

Parameters
hWnd
Handle to the window whose device context is to be retrieved. If this value
is NULL, GetDC retrieves the device context for the entire screen.

***********

HWND hWnd   // handle to a window -- THIS IS MY PROBLEM.

Where or how can I find it ?

I'm working in a global function and I havent any hWnd of any type.
Tamas Demjen - 12 Jul 2005 17:43 GMT
> HWND hWnd   // handle to a window -- THIS IS MY PROBLEM.
>
> Where or how can I find it ?
>
> I'm working in a global function and I havent any hWnd of any type.

It depends what you want to do:

1. GetDC(0) gets a DC to the screen. Don't forget to call ReleaseDC.
2. CreateCompatibleDC(0) creates a new DC that's compatible with the
screen's bit depth. This is what you usually do for rendering off-screen
bitmaps or something like that. Don't forget to call DeleteDC.
3. CreateDC to create a DC for printers. Use DeleteDC in the end.
4. If you paint somewhere in a widget, the DC is usually provided by the
GUI toolkit.

Perhaps your function should be generic enough to work with any DC, and
thus the DC should be a parameter. Be careful, because DCs may change
during the lifetime of an application. Avoid storing a DC permanently,
always obtain it right before painting.

You have to provide more specific details if you need more help, and
maybe post your question to a graphics or GDI related group.

Tom
mark - 12 Jul 2005 18:17 GMT
> > HWND hWnd   // handle to a window -- THIS IS MY PROBLEM.
> >
[quoted text clipped - 21 lines]
>
> Tom

Thank you Tom

Ok.
I need to create a DIBSection and below there is a piece of my code ( Idon't
know if it is right).

***
    HBITMAP Bitmap;
    int Width, Height;
    HDC WindowDC, MemDC;
    BITMAPINFO BitmapInfo;
    unsigned char *Data;

    HWND hwnd = NULL;
    CRect rect;
    WindowDC = GetDC(hwnd);

    Width = image_width;
    Height = image_height;

    memset(&BitmapInfo.bmiHeader, 0, sizeof(BitmapInfo.bmiHeader));
    BitmapInfo.bmiHeader.biWidth = Width;
    BitmapInfo.bmiHeader.biHeight = -Height;
    BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    BitmapInfo.bmiHeader.biPlanes = 1;
    BitmapInfo.bmiHeader.biBitCount = 24;
    BitmapInfo.bmiHeader.biCompression = BI_RGB;

    MemDC = CreateCompatibleDC(WindowDC);
    Bitmap = CreateDIBSection(WindowDC, &BitmapInfo, DIB_RGB_COLORS, (void
**)&Data, 0, 0);
           
***

how you can see I'm using "hwnd = NULL" that is the full screen. I need only
the window region of the application. What I have to do to put to hwnd the
right value to do that?
Tamas Demjen - 12 Jul 2005 18:50 GMT
>     MemDC = CreateCompatibleDC(WindowDC);
>     Bitmap = CreateDIBSection(WindowDC, &BitmapInfo, DIB_RGB_COLORS, (void
> **)&Data, 0, 0);

I simply use WindowDC = 0, and it works just fine. The first parameter
for CreateDIBSection is not used anyway, unless the 3rd parameter is
DIB_PAL_COLORS. You're passing DIB_RGB_COLORS, which means WindowDC is
irrelevant. I think you'll be fine with WindowDC = 0. If you're
compatible with the screen, you're compatible with the current window.
If you have concerns, you can always pass the current window handle to
your function.

Tom
mark - 13 Jul 2005 14:49 GMT
>If you have concerns, you can always pass the current window handle to
> your function.
>
> Tom

The question is that i don't know how to obtain the current window handle

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.