Forum > Windows

WinAPI - examples - post 8

<< < (2/3) > >>

440bx:
Continued from previous post ...


Utility - ColorMixer           

This example which doubles as a simple color mixing/selection utility demonstrates how to eliminate flicker using ExtTextOut, Regions and InvalidateRect.

It uses all the methods to prevent flicker except double buffering.

In addition to that, it demonstrates how to use scroll bars as controls, how to subclass a window (in this case the scroll bars), how to handle keyboard input to set and select which scroll bar has the focus, as well as, setting the numeric value for each color (use arrow keys, home/end, page up/down), and how to process the WM_GETMINMAXINFO to set the minimum, maximum and maximized sizes of a window.

Aside from the 3 scroll bars that control the settings of the Red, Green and, blue colors, there is only _one_ window.  The right and left hand side are _not_ separate windows.

The example provides the option of displaying the coordinates of the various rectangles used to eliminate flicker by enabling the SHOW_RECTANGLE_COORDINATES define.

It also allows controlling whether or not the sample text will flicker by enabling or disabling the define NO_SAMPLE_TEXT_FLICKER.

The numeric values of Red, Green and Blue shown below the scroll bars are _not_ protected against flicker.  Grabbing any of the scroll bar thumbs and moving it up and down quickly for several seconds while paying close attention to the numbers will make a very slight amount of flicker visible.  Because the amount of flicker is usually not noticeable, there is no code to prevent it.  However, the same method used to ensure the sample text does not flicker can be used with the Red, Green and Blue values for a totally flicker free utility.

ColorMixer uses its own definitions for most of the APIs it uses.  The purpose of the definitions is to minimize the number of useless hints and give better parameter names, which are used by CODETOOLS, thereby providing better guidance when programming.


Continued on next post ...

440bx:
Continued from previous post ...


Dead BUG                       

There is a "dead" bug in DrawWindowFrame.  That function appears in multiple examples presented in Post 6.  The bug is as follows:
   
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---   SelectObject(dc, OldPen);          { restore the original pen               }  ReleaseDC(Wnd, dc);  DeleteObject(Pen);                 { get rid of the pen                     }   {---------------------------------------------------------------------------}  { release the window dc                                                     }   ReleaseDC(dc, Wnd);end;The last statement "ReleaseDC(dc, Wnd);" is erroneous for two reasons. First, the dc has already been released (just a few lines above) and second, the parameters in that call are reversed.   The erroneous statement has no effect on the proper operation of the examples in which it appears but should be removed.  Corrected code should read:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---   SelectObject(dc, OldPen);          { restore the original pen               }  ReleaseDC(Wnd, dc);   DeleteObject(Pen);                 { get rid of the pen                     }end;
The examples affected by the above bug are :

    GetDesktopWindow.lpr
    GetShellWindow.lpr
    GetTaskmanWindow.lpr
    GetTopLevelWindow.lpr
    IsTopLevelWindow.lpr
    GetWindowTextLength.lpr

Corrected versions of the source files above are attached to this post in the file named "CorrectionsToPost6Examples.7z"  (NOTE: only examples presented in Post 6 are affected.)




Enjoy!

Alextp:
Posted to wiki and Github.

440bx:

--- Quote from: Alextp on March 21, 2021, 06:50:00 pm ---Posted to wiki and Github.

--- End quote ---
Thank you Alexey.

Alextp:
Posts are in the Wiki:
https://wiki.freepascal.org/Windows_API_examples

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version