简体   繁体   中英

How do edit controls work internally? class windowProcedure and allocated buffers

CreateWindowEx creates a window, and if you set the lpClassName parameter as "Edit" it creates an edit box.

I know that lpClassName has his own WindowProcedure registered to its structure. That procedure handles all messages that interact with the edit box.

Suppose we have a few edit boxes, and that each edit box has its own buffer. What I don't understand is, how does that WindowProcedure know which buffer to handle? For example, on a key pressed, or when you use SendMessage() / GetMessage() and you pass only the window handle. Because, you don't specify which buffer to use, how is that buffer determined by the shared (between edit controls) WindowsProcedure ?

I suppose that is somehow internal. But how? Does it have an internal list of edit box structures in which it associates the window handle with the allocated buffer for each edit box, and loops through them to find the buffer determined by the handle?

When the Edit box is created, it likely creates an object in memory to save information about the Edit's data, state, etc, and then saves that object in the HWND itself (HOW it is saved is an implementation detail - for example, WNDCLASS::cbWndExtra could be used to set aside extra bytes inside the HWND to hold a pointer to the object). The buffer would be a member of that object. The HWND simply refers to the window that owns the object, and the Edit's WindowProc knows how the object is stored and thus how to access it (ie, by using GetWindowLongPtr() , etc) from whichever HWND is given to it. There is no list to look through.

If you want definitive implementation details , you will have to ask Microsoft for that (or otherwise reverse-engineer the user32 and comctl32 libraries, or find leaked source code online).

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