Message Handler win32

I am creating a program where when the user clicks on the window text is printed on the window at that position. I have posted my message handler I am just stuck on how you can find the mouse position and print text to that position.

to draw text into a window you need a device-context (DC) associated with that window.

You can retrieve such a DC i.e. using 'GetDC()' passing the handle of the window. Then you can write text using 'TextOut' or 'DrawText'.

You need to release the DC after finishing drawing using 'ReleaseDC'.

BTW you need to decide how your app should work: Just drawing a text into a window means the text will vanish next time the window is redrawn. If you want the text to stay you need to implement the drawing of the text within a WM_PAINT message handler. To do so you will need to store info about the texts generated by mouse clicks so the WM_PAINT message handler knows where to draw the texts.

I have added hdc = GetDC(hwnd); and the release of the DC at the end so far my code now looks like this. At the minute though the program is printing out the text to a set position how do I change it so that it checks where the mouse is and prints the text to that position.

I think ZOPPO has done everything except give complete code, so I will fill in that blank here. What follows is a rudimentary solution: you remember the location the mouse was clicked, then force a redraw on the window. Nice and simple.

Heh, no problem. It is a pretty dirty solution though, a far better one would have been to just draw the text again at the original location, except in the same colour as the background, thereby erasing it... but I guess we can leave that as an exercise to the questioner :)

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…

What is C++ STL?:
STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector.
…

The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…