共用方式為


繪圖筆

您可以使用線條函式來繪製標記。 標記是以點為中心符號。 繪圖應用程式會使用標記來指定起點、結束點和控制點。 電子表格應用程式會使用標記來指定圖表或圖形上的重點。

在下列程式代碼範例中,應用程式定義的 Marker 函式會使用 moveToExLineTo 函式來建立標記。 這些函式會繪製兩條交集線,長度為 20 像素,置中於游標座標上。

void Marker(LONG x, LONG y, HWND hwnd) 
{ 
    HDC hdc; 
 
    hdc = GetDC(hwnd); 
        MoveToEx(hdc, (int) x - 10, (int) y, (LPPOINT) NULL); 
        LineTo(hdc, (int) x + 10, (int) y); 
        MoveToEx(hdc, (int) x, (int) y - 10, (LPPOINT) NULL); 
        LineTo(hdc, (int) x, (int) y + 10); 

    ReleaseDC(hwnd, hdc); 
} 

當使用者按下滑鼠左鍵時,系統會將游標的座標儲存在 WM_LBUTTONDOWN 訊息的 lParam 參數中。 下列程式代碼示範應用程式如何取得這些座標、判斷它們是否位於其工作區內,並將其傳遞至 Marker 函式以繪製標記。

// Line- and arc-drawing variables  
 
static BOOL bCollectPoints; 
static POINT ptMouseDown[32]; 
static int index; 
POINTS ptTmp; 
RECT rc; 
 
    case WM_LBUTTONDOWN: 
 
 
        if (bCollectPoints && index < 32)
        { 
            // Create the region from the client area.  
 
            GetClientRect(hwnd, &rc); 
            hrgn = CreateRectRgn(rc.left, rc.top, 
                rc.right, rc.bottom); 
 
            ptTmp = MAKEPOINTS((POINTS FAR *) lParam); 
            ptMouseDown[index].x = (LONG) ptTmp.x; 
            ptMouseDown[index].y = (LONG) ptTmp.y; 
 
            // Test for a hit in the client rectangle.  
 
            if (PtInRegion(hrgn, ptMouseDown[index].x, 
                    ptMouseDown[index].y)) 
            { 
                // If a hit occurs, record the mouse coords.  
 
                Marker(ptMouseDown[index].x, ptMouseDown[index].y, 
                    hwnd); 
                index++; 
            } 
        } 
        break;