Continuation of this topic . There is a class Foo (for example), which is a container, it has a panel in it which will be titlte bar. Ie, I cannot add code to the class of the main window and therefore it is not possible to process the message in wndProc. But how then to return the result HTCAPTION for this window.
- Do you need to return HTCAPTION to whom? If in response to a window message NC_HITTEST, coming from WndProc, I think the answer is self-evident. I would advise you to remake the architecture of the application so that the panel representing the title bar has access / influence on WndProc. - VladD
- "Do you need to return HTCAPTION to whom?" The main window in which my element is located. "If, in response to the window message NC_HITTEST, coming from WndProc, I think the answer is self-evident." Do not quite understand. I need on WM_NCHITTEST for the panel I need to return HTCAPTION for the main form. - cyber_ua
- unsafe and Win API. If the window, the title of which you want to receive, is not created in your process, then only FindWindowEx will help you - uilenspiegel
- And then another process? This window is the parent of my item. - cyber_ua
- @cyber_ua: well, you can also return to the main window: let it find the control at the right point on WM_HITTEST, and ask the control it found about its HITTEST code. If you have WPF, this is perfectly organized through attached properties. If WinForms, have to manually. - VladD
1 answer
let it find the WM_HITTEST control at the right point, and ask the control it found about its HITTEST code
@VladD, do not do this. The vehicle, apparently, has another question: how, without changing the main window's WndProc
, add its exclusive functionality.
-
@cyber_ua, is it possible to inherit the class of the main window from another window class?
-
In other words, is it possible to use superclassing ?
-
Actually, in my opinion, to solve the problem it is difficult to think of another way:
- Create your own window class, in which dynamically add a child panel to
WM_CREATE
, in whichWM_NCHITTEST
will returnTRANSPARENT
, andWM_NCHITTEST
withHTCAPTION
will be processed in the mainWndProc
. - Highlight this
WndProc
in the dynamic link library. - In her
DllMain
list the registration and removal of its class. - Connect it to an arbitrary project and inherit the main form from your class in
CreateParams
.
You will be able to connect your exclusive component to arbitrary projects, and, moreover, these will not even necessarily be Си#
projects.
ps: I just want to note that VS does not use child windows to display its title, it simply draws the title on the main form, this is a more “advanced” method, because requires much less resources.
- "Actually, in my opinion, it’s hard to come up with another way to solve the problem" The bottom line is: 1. create a class that inherits from Form. 2. add the necessary code and then what would it inherit (this class) user form? About superclassing did not quite understand. - cyber_ua
- one> The bottom line is Yes, the bottom line is this. > About superclassing, I did not quite understand Subclassing - this is a substitution of the window procedure at some point in time, and superclassing is an inheritance of the window procedure. - The concepts are almost the same, but in the case of superclassing, the window procedure is replaced at the stage of registering the window class . - In the case that I described with the
DLL
, it turns out that any message sent to the user form will be first processed by the user window procedure, and then, if the user does not decide otherwise, yours. - mega - oneThose. Your added functionality will be outside the user's window procedure in your library. - mega
- oneYou are welcome! > Do not advise literature where you can read about working with winapi?
WinAPI
is a fairly large system with many subsystems. In today's ordinary life, all this material is not required by the programmer. But on the window and graphics subsystem Petzold has a good guide , you can read. And do not look that it is old, this subsystem is conservative enough for time to have a strong influence on it. The main thing is that the author's text is clear. - mega - oneTrue, no book will replace the most detailed documentation from the developer . So, I advise: first read the manual in Russian, and places that are particularly interested - to fix in
MSDN
. - mega