- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试绘制一个矩形,当您左键单击一个点然后拖过它时,当您拖过矩形时会形成一个预览矩形的外观。这工作正常,除非我拖回一个较小的矩形,旧的矩形仍然存在。
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
if(painting)
{
HPEN greenPen=CreatePen(PS_SOLID, 1, RGB(0,255,0));
SelectObject(hdc,greenPen);
Rectangle(hdc, x1, y1, x2, y2);
}
EndPaint(hWnd, &ps);
break;
case WM_LBUTTONDOWN:
painting=true;
x1=LOWORD(lParam);
y1=HIWORD(lParam);
InvalidateRect(hWnd, NULL ,false);
break;
case WM_MOUSEMOVE:
x2=LOWORD(lParam);
y2=HIWORD(lParam);
InvalidateRect(hWnd, NULL ,false);
break;
case WM_LBUTTONUP:
painting=false;
break;
最佳答案
@user1788175 - 只需使用 RECT 结构。绘图开始时,将左侧和顶部成员设置为鼠标的 x,y 位置。松开鼠标后,设置右下角成员。如有必要,向左、向右交换,以确保向左
这是从我编写的用于处理选择矩形的类中提取的一些代码。您可以忽略规范化代码 - 它只是将像素坐标转换为 [0..1] 范围内的像素坐标,因此我可以在图像的缩小版本上绘制选区,但如果图像仍然选择相同的区域以不同的比例显示。我的图像是 4944x6992,所以我必须显示它们的缩小版本。
LRESULT CALLBACK cSelBoxImg::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RECT mappedRect, tmpRect, myRect;
HBRUSH myBrush;
BITMAP bm;
PAINTSTRUCT ps;
HDC mDC;
HBITMAP tmpBmp;
switch (uMsg)
{
case WM_LBUTTONDOWN:
if (bMouseSelectionEnabled)
{
bRubberBanding = true;
mouseClickDownPos.x = LOWORD(lParam);
mouseClickDownPos.y = HIWORD(lParam);
curMousePos = mouseClickDownPos;
selectionRect.left = min(curMousePos.x, mouseClickDownPos.x);
selectionRect.right = max(curMousePos.x, mouseClickDownPos.x);
selectionRect.top = min(curMousePos.y, mouseClickDownPos.y);
selectionRect.bottom = max(curMousePos.y, mouseClickDownPos.y);
normalizeSelRect();
InvalidateRect(mHwnd, NULL, isBkgTransparent);
PostMessage(GetParent(hWnd), WM_COMMAND, GetDlgCtrlID(hWnd), (LPARAM)hWnd);
}
return 1;
case WM_LBUTTONUP:
if (bMouseSelectionEnabled)
if (bRubberBanding)
{
bRubberBanding = false;
mouseClickUpPos.x = LOWORD(lParam);
mouseClickUpPos.y = HIWORD(lParam);
selectionRect.left = min(mouseClickUpPos.x, mouseClickDownPos.x);
selectionRect.right = max(mouseClickUpPos.x, mouseClickDownPos.x);
selectionRect.top = min(mouseClickUpPos.y, mouseClickDownPos.y);
selectionRect.bottom = max(mouseClickUpPos.y, mouseClickDownPos.y);
normalizeSelRect();
InvalidateRect(mHwnd, NULL, isBkgTransparent);
PostMessage(GetParent(hWnd), WM_COMMAND, GetDlgCtrlID(hWnd), (LPARAM)hWnd);
}
return 1;
case WM_MOUSEMOVE:
if (bMouseSelectionEnabled)
if (bRubberBanding)
{
curMousePos.x = LOWORD(lParam);
curMousePos.y = HIWORD(lParam);
selectionRect.left = min(curMousePos.x, mouseClickDownPos.x);
selectionRect.right = max(curMousePos.x, mouseClickDownPos.x);
selectionRect.top = min(curMousePos.y, mouseClickDownPos.y);
selectionRect.bottom = max(curMousePos.y, mouseClickDownPos.y);
// UpdateWindow(hWnd);
//RedrawWindow(hWnd, NULL, NULL, RDW_UPDATENOW);
normalizeSelRect();
InvalidateRect(hWnd, NULL, false);
PostMessage(GetParent(hWnd), WM_COMMAND, GetDlgCtrlID(hWnd), (LPARAM)hWnd);
// printf("Message posted\n");
}
return 0;
case WM_PAINT:
mDC = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &tmpRect);
// GetObject(mBmp, sizeof(bm), &bm);
mappedRect.left = mLeft * tmpRect.right;
mappedRect.right = mRight * tmpRect.right;
mappedRect.top = mTop * tmpRect.bottom;
mappedRect.bottom = mBottom * tmpRect.bottom;
displayImage();
if (mBmp) drawRect(mDC, mappedRect, RGB(0,0,255));
DeleteObject(tmpBmp);
EndPaint(hWnd, &ps);
return 0;
case WM_ERASEBKGND:
if (isBkgTransparent)
{
GetClientRect(hWnd, &myRect);
myBrush = (HBRUSH) GetWindowLong(hWnd, GCL_HBRBACKGROUND);
FillRect((HDC)wParam, &myRect, myBrush);
printf("background cleared\n");
}
return true;
case WM_SETCURSOR:
SetCursor(mCursor);
return true;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
关于c++ - Win32 绘制拖动矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13336225/
在项目属性窗口的应用程序选项卡和启动对象组合框中,我无法看到我的 win 表单以将其中一个设置为启动对象。 它出什么问题了? 最佳答案 开通 Program.cs启动项目的文件(在解决方案中选择为启动
我的问题是,当我得到正确的数字时,python 脚本结束,但不打印:你赢了! import random number = random.randint(1,100) # This part work
我使用 Eclipse 开发了一个 Java 应用程序。我使用的电脑操作系统是Win Vista。我在 Win XP 计算机上使用此应用程序时遇到问题。我发现的问题是: 如果在我的代码中我使用以下几行
显然,这将打印出石头/剪刀/布获胜或平局。 实现“石头胜剪刀——计算机胜!”这样的结果的最佳方式是什么?等等? var userChoice = prompt("Do you choose rock,
我正在开发一个使用HttpWebRequest将请求发送到另一台服务器的ASP.NET Web应用程序。它通过HTTPS发送请求,并且远程服务器需要客户端证书。该请求在.NET应用程序中失败,显然无法
我正在 WIn XP 上使用 VC6 开发应用程序。使用 GetKeyBoardLayoutList() 和 GetLocalInfo() API 从系统检索默认输入语言列表。 代码如下。 `UINT
我在 WPF 中创建了一个无边框窗口。我已经编写了一个事件来最大化窗口,但是在最大化时,部分窗口有时会隐藏在任务栏后面,片刻之后会出现在任务栏顶部。 如何确保窗口每次都保持在任务栏的顶部?以下是我实现
我开始制作 3d 游戏。然后我停了一段时间并安装了win7。现在我想继续研究它只是为了发现代码卡住了!在 XP 上,我将 View 渲染到窗体上。并且游戏循环和所有游戏形式都在同一个线程上运行! 这在
main() { int *p; free(p); } 此代码在 Win 2K 中崩溃。但不知何故不会在 Win Xp 中崩溃!知道为什么吗? 编辑:是的。这是一个错误,不应该被写入。更多
我在我的应用程序中使用 libeay32.dll/ssleay32.dll 库来支持 https。库在 Windows 7 上成功加载(不是通过我的应用程序,通过 Qt 库),但是我在 Windows
在源代码下方添加了新的详细信息。 有一个问题是 Delphi,其中 Internet 代码可在 Win 10 上运行,但不能在 Win 7 上运行。我正在尝试将一个小项目连接到 haveibeenpw
我在 Win 7 上为 Perfmon 创建了 xml 模板。我能够导入它并运行它 - 一切正常。现在,当我将此 xml 复制到 Win 2008 R2 计算机并尝试将其导入到 perfmon 中时,
我在使用标准数据驱动的 Winform 应用程序时遇到了一个有趣的问题。 该应用程序最初是在 Windows 7 和 Visual Studio 2010 上开发的。然后我用 Windows 8 和
我有一个在 Windows 7(64 位)上编写的程序,可以在我的计算机上正确编译和运行。 但在其他计算机上(特别是在 Windows 8(64 位)上)该程序无法运行。当我尝试运行它时,它说我的程序
将现有的基于 Vb6.0 win 的应用程序转换为基于 c# win 的应用程序的最快方法是什么? 最佳答案 核心语言如此不同,我不得不说从头开始,只复制复杂的代码位。如果您从头开始,您将不必处理所有
我正在处理 IE 11 在 Windows 8 和 Windows 8.1 上的奇怪行为。我正在固定定位元素内的元素位置。而且它变得很奇怪。当我用开发工具检查它时它在正确的位置,但在视觉上它完全在不同
将使用 Java x32 在 eclipse x32 上创建的项目导入到使用 java x64 的 eclipse x64 上有哪些挑战? 最佳答案 Java 是跨平台的,所以你应该不会有任何问题。
鉴于 l 是一个整数列表并且 win 是一个整数,下面的代码生成一个列表 lpadded: lpadded = win // 2 * [-1] + l + win // 2 * [-1] 在 lpad
我有一个适用于 Windows Phone 8.1 的应用程序及其 UWP 版本。我想在 Windows 中更改应用程序的背景时动态更改它。 用例是: 启动应用,背景主题为深色。 按下手机上的主页按钮
不完全确定我是否已经解决了这个问题,但这是我所看到的以及我认为正在发生的事情。 我有一个主要用 C 编写的 Win32 程序,它加载一个 C++ DLL。该 DLL 通过 COM 对象将数据从 C 程
我是一名优秀的程序员,十分优秀!