我有一个 Visual C++ 项目,但我无法刷新窗口并重绘自身。我用过
RedrawWindow();
m_ProgressDlg->RedrawWindow();
Run Code Online (Sandbox Code Playgroud)
并且
UpdateData(false);
m_ProgressDlg->UpdateData(false);
Run Code Online (Sandbox Code Playgroud)
但似乎永远不会顺利。
我能怎么做?
我刚刚开始使用vc++ 2008。我只想看到一条消息(对话框)。我已将我的项目创建为 win32 项目应用程序。
我写了下面的代码来查看 MessageBox
MessageBoxW(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误
错误 C2664:“MessageBoxW”:无法将参数 2 从“const char [28]”转换为“LPCWSTR”
这是什么错误?我需要做什么才能看到一个简单的消息框显示。
我有一个 C++ 函数,它将 LPSTR 类型变量拆分为一个字符数组 (char*) 示例:
this->XMeshTexturePath = FindTexturePath(XMeshTexturePath,d3dxMaterials[i].pTextureFilename);
//the value of XMeshTexturePath is: Models\\Textures\\
//the value of d3dxMaterials[i].pTextureFilename is: BlaBlaBla\\BlaBla\\Cyrex.x
//The Result(XMeshTexturePath) should be like this:"Models\\Textures\\Cyrex.x"
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试编写的功能:
int FindTextLength(char* Text){
int length
Run Code Online (Sandbox Code Playgroud)
h=0; for(int i=0;i
char* FindTexturePath( char* TexturePath ,LPSTR FileNameToCombine){
int FileLength=0;
int PathAndFileLength=0;
char *FileName = new char;
char *TexPathAndName = new char;
strcpy(TexPathAndName, FileNameToCombine);
PathAndFileLength = FindTextLength(TexPathAndName);
for(int i=0; i<PathAndFileLength; i++){
if( TexPathAndName[i] != NULL){
if(TexPathAndName[i] != '\\'){
FileName[FileLength] = TexPathAndName[i];
FileLength++;
}
else
FileLength …Run Code Online (Sandbox Code Playgroud) 如何使用基于 MFC 对话框的应用程序打印文档?我做了一个打印按钮。单击此按钮后,我想打印一些文档或一些文本。
因此,我创建了一个基本的 VC++ 程序,并创建了一个具有 1 个方法的模板类(除了构造函数和析构函数)。我收到以下错误:
>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Vector<int>::~Vector<int>(void)" (??1?$Vector@H@@QAE@XZ) referenced in function _main
>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Vector<int>::Vector<int>(int)" (??0?$Vector@H@@QAE@H@Z) referenced in function _main
>c:\users\edy\documents\visual studio 2010\Projects\ex01\Debug\ex01.exe : fatal error LNK1120: 2 unresolved externals
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
(CPP 类文件)
using namespace std;
#include "Vector.h"
template <class T> Vector<T>::Vector(int n)
{
this.crt = 0;
this.dim = n;
this.elem = new T[100];
}
template <class T> void Vector<T>::add(T e)
{
this.elem[crt] = e; …Run Code Online (Sandbox Code Playgroud) 好吧,我遇到了一个奇怪的问题。
由于将spdlog库添加到我的项目中并相应地调整了所有日志输出,因此将忽略if-else语句的所有其他块。日志输出已替换为具有简单正则表达式模式(printf样式到fmtlib样式)的搜索和替换过程。
spdlog:https://github.com/gabime/spdlog
经过一些调试之后,我现在编写了以下非常简单的测试函数:
void dbg_test() {
bool success = false;
BOOST_ASSERT_MSG(!success, "Sanity check");
// This works
if (success) {
LOG_ERROR("Successful");
} else {
LOG_ERROR("Unsuccessful"); // Log's written
}
// This doesn't work
if (success)
LOG_ERROR("Successful (w/o)");
else
LOG_ERROR("Unsuccessful (w/o)"); // Log's missing
}
Run Code Online (Sandbox Code Playgroud)
根据“成功”的值,现在会发生以下情况(将相应地调整BOOST_ASSERT_MSG):如果将success == true“成功”和“成功(不包括)”写入日志。如果为success == false,则写“不成功”,但不写“不成功(w / o)”。
当然,我还检查了日志记录,并希望以exit(0)结束程序而不是编写日志,但是此代码也不起作用:
void dbg_test() {
bool success = false;
BOOST_ASSERT_MSG(!success, "Sanity check");
// This works
if (success) {
LOG_ERROR("Successful");
} else {
exit(0); …Run Code Online (Sandbox Code Playgroud) 我有以下程序:
#include <iostream>
void Init();
struct Foo {
Foo() {
int *p = new int; // just to make sure Foo's ctor is not a constant expression
Init();
}
} foo;
struct Bar {
constexpr Bar()
: value(0) { }
int value;
} bar;
void Init() {
bar.value = 1;
}
int main()
{
std::cout << bar.value << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
这里foo的构造函数不是常量表达式,因此我们将动态初始化foo。但是bar的构造函数似乎是一个常量表达式,因此我们将对进行静态初始化bar。因此,bar必须先调用的ctor,然后foo将其1视为输出。我在GCC 8.3.0和Clang 8.0.0中观察到了这样的结果。但是对于Visual C ++,实际的输出是,0 …
c++ static-variables visual-c++ static-initialization constexpr
我正在尝试将项目从迁移Borland C++到Visual C++
我注意到如本例所述在处理枚举方面存在差异
档案:Test_enum.cpp
#ifdef _MSC_VER
#include <iostream>
#else
#include <iostream.h>
#endif
#include <conio.h>
using namespace std;
enum {
ENUM_0 =0,
ENUM_1,
ENUM_2,
ENUM_3
} ;
int main(int argc, char* argv[])
{
#ifdef _MSC_VER
cout << "Microsoft Visual compiler detected!" << endl;
#elif defined(__BORLANDC__)
cout << "Borland compiler detected!" << endl;
#elif
cout << "Other compiler detected!" << endl;
#endif
#if ENUM_1 > 0
cout << "ENUM_1 is well defined at preprocessing time" << endl;
#else …Run Code Online (Sandbox Code Playgroud) 我正在尝试为分配创建程序,该程序将从字符串向量中添加和删除字符串,但是首先我需要创建一个函数来查找向量中是否已经存在该字符串。
我已经尝试过使用循环搜索向量,以在每个索引处找到特定的所需字符串。break;如果找到了字符串,我尝试添加a 退出。我不知道该函数应该为空还是布尔值。
bool FindString(int vctrSize, vector<string> restaurantVctr, string targetRestnt) {
int i;
for (i = 0; i < vctrSize; ++i) {
if (restaurantVctr.at(i) == targetRestnt) {
return true;
break;
}
else {
return false;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望如果找到该字符串,输出将为true,否则显然将为false。
编辑:我忘了提到我也收到了警告:“并非所有控制路径都返回一个值”
该snmp.h头文件包含的定义,AsnObjectIdentifier结构和遗憾的是这个结构不相等运算符重载。我想AsnObjectIdentifier成为的钥匙,std::map但问题find()是无法在地图上找到钥匙。我定义了一个自定义比较器AsnObjectIdentifierComparator,用作std :: map声明的第三个模板参数。该方案的最小可复制代码如下:
#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef unsigned int UINT;
typedef struct {
UINT idLength;
UINT * ids;
} AsnObjectIdentifier;
struct AsnObjectIdentifierComparator {
bool operator()(const AsnObjectIdentifier& left, const AsnObjectIdentifier& right) const {
UINT* leftOidArr = left.ids, * rightOidArr = right.ids;
UINT smallerOidLen = (left.idLength < right.idLength ? left.idLength : right.idLength);
for (UINT i = 0; i < smallerOidLen; i++) {
if (leftOidArr[i] …Run Code Online (Sandbox Code Playgroud) visual-c++ ×10
c++ ×9
borland-c++ ×1
constexpr ×1
directx ×1
directx-9 ×1
enums ×1
equality ×1
if-statement ×1
key ×1
linker ×1
mfc ×1
refresh ×1
stdmap ×1
vector ×1