說實話,微軟設計的這個函式我沒看懂!
int ReleaseDC(HWND hWnd, HDC hdc);
不是已經有hdc了,為什么還要指定hWnd?
WINGDIAPI BOOL WINAPI MoveToEx(
HDC hdc,
int X,
int Y,
LPPOINT lpPoint
);
MoveToEx()為什么就不用指定hWnd?
哪位同學能解答一下,謝了!
uj5u.com熱心網友回復:
可能看一下ReleaseDC函式的源代碼就知道uj5u.com熱心網友回復:
一個視窗 一個 DCint ReleaseDC(HWND hWnd, HDC hdc);要知道 那個 視窗 的 DC
視窗 類 的
CWnd::ReleaseDC
int ReleaseDC( CDC* pDC );
全域 的
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 window device contexts. It has no effect on class or private device contexts.
int ReleaseDC(
HWND hWnd, // handle to window
HDC hDC // handle to device context
);
uj5u.com熱心網友回復:
每個視窗都有自己的繪圖設備DC,你要釋放主框口還是子視窗的DC?所有得有視窗句柄。至于你說的MOVE函式,你寫在那個視窗它就是在這個視窗中移動點的坐標,所以不需要指定視窗句柄。uj5u.com熱心網友回復:
MoveToEx 是個 全域 API 需要 一個 hdc (這個 hdc 要 先 得到 )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
);
有了dc 就 可以 繪制了,即繪制是在 DC 上 進行的
The MoveToEx function updates the current position to the specified point and optionally returns the previous position.
BOOL MoveToEx(
HDC hdc, // handle to device context
int X, // x-coordinate of new current position
int Y, // y-coordinate of new current position
LPPOINT lpPoint // pointer to old current position
);
uj5u.com熱心網友回復:
hDC是與hWnd相關的,很可能通過hDC無法直接得到其對應的hWnd的。(因為這二者都是“HANDLE”這種資料型別的內核物件,其“資訊結構”是等同的吧)
因此,如果你不給出對應的hWnd的話,
那么在函式內部,豈不是要在“一片茫茫大海的hWnd”中,去找一下這個hDC屬于哪個hWnd?
這樣“運行效率”會不會太低了…………
所以,函式要求直接給出對應的hWnd。

PS:
以上內容,
純屬臆測。
如有失誤,
請勿見怪。
uj5u.com熱心網友回復:
微軟有許多介面設計的是不合理,這是歷史原因。微軟對用戶友好,但是對程式員是很不友好的
uj5u.com熱心網友回復:
按照你們的說法,MoveToEx()也應該指定hWnd,否則GDI函式就不知道應該在哪個視窗上繪圖?但是,GDI函式只要指定HDC就可以了!為什么呢?因為你檢索HDC的時候就已經傳入了HWND引數。
奇怪的是釋放HDC的時候,ReleaseDC()為什么要求指定hWnd?
微軟肯定不會多加一個引數,這其中必然有他的道理?
uj5u.com熱心網友回復:
GDI繪圖,是只管操作相應的hDC,不會去管視窗的,好不好!有相應的hDC了,它就可以知道該去操作哪塊“記憶體資料區”,
此時用得著去理會“視窗”嗎?
它的“繪圖結果”要顯示出來,那是“視窗重繪(重繪)”時的事情了……
這時自然有相應的hWnd來“指導”操作。
uj5u.com熱心網友回復:
ReleaseDC(NULL, hDC);
這句怎么解釋?msdn上的原代碼
uj5u.com熱心網友回復:
HDC hDC=::GetDC(NULL);// 取得螢屏的HDC.::MoveToEx(hDC,0,0,NULL);
LineTo(hDC,200,20);
::ReleaseDC(NULL,hDC);// 釋放螢屏的HDC.
uj5u.com熱心網友回復:
MSDN上的說明 GetDC GetWindowDCParameters
hWnd
[in] Handle to the window with a device context that is to be retrieved. If this value is NULL, GetWindowDC retrieves the device context for the entire screen.
Windows 98/Me, Windows 2000/XP: If this parameter is NULL, GetWindowDC retrieves the device context for the primary display monitor.
使用NULL回傳螢屏DC, 而不是不使用視窗句柄, 那么ReleaseDC對應的銷毀也用NULL做引數
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/61041.html
標籤:基礎類
