久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

存儲此指針以在 WndProc 中使用的最佳方法

Best method for storing this pointer for use in WndProc(存儲此指針以在 WndProc 中使用的最佳方法)
本文介紹了存儲此指針以在 WndProc 中使用的最佳方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我很想知道存儲 this 指針以在 WndProc 中使用的最佳/常用方法.我知道幾種方法,但據我所知,每種方法都有自己的缺點.我的問題是:

I'm interested to know the best / common way of storing a this pointer for use in the WndProc. I know of several approaches, but each as I understand it have their own drawbacks. My questions are:

生成這種代碼有哪些不同的方法:

What different ways are there of producing this kind of code:

CWindow::WndProc(UINT msg, WPARAM wParam, LPARAM)
{
  this->DoSomething();
}

我可以想到 Thunks、HashMaps、線程本地存儲和窗口用戶數據結構.

I can think of Thunks, HashMaps, Thread Local Storage and the Window User Data struct.

每種方法的優缺點是什么?

What are the pros / cons of each of these approaches?

獲得代碼示例和建議的積分.

Points awarded for code examples and recommendations.

這純粹是為了好奇.使用 MFC 后,我一直想知道它是如何工作的,然后開始考慮 ATL 等.

This is purely for curiosities sake. After using MFC I've just been wondering how that works and then got to thinking about ATL etc.

我可以在窗口 proc 中有效使用 HWND 的最早位置是什么?它被記錄為 WM_NCCREATE - 但如果您實際進行實驗,那不是發送到窗口的第一條消息.

What is the earliest place I can validly use the HWND in the window proc? It is documented as WM_NCCREATE - but if you actually experiment, that's not the first message to be sent to a window.

ATL 使用 thunk 來訪問 this 指針.MFC 使用 HWND 的哈希表查找.

ATL uses a thunk for accessing the this pointer. MFC uses a hashtable lookup of HWNDs.

推薦答案

在您的構造函數中,使用this"作為 lpParam 參數調用 CreateWindowEx.

In your constructor, call CreateWindowEx with "this" as the lpParam argument.

然后,在 WM_NCCREATE 上,調用以下代碼:

Then, on WM_NCCREATE, call the following code:

SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) ((CREATESTRUCT*)lParam)->lpCreateParams);
SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);

然后,在窗口過程的頂部,您可以執行以下操作:

Then, at the top of your window procedure you could do the following:

MyWindowClass *wndptr = (MyWindowClass*) GetWindowLongPtr(hwnd, GWL_USERDATA);

允許您這樣做:

wndptr->DoSomething();

當然,您可以使用相同的技術來調用上面的函數:

Of course, you could use the same technique to call something like your function above:

wndptr->WndProc(msg, wparam, lparam);

... 然后可以按預期使用其this"指針.

... which can then use its "this" pointer as expected.

這篇關于存儲此指針以在 WndProc 中使用的最佳方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What do compilers do with compile-time branching?(編譯器如何處理編譯時分支?)
Can I use if (pointer) instead of if (pointer != NULL)?(我可以使用 if (pointer) 而不是 if (pointer != NULL) 嗎?)
Checking for NULL pointer in C/C++(在 C/C++ 中檢查空指針)
Math-like chaining of the comparison operator - as in, quot;if ( (5lt;jlt;=1) )quot;(比較運算符的數學式鏈接-如“if((5<j<=1)))
Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之間的區別與“if())
C++, variable declaration in #39;if#39; expression(C++,if 表達式中的變量聲明)
主站蜘蛛池模板: 成人精品 | 精品欧美一区免费观看α√ | 亚洲综合视频 | 国产中文字幕在线 | 亚洲精品一二三区 | 草草视频在线观看 | 亚洲狠狠丁香婷婷综合久久久 | 亚洲精品日韩一区二区电影 | 一区二区在线 | 欧美一区二区三区视频 | 特黄色一级毛片 | 中国美女一级黄色片 | 粉嫩粉嫩芽的虎白女18在线视频 | 午夜精品久久久久久久久久久久久 | 中文字幕日韩在线观看 | 欧美寡妇偷汉性猛交 | 91精品国产一区二区三区 | 国产精品污www一区二区三区 | 国产在线97| 欧美日韩一二三区 | 国产在线精品一区二区 | 国产视频导航 | 国产精品国产三级国产aⅴ浪潮 | 日韩av一区在线观看 | 欧美淫片| 亚洲电影专区 | 精品国产一区二区三区日日嗨 | 色婷婷综合网 | 欧美操操操 | 在线播放国产一区二区三区 | 亚洲精品av在线 | 成人免费在线观看 | 亚洲成av| 国产欧美三区 | 国产精品久久久久久久久免费桃花 | 精品一区二区三区四区 | 欧美日韩精品一区二区三区四区 | 日韩男人天堂 | 男女激情网站免费 | 中文二区 | 亚洲欧美日韩国产综合 |