![]() This example requires that you have a Form with a Button named button2 on it. (rcBmp.bottom - rcBmp.The following code example enables auto-scrolling for a form, resizes the form, and ensures that a button remains visible after the form is resized. StretchBlt(hdc, rcBmp.left + 1, rcBmp.top + 1, Draw the bitmap rectangle, copy the bitmap into rectangle to 0, then reset the fDragRect flag. ![]() rectangle, set the coordinates of the target Copy the target rectangle to the bitmap (rcTarget.bottom - rcTarget.top) - 2, hdcCompat, StretchBlt(hdc, rcTarget.left + 1, rcTarget.top + 1, Copy the bitmap into the target rectangle. that intersected with the bitmap rectangle was Redraw the target rectangle because the part Erase the bitmap rectangle by filling it with If (IntersectRect(&rcTmp, &rcBmp, &rcTarget)) intersect, copy the bitmap into the target If the bitmap rectangle and target rectangle OffsetRect(&rcBmp, LOWORD(lParam) - pt.x, Set the new coordinates of the bitmap rectangle, the previous bitmap rectangle by drawing Select the dotted pen into the DC and erase SetRect(&rcTarget, pt.x, pt.y, LOWORD(lParam), coordinate is lesser than the bottom coordinate.Įlse if ((pt.x > (LONG) LOWORD(lParam)) & right coordinate, and that the value of the top the left coordinate is lesser than the invalid rectangles by ensuring that the value of Save the coordinates of the target rectangle. ![]() Rectangle(hdc, rcTarget.left, rcTarget.top, it by drawing another rectangle on top of it. If a previous target rectangle exists, erase rectangle can then be erased by drawing Set the mix mode so that the pen color is the depending on the status of the fDragRect flag. Draw a target rectangle or drag the bitmap rectangle, Rectangle(hdc, rcBmp.left, rcBmp.top, rcBmp.right, indicate that the user is about to drag the rectangle. If the user has clicked the bitmap rectangle, redraw Save the coordinates of the mouse cursor. ensures that the window receives a matching Restrict the mouse cursor to the client area. SetRect(&rcClient, ptClientUL.x, ptClientUL.y, function during WM_LBUTTONDOWN processing. The rectangle is passed to the ClipCursor rectangle to screen coordinates and save them in a Convert the client coordinates of the client-area (rcBmp.bottom - rcBmp.top) - 2, hdcCompat, StretchBlt(ps.hdc, rcBmp.left + 1, rcBmp.top + 1, from the right and bottom coordinates. coordinates of the bitmap rectangle, and subtracting 2 in the rectangle by adding 1 to the left and top The 32-pixel by 32-pixel bitmap is centered Draw the bitmap rectangle and copy the bitmap into The rectangle is slightly larger than the this application supports only a 32- by 32-pixel Set the initial rectangle for the bitmap. HpenDot = CreatePen(PS_DOT, 1, RGB(0, 0, 0)) bitmap rectangle as the user drags it. the old bitmap before copying the bitmap into the Create a brush of the same color as the background ![]() The bitmap is copied from this DC to the window's DC Create a device context (DC) to hold the bitmap. Hbmp = LoadBitmap(hinst, MAKEINTRESOURCE(1)) Static HPEN hpenDot // handle of dotted pen Static COLORREF crBkgnd // color of client-area background Static HBRUSH hbrBkgnd // handle of background-color brush Static HBITMAP hbmp // handle of bitmap to display Static BOOL fDragRect // TRUE if bitmap rect. Static RECT rcClient // client-area rectangle Static RECT rcTarget // rectangle to receive bitmap Static RECT rcBmp // rectangle that encloses bitmap Static POINT pt // x and y coordinates of cursor Static HDC hdcCompat // DC for copying bitmap POINT ptClientLR // client area lower right corner POINT ptClientUL // client area upper left corner PAINTSTRUCT ps // paint data for BeginPaint and EndPaint HDC hdc // device context (DC) for window LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) The window procedure that allows the user to move and size the bitmap is given in the following example. The application responds by copying the bitmap into the target rectangle. To size the bitmap, the user creates a target rectangle by dragging the mouse, then drags the bitmap and "drops" it on the target rectangle. The user can move the bitmap by dragging it. When the application starts, it draws a 32-pixel by 32-pixel bitmap in the upper left corner of the screen. It consists of the main window procedure from an application that enables the user to move and size a bitmap. The example in this section illustrates how to use the rectangle functions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |