Author Topic: Colored Button  (Read 2234 times)

0 Members and 1 Guest are viewing this topic.

Nicola

  • Guest
Colored Button
« on: December 07, 2020, 02:24:22 PM »
Hi,
Excuse me for my very little experience in O2, but I can't color the buttons. I did a lot of research, but I couldn't find the right path.
Among other things I tried this, but it's not good ...

Code: OxygenBasic
  1. % IDC_BTN = 1005
  2. ...
  3. ...
  4. case WM_CREATE
  5. sys hBtn
  6.  hBtn=CreateWindowEx(0,"Button", "Stop", style,178, 58, 79, 24, hWin, IDC_BTN, inst, null)
  7.  SendMessaGE(hBtn,0x100A,IDC_BTN,red)
  8.  

The compiler does not detect errors, but the result is not as expected. Everything remains gray ...
Help please. :-[
« Last Edit: December 10, 2020, 01:54:46 AM by Nicola »

JRS

  • Guest
Re: Colored Button
« Reply #1 on: December 07, 2020, 03:33:05 PM »
Under the Windows API I believe you need to define it as a custom control. Unlike VB which allows changing it via a property setting.

Maybe this will help.

https://stackoverflow.com/questions/18745447/how-can-i-change-the-background-color-of-a-button-winapi-c

Nicola

  • Guest
Re: Colored Button
« Reply #2 on: December 08, 2020, 11:37:29 AM »
Hi john,
Really very interesting and also nice effect created.
But is there an easier way?
such as (in windows API)

SetBkColor (hwnd, Color)

JRS

  • Guest
Re: Colored Button
« Reply #3 on: December 08, 2020, 12:43:50 PM »
This is why I use VB6 and IUP for GUI projects. I'm too old to recreate the wheel.

Nicola

  • Guest
Re: Colored Button
« Reply #4 on: December 08, 2020, 12:49:00 PM »
lol
I have to learn how to use IUP, also because I understand that it is also used under other OS ...
 ;)

JRS

  • Guest
Re: Colored Button
« Reply #5 on: December 08, 2020, 01:16:33 PM »
IUP  is cross platform. Write once, run anywhere.

Nicola

  • Guest
Re: Colored Button
« Reply #6 on: December 09, 2020, 05:58:44 AM »
Ok about IUP.
However, I would like to ask a question: why the compiler does not detect any errors?
It doesn't detect any errors even if I use the command:

SetBkColor hBtn, white

So, the command is implemented and am I not using it correctly?
Or not?
 :-\

JRS

  • Guest
Re: Colored Button
« Reply #7 on: December 09, 2020, 10:56:21 AM »
Quote
If the function succeeds, the return value specifies the previous background color as a COLORREF value.

If the function fails, the return value is CLR_INVALID.


I don't think O2 would see this as an error.

Google is your friend and programming mentor.
« Last Edit: December 09, 2020, 12:34:40 PM by John »

Brian Alvarez

  • Guest
Re: Colored Button
« Reply #8 on: December 09, 2020, 08:53:28 PM »
...
So, the command is implemented and am I not using it correctly?
Or not?
 :-\

 What data types are hBtn and white? What values do they hold? What value does SetBkColor return?

Nicola

  • Guest
Re: Colored Button
« Reply #9 on: December 10, 2020, 01:50:29 AM »
Hi Brian.
hBtn is  SYS
The SETBKCOLOR gives value -1
I used this command line.

Print SetBkColor hBtn,0x00FF0000 'blue

Uhmm -1 is an error...

Code: OxygenBasic
  1.  
  2. $ filename "Prova_Button.exe"
  3. $ EscapeKeyEnd
  4.  
  5.   uses WinUtil
  6.  
  7.   MainWindow 271,118,WS_SYSMENU|WS_MINIMIZEBOX|WS_EX_TOPMOST
  8.  
  9.  % SWP_NOZORDER=4
  10.  % HWND_TOPMOST= -1
  11.  % DS_SETFONT=0x40
  12.                                                        
  13.  % IDD_MAIN = 1000
  14.  % IDC_LBL1 = 1001         ' LABEL
  15. % IDC_BTN  = 1002
  16.  
  17. global hWin As sys
  18. global ac as int
  19.  
  20. function WndProc(sys hWin, uMsg, wParam, lParam) as long callback
  21.   ================================================================
  22.   sys style
  23.    
  24.   select umsg
  25.  
  26.   case WM_CREATE
  27.  
  28.    style=WS_CHILD | WS_VISIBLE | ES_CENTER | DS_SETFONT
  29.    sys Lbl1=CreateWindowEx(0,"Static", "Hello", style, 0, 5, 264, 50, hWin, IDC_LBL1, inst, null)
  30.  
  31.    style=WS_CHILD | BS_TEXT ! BS_PUSHBOX | WS_VISIBLE
  32.    sys hBtn=CreateWindowEx(0,"Button", "Start", style,8, 58, 79, 24, hWin, IDC_BTN, inst, null)
  33.         print SetBkColor   hBtn,0x00FF0000 'blue
  34.        
  35.         SetWindowText hWin,"Nicola 12/2020"
  36.         SetWindowPos(hWin, HWND_TOPMOST,1,1,271,118)
  37.  
  38.     case WM_COMMAND
  39.  
  40.             select loword(wParam)
  41.                            
  42.                 case IDC_BTN   'start
  43.                         if ac=0 then
  44.                                 ac=1
  45.                         else
  46.                                 ac=0
  47.                         end if
  48.              
  49.             end select
  50.  
  51.     case WM_CLOSE
  52.       DestroyWindow(hWin)
  53.  
  54.     case WM_DESTROY:
  55.                 DestroyWindow(hWin)
  56.       PostQuitMessage 0
  57.  
  58.     case else
  59.  
  60.       return DefWindowProc(hWin, uMsg, wParam, lParam)
  61.     end select
  62.  
  63.         return 0
  64. end function
  65.  

JRS

  • Guest
Re: Colored Button
« Reply #10 on: December 10, 2020, 02:37:48 AM »
I think the easiest way to deal with your button color issue is use a bitmap image with a standard button. I'm sure there are tons of examples of owner draw buttons if this is something you will be dealing with more than once.

I can't wait to show off using VB6 ActiveX DLL forms as OLE automation objects once Charles releases his COM/OLE automation extension for O2.
« Last Edit: December 10, 2020, 02:45:03 AM by John »

Brian Alvarez

  • Guest
Re: Colored Button
« Reply #11 on: December 10, 2020, 04:34:14 PM »
Also, in some cases, you can check what error ocurred with the GetLastError() API.

Quote
https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror

Nicola

  • Guest
Re: Colored Button
« Reply #12 on: December 11, 2020, 06:18:14 AM »
GetLastError ()
gives the value 0

jack

  • Guest
Re: Colored Button
« Reply #13 on: December 11, 2020, 10:19:59 AM »
@Nicola
somebody tried to answer your questions here http://www.jose.it-berater.org/smfforum/index.php?topic=5739.0;topicseen

Nicola

  • Guest
Re: Colored Button
« Reply #14 on: December 13, 2020, 04:56:57 AM »
Hi Jack.
I saw the link he kindly gave me.
The proposed solution is a ploy, but it is not a real solution to my request. I have seen that in other basic language dialects the command is explicitly present. So, it seems very strange to me that O2 is not there.