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

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
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
https://forum.powerbasic.com/forum/user-to-user-discussions/source-code/23540-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.

Roland

Code: OxygenBasic
  1. 'https://forum.powerbasic.com/forum/user-to-user-discussions/source-code/23540-ownerdraw-button-regions-demo
  2. '--------------------------------------------------------------------------------
  3. ' Universal Button - beauty of HRGN
  4. ' Origional Author: Pavel A. Simakov
  5. ' Origional Code:
  6. 'https://www.codeguru.com/cpp/controls/buttonctrl/non-rectangularbuttons/article.php/c2085/Universal-Button--beauty-of-HRGN.htm
  7. '
  8. ' MFC C++ to PowerBasic Conversion by Jules Marchildon. FEB.15th,2001
  9. 'https://forum.powerbasic.com/forum/user-to-user-discussions/source-code/23540-ownerdraw-button-regions-demo
  10. '
  11. ' Ported to Oxygenbasic
  12. ' No warrenty applies, use at your own risk...
  13. '--------------------------------------------------------------------------------
  14.  
  15. $ filename "UniversalButton.exe"
  16.  
  17. 'uses rtl32
  18. 'uses rtl64
  19.  
  20. uses corewin
  21.  
  22. ...
  23.  

JRS

  • Guest
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

  • Guest
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++.

Charles Pegge

  • Guest
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.

Arnold

  • Guest
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.

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