简体   繁体   English

处理当前窗口而不使用“ this”?

[英]handle to current window without use of “this”?

In my MFC application, I have a non-Dlg-member function that needs access to the window handle, but since it's not a member function I can't use the "this" pointer. 在我的MFC应用程序中,我有一个非Dlg成员函数,需要访问窗口句柄,但是由于它不是成员函数,所以不能使用“ this”指针。

Specifically, here is what I mean: 具体来说,这就是我的意思:

void BlahDlg::OnBnClickedblah()
{
    //whatever
    //...

    CClientDC dc(this);

    //...
    //whatever
}

^ that works fine. ^效果很好。 But I'm using a non-member function: 但是我正在使用一个非成员函数:

void nonMember()
{
    //whatever
    //...

    CClientDC dc(this); //will not work!

    //...
    //whatever
}

So my question is: what can I replace 'this' with in the latter piece of code that will make it have the same effect as the former. 所以我的问题是:在后一段代码中我可以用什么替换“ this”,使其具有与前者相同的效果。

Simply you need to pass this to a non-member function, and such non-member function should have a corresponding parameter. 只要你需要通过this一个非成员函数,这样的非成员函数应该有一个相应的参数。 For example: 例如:

void nonMember(BlahDlg* dlg) {
  ...
  CClientDC dc(dlg);
  ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM