When I click on button, might be in windows apps, web apps, etc it has some animation to actually see it clicked and event is raised in background. I've knowledge of events and its attaching to button click events but I wanted to know how this mechanism works. I always assumed it is inbuilt in operating systems.
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
Obviously the implementation is different for different operating systems. In particular Windows lumps a lot of the layers together for the programmer and user point of view, but that's the basic lay of the land. I gave you some names for Linux because those are open source and if you were so inclined you could trace everything from the silicon on up. Qt and other widget toolkits, which seems to be the part you're most interested in, are also available for Windows.
It's pretty amazing to contemplate the precise flow of electrons needed starting at the mouse button switch, through the CPU, out to the Internet and back through countless routers and servers, back through your CPU, eventually resulting in every single pixel on your display being commanded to its own specific color. We sum up that result of millions of hours of collaborative effort simply as "clicking a link."
There really isn't an interface. There is the object that raises the event and then a delegate(s) that handles the event. The object that raises the event has no idea who/what/how the event will be handled. It just raises the event with any relevant data on the message so that the delegate(s) can handle it properly.
The delegate has to register itself as a handler for that event.
Something like this:
Then there will be the method that will handle the event:
Its not garanteed that "Event Driven Programming Model" will exist on your platform or environment. It so happens on Windows that this is supported.
With .Net, the support is baked with the ability to raise events and use delegates to handle them. There also built in async support as well.
Underlying, the OS (Windows) has a message pump or loop which is constantly cycling and handling messages that are posted. Typically, in higher level languages you do not have to interact with the internals as these are shielded from you from the framework with namespaces such as
You can learn more abou the message pump here: