小编Chr*_*isN的帖子

禁用/启用MFC功能包的功能区按钮

我正在使用MFC功能包,我在功能区栏上有一些按钮,CMFCRibbonButton的实例.问题是我想在某些条件下启用和禁用其中一些,但是在运行时.我怎样才能做到这一点?因为没有具体的方法...我听说解决方案是在运行时附加/分离事件处理程序,但我不知道如何...

c++ mfc mfc-feature-pack

4
推荐指数
1
解决办法
1万
查看次数

CString :: Format的替代品?

在VC6中进行字符串格式化是否有更好的替代方法,在替换之前进行语法检查?

c++ string format mfc

3
推荐指数
1
解决办法
4253
查看次数

在C++中动态创建和调用类方法的最简单方法是什么?

我想用类名和方法填充一个映射,一个唯一的标识符和指向该方法的指针.

typedef std::map<std::string, std::string, std::string, int> actions_type;
typedef actions_type::iterator actions_iterator;

actions_type actions;
actions.insert(make_pair(class_name, attribute_name, identifier, method_pointer));

//after which I want call the appropriate method in the loop

while (the_app_is_running)
{
    std::string requested_class = get_requested_class();
    std::string requested_method = get_requested_method();

    //determine class
    for(actions_iterator ita = actions.begin(); ita != actions.end(); ++ita)
    {
        if (ita->first == requested_class && ita->second == requested_method)
        {
            //class and method match
            //create a new class instance
            //call method
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果方法是静态的,那么一个简单的指针就足够了,问题很简单,但我想动态创建对象,所以我需要存储一个指向类的方法和方法的偏移量,我不知道这是否有效(如果偏移总是相同的等等).

问题是C++缺乏反射,使用反射的解释语言中的等效代码应如下所示(PHP中的示例):

$actions = array
(
     "first_identifier" => …
Run Code Online (Sandbox Code Playgroud)

c++ model-view-controller object

3
推荐指数
2
解决办法
1354
查看次数

将新节点添加到链接列表的新方法

void addNewNode (struct node *head, int n)
{
    struct node* temp = (struct node*) malloc(sizeof(struct node));
    temp -> data = n;
    temp -> link = head;
    head = temp;
}
Run Code Online (Sandbox Code Playgroud)

上面给出的代码是用于在链表头部添加新节点的功能的普遍错误版本.通常正确的版本是,像,

void addNewNode (struct node **head, int n);
void addNewNode (struct node * &head, int n);
Run Code Online (Sandbox Code Playgroud)

我为了这个目的而制定了另一个但很简单的功能.

struct node* addNewNode (struct node *head, int n)
{
    struct node* temp = (struct node*) malloc(sizeof(struct node));
    temp -> data = n;
    temp -> link = head;
    return temp;
}
Run Code Online (Sandbox Code Playgroud)

但我还没有看到在代码和教程中使用或讨论过这个问题,因此我很想知道这种方法是否有一些缺陷.

c c++ pointers data-structures

2
推荐指数
1
解决办法
3256
查看次数

LaTeX中的超链接不正确

到目前为止hyperref,LaTeX中的包已自动链接到报表中的所有项目.但有一个没有得到正确链接,可能是因为我手动将它添加到目录中,如下所示:

\addcontentsline{toc}{chapter}{Bibliography}
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

latex report hyperlink hyperref pdflatex

2
推荐指数
1
解决办法
1715
查看次数

键盘钩...没有得到大写或大写字符

下面的功能是记录"0","z"和"1"确定...但它没有捕获"Z"(shift-z)...任何帮助将不胜感激...

__declspec(dllexport)
LRESULT CALLBACK HookProc (UINT nCode, WPARAM wParam, LPARAM lParam)
{
    if ((nCode == HC_ACTION) && (wParam == WM_KEYUP))
    {
        // This Struct gets infos on typed key
        KBDLLHOOKSTRUCT hookstruct = *((KBDLLHOOKSTRUCT*)lParam);

        // Bytes written counter for WriteFile()
        DWORD Counter;

        wchar_t Logger[1];

        switch (hookstruct.vkCode)
        {
        case 060: Logger[0] = L'0'; break;
        case 061: Logger[0] = L'1'; break;
        case 90: Logger[0] = L'z'; break;
        case 116: Logger[0] = L'Z'; break;
        }

        // Opening of a logfile. Creating it if it …
Run Code Online (Sandbox Code Playgroud)

c++ hook winapi keyboard-hook

1
推荐指数
2
解决办法
4180
查看次数

错误C2065:'CoInitializeEx':未声明的标识符

尝试使用时出现以下错误 hres = CoInitializeEx(0, COINIT_MULTITHREADED);

错误C2065:'CoInitializeEx':未声明的标识符

我已经包括:

#define _WIN32_DCOM
#include <iostream>
using namespace std;
#include <comdef.h>
#include <Wbemidl.h>
Run Code Online (Sandbox Code Playgroud)

在我的cpp文件中.

请帮助.

谢谢,Neha

c++ mfc

1
推荐指数
1
解决办法
4792
查看次数

用于修改非const对象的编译器错误

 #include "iostream"
 #include "vector"


 class ABC {

  private:
      bool m_b;
  public:
      ABC() : m_b(false) {}

      ABC& setBool(bool b) {
          m_b = b;
          return *this;
      }

      bool getBool() const {
          return m_b;
      }
};

 void foo(const std::vector<ABC> &vec) {

      vec[0].setBool(true);
 }

 int main(int argc, char*argv[]) {

     std::vector<ABC> vecI;
     ABC i;
     vecI.push_back(i);
     foo(vecI);
 }
Run Code Online (Sandbox Code Playgroud)

当我编译它时,我得到这个错误:const ABC作为discards限定符的this参数传递ABC& ABC::setBool(bool)

任何想法为什么会发生这种情况,因为对象本身并不是一个常数.

c++

-1
推荐指数
1
解决办法
211
查看次数

如何将 C++ 或 C 中的字符串转换为整数数组?

如何将字符串转换为整数数组?我可以使用sstream,因为atoi不起作用?!

c c++

-4
推荐指数
1
解决办法
1856
查看次数