November 28, 2020, 02:07:16 AM

Author Topic: [bb] Resize and Maximize Blitz Window! by fredborg [ 1+ years ago ]  (Read 547 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Resize and Maximize Blitz Window!
Author : fredborg
Posted : 1+ years ago

Description : Shows how you can make a resizeable window in Blitz2D and Blitz3D, without the contents get scaled.

Take a close look at the Viewport command in the Blitz Docs. You will probably need this to clip your graphics, so you don't waste any power on drawing outside the screen!

At the top of the code is a userlib definition, put this in your userlib folder!

Have fun!


Code :
Code: BlitzBasic
  1. ;
  2. ; User32.decls - place in your userlibs folder
  3. ; And uncomment the commands.
  4. ;
  5. ;.lib "user32.dll"
  6. ;
  7. ;User32_GetActiveWindow%():"GetActiveWindow"
  8. ;User32_SetWindowLong% (hwnd%, nIndex%, dwNewLong%) : "SetWindowLongA"
  9. ;User32_GetSystemMetrics% (nIndex%) : "GetSystemMetrics"
  10. ;User32_MoveWindow% (hwnd%, x%, y%, nWidth%, nHeight%, bRepaint%) : "MoveWindow"
  11. ;User32_GetWindowRect% (hwnd%, lpRect*) : "GetWindowRect"
  12. ;User32_GetClientRect% (hwnd%, lpRect*) : "GetClientRect"
  13. ;User32_ClientToScreen% (hwnd%, lpwndpl*): "ClientToScreen"
  14. ;User32_ScreenToClient% (hwnd%, lpwndpl*): "ScreenToClient"
  15. ;User32_GetCursorPos%( lpwndpl* ):"GetCursorPos"
  16.  
  17. Type WinPoint
  18.     Field X,Y
  19. End Type
  20.  
  21. Type WinRect
  22.         Field x,y,w,h
  23. End Type
  24.  
  25. ; Desktop Size
  26. Const SM_CXSCREEN=0
  27. Const SM_CYSCREEN=1
  28.  
  29. ; Set Window Long
  30. Const GWL_WNDPROC               =(-4)
  31. Const GWL_HINSTANCE             =(-6)
  32. Const GWL_HWNDPARENT    =(-8)
  33. Const GWL_STYLE                 =(-16)
  34. Const GWL_EXSTYLE               =(-20)
  35. Const GWL_USERDATA              =(-21)
  36. Const GWL_ID                    =(-12)
  37.  
  38. ; Window Style
  39. Const WS_OVERLAPPED             =$0
  40. Const WS_POPUP                  =$80000000
  41. Const WS_CHILD                  =$40000000
  42. Const WS_MINIMIZE               =$20000000
  43. Const WS_VISIBLE                =$10000000
  44. Const WS_DISABLED               =$8000000
  45. Const WS_CLIPSIBLINGS   =$4000000
  46. Const WS_CLIPCHILDREN   =$2000000
  47. Const WS_MAXIMIZE               =$1000000
  48. Const WS_CAPTION                =$C00000
  49. Const WS_BORDER                 =$800000
  50. Const WS_DLGFRAME               =$400000
  51. Const WS_VSCROLL                =$200000
  52. Const WS_HSCROLL                =$100000
  53. Const WS_SYSMENU                =$80000
  54. Const WS_THICKFRAME             =$40000
  55. Const WS_GROUP                  =$20000
  56. Const WS_TABSTOP                =$10000
  57. Const WS_MINIMIZEBOX    =$20000
  58. Const WS_MAXIMIZEBOX    =$10000
  59. Const WS_TILED                  =WS_OVERLAPPED
  60. Const WS_ICONIC                 =WS_MINIMIZE
  61. Const WS_SIZEBOX                =WS_THICKFRAME
  62. Const WS_OVERLAPPEDWINDOW=(WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
  63. Const WS_TILEDWINDOW    =WS_OVERLAPPEDWINDOW
  64. Const WS_POPUPWINDOW    =(WS_POPUP Or WS_BORDER Or WS_SYSMENU)
  65. Const WS_CHILDWINDOW    =(WS_CHILD)
  66.  
  67. ; Window Messages
  68. Const SW_HIDE=0
  69. Const SW_SHOWNORMAL=1
  70. Const SW_NORMAL=1
  71. Const SW_SHOWMINIMIZED=2
  72. Const SW_SHOWMAXIMIZED=3
  73. Const SW_MAXIMIZE=3
  74. Const SW_SHOWNOACTIVATE=4
  75. Const SW_SHOW=5
  76. Const SW_MINIMIZE=6
  77. Const SW_SHOWMINNOACTIVE=7
  78. Const SW_SHOWNA=8
  79. Const SW_RESTORE=9
  80. Const SW_SHOWDEFAULT=10
  81. Const SW_MAX=10
  82.  
  83. Type win
  84.         Field TempPos.WinPoint
  85.         Field MousePos.WinPoint
  86.         Field WindowRect.WinRect
  87.         Field DesktopW,DesktopH
  88.         Field hWindow
  89.         Field WindowStyle
  90.         Field W,H,X,Y
  91.         Field MX,MY,MZ,MSX,MSY,MSZ
  92. End Type
  93.  
  94. ;
  95. ; This function initializes the actual blitz window
  96. Function InitBlitzWindow()
  97.  
  98.         ; Prepare custom types
  99.         winTempPos.WinPoint     = New WinPoint
  100.         winMousePos.WinPoint    = New WinPoint
  101.         winWindowRect.WinRect   = New WinRect
  102.        
  103.         ; Get Desktop Dimensions
  104.         winDesktopW = User32_GetSystemMetrics(SM_CXSCREEN)
  105.         winDesktopH = User32_GetSystemMetrics(SM_CYSCREEN)
  106.  
  107.         ; Initialize Graphics Window
  108.         Graphics3D winDesktopW,winDesktopH,0,2
  109.        
  110.         ; Get hWnd pointer for the Blitz Window
  111.         winhWindow = User32_GetActiveWindow()
  112.  
  113.         ; Set the Blitz Window Style
  114.         winWindowStyle = WS_VISIBLE + WS_BORDER + WS_MINIMIZEBOX + WS_MAXIMIZEBOX + WS_SIZEBOX + WS_SYSMENU + WS_DLGFRAME;+ WS_THICKFRAME
  115.         User32_SetWindowLong(winhWindow,GWL_STYLE,winWindowStyle)
  116.        
  117.         ; Resize and center Blitz Window       
  118.         User32_MoveWindow(winhWindow,(winDesktopW/2)-(640/2),(winDesktopH/2)-(480/2),640,480,True)
  119.  
  120. End Function
  121.  
  122.  
  123. Function UpdateBlitzWindow()
  124.  
  125.         User32_GetWindowRect(winhWindow,winWindowRect)
  126.        
  127.         winWindowRectw = winWindowRectw-winWindowRectx
  128.         winWindowRecth = winWindowRecth-winWindowRecty
  129.                        
  130.         If winWindowRectw<320
  131.                 toosmall = True
  132.                 winWindowRectw = 320
  133.         End If
  134.         If winWindowRecth<240
  135.                 toosmall = True
  136.                 winWindowRecth = 240
  137.         End If
  138.         If toosmall
  139.                 User32_MoveWindow(winhWindow,winWindowRectx,winWindowRecty,winWindowRectw,winWindowRecth,True) 
  140.         End If
  141.        
  142.         ; Get Screen position of pixel 0,0
  143.         winTempPosx = 0
  144.         winTempPosy = 0
  145.         User32_ClientToScreen(winhWindow,winTempPos)
  146.         winX = winTempPosx
  147.         winY = winTempPosy
  148.        
  149.         ; Get Width and Height of the Blitz Window
  150.         User32_GetClientRect(winhWindow,winWindowRect)
  151.         winW = winWindowRectw
  152.         winH = winWindowRecth
  153.         Viewport 0,0,winW,winH
  154.        
  155.         ; Store old mouse position
  156.         winMSX = winMX
  157.         winMSY = winMY
  158.         winMSZ = winMZ
  159.                
  160.         ; Get the mouse position (even if mouse is outside the Blitz Window)
  161.         User32_GetCursorPos(winMousePos)
  162.         User32_ScreenToClient(winhWindow,winMousePos)
  163.         winMX            = winMousePosx
  164.         winMY            = winMousePosy
  165.         winMZ            = MouseZ()
  166.  
  167.         ; Update Mouse Speed
  168.         winMSX = winMX-winMSX
  169.         winMSY = winMY-winMSY
  170.         winMSZ = winMZ-winMSZ
  171.        
  172. End Function
  173.  
  174. ; Example
  175.  
  176. Global win.win = New win
  177. InitBlitzWindow()
  178. SetBuffer BackBuffer()
  179.  
  180. Repeat
  181.         Cls
  182.         UpdateBlitzWindow()
  183.         Text 0, 0,"Window Width  - "+winW
  184.         Text 0,10,"Window Height - "+winH
  185.         Text 0,20,"Window X - "+winX
  186.         Text 0,30,"Window Y - "+winY
  187.         Text 0,40,"Mouse X - "+winMX
  188.         Text 0,50,"Mouse Y - "+winMY
  189.         Flip
  190. Until KeyHit(1)
  191. End


Comments :


Red(Posted 1+ years ago)

 Thanx,Thanx,Thanx :)


Richard Betson(Posted 1+ years ago)

 Yes Nice! ...also much thanks. :)L8r,


ShadowTurtle(Posted 1+ years ago)

 Its nice code. I use it now :)(ps fredborg: thanks!)


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal