Home > Software engineering >  Specifies the window handle ReleaseDC why requirements?
Specifies the window handle ReleaseDC why requirements?

Time:09-21


To be honest, Microsoft designed the function I didn't understand!
Int ReleaseDC (HWND HWND, HDC HDC);
Not already has HDC, why should specify the hWnd?

WINGDIAPI BOOL WINAPI MoveToEx (

HDC HDC,

Int X,

Int Y,

LPPOINT LPPOINT

);
Why you don't have to specify hWnd MoveToEx ()?
Which students can solve, thanks!

CodePudding user response:

May look at the ReleaseDC function source code, you'll know

CodePudding user response:

A window on a DC
Int ReleaseDC (HWND HWND, HDC HDC); Want to know that window DC
The window class
The CWnd: : ReleaseDC
Int ReleaseDC * pDC (CDC);
Global
ReleaseDC
The ReleaseDC function releases a device context (DC), freeing it for use by other applications. The effect of The ReleaseDC function depends on The type of device context. It frees only common and Windows device contexts. It has no effect on The class or private device contexts.

Int ReleaseDC (
HWND HWND,//handle to the window
HDC HDC//handle to the device context
);


CodePudding user response:

Each window has its own DC drawing equipment, do you want to release the main frame mouth or child window DC? All have to have a handle to the window, MOVE function as to what you say, you write it in the window is moving point coordinates in this window, so there's no need to specify the window handle,

CodePudding user response:

MoveToEx is a global API requires a HDC (the HDC must first get)

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

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

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

With dc can draw, the draw was conducted on the dc

The MoveToEx function updates The current position to The specified point and optionally returns The previous position.

BOOL MoveToEx (
HDC HDC,//handle to the device context
Int X,//X coordinate of the new current position
Int Y,//Y - coordinate of the new current position
LPPOINT LPPOINT//pointer to old current position
);

CodePudding user response:

HDC is related to the hWnd, probably by hDC cannot directly by its corresponding hWnd,
(because it is both "HANDLE" the kernel of the data type object, its information structure is equivalent)
So, if you don't give corresponding hWnd,
So within the function, is it not want to be in "a piece of the ocean hWnd", to look for the hDC which hWnd belong to?
So "efficiency" will not be too low...
So, function request directly to the corresponding hWnd,





PS:
The above content,
Is purely speculation,
If there are any errors,
No offense,

CodePudding user response:

Microsoft has many interface design is not reasonable, this is the historical reasons,
Microsoft's friendly to the user, but for programmers, it is very unfriendly

CodePudding user response:

According to you, MoveToEx () should also specify the hWnd, otherwise the GDI functions do not know should be drawing on which window?

However, GDI functions as long as you specify HDC is ok! Why is that? Because when you retrieve HDC has passed the HWND parameter,

Strange is the time to release the HDC, ReleaseDC () specifies the hWnd why requirements?

Microsoft will not add one parameter, which must have his reason?

CodePudding user response:

GDI drawing, it is just the corresponding hDC operation, won't go to tube of the window, is good!
Have the corresponding hDC, it can know the operation which block "memory data area",
The need to "window"?

Its "mapping results to show come out," that is "window to refresh (redraw)" when things...
Comes naturally have corresponding hWnd "guidance",

CodePudding user response:


ReleaseDC (NULL, hDC);

How do you explain this sentence? The original code on MSDN

CodePudding user response:

HDC HDC=: : GetDC (NULL);//screen HDC.
: : MoveToEx (hDC, 0, 0, NULL);
LineTo (hDC, 200, 20);
: : ReleaseDC (NULL, hDC);//release the HDC screen.

CodePudding user response:

The information on the MSDN GetDC GetWindowDC
The Parameters
HWnd
[in] Handle to the window with a device context that is to be retrieved. If this value is NULL, the GetWindowDC retrieves the device context for - screen.
Windows 98/Me, Windows 2000/XP: If this parameter is NULL, the GetWindowDC retrieves the device context for the primary display monitor.

Use NULL return DC screen, rather than do not use the handle to the window, and then the ReleaseDC corresponding destruction also do parameter with a NULL
  • Related