制作:KrK (Knuth for Kludge)
#include <windows.h> // Win32API
//-------------------------------------------------
// スクリーン矩形をクライアント矩形に
// 作成 20170817 KrK
// 引数 hWnd:ウィンドウハンドル
// 引数(I/O) pRec:矩形
//-------------------------------------------------
VOID RectToClient(HWND hWnd, RECT *pRec)
{
POINT pt_lt; // 左上(left/top)
POINT pt_rb; // 右下(right/bottom)
// 位置に代入
pt_lt.x = pRec->left;
pt_lt.y = pRec->top;
pt_rb.x = pRec->right;
pt_rb.y = pRec->bottom;
// クライアント領域に
ScreenToClient(hWnd, &pt_lt);
ScreenToClient(hWnd, &pt_rb);
// 矩形に書き戻す
pRec->left = pt_lt.x;
pRec->top = pt_lt.y;
pRec->right = pt_rb.x;
pRec->bottom = pt_rb.y;
}
RECT rec; // コントロール領域
// スクリーン矩形取得
GetWindowRect(hChild, &rec);
(中略)
// クライアント矩形に変換
RectToClient(hWnd, &rec);