Buit矩形(我自己的类型),不会随窗口调整大小
Buit Rectangles( my own type ), will not resize with window?
我在摆弄窗口,到目前为止,当我点击(按钮向下)并拖动,然后放开(按钮向上)时,我确实会出现一个squere。。。当我调整窗口大小时,它怎么会消失?为什么?我错过了什么?谢谢你花时间复习这篇文章。
//LEFT BUTTON DOWN MOVEMENT
case WM_LBUTTONDOWN:
// if not drwing then save start poostion and set drawing flag
// goes here startPosition
if(! isDrawing )
{
startPosition = MAKEPOINTS( lParam );// poiint where the mouseis clicked
isDrawing = true;
}
else{
// how did I get a button down while I was drawing
}
break;
//when the button is let up the message is sent, its a drawing mode or not drawing, or draging draw.....
// LEFT BUTTON UP movement
case WM_LBUTTONUP:
// if drawing is not occuring, then
// if I am drawing then save endeding point(position), draw a rectangle (startPositon and endPoistion)
//
if(isDrawing )
{
endPosition = currentPosition = MAKEPOINTS( lParam );
//draw rectangle here.
// This is what we had 1st.... RectType rect( startPosition.x, startPosition.y, endPosition.x, endPosition.y);
RectType rec( startPosition , endPosition );// this is what we want...need to write teh code for this.
//something and I cant call beginPaint(),and end paint();
if( hdc = GetDC(hWnd) )
{
::Rectangle(hdc, rec.myRect.left, rec.myRect.top, rec.myRect.right, rec.myRect.bottom);
ReleaseDC( hWnd, hdc );// this is how we call on paint with out being in WM_Paint
}
isDrawing = false; // this is the flag.
}
break;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
//LEFT BUTTON DOWN MOVEMENT
case WM_LBUTTONDOWN:
// if not drwing then save start poostion and set drawing flag
// goes here startPosition
if(! isDrawing )
{
startPosition = MAKEPOINTS( lParam );// poiint where the mouseis clicked
isDrawing = true;
}
else{
// how did I get a button down while I was drawing
}
break;
//when the button is let up the message is sent, its a drawing mode or not drawing, or draging draw.....
// LEFT BUTTON UP movement
case WM_LBUTTONUP:
// if drawing is not occuring, then
// if I am drawing then save endeding point(position), draw a rectangle (startPositon and endPoistion)
//
if(isDrawing )
{
endPosition = currentPosition = MAKEPOINTS( lParam );
//draw rectangle here.
// This is what we had 1st.... RectType rect( startPosition.x, startPosition.y, endPosition.x, endPosition.y);
RectType rec( startPosition , endPosition );// this is what we want...need to write teh code for this.
//something and I cant call beginPaint(),and end paint();
if( hdc = GetDC(hWnd) )
{
::Rectangle(hdc, rec.myRect.left, rec.myRect.top, rec.myRect.right, rec.myRect.bottom);
ReleaseDC( hWnd, hdc );// this is how we call on paint with out being in WM_Paint
}
isDrawing = false; // this is the flag.
}
break;
case WM_MOUSEMOVE:
//if I am drawing...
//if I am not drawing save current postion, and latested or endingPositon
// darw rectangle( StartPos, latestPos)
if( isDrawing )//
{
currentPosition = MAKEPOINTS( lParam );
RectType rec( startPosition , currentPosition );// this is what we want.
//draw rectangle here.
if( hdc = GetDC(hWnd) ) // GetDC is the window function....
{
POINTS prevPosition = currentPosition;
currentPosition = MAKEPOINTS(lParam);
RectType rec( startPosition , currentPosition );
RectType prevRec( startPosition, prevPosition);
HDC dc = GetDC( hWnd );
HPEN pen = CreatePen( PS_DASH, 0, RGB(0, 0, 0 ));
HBRUSH brush = CreateSolidBrush( RGB(rand()%255, rand()%255, rand()%255) );//---------------------------------------------NEWWWWWWWWWWWWRGB(200,0,0)
SelectObject(hdc,pen);
//give us a quaiz hollow square.below.
SelectObject(hdc,GetStockObject( HOLLOW_BRUSH ) );
//::SetROP2( hdc, R2_XORPEN );//these use exclusive OR bit wise logical operator...try R2_NOT,for later
// 1^0 = 1...so if the comparing two are differnet 1 and 0 we have 1
// 1^1 = 0...if we have all the same 0,0 then it would be 1....
::Rectangle(hdc, prevRec.myRect.left, prevRec.myRect.top , prevRec.myRect.right, prevRec.myRect.bottom );
::Rectangle(hdc, rec.myRect.left, rec.myRect.top , rec.myRect.right, rec.myRect.bottom );
ReleaseDC( hWnd, hdc );// this is how we call on paint with out being in WM_Paint
}
}
break;
您需要处理WM_PAINT并在那里进行绘图,而不是在WM_MOUSEMOVE中。在WM_MOUSEMOVE(或其他地方)中,移动矩形后调用::Invalidate。这将导致Windows发送WM_PAINT消息。
相关文章:
- SDL2 调整窗口大小后如何缩放鼠标坐标?
- GTK3 检测用户大小调整窗口
- Wxwidgets - 如何添加调整大小事件处理程序以使"X"绘图随窗口调整大小?
- 尝试在 win 32 中禁用窗口大小调整时,窗口样式行为不一致
- QGraphics手动调整窗口大小后场景宽度/高度没有变化
- Qt - 防止在拖动标题栏时调整窗口大小
- 在使用 resizeEvent 调整窗口大小时调整 Qlabel 图像的大小
- 在 Direct2D 绘图中,调整窗口大小后尺寸会更改
- 如何让用户垂直调整大小窗口
- win32 自动调整父窗口的大小以适合其内容
- WinAPI.检查窗口大小调整是否已完成
- QQuickView窗口在调整鼠标大小时冻结
- 如何设置启用setFixize后再次调整主窗口大小
- C++MFC按钮在窗口调整大小时消失
- Buit矩形(我自己的类型),不会随窗口调整大小
- 当GLFW窗口调整大小时,渲染区域不会改变
- 根据窗口调整QLabel内的QPixmap的大小
- GLFW轮询等待窗口调整完成,如何修复
- 在win32 api c中使用窗口调整文本框大小
- 如果在父窗口调整大小期间打开,子窗口将冻结