![]() 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. Rectangle(hdc, r.left, r.top, r.right, r.The example in this section illustrates how to use the rectangle functions. SelectObject(hdc, GetStockObject(DC_PEN)) Rectangle(hdc, r.left, r.top, r.right, r.bottom) SelectObject(hdc, GetStockObject(DC_PEN)) // Can be set to any color. SelectObject(hdc, GetStockObject(DC_BRUSH)) Overcoming these two issues is what I need help with.Ī c++ vector is being used to collect and process dynamically allocated CRect objects, in case it matters. While dragging, the selected rectangle being dragged flashes white / flickers, and also temporarily erases the pen drawn borders of the other rectangles. Basically, the goal is to click around the client area to place rectangles, alt click them to cycle through 4 colors, right click them to reassign a color directly with one of the f keys, or right click and hold to reposition with drag and drop, with the currently selected rectangle having a dotted outline instead of solid.ĭragging correctly is proving to be difficult. I've been messing around with a little toy Win32 app to try and get the hang of basic drawing and processing mouse and keyboard messages.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |