我正在尝试创建一个在父窗口中显示控制台窗口的小类.(你可以想象那里显示的聊天或调试信息)
现在,由于不同的instanes确实有不同的私有变量(例如消息数组或父窗口),我需要使用非静态方法作为Windows事件的回调.
我已经想到了方法,我将实际的类实例传递给静态回调函数,然后在其上调用正确的方法,但是在winAPI中,一切都是使用TranslateMessage并且DispatchMessage没有机会使用我自己的参数.
我在这里找到了一些代码:类方法作为winAPI回调,但我不明白,我认为这不是我需要的.如果是,那么请给我进一步解释所提供的代码.
我得到的错误:
错误:类型的参数'LRESULT(
WindowConsole::)(HWND__ ,UINT,WPARAM,LPARAM)'不匹配'LRESULT(*)(HWND__,UINT,WPARAM,LPARAM)'
我不知道括号中的那个星是什么意思,但这是不匹配的.
和代码:
class WindowConsole {
char messages[255][255];
HWND mainWindow;
public:
int width;
int height;
inline HWND create(HWND parent);
inline bool update();
inline LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
};
HWND WindowConsole::create(HWND parent) {
HINSTANCE inst = GetModuleHandle (0);
WNDCLASSEX wincl;
/* The Window structure */
wincl.hInstance = inst;
wincl.lpszClassName = "ConsoleClass";
wincl.lpfnWndProc = this->WndProc; /* This function is called by …Run Code Online (Sandbox Code Playgroud) 我正在设计应该在图像上显示开放CV的程序.我注意到基本SDL应用程序的概念非常糟糕 - 它由循环和延迟组成.
while(true) {
while(event_is_in_buffer(event)) {
process_event(event);
}
do_some_other_stuff();
do_some_delay(100); //Program is stuck here, unable to respond to user input
}
Run Code Online (Sandbox Code Playgroud)
这使得程序即使在背景上也可以执行和渲染(或者如果首先不需要重新渲染).如果我使用更长的延迟,我获得的资源消耗更少,但我必须等待更长时间才能处理事件,如鼠标点击.
我想要的是使程序等待事件,如WinApi或类似套接字请求.那可能吗?
我想要的概念:
bool go=true;
while(get_event(event)&&go) { //Program gets stuck here if no events happen
switch(event.type){
case QUIT: go=false;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个简单的类,旨在将整数转换为字节数组.
class mc_int {
private:
int val; //actual int
public:
int value(); //Returns value
int value(int); //Changes and returns value
mc_int(); //Default constructor
mc_int(int);//Create from int
void asBytes(char*); //generate byte array
mc_int& operator=(int);
mc_int& operator=(const mc_int&);
bool endianity; //true for little
};
Run Code Online (Sandbox Code Playgroud)
为了转换和更简单的使用,我决定添加operator=方法.但我认为我的实施mc_int& operator=(const mc_int&);是不正确的.
mc_int& mc_int::operator=(const mc_int& other) {
val = other.value();
// |-------->Error: No instance of overloaded function matches the argument list and object (object has type quelifiers that prevent the match)
}
Run Code Online (Sandbox Code Playgroud)
这可能是什么?我试过用 …
我正在为Minecraft制作一个基于文本的雷达.如果玩家距离你不到20个街区,它会在聊天中说出来.截至目前,它正在骚扰聊天.如何才能让它只写入关于该玩家ONCE的聊天?即使你不玩游戏,也应该很容易理解.
if (Camb.radar)
{
for (Entity e: (List < Entity > ) mc.theWorld.loadedEntityList)
{
if (e instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) e;
if (player == mc.thePlayer || mc.thePlayer.getDistanceToEntity(e) > 20.0)
continue;
mc.thePlayer.addChatMessage("\2479[CAMB] \247e" + player.getEntityName() + " has entered your 20 block radius!"); //Write to chat, only want this line done once for every player
}
}
}
Run Code Online (Sandbox Code Playgroud) 如果能够在Stack Exchange上将图像粘贴到此处而不是干预文件对话框,那将非常方便。此处已实现了类似功能,但仅适用于Webkit浏览器。
我正在开发可以做到这一点的用户脚本。有趣的是,在Webkit浏览器中,我从未从剪贴板中获取文件(与原始图像数据不同),而在Firefox中却可以。
Firefox解决方案:
div.addEventListener('paste', function(event){
//I'm actually not sure what should event.originalEvent be. I copypasted this
var items = (event.clipboardData || event.originalEvent.clipboardData);
console.log("paste", items);
//Try to get a file and handle it as Blob/File
var files = items.items || items.files;
if(files.length>0) {
//Being lazy I just pick first file
var file = files[0];
//handle the File object
_this.processFile(file);
event.preventDefault();
event.cancelBubble = true;
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
在Chrome没有像Firefox一样好的文档(我的意思是MDN)之前,我试图检查正在发生的事情。我复制了一个文件,并将其粘贴到Google chrome(v39)中。这是我DataTransfer在控制台中获得的对象:

供参考,这是Firefox中的同一事件:

另外两个阵列,items …
我已经阅读了一些相关内容boost::interprocess::file_lock,它似乎做了我想要做的事情(支持共享和独占锁定,并在进程崩溃或退出时解锁)。
但我不确定的一件事是它对文件有什么作用?例如,我可以使用 0 字节长的文件吗?boost::interprocess里面写东西吗?或者系统只关心它的存在吗?
我现在已经使用了boost::interprocess一段时间来可靠地内存映射文件并写入文件,现在我需要进行多进程并确保对此文件的读取和写入受到保护;file_lock似乎是可行的方法,我只是想知道我现在是否需要添加另一个文件来用作互斥体。
提前致谢
假设抽象验证器回调根据新字符串值是否有效返回 true 或 false:
function isValid(text) {
/* arbitrary code, returns true or false */
}
Run Code Online (Sandbox Code Playgroud)
我想在 HTML/JavaScript 的输入字段中应用此回调。验证器中的代码可以是任何类型的验证器。
我见过人们使用keyup事件来阻止输入某些字符。这是有缺陷的方法,显然无法验证整个输入字段。
我尝试取消input活动,但不起作用:
myInputField.addEventListener("input", function(e) {
console.log(e);
e.preventDefault();
return false;
});
Run Code Online (Sandbox Code Playgroud)
在我遇到的大多数 GUI 框架(Java Swing、C++ Qt)中,这就像在输入字段上分配验证器回调一样简单。我如何在 JavaScript 中执行此操作?
突然,当我尝试从Sourcetree启动"外部合并工具"时,该工具不会出现.我突然说,因为我上次尝试时效果很好.对话框永远存在:

最终我发现这个过程与视觉合并有关(不知道如何从windows任务管理器复制命令行):

顺便说一句,当我按下中止时,这个过程并没有消失,所以有人可能没有完成他们的功课.实际上,如果这个命令行没有六个相同的进程,我可能不会注意到它.
这些是我的设置:

我该如何解决?我需要合并项目,我不知道该怎么做......
我正在制作C动态数组库,有点像.请注意,我在空闲时间这样做是为了好玩,所以请不要推荐数百万现有的库.
我开始实施排序.该数组具有任意元素大小,定义为struct:
typedef struct {
//[PRIVATE] Pointer to array data
void *array;
//[READONLY] How many elements are in array
size_t length;
//[PRIVATE] How many elements can further fit in array (allocated memory)
size_t size;
//[PRIVATE] Bytes per element
size_t elm_size;
} Array;
Run Code Online (Sandbox Code Playgroud)
我最初准备这个以sort函数开始:
/** sorts the array using provided comparator method
* if metod not provided, memcmp is used
* Comparator signature
* int my_comparator ( const void * ptr1, const void * ptr2, size_t type_size …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Visual Studio 2017 中的内置分析器来分析我的应用程序:
这是我在输出窗口中看到的:
Profiling of 'MyProjectName' started.
MyProjectName has exited.
Profiling of 'MyProjectName' stopped.
Diagnostics session stopped with errors.
Merging of ETL files has failed (0x80071069) (Flags: 0x0000001f).
Run Code Online (Sandbox Code Playgroud)
怎么了?我在 Windows 7 x64 上运行 MS Visual Studio Community 2017。我正在分析 C++ Qt 应用程序。