简体   繁体   中英

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.

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.

Simply you need to pass this to a non-member function, and such non-member function should have a corresponding parameter. For example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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