我想我在Window的批处理脚本中遇到了一个错误.
我无法设置扩展if语句中的变量.
这是我的脚本的一个孤立的部分:
@echo off
set success=1
set Version=12345
set Target=Client
set Type=456
set dir=
set zip=
if "%Version%"=="" set success=0
if "%Type%"=="" set success=0
if 1==1 set test=42
if %success%==1 (
set test2=57005
if "%Target%"=="Client" (
set dir=ModName v%Version%
set zip=ModName v%Version% %Type%.zip
echo Version: %Version%
echo Type: %Type%
echo.
echo Target: %Target%
echo dir: %dir%
echo zip: %zip%
echo.
echo test: %test%
echo test2: %test2%
)
) else (
echo Not successful.
)
Run Code Online (Sandbox Code Playgroud)
这是一个全新的cmd实例的输出:
C:\Users\RandomClown\Desktop>test.bat
Version: 12345
Type: …Run Code Online (Sandbox Code Playgroud) 我注意到在C和C++中,我们可以使用int64_t,或者只是一个long long.
如果我使用这些类型编译32位代码,我会在64位和/或32位机器上遇到任何性能问题吗?
除了节省一些RAM,我还有理由使用int吗?
毕竟,64位整数在存储大数字时更有用.
我试图专门为我自己的类型哈希,一个模板化的键.
我是基于cppreference.
我得到编译错误"C++标准不提供此类型的哈希".我想我做错了.编译器甚至可以支持这种模板吗?
namespace std {
template<typename SType, typename AType, typename PType>
struct MyKey {
const SType from;
const AType consume;
const PType pop;
};
template<typename SType, typename AType, typename PType>
struct hash<MyKey<SType, AType, PType>> {
size_t operator ()(MyKey const &key) {
std::hash<SType>()(key.from);
std::hash<AType>()(key.consume);
std::hash<PType>()(key.pop);
}
};
}
Run Code Online (Sandbox Code Playgroud) 我试图在调整窗口大小时调整图形设备缓冲区的大小,但我没有运气检测到该事件。
这是 C++ Windows 编程。我试过:
while(WM_QUIT != msg.message){
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
switch(msg.message){
case WM_SIZE:
return; //<-- If the program closes because of this return, then I know I found the right statements.
}
//TranslateMessage(&msg);
//DispatchMessage(&msg);
}else{
poly.setConstantBuffer(space.getCamera());
poly.draw(iSize);
graphics.render();
}
}
Run Code Online (Sandbox Code Playgroud)
它没有返回,所以这意味着这是不正确的。捕获调整大小事件的正确方法是什么?
我正在尝试使用capture [&]传递lambda函数.存储捕获lambda的变量的正确声明是什么?[f2以下]
// Non-capturing
void (*f1)() = [](){ }; // Works
// All by reference
void (*f2)() = [&](){ }; // Syntax Error
Run Code Online (Sandbox Code Playgroud) 如何在不使用传统方法e.stopPropagation(底部相关问题)的情况下阻止文本选择?
是否有一个电话,我可以说"不突出任何突出显示"?
我将鼠标事件绑定在文档上,因为页面中有大约一百个[或多或少]元素,我希望彼此进行交互.
我没有将事件绑定到元素的原因是因为当鼠标离开元素时,所有鼠标事件都会停止触发.我需要绑定到文档以正确观看鼠标事件.
使用传统方法(下面的链接)的方法的问题是,在触发侦听器时,具有文本的元素已经评估了鼠标事件.
我的代码适用于Chrome.以下问题适用于Firefox.
相关问题: 如何使用光标拖动阻止文本/元素选择
这里讨论了防止冒泡到文本元素:
if(e.stopPropagation) e.stopPropagation();
if(e.preventDefault) e.preventDefault();
e.cancelBubble=true;
e.returnValue=false;
return false;
Run Code Online (Sandbox Code Playgroud) 我注意到一个问题,当不相关的状态/属性发生变化时,同一父级中的每个组件(下面示例中的应用程序)都会重新渲染,从而使页面/表单明显变慢。
我遵循了许多建议,例如记住事件处理程序和道具,但不相关的组件仍然会重新渲染。我很困惑。我对 React 有什么不理解的地方?
[ CodeSandbox ] 在 React 调试器中,启用:组件渲染时突出显示更新
import React, { useMemo, useState } from "react";
import { TextField } from "@material-ui/core";
function MyTextInput(props) {
return (
<TextField
variant={"outlined"}
onChange={props.onChange}
value={props.value}
/>
);
}
export default function App() {
const [exampleTextValue1, setExampleTextValue1] = useState("");
const [exampleTextValue2, setExampleTextValue2] = useState("");
const handleChange1 = useMemo(
() => (event) => setExampleTextValue1(event.target.value),
[]
);
const handleChange2 = useMemo(
() => (event) => setExampleTextValue2(event.target.value),
[]
);
return (
<>
<div> …Run Code Online (Sandbox Code Playgroud) 我正在关注DX样本和MSDN参考,但我现在碰壁了.
我从D3D11CreateDeviceAndSwapChain()获得了E_InvalidArg的HRESULT.我知道它是我传递的IDXGIAdapter,因为如果我将其更改为null,它就可以工作.
我无法弄清楚我的初始化有什么问题.也许知识渊博的人知道我做错了什么.这里是:
vars:
vector<IDXGIAdapter1*> vAdapters;
IDXGIAdapter1* selectedVAdapter; // Constructor inits this to null
Run Code Online (Sandbox Code Playgroud)
方法:
void refreshVideoAdapters(){
IDXGIAdapter1* pAdapter;
IDXGIFactory1* pFactory=NULL;
uint lastID=0;
if(selectedVAdapter){
DXGI_ADAPTER_DESC1* desc=NULL;
selectedVAdapter->GetDesc1(desc);
lastID=desc->DeviceId;
releaseVideoAdapter();
}
if(FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory))) return;
for(uint i=0; pFactory->EnumAdapters1(i, &pAdapter)!=DXGI_ERROR_NOT_FOUND; i++){
vAdapters.push_back(pAdapter);
if(lastID){
DXGI_ADAPTER_DESC1* desc=NULL;
pAdapter->GetDesc1(desc);
if(lastID==desc->DeviceId){
selectedVAdapter=pAdapter;
lastID=0;
}
}
}
if(pFactory) pFactory->Release();
}
void releaseVideoAdapter(){
for(uint i=0; i<vAdapters.size(); i++){
vAdapters[i]->Release();
vAdapters[i]=NULL;
}
vAdapters.clear();
selectedVAdapter=NULL;
}
IDXGIAdapter1* getVideoAdapter(){return selectedVAdapter;}
bool setVideoAdapter(uint num=0){
if(num<vAdapters.size()){
selectedVAdapter=vAdapters[num];
return 1;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
电话的相关部分:
... …Run Code Online (Sandbox Code Playgroud) 我试图找到调整图形界面大小的最佳方法.我尝试重新初始化设备而不删除我制作的形状的缓冲区,但我最终得到了大量的内存泄漏.
我在这个问题上找不到任何有用的东西.
我是否需要删除所有[缓冲区,设备,适配器]并从头开始重新启动图形界面?或者有一种有效的方法吗?
这适用于DX 10/11接口.
编辑: 要显示的代码很多,但我只是:
cleanup(); // Pointers related to the device
initDevice(hWnd); // Create new device with updated size
draw(stuff); // I never deleted my constant/index/vertex buffers
Run Code Online (Sandbox Code Playgroud)
具体来说,我没有删除这些:
ID3D11Buffer* constantBuffer;
ID3D11Buffer* vertexBuffer;
ID3D11Buffer* indexBuffer;
ID3D11VertexShader* vertexShader;
ID3D11PixelShader* pixelShader;
ID3D11InputLayout* vertexLayout;
Run Code Online (Sandbox Code Playgroud)
我希望每次用户调整大小时都不重新创建图形来保存性能.
我几乎无法理解管道的手册页,所以我需要帮助理解如何在外部可执行文件中获取管道输入.
我有2个程序:main.o和log.o
我把main.o写成了fork.这是它正在做的事情:
我需要子fork for main来管道到log.o的 STDIN
log.o只是将带有时间戳的STDIN和日志带到文件中.
我的代码是由我不记得的各种StackOverflow页面的一些代码和管道的手册页组成的:
printf("\n> ");
while(fgets(input, MAXINPUTLINE, stdin)){
char buf;
int fd[2], num, status;
if(pipe(fd)){
perror("Pipe broke, dood");
return 111;
}
switch(fork()){
case -1:
perror("Fork is sad fais");
return 111;
case 0: // Child
close(fd[1]); // Close unused write end
while (read(fd[0], &buf, 1) > 0) write(STDOUT_FILENO, &buf, 1);
write(STDOUT_FILENO, "\n", 1);
close(fd[0]);
execlp("./log", "log", "log.txt", 0); // This …Run Code Online (Sandbox Code Playgroud) 我试图做一个支持Unicode的C++ hello世界,但我有点卡住了.
我做了一个指向TCHAR的指针[我认为它是一个char数组],在使用它之后,我尝试删除它.它崩溃说Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse).
检查互联网,有人说这是因为使用了错误的删除.我尝试了两个删除,但它仍然给出相同的消息.
我错过了一些明显的东西吗
我试过的代码:
TCHAR *str=TEXT("????, World!");
delete[] str;
Run Code Online (Sandbox Code Playgroud)
还尝试过:
TCHAR *str=TEXT("????, World!");
delete str;
Run Code Online (Sandbox Code Playgroud)