- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
#include <windows.h>
#include <iostream>
using namespace std;
#define ID_DDA 9001
#define ID_MID 9002
#define ID_UNDO 9003
#define ID_REDO 9004
HPEN hPen;
PAINTSTRUCT ps ;
int firstX , firstY , lastX , lastY;
int numClicks = 0;
class algo
{
HWND hwnd;
int algorithm;
int x,y,size,sizeRemoved;
int *x1Data;
int *y1Data;
int *x2Data;
int *y2Data;
int *x1Removed;
int *y1Removed;
int *x2Removed;
int *y2Removed;
void Draw()
{
for (int i=0;i<size;i++)
{
if (algorithm == 0)
{
BeginPaint(hwnd , &ps );
hPen = CreatePen(PS_SOLID,3,RGB(0,0,255));
SelectObject(ps.hdc, hPen);
MoveToEx(ps.hdc, x1Data[i], y1Data[i], NULL);
LineTo(ps.hdc, x2Data[i], y2Data[i]);
EndPaint(hwnd , & ps);
}
else
{
BeginPaint(hwnd , &ps );
hPen = CreatePen(PS_SOLID,3,RGB(255,0,0));
SelectObject(ps.hdc, hPen);
MoveToEx(ps.hdc, x1Data[i], y1Data[i], NULL);
LineTo(ps.hdc, x2Data[i], y2Data[i]);
EndPaint(hwnd , & ps);
}
}
}
public:
algo(HWND hwnd)
{
this->hwnd = hwnd;
x1Data = new int [1];
y1Data = new int [1];
x2Data = new int [1];
y2Data = new int [1];
x1Removed = new int [1];
y1Removed = new int [1];
x2Removed = new int [1];
y2Removed = new int [1];
size=0;
sizeRemoved=0;
algorithm = 0;
}
void setHWND (HWND hwnd)
{
this->hwnd = hwnd;
}
void ChangeAlgo(int num)
{
algorithm = num;
size = 0;
sizeRemoved = 0;
int * tempx1 = new int [1];
int * tempy1 = new int [1];
int * tempx2 = new int [1];
int * tempy2 = new int [1];
int * tx1 = new int [1];
int * ty1 = new int [1];
int * tx2 = new int [1];
int * ty2 = new int [1];
x1Data = tempx1;
y1Data = tempy1;
x2Data = tempx2;
y2Data = tempy2;
x1Removed = tx1;
y1Removed = ty1;
x2Removed = tx2;
y2Removed = ty2;
}
int getAlgo ()
{
return algorithm;
}
void undo ()
{
x1Removed[sizeRemoved] = x1Data[size];
y1Removed[sizeRemoved] = y1Data[size];
x2Removed[sizeRemoved] = x2Data[size];
y2Removed[sizeRemoved] = y2Data[size];
sizeRemoved++;
int * tempx1 = new int [size];
int * tempy1 = new int [size];
int * tempx2 = new int [size];
int * tempy2 = new int [size];
for (int i=0;i<size;i++)
{
tempx1[i] = x1Data[i];
tempy1[i] = y1Data[i];
tempx2[i] = x2Data[i];
tempy2[i] = y2Data[i];
}
x1Data = tempx1;
y1Data = tempy1;
x2Data = tempx2;
y2Data = tempy2;
size--;
int * tx1 = new int [sizeRemoved + 1];
int * ty1 = new int [sizeRemoved + 1];
int * tx2 = new int [sizeRemoved + 1];
int * ty2 = new int [sizeRemoved + 1];
for (int i=0;i<sizeRemoved;i++)
{
tx1[i] = x1Removed[i];
ty1[i] = y1Removed[i];
tx2[i] = x2Removed[i];
ty2[i] = y2Removed[i];
}
x1Removed = tx1;
y1Removed = ty1;
x2Removed = tx2;
y2Removed = ty2;
Draw();
}
void redo ()
{
x1Data[size] = x1Removed[sizeRemoved - 1];
y1Data[size] = y1Removed[sizeRemoved - 1];
x2Data[size] = x2Removed[sizeRemoved - 1];
y2Data[size] = y2Removed[sizeRemoved - 1];
size++;
int * tempx1 = new int [size+1];
int * tempy1 = new int [size+1];
int * tempx2 = new int [size+1];
int * tempy2 = new int [size+1];
for (int i=0;i<size;i++)
{
tempx1[i] = x1Data[i];
tempy1[i] = y1Data[i];
tempx2[i] = x2Data[i];
tempy2[i] = y2Data[i];
}
tempx1 = x1Data;
tempy1 = y1Data;
tempx2 = x2Data;
tempy2 = y2Data;
int * tx1 = new int [sizeRemoved];
int * ty1 = new int [sizeRemoved];
int * tx2 = new int [sizeRemoved];
int * ty2 = new int [sizeRemoved];
for (int i=0;i<sizeRemoved;i++)
{
tx1[i] = x1Removed[i];
ty1[i] = y1Removed[i];
tx2[i] = x2Removed[i];
ty2[i] = y2Removed[i];
}
sizeRemoved--;
x1Removed = tx1;
y1Removed = ty1;
x2Removed = tx2;
y2Removed = ty2;
Draw();
}
void Draw (int x1, int y1 , int x2 , int y2)
{
BeginPaint(hwnd , &ps );
for (int i=0;i<size;i++)
{
if (algorithm == 0)
{
hPen = CreatePen(PS_SOLID,3,RGB(0,0,255));
SelectObject(ps.hdc, hPen);
MoveToEx(ps.hdc, x1Data[i], y1Data[i], NULL);
LineTo(ps.hdc, x2Data[i], y2Data[i]);
}
else
{
//BeginPaint(hwnd , &ps );
hPen = CreatePen(PS_SOLID,3,RGB(255,0,0));
SelectObject(ps.hdc, hPen);
MoveToEx(ps.hdc, x1Data[i], y1Data[i], NULL);
LineTo(ps.hdc, x2Data[i], y2Data[i]);
//EndPaint(hwnd , & ps);
}
}
if (algorithm == 0)
{
//BeginPaint(hwnd , &ps );
hPen = CreatePen(PS_SOLID,3,RGB(0,0,255));
SelectObject(ps.hdc, hPen);
MoveToEx(ps.hdc, x1, y1, NULL);
LineTo(ps.hdc, x2, y2);
//EndPaint(hwnd , & ps);
}
else
{
//BeginPaint(hwnd , &ps );
hPen = CreatePen(PS_SOLID,3,RGB(255,0,0));
SelectObject(ps.hdc, hPen);
MoveToEx(ps.hdc, x1, y1, NULL);
LineTo(ps.hdc, x2, y2);
//EndPaint(hwnd , & ps);
}
EndPaint(hwnd , & ps);
x1Data[size] = x1;
y1Data[size] = y1;
x2Data[size] = x2;
y2Data[size] = y2;
size++;
int * tempx1 = new int [size+1];
int * tempy1 = new int [size+1];
int * tempx2 = new int [size+1];
int * tempy2 = new int [size+1];
for (int i=0;i<size;i++)
{
tempx1[i] = x1Data[i];
tempy1[i] = y1Data[i];
tempx2[i] = x2Data[i];
tempy2[i] = y2Data[i];
}
tempx1 = x1Data;
tempy1 = y1Data;
tempx2 = x2Data;
tempy2 = y2Data;
}
};
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Graphics", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
algo Object(hwnd);
switch (message) /* handle the messages */
{
case WM_CREATE:
{
HMENU hMenu, hSubMenu;
hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, ID_DDA, "DDA");
AppendMenu(hSubMenu, MF_STRING, ID_MID, "Mid-Point");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, "Algorithm");
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, ID_UNDO, "Undo");
AppendMenu(hSubMenu, MF_STRING, ID_REDO, "Redo");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, "Edit");
SetMenu(hwnd, hMenu);
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_DDA:
Object.ChangeAlgo(0);
LPCSTR name;
if (Object.getAlgo() == 0)
{
name = "DDA";
}
MessageBox(hwnd, name, "Algorithm Changed", MB_OK);
break;
case ID_MID:
Object.ChangeAlgo(1);
if (Object.getAlgo() == 1)
{
name = "Mid-point";
}
MessageBox(hwnd, name, "Algorithm Changed", MB_OK);
break;
}
break;
case WM_LBUTTONDOWN :
{
int XPos = LOWORD(lParam);
int YPos = HIWORD(lParam);
if(numClicks == 0)
{
firstX = XPos ;
firstY = YPos ;
numClicks++;
}
else if(numClicks == 1)
{
lastX = XPos ;
lastY = YPos ;
numClicks = 0;
InvalidateRect(hwnd , NULL , true );
Object.Draw(firstX , firstY , lastX , lastY);
Object.setHWND(hwnd);
}
break ;
}
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
现在,我正在编写代码来画线,如果我选择 DDA,它会用蓝色笔画它,如果我选择中点,它会用红线画它
这是根据变量算法发生的,问题是算法变量已更改,但线条颜色未更改,代码中有些地方不合逻辑但我无法检测到。
有什么帮助吗?
最佳答案
您正在创建一个新的 algo
每次将消息发送到您的窗口过程时的实例。一旦窗口过程返回,响应用户事件而对算法所做的任何更改都会被丢弃。
还有其他各种问题:
new[]
)。尝试使用 std::vector<int>
相反。if (algorithm == 0)
和 else
block 看起来几乎相同。复制代码是不好的。BeginPaint
/EndPaint
在每次迭代中。这很慢并且会泄漏 GDI 资源。关于c++ - 使用多色 GDI C++ 绘制线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22718407/
我在网上搜索但没有找到任何合适的文章解释如何使用 javascript 使用 WCF 服务,尤其是 WebScriptEndpoint。 任何人都可以对此给出任何指导吗? 谢谢 最佳答案 这是一篇关于
我正在编写一个将运行 Linux 命令的 C 程序,例如: cat/etc/passwd | grep 列表 |剪切-c 1-5 我没有任何结果 *这里 parent 等待第一个 child (chi
所以我正在尝试处理文件上传,然后将该文件作为二进制文件存储到数据库中。在我存储它之后,我尝试在给定的 URL 上提供文件。我似乎找不到适合这里的方法。我需要使用数据库,因为我使用 Google 应用引
我正在尝试制作一个宏,将下面的公式添加到单元格中,然后将其拖到整个列中并在 H 列中复制相同的公式 我想在 F 和 H 列中输入公式的数据 Range("F1").formula = "=IF(ISE
问题类似于this one ,但我想使用 OperatorPrecedenceParser 解析带有函数应用程序的表达式在 FParsec . 这是我的 AST: type Expression =
我想通过使用 sequelize 和 node.js 将这个查询更改为代码取决于在哪里 select COUNT(gender) as genderCount from customers where
我正在使用GNU bash,版本5.0.3(1)-发行版(x86_64-pc-linux-gnu),我想知道为什么简单的赋值语句会出现语法错误: #/bin/bash var1=/tmp
这里,为什么我的代码在 IE 中不起作用。我的代码适用于所有浏览器。没有问题。但是当我在 IE 上运行我的项目时,它发现错误。 而且我的 jquery 类和 insertadjacentHTMl 也不
我正在尝试更改标签的innerHTML。我无权访问该表单,因此无法编辑 HTML。标签具有的唯一标识符是“for”属性。 这是输入和标签的结构:
我有一个页面,我可以在其中返回用户帖子,可以使用一些 jquery 代码对这些帖子进行即时评论,在发布新评论后,我在帖子下插入新评论以及删除 按钮。问题是 Delete 按钮在新插入的元素上不起作用,
我有一个大约有 20 列的“管道分隔”文件。我只想使用 sha1sum 散列第一列,它是一个数字,如帐号,并按原样返回其余列。 使用 awk 或 sed 执行此操作的最佳方法是什么? Accounti
我需要将以下内容插入到我的表中...我的用户表有五列 id、用户名、密码、名称、条目。 (我还没有提交任何东西到条目中,我稍后会使用 php 来做)但由于某种原因我不断收到这个错误:#1054 - U
所以我试图有一个输入字段,我可以在其中输入任何字符,但然后将输入的值小写,删除任何非字母数字字符,留下“。”而不是空格。 例如,如果我输入: 地球的 70% 是水,-!*#$^^ & 30% 土地 输
我正在尝试做一些我认为非常简单的事情,但出于某种原因我没有得到想要的结果?我是 javascript 的新手,但对 java 有经验,所以我相信我没有使用某种正确的规则。 这是一个获取输入值、检查选择
我想使用 angularjs 从 mysql 数据库加载数据。 这就是应用程序的工作原理;用户登录,他们的用户名存储在 cookie 中。该用户名显示在主页上 我想获取这个值并通过 angularjs
我正在使用 autoLayout,我想在 UITableViewCell 上放置一个 UIlabel,它应该始终位于单元格的右侧和右侧的中心。 这就是我想要实现的目标 所以在这里你可以看到我正在谈论的
我需要与 MySql 等效的 elasticsearch 查询。我的 sql 查询: SELECT DISTINCT t.product_id AS id FROM tbl_sup_price t
我正在实现代码以使用 JSON。 func setup() { if let flickrURL = NSURL(string: "https://api.flickr.com/
我尝试使用for循环声明变量,然后测试cols和rols是否相同。如果是,它将运行递归函数。但是,我在 javascript 中执行 do 时遇到问题。有人可以帮忙吗? 现在,在比较 col.1 和
我举了一个我正在处理的问题的简短示例。 HTML代码: 1 2 3 CSS 代码: .BB a:hover{ color: #000; } .BB > li:after {
我是一名优秀的程序员,十分优秀!