It is currently Wed Oct 28, 2020 8:48 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Make a ComboboxGadget Flat
PostPosted: Sun May 27, 2007 1:50 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Aug 05, 2003 11:30 pm
Posts: 448
Ok here a small example how you can make a Combobox flat.
I hope you like it :wink:

Code:
; Make a Combobox Flat
; for PureBasic 4.x
; by Nico Grüner, forum-nick: "nicolaus"
; 27.05.2007 for german and English PureBasic forum


Global OldComboProc, hdc
Global ps.PAINTSTRUCT
Global rect.RECT
Global rect2.RECT
Global pt.POINT
Global fMouseDown
Global fButtonDown
fMouseDown   = #False
fButtonDown  = #False



Macro LOWORD(Value)
  Value & $FFFF
EndMacro
Macro HIWORD(Value)
  (Value >> 16) & $FFFF
EndMacro
 
Procedure FlatComboProc( hwnd,  msg, wParam,  lParam)
  OldComboProc = GetWindowLong_(hwnd, #GWL_USERDATA)
 
  Select msg
    Case #WM_PAINT
      If wParam = 0      
        hdc = BeginPaint_(hwnd, ps)
      Else
        hdc = wParam
      EndIf
     
      GetClientRect_(hwnd, rect)
      InflateRect_(rect, -GetSystemMetrics_(#SM_CXEDGE), -GetSystemMetrics_(#SM_CYEDGE))
      rect\right = rect\right - GetSystemMetrics_(#SM_CXVSCROLL)
      IntersectClipRect_(hdc, rect\left, rect\top, rect\right, rect\bottom)
     
      CallWindowProc_(OldComboProc, hwnd, msg, hdc, lParam)
     
      SelectClipRgn_(hdc, null)
      rect\right = rect\right + GetSystemMetrics_(#SM_CXVSCROLL)
     
      ExcludeClipRect_(hdc, rect\left, rect\top, rect\right, rect\bottom)
     
      GetClientRect_(hwnd, rect2)
      FillRect_(hdc, rect2, GetSysColorBrush_(#COLOR_3DSHADOW))
     
      SelectClipRgn_(hdc, #Null)
      rect\left = rect\right - GetSystemMetrics_(#SM_CXVSCROLL)
     
      If fButtonDown
        DrawFrameControl_(hdc, rect, #DFC_SCROLL, #DFCS_SCROLLCOMBOBOX|#DFCS_FLAT|#DFCS_PUSHED)
      Else
        DrawFrameControl_(hdc, rect, #DFC_SCROLL, #DFCS_SCROLLCOMBOBOX|#DFCS_FLAT)
      EndIf
       
      If wParam = 0
        EndPaint_(hwnd, ps)
      EndIf
      ProcedureReturn 0
    Case #WM_LBUTTONDOWN
     
      pt\x = LOWORD(lParam)
      pt\y = HIWORD(lParam)
     
      GetClientRect_(hwnd, rect)
     
      InflateRect_(rect, -GetSystemMetrics_(#SM_CXEDGE), -GetSystemMetrics_(#SM_CYEDGE))
      rect\left = rect\right - GetSystemMetrics_(#SM_CXVSCROLL)
     
      If PtInRect_(@rect, pt\x, pt\y)
        fMouseDown = #True
        fButtonDown = #True
        InvalidateRect_(hwnd, 0, 0)
      EndIf

    Case #WM_LBUTTONUP
      If fMouseDown
        fMouseDown = #False
        fButtonDown = #False
        InvalidateRect_(hwnd, 0, 0)
      EndIf
     
    Case #WM_MOUSEMOVE
     
      pt\x = LOWORD(lParam)
      pt\y = HIWORD(lParam)
     
      If (fMouseDown = (wParam & #MK_LBUTTON))
        GetClientRect_(hwnd, rect)
        InflateRect_(rect, -GetSystemMetrics_(#SM_CXEDGE), -GetSystemMetrics_(#SM_CYEDGE))
        rect\left = rect\right - GetSystemMetrics_(#SM_CXVSCROLL)
       
        If (fButtonDown <> PtInRect_(@rect, pt\x, pt\y))
          fButtonDown = PtInRect_(@rect, pt\x, pt\y)
          InvalidateRect_(hwnd, 0, 0)
        EndIf
      EndIf
     
    Case #WM_LBUTTONUP
     
      If fMouseDown
        fMouseDown = #False
        fButtonDown = #False
        InvalidateRect_(hwnd, 0, 0)
      EndIf
  EndSelect
 
  ProcedureReturn CallWindowProc_(OldComboProc, hwnd, msg, wParam, lParam)
EndProcedure
Procedure FlatCombobox(hwndCombo)
  OldComboProc = GetWindowLong_(hwndCombo, #GWL_WNDPROC)
  SetWindowLong_(hwndCombo, #GWL_USERDATA, OldComboProc)
  SetWindowLong_(hwndCombo, #GWL_WNDPROC, @FlatComboProc())
EndProcedure


OpenWindow(0,0,0,400,100,"Flat Combobox",#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
ComboBoxGadget(0,5,5,300,100)
FlatCombobox(GadgetID(0))

AddGadgetItem(0,-1,"item 1")
AddGadgetItem(0,-1,"item 2")
AddGadgetItem(0,-1,"item 3")
AddGadgetItem(0,-1,"item 4")
AddGadgetItem(0,-1,"item 5")
AddGadgetItem(0,-1,"item 6")
AddGadgetItem(0,-1,"item 7")


Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow

_________________
my live space


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun May 27, 2007 2:12 am 
Offline
Addict
Addict

Joined: Wed Aug 24, 2005 8:39 am
Posts: 2736
Location: Southwest OH - USA
Nice one!

Yes, I like it :D

cheers


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 28, 2007 1:28 pm 
Offline
Addict
Addict
User avatar

Joined: Mon May 14, 2007 2:13 am
Posts: 979
Location: Darling River
Nice

Very helpful for me, since I am getting to know API.

Thanks


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye