changing main windowcolor using API

Windows specific forum
ly47
User
User
Posts: 23
Joined: Mon May 05, 2014 6:51 pm

changing main windowcolor using API

Post by ly47 »

Hi
The following code does not work with PureBasic.
(I'm using API calls and not PureBasic native code)
This code works fine using FreeBasic.
Please help.
Thanks
ly

Code: Select all

Declare SetWinColor(hWnd, clr)

Global wc.WNDCLASSEX, hInstance, msg.MSG

hInstance = GetModuleHandle_( null )

Enumeration
	#Button_1
	#Button_2
	#Button_3
EndEnumeration

#Style = #WS_OVERLAPPEDWINDOW | #WS_VISIBLE

Procedure WindowCallback(hWnd, uMsg, wParam, lParam) 

	Select uMsg 
			
		Case #WM_CREATE
						
			hBtn1 = CreateWindowEx_(0, "Button", "Exit", #WS_CHILD | #WS_VISIBLE, 520, 328, 60, 25, hWnd, #Button_1, hInstance, 0)
			hBtn2 = CreateWindowEx_(0, "Button", "RED", #WS_CHILD | #WS_VISIBLE, 440, 328, 60, 25, hWnd, #Button_2,hInstance, 0)
			hBtn2 = CreateWindowEx_(0, "Button", "BLUE", #WS_CHILD | #WS_VISIBLE, 360, 328, 60, 25, hWnd, #Button_3, hInstance, 0)
		
		Case #WM_COMMAND
			
			Select wParam
				
				Case #Button_1
					
					Debug "#Button_1"
					
					PostQuitMessage_(0)
					
				Case #Button_2
					
					Debug "#Button_2"
					
					SetWinColor(hWnd,RGB(233,95,85))
					InvalidateRect_(hWnd,False,True)
					UpdateWindow_(hWnd)
					
				Case  #Button_3
					
					Debug "#Button_3"
					
					SetWinColor(hWnd, RGB(85,95,233))
					InvalidateRect_(hWnd,False,True)
					UpdateWindow_(hWnd)
					
			EndSelect

		Case #WM_CLOSE 
			DestroyWindow_(Window) 
			Result  = 0 
		Case #WM_DESTROY 
			PostQuitMessage_(0) 
			Result  = 0 
		Default 
			Result  = DefWindowProc_(hWnd, uMsg, wParam, lParam) 
	EndSelect 
	ProcedureReturn Result 
EndProcedure  

Define.s appName
appName = "Win32" 

	wc\style         = #CS_HREDRAW | #CS_VREDRAW 
	wc\cbsize  = SizeOf(WNDCLASSEX) 
	wc\lpfnWndProc  = @WindowCallback() 
	wc\hInstance     = hInstance 
	wc\hIcon         = LoadIcon_(0, #IDI_APPLICATION ) 
	wc\hCursor  = LoadCursor_(0,#IDC_ARROW)
	wc\hbrBackground  = #COLOR_WINDOW + 1
	wc\lpszMenuName  = 0
	wc\lpszClassName  = @appName

;	RegisterClassEx_(@wc) 
	
 	If ( RegisterClassEx_( @wc ) = false ) 
         MessageBox_( null, "Failed to register wc!", appName, #MB_ICONERROR )
         End 1
        EndIf 

hWnd  = CreateWindowEx_(0, appName, "Simple", #Style, 100, 100, 600, 450, 0, 0, hInstance, 0) 

ShowWindow_(hWnd,  #SW_SHOWDEFAULT) 
UpdateWindow_(hWnd)
SetForegroundWindow_(hWnd)

While GetMessage_(msg, 0, 0, 0 ) 
	TranslateMessage_(msg) 
	DispatchMessage_(msg) 
Wend
    
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Procedure SetWinColor(hWnd, clr)
	Static obj, hbr

	hbr = CreateSolidBrush_(clr)
	obj  = SetClassLongPtr_(hWnd ,#GCL_HBRBACKGROUND ,hbr)
	DeleteObject_(obj)
	RedrawWindow_(hWnd, 0, 0, 0)
	
	ProcedureReturn 0
EndProcedure
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: changing main windowcolor using API

Post by ts-soft »

Some Variables / Constants false:

Code: Select all

EnableExplicit

Declare SetWinColor(hWnd, clr)

Global wc.WNDCLASSEX, hInstance, msg.MSG

hInstance = GetModuleHandle_( #Null )

Enumeration
  #Button_1
  #Button_2
  #Button_3
EndEnumeration

#Style = #WS_OVERLAPPEDWINDOW | #WS_VISIBLE

Procedure WindowCallback(hWnd, uMsg, wParam, lParam)
  Protected hBtn1, hBtn2, hBtn3, Result
  
  Select uMsg
      
    Case #WM_CREATE
      
      hBtn1 = CreateWindowEx_(0, "Button", "Exit", #WS_CHILD | #WS_VISIBLE, 520, 328, 60, 25, hWnd, #Button_1, hInstance, 0)
      hBtn2 = CreateWindowEx_(0, "Button", "RED", #WS_CHILD | #WS_VISIBLE, 440, 328, 60, 25, hWnd, #Button_2,hInstance, 0)
      hBtn3 = CreateWindowEx_(0, "Button", "BLUE", #WS_CHILD | #WS_VISIBLE, 360, 328, 60, 25, hWnd, #Button_3, hInstance, 0)
      
    Case #WM_COMMAND
      
      Select wParam
          
        Case #Button_1
          
          Debug "#Button_1"
          
          PostQuitMessage_(0)
          
        Case #Button_2
          
          Debug "#Button_2"
          
          SetWinColor(hWnd,RGB(233,95,85))
          InvalidateRect_(hWnd, #False, #True)
          UpdateWindow_(hWnd)
          
        Case  #Button_3
          
          Debug "#Button_3"
          
          SetWinColor(hWnd, RGB(85,95,233))
          InvalidateRect_(hWnd, #False, #True)
          UpdateWindow_(hWnd)
          
      EndSelect
      
    Case #WM_CLOSE
      DestroyWindow_(hWnd)
      Result  = 0
    Case #WM_DESTROY
      PostQuitMessage_(0)
      Result  = 0
    Default
      Result  = DefWindowProc_(hWnd, uMsg, wParam, lParam)
  EndSelect
  ProcedureReturn Result
EndProcedure 

Define.s appName
appName = "Win32"

wc\style         = #CS_HREDRAW | #CS_VREDRAW
wc\cbsize  = SizeOf(WNDCLASSEX)
wc\lpfnWndProc  = @WindowCallback()
wc\hInstance     = hInstance
wc\hIcon         = LoadIcon_(0, #IDI_APPLICATION )
wc\hCursor  = LoadCursor_(0,#IDC_ARROW)
wc\hbrBackground  = #COLOR_WINDOW + 1
wc\lpszMenuName  = 0
wc\lpszClassName  = @appName

;   RegisterClassEx_(@wc)

If ( RegisterClassEx_( @wc ) = #False )
  MessageBox_( #Null, "Failed to register wc!", appName, #MB_ICONERROR )
  End 1
EndIf

Define hWnd  = CreateWindowEx_(0, appName, "Simple", #Style, 100, 100, 600, 450, 0, 0, hInstance, 0)

ShowWindow_(hWnd,  #SW_SHOWDEFAULT)
UpdateWindow_(hWnd)
SetForegroundWindow_(hWnd)

While GetMessage_(msg, 0, 0, 0 )
  TranslateMessage_(msg)
  DispatchMessage_(msg)
Wend

; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Procedure SetWinColor(hWnd, clr)
  Static obj, hbr
  
  hbr = CreateSolidBrush_(clr)
  obj  = SetClassLongPtr_(hWnd ,#GCL_HBRBACKGROUND ,hbr)
  DeleteObject_(obj)
  RedrawWindow_(hWnd, 0, 0, 0)
  
  ProcedureReturn 0
EndProcedure 
You should better use EnableExplicit

Greetings
Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
ly47
User
User
Posts: 23
Joined: Mon May 05, 2014 6:51 pm

Re: changing main windowcolor using API

Post by ly47 »

Hi Thomas
Thanks a lot.
ly
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: changing main windowcolor using API

Post by TI-994A »

ly47 wrote:I'm using API calls and not PureBasic native code
Hi ly47, and welcome to the PureBasic forum. :)

I'm sure that you'd have your reasons for utilising API functions, but here's what your code looks like in native PureBasic:

Code: Select all

wFlags = #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
wnd1 = OpenWindow(#PB_Any, 100, 100, 600, 450, "Simple", wFlags)
btn1 = ButtonGadget(#PB_Any, 520, 328, 60, 25, "Exit")
btn2 = ButtonGadget(#PB_Any, 440, 328, 60, 25, "RED")
btn3 = ButtonGadget(#PB_Any, 360, 328, 60, 25, "BLUE")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      appQuit = 1
    Case #PB_Event_Gadget
      Select EventGadget()
        Case btn1
          appQuit = 1
        Case btn2
          SetWindowColor(wnd1, RGB(233, 95, 85))
        Case btn3
          SetWindowColor(wnd1, RGB(85, 95, 233))
      EndSelect
  EndSelect
Until appQuit = 1
Short, sharp, and so simple! :D
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
ly47
User
User
Posts: 23
Joined: Mon May 05, 2014 6:51 pm

Re: changing main windowcolor using API

Post by ly47 »

hi TI-994A
Thanks.
I know that in native PureBasic dialect it is very short and simple, and I know how to do it,
but I wanted to test pure Win32 API codes with PureBasic to see how it works...
If you want to understand how API works than you have to write some native API codes(just for learning purpose)
Thanks again
ly

BTW
the exe file created with native PB is 22,528 bytes ,compared to native PB API only 13,312 bytes, and it seems that the API version
is faster...
(The same code compiled with FreeBasic produces exe 17,408 bytes)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: changing main windowcolor using API

Post by RASHAD »

Using your own code

Code: Select all

;Declare SetWinColor(hWnd, clr)

Global wc.WNDCLASSEX, hInstance, msg.MSG,b.LOGBRUSH

b\lbStyle = #BS_SOLID

hInstance = GetModuleHandle_( null )

Enumeration
   #Button_1
   #Button_2
   #Button_3
EndEnumeration

#Style = #WS_OVERLAPPEDWINDOW | #WS_VISIBLE

Procedure WindowCallback(hWnd, uMsg, wParam, lParam) 

   Select uMsg 
         
      Case #WM_CREATE
                  
         hBtn1 = CreateWindowEx_(0, "Button", "Exit", #WS_CHILD | #WS_VISIBLE, 520, 328, 60, 25, hWnd, #Button_1, hInstance, 0)
         hBtn2 = CreateWindowEx_(0, "Button", "RED", #WS_CHILD | #WS_VISIBLE, 440, 328, 60, 25, hWnd, #Button_2,hInstance, 0)
         hBtn2 = CreateWindowEx_(0, "Button", "BLUE", #WS_CHILD | #WS_VISIBLE, 360, 328, 60, 25, hWnd, #Button_3, hInstance, 0)
      
      Case #WM_COMMAND
         
         Select wParam
            
            Case #Button_1
               
               Debug "#Button_1"
               
               PostQuitMessage_(0)
               
            Case #Button_2               
               Debug "#Button_2"	
               b\lbColor = $0000FF
               DeleteObject_(hBrush)
               hBrush = CreateBrushIndirect_(b)
               SetClassLongPtr_(hWnd, #GCL_HBRBACKGROUND, hBrush)
               InvalidateRect_(hWnd, 0, 1)
               
            Case  #Button_3               
               Debug "#Button_3"
               b\lbColor = $FF0000
               DeleteObject_(hBrush)
               hBrush = CreateBrushIndirect_(b)
               SetClassLongPtr_(hWnd, #GCL_HBRBACKGROUND, hBrush)
               InvalidateRect_(hWnd, 0, 1)
               
         EndSelect

      Case #WM_CLOSE 
         DestroyWindow_(Window) 
         Result  = 0 
      Case #WM_DESTROY 
         PostQuitMessage_(0) 
         Result  = 0 
      Default 
         Result  = DefWindowProc_(hWnd, uMsg, wParam, lParam) 
   EndSelect 
   ProcedureReturn Result 
EndProcedure  

Define.s appName
appName = "Win32" 

   wc\style         = #CS_HREDRAW | #CS_VREDRAW 
   wc\cbsize  = SizeOf(WNDCLASSEX) 
   wc\lpfnWndProc  = @WindowCallback() 
   wc\hInstance     = hInstance 
   wc\hIcon         = LoadIcon_(0, #IDI_APPLICATION ) 
   wc\hCursor  = LoadCursor_(0,#IDC_ARROW)
   wc\hbrBackground  = #COLOR_WINDOW + 1
   wc\lpszMenuName  = 0
   wc\lpszClassName  = @appName

;   RegisterClassEx_(@wc) 
   
    If ( RegisterClassEx_( @wc ) = false ) 
         MessageBox_( null, "Failed to register wc!", appName, #MB_ICONERROR )
         End 1
        EndIf 

hWnd  = CreateWindowEx_(0, appName, "Simple", #Style, 100, 100, 600, 450, 0, 0, hInstance, 0) 

ShowWindow_(hWnd,  #SW_SHOWDEFAULT) 
UpdateWindow_(hWnd)
SetForegroundWindow_(hWnd)

While GetMessage_(msg, 0, 0, 0 ) 
   TranslateMessage_(msg) 
   DispatchMessage_(msg) 
Wend
    
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

; Procedure SetWinColor(hWnd, clr)
;    Static obj, hbr
; 
;    hbr = CreateSolidBrush_(clr)
;    obj  = SetClassLongPtr_(hWnd ,#GCL_HBRBACKGROUND ,hbr)
;    DeleteObject_(obj)
;    RedrawWindow_(hWnd, 0, 0, 0)
;    
;    ProcedureReturn 0
; EndProcedure
Egypt my love
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: changing main windowcolor using API

Post by TI-994A »

ly47 wrote:the exe file created with native PB is 22,528 bytes ,compared to native PB API only 13,312 bytes...
But would the API code run on OSX or Linux? :wink:

Enough said. :lol:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
ly47
User
User
Posts: 23
Joined: Mon May 05, 2014 6:51 pm

Re: changing main windowcolor using API

Post by ly47 »

Hi RASHAD

Thanks for your modified code.

I have added a status bar, it appears but does not receive any string message.
I don't know why(same code in FreeBasic works)

thanks
ly

Code: Select all

;Declare SetWinColor(hWnd, clr)

Global wc.WNDCLASSEX, hInstance, msg.MSG,b.LOGBRUSH

b\lbStyle = #BS_SOLID

hInstance = GetModuleHandle_( null )

Enumeration
   #Button_1
   #Button_2
   #Button_3
EndEnumeration

; #Style = #WS_OVERLAPPEDWINDOW | #WS_VISIBLE
#Style = #WS_VISIBLE | #WS_DLGFRAME | #WS_SYSMENU | #WS_MINIMIZEBOX

Procedure WindowCallback(hWnd, uMsg, wParam, lParam) 

   Select uMsg 
         
      Case #WM_CREATE
                  
         hBtn1 = CreateWindowEx_(0, "Button", "Exit", #WS_CHILD | #WS_VISIBLE, 520, 328, 60, 25, hWnd, #Button_1, hInstance, 0)
         hBtn2 = CreateWindowEx_(0, "Button", "RED", #WS_CHILD | #WS_VISIBLE, 440, 328, 60, 25, hWnd, #Button_2,hInstance, 0)
         hBtn2 = CreateWindowEx_(0, "Button", "BLUE", #WS_CHILD | #WS_VISIBLE, 360, 328, 60, 25, hWnd, #Button_3, hInstance, 0)
         
         hStatus = CreateWindowEx_(0,
                                   #STATUSCLASSNAME,0, 
                                   #SBARS_SIZEGRIP | #WS_CHILD | #WS_VISIBLE,
                                   0, 0, 0, 0,
                                   hWnd , idStatus,hInstance,#Null)
         
      Case #WM_COMMAND
         
         Select wParam
            
            Case #Button_1
               
               Debug "#Button_1 EXIT"
               
               PostQuitMessage_(0)
               
            Case #Button_2               
;                Debug "#Button_2"   
               b\lbColor = $0000FF
               DeleteObject_(hBrush)
               hBrush = CreateBrushIndirect_(b)
               SetClassLongPtr_(hWnd, #GCL_HBRBACKGROUND, hBrush)
               InvalidateRect_(hWnd, 0, 1)
               
               	Define statusText$ = "RED"
				Debug statusText$
							
    			SendMessage_(hStatus,#WM_SETTEXT,0,@statusText$)
               
            Case  #Button_3               
;                Debug "#Button_3"
               b\lbColor = $FF0000
               DeleteObject_(hBrush)
               hBrush = CreateBrushIndirect_(b)
               SetClassLongPtr_(hWnd, #GCL_HBRBACKGROUND, hBrush)
               InvalidateRect_(hWnd, 0, 1)
               
               Define statusText$ = "BLUE"
			   Debug statusText$
							
				SendMessage_(hStatus,#WM_SETTEXT,0,@statusText$)
				
         EndSelect

      Case #WM_CLOSE 
         DestroyWindow_(hWnd) 
         Result  = 0 
      Case #WM_DESTROY 
         PostQuitMessage_(0) 
         Result  = 0 
      Default 
         Result  = DefWindowProc_(hWnd, uMsg, wParam, lParam) 
   EndSelect 
   ProcedureReturn Result 
EndProcedure  

Define.s appName
appName = "Win32" 

   wc\style         = #CS_HREDRAW | #CS_VREDRAW 
   wc\cbsize  = SizeOf(WNDCLASSEX) 
   wc\lpfnWndProc  = @WindowCallback() 
   wc\hInstance     = hInstance 
   wc\hIcon         = LoadIcon_(0, #IDI_APPLICATION ) 
   wc\hCursor  = LoadCursor_(0,#IDC_ARROW)
   wc\hbrBackground  = #COLOR_WINDOW + 1
   wc\lpszMenuName  = 0
   wc\lpszClassName  = @appName

;   RegisterClassEx_(@wc) 
   
    If ( RegisterClassEx_( @wc ) = false ) 
         MessageBox_( null, "Failed to register wc!", appName, #MB_ICONERROR )
         End 1
        EndIf 

hWnd  = CreateWindowEx_(0, appName, "Simple", #Style, 100, 100, 600, 450, 0, 0, hInstance, 0) 

ShowWindow_(hWnd,  #SW_SHOWDEFAULT) 
UpdateWindow_(hWnd)
SetForegroundWindow_(hWnd)

While GetMessage_(msg, 0, 0, 0 ) 
   TranslateMessage_(msg) 
   DispatchMessage_(msg) 
Wend
    
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

; Procedure SetWinColor(hWnd, clr)
;    Static obj, hbr
; 
;    hbr = CreateSolidBrush_(clr)
;    obj  = SetClassLongPtr_(hWnd ,#GCL_HBRBACKGROUND ,hbr)
;    DeleteObject_(obj)
;    RedrawWindow_(hWnd, 0, 0, 0)
;    
;    ProcedureReturn 0
; EndProcedure
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: changing main windowcolor using API

Post by RASHAD »

Hi

Code: Select all

;Declare SetWinColor(hWnd, clr)

Global wc.WNDCLASSEX, hInstance, msg.MSG,b.LOGBRUSH,hStatus

b\lbStyle = #BS_SOLID

hInstance = GetModuleHandle_( null )

Global Dim Parts(3)
Parts(0) = 100
Parts(1) = 280
Parts(2) = 380

Enumeration
   #Button_1
   #Button_2
   #Button_3
EndEnumeration

; #Style = #WS_OVERLAPPEDWINDOW | #WS_VISIBLE
#Style = #WS_VISIBLE | #WS_DLGFRAME | #WS_SYSMENU | #WS_MINIMIZEBOX

Procedure WindowCallback(hWnd, uMsg, wParam, lParam) 

   Select uMsg 
         
      Case #WM_CREATE
                  
         hBtn1 = CreateWindowEx_(0, "Button", "Exit", #WS_CHILD | #WS_VISIBLE, 520, 328, 60, 25, hWnd, #Button_1, hInstance, 0)
         hBtn2 = CreateWindowEx_(0, "Button", "RED", #WS_CHILD | #WS_VISIBLE, 440, 328, 60, 25, hWnd, #Button_2,hInstance, 0)
         hBtn2 = CreateWindowEx_(0, "Button", "BLUE", #WS_CHILD | #WS_VISIBLE, 360, 328, 60, 25, hWnd, #Button_3, hInstance, 0)
         
         hStatus = CreateWindowEx_(0,
                                   #STATUSCLASSNAME,0, 
                                   #SBARS_SIZEGRIP | #WS_CHILD | #WS_VISIBLE,
                                   0, 0, 0, 0,
                                   hWnd , idStatus,hInstance,#Null)
         SendMessage_(hStatus, #SB_SETPARTS, 3, @Parts())
         
      Case #WM_COMMAND
         
         Select wParam
            
            Case #Button_1
               
               Debug "#Button_1 EXIT"
               
               PostQuitMessage_(0)
               
            Case #Button_2
               b\lbColor = $0000FF
               DeleteObject_(hBrush)
               hBrush = CreateBrushIndirect_(b)
               SetClassLongPtr_(hWnd, #GCL_HBRBACKGROUND, hBrush)
               InvalidateRect_(hWnd, 0, 1)                              
               SendMessage_(hStatus, #SB_SETTEXT, 0, "  Red")
               SendMessage_(hStatus, #SB_SETTEXT, 1, "  #Button_2 clicked")
               
            Case  #Button_3 
               b\lbColor = $FF0000
               DeleteObject_(hBrush)
               hBrush = CreateBrushIndirect_(b)
               SetClassLongPtr_(hWnd, #GCL_HBRBACKGROUND, hBrush)
               InvalidateRect_(hWnd, 0, 1)
               SendMessage_(hStatus, #SB_SETTEXT, 0, "  Blue")
               SendMessage_(hStatus, #SB_SETTEXT, 1, "  #Button_3 clicked")               
            
         EndSelect

      Case #WM_CLOSE
          DestroyWindow_(hWnd) 
          
      Case #WM_DESTROY 
         PostQuitMessage_(0) 
         Result  = 0 
      Default 
         Result  = DefWindowProc_(hWnd, uMsg, wParam, lParam) 
   EndSelect 
   ProcedureReturn Result 
EndProcedure  

Define.s appName
appName = "Win32" 

   wc\style         = #CS_HREDRAW | #CS_VREDRAW 
   wc\cbsize  = SizeOf(WNDCLASSEX) 
   wc\lpfnWndProc  = @WindowCallback() 
   wc\hInstance     = hInstance 
   wc\hIcon         = LoadIcon_(0, #IDI_APPLICATION ) 
   wc\hCursor  = LoadCursor_(0,#IDC_ARROW)
   wc\hbrBackground  = #COLOR_WINDOW + 1
   wc\lpszMenuName  = 0
   wc\lpszClassName  = @appName

;   RegisterClassEx_(@wc) 
   
    If ( RegisterClassEx_( @wc ) = false ) 
         MessageBox_( null, "Failed to register wc!", appName, #MB_ICONERROR )
         End 1
        EndIf 

hWnd  = CreateWindowEx_(0, appName, "Simple", #Style, 100, 100, 600, 450, 0, 0, hInstance, 0) 

ShowWindow_(hWnd,  #SW_SHOWDEFAULT) 
UpdateWindow_(hWnd)
SetForegroundWindow_(hWnd)

While GetMessage_(msg, 0, 0, 0 ) 
   TranslateMessage_(msg) 
   DispatchMessage_(msg) 
Wend
    
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

; Procedure SetWinColor(hWnd, clr)
;    Static obj, hbr
; 
;    hbr = CreateSolidBrush_(clr)
;    obj  = SetClassLongPtr_(hWnd ,#GCL_HBRBACKGROUND ,hbr)
;    DeleteObject_(obj)
;    RedrawWindow_(hWnd, 0, 0, 0)
;    
;    ProcedureReturn 0
; EndProcedure
Egypt my love
ly47
User
User
Posts: 23
Joined: Mon May 05, 2014 6:51 pm

Re: changing main windowcolor using API

Post by ly47 »

Hi RASHAD
Thanks a lot again
ly
ly47
User
User
Posts: 23
Joined: Mon May 05, 2014 6:51 pm

Re: changing main windowcolor using API

Post by ly47 »

TI-994A wrote:
ly47 wrote:the exe file created with native PB is 22,528 bytes ,compared to native PB API only 13,312 bytes...
But would the API code run on OSX or Linux? :wink:

Enough said. :lol:
Hi TI-994A

No API code does not run on Linux.
I have tried on Linux (mint-16) on VirtualBox.
I don't have OSX so I can't tell you, but I assume it would not work.

Even native PB code which run perfect on Windows but not perfect on Linux.(I have tried it on a complex code)
May be because I have used VirtualBox to run Linux.
ly
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: changing main windowcolor using API

Post by Thunder93 »

TI-994A, LOL!

@ly47, TI-994A already knew the answer to that question. ;p

TI-994A is basically saying that the file size increase is due to PureBasic making it support other platforms. When you use Windows APIs you target just Windows. Later if you decide to make it support other platforms, you'll need to work more.

If you know Windows be the only target platform, or you don't mind maintaining multiple source codes for this application. Specifically coding to Windows, use of winAPIs would make the application smaller.


Because you using PB native code doesn't mean the native code all cross-platforms supported. You have to see documentation to ensure you using that's cross-platform supported.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: changing main windowcolor using API

Post by Dude »

Thunder93 wrote:the file size increase is due to PureBasic making it support other platforms.
What the? That's gotta be wrong. You're saying a Windows executable built using native PureBasic commands also has Linux and Mac code in it? :shock:
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: changing main windowcolor using API

Post by Demivec »

Dude wrote:
Thunder93 wrote:the file size increase is due to PureBasic making it support other platforms.
What the? That's gotta be wrong. You're saying a Windows executable built using native PureBasic commands also has Linux and Mac code in it? :shock:
@Dude: No. I think he is saying that the code for the API's is wrapped in code PureBasic uses to standardize things between the different platforms.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: changing main windowcolor using API

Post by Marc56us »

There are several advantages to program directly in PureBasic and prevent the direct use of APIs, even if the code is (slightly) bigger and even if we do program for Windows Only.

- The code is much more readable (Think of the potential code maintenance in a few months or years.)
- There is no need to have access to MSDN to find the syntax of a command, simply press F1
- PB commands are adapted to the API, even if API change over time, there is often no need to change the PB code.

:wink:
Post Reply