Author Topic: A nice Ownerdraw Button project  (Read 1669 times)

0 Members and 1 Guest are viewing this topic.


  • Hero Member
  • *****
  • Posts: 977
A nice Ownerdraw Button project
« on: November 28, 2018, 05:17:37 am »
Hi Charles,

this is a nice little ownerdraw button project which I found here:

OwnerDraw Button & Regions demo

I ported the code to Oxygenbasic using the same logic as much as possible. It should run in 32-bit and 64-bit mode. Moving the mouse over a button should change the color. Clicking Btn1 and Exit should have an effect. Will this app run with the next O2 release too?

Attached is the resulting .o2bas file. As I also found the original c++ code, it would be interesting to use an object-oriented approach for this project. But I suppose this can wait a little bit.


Code: OxygenBasic
  1. '
  2. '--------------------------------------------------------------------------------
  3. ' Universal Button - beauty of HRGN
  4. ' Origional Author: Pavel A. Simakov
  5. ' Origional Code:
  6. '
  7. '
  8. ' MFC C++ to PowerBasic Conversion by Jules Marchildon. FEB.15th,2001
  9. '
  10. '
  11. ' Ported to Oxygenbasic
  12. ' No warrenty applies, use at your own risk...
  13. '--------------------------------------------------------------------------------
  15. $ filename "UniversalButton.exe"
  17. 'uses rtl32
  18. 'uses rtl64
  20. uses corewin
  22. ...


  • Hero Member
  • *****
  • Posts: 3966
Re: A nice Ownerdraw Button project
« Reply #1 on: November 28, 2018, 02:43:36 pm »
Patrice is the master of owner draw. His WinLift theming API is killer.

Mike Lobanovsky

  • Hero Member
  • *****
  • Posts: 1993
Re: A nice Ownerdraw Button project
« Reply #2 on: November 28, 2018, 04:12:32 pm »
Strictly speaking, Patrice's WinLIFT is not a theming framework, at least not in its window frame part. Patrice's frame windows have no native decorations (a.k.a. non-client areas) at all and are effectively bare border-less client area quads with the outlines elaborately dressed in matching textures to emulate custom drawn decorations. As a result, WinLIFT is unable to skin (theme) 3rd party windows such as e.g. message boxes or common dialogs even though they belong to the same process as the app main window and its siblings/children. The window "decorations" created with WinLIFT use transparent message pump subclassing to emulate non-client area hit tests to fool Windows into reacting to the mouse events as if they were occurring over Windows native decorations.

But the overall aesthetic effect is very cool indeed. Patrice is a very talented graphics designer and an able programmer too. :)

WinLIFT's custom controls are however built around the Windows common controls as they are. Wherever possible, WinLIFT uses (and sometimes overrides/suppresses) the common controls' built-in ownerdraw options to skin the controls in a style common with the emulated decorations of Patrice's "frame" windows, basically pretty much like what Roland's code does in O2, PB, and C++.
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
Re: A nice Ownerdraw Button project
« Reply #3 on: November 29, 2018, 07:28:35 pm »
Thanks, Roland.

I had a problem with istrue and isfalse when used without brackets.

But o2 will accept any primitive as a boolean in a simple if statement. It will even work with strings.

This resolves the problem:

% istrue
% isfalse not

Interesting example.


  • Hero Member
  • *****
  • Posts: 977
Re: A nice Ownerdraw Button project
« Reply #4 on: November 30, 2018, 12:23:34 am »
Hi Charles,

if this example (you know where I needed your help) will work with the next release of O2 without too many modifications, then this is really good news. Although it is old code it is still valid and instructive in several ways, at least for me.

As I applied unprototyped functions I used the console to fetch the runtime errors. I added after Winmain():
printl "Enter ... " : waitkey

If I do not see this prompt after closing the main window or if the console window disappears unexpectedly then something went wrong and I can add more print statements to find out the reason. For me the console is a very good debugging tool. Eventually I will hopefully be able to use also your diagnostic tools and Laurent's O2debugger to be more efficient.

Btw: the defines of istrue and isfalse are really brilliant. I did not understand them immediately.

« Last Edit: November 30, 2018, 12:47:21 am by Arnold »