
How can i create window that will automatically resize with every mouse move (?), not only when i release mouse button, like in windows.
I have a lot of apps installed on my mac and neither one of them is behaving like this one created in purebasic.
Code: Select all
ChangeWindowAttributes_(WindowID(0),(1 << 28),0)
Code: Select all
setwindowmodified_(WindowID(0),1)
Code: Select all
err = SetWindowModified_(WindowID(0),#C_TRUE)
You'll need to import it along with IsWindowModified (to check the status):Your application can use the functions SetWindowModified and IsWindowModified instead of maintaining its own separate record of the modification state of the content of a window. The modification state of a window is visually represented by a dot in the window’s close box. If the dot is present, the window is modified; if the dot is absent, the window is not modified.
Your application should distinguish between the modification state of the window and the modification state of the window’s contents, typically a document. The modification state of the window contents are what should affect SetWindowModified. For example, in the case of a word processing document, you call SetWindowModified (passing true in the modified parameter) whenever the user types new characters into the document. However, you do not call SetWindowModified when the user moves the window, because that change does not affect the document contents. If you need to track whether the window position has changed, you need to do this with your own flag.
Code: Select all
ImportC "/System/Library/Frameworks/Carbon.framework/Carbon"
SetWindowModified(WindowRef.l, State.l)
IsWindowModified(WindowRef.l) ; returns Boolean
EndImport
Code: Select all
Procedure CFSTR(cString.s)
ProcedureReturn CFStringCreateWithCString_(0, cString, 0)
EndProcedure
Code: Select all
CFPreferencesSetAppValue(CFSTR(key),CFSTR(value),CFSTR(plist))
Code: Select all
#kEventClassWindow = 'wind'
#kEventParamCurrentBounds = 'crct'
#kEventParamPreviousBounds = 'prct'
#kEventWindowBoundsChanging = 26
#kWindowNoAttributes = $0
#kWindowLiveResizeAttribute = $10000000
#noErr = 0
#typeHIRect = 'hirc'
ImportC "/System/Library/Frameworks/Carbon.framework/Carbon"
ChangeWindowAttributes (window, setTheseAttributes, clearTheseAttributes)
GetEventParameter (event, name, desiredType, ptrActualType, bufferSize, ptrActualSize, ptrData)
GetWindowEventTarget (target)
InstallEventHandler (target, handler, numTypes, ptrList, userData, outHandlerRef)
NewEventHandlerUPP (userRoutine)
SetWindowResizeLimits (window, minLimits, maxLimits)
EndImport
Macro InstallWindowEventHandler (target, handler, numTypes, ptrList, userData, outHandlerRef)
InstallEventHandler(GetWindowEventTarget(target), handler, numTypes, ptrList, userData, outHandlerRef)
EndMacro
Structure EventTypeSpec
eventClass.l
eventKind.l
EndStructure
Structure HIRect
x.f
y.f
width.f
height.f
EndStructure
Structure HISize
width.f
height.f
EndStructure
ProcedureC.l ResizeHandler (nextHandler, theEvent, ptrUserData)
GetEventParameter(theEvent, #kEventParamCurrentBounds, #typeHIRect, #Null, SizeOf(HIRect), #Null, @current.HIRect)
GetEventParameter(theEvent, #kEventParamPreviousBounds, #typeHIRect, #Null, SizeOf(HIRect), #Null, @previous.HIRect)
If current\width <> previous\width Or current\height <> previous\height
ResizeGadget(0, 10, 10, current\width - 20, current\height - 50)
EndIf
ProcedureReturn #noErr
EndProcedure
WindowRef.l = OpenWindow(0, 0, 0, 640, 480, "PureBasic - Live Resize", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
If WindowRef
minSize.HISize\width = 120
minSize\height = 150
maxSize.HISize\width = 1024
maxSize\height = 768
SetWindowResizeLimits(WindowRef, @minSize, @maxSize)
ChangeWindowAttributes(WindowRef, #kWindowLiveResizeAttribute, #kWindowNoAttributes)
EventList.EventTypeSpec\eventClass = #kEventClassWindow
EventList\eventKind = #kEventWindowBoundsChanging
InstallWindowEventHandler(WindowRef, NewEventHandlerUPP(@ResizeHandler()), 1, @EventList, #Null, #Null)
WebGadget(0, 10, 10, 620, 430, "http://www.purebasic.com")
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
EndIf
End
Nice, it works under 10.5.8 here using PureBasic 4.30 x86.wilbert wrote:Never mind, I got it working.
It works on OSX 10.6.2 . From what I understand so far, it should also work on OSX 10.2 or higher.
If someone has a OSX version from 10.2 to 10.5 and wants to test it, I would appreciate it if you let me know if it works.
The commented API functions don't need to be imported; they're already "included". Just append an underscore when you call the function { for ex, ChangeWindowAttribute_(...) }Code: Select all
ImportC "/System/Library/Frameworks/Carbon.framework/Carbon" ;ChangeWindowAttributes (window, setTheseAttributes, clearTheseAttributes) ;GetEventParameter (event, name, desiredType, ptrActualType, bufferSize, ptrActualSize, ptrData) ;;GetWindowEventTarget (target) ;InstallEventHandler (target, handler, numTypes, ptrList, userData, outHandlerRef) SetWindowResizeLimits (window, minLimits, maxLimits) EndImport
Great job, thanks for sharingwilbert wrote:Never mind, I got it working.
It works on OSX 10.6.2 . From what I understand so far, it should also work on OSX 10.2 or higher.
If someone has a OSX version from 10.2 to 10.5 and wants to test it, I would appreciate it if you let me know if it works.
Code: Select all
#kEventClassWindow = 'wind' #kEventParamCurrentBounds = 'crct' #kEventParamPreviousBounds = 'prct' #kEventWindowBoundsChanging = 26 #kWindowNoAttributes = $0 #kWindowLiveResizeAttribute = $10000000 #noErr = 0 #typeHIRect = 'hirc' ImportC "/System/Library/Frameworks/Carbon.framework/Carbon" ChangeWindowAttributes (window, setTheseAttributes, clearTheseAttributes) GetEventParameter (event, name, desiredType, ptrActualType, bufferSize, ptrActualSize, ptrData) GetWindowEventTarget (target) InstallEventHandler (target, handler, numTypes, ptrList, userData, outHandlerRef) NewEventHandlerUPP (userRoutine) SetWindowResizeLimits (window, minLimits, maxLimits) EndImport Macro InstallWindowEventHandler (target, handler, numTypes, ptrList, userData, outHandlerRef) InstallEventHandler(GetWindowEventTarget(target), handler, numTypes, ptrList, userData, outHandlerRef) EndMacro Structure EventTypeSpec eventClass.l eventKind.l EndStructure Structure HIRect x.f y.f width.f height.f EndStructure Structure HISize width.f height.f EndStructure ProcedureC.l ResizeHandler (nextHandler, theEvent, ptrUserData) GetEventParameter(theEvent, #kEventParamCurrentBounds, #typeHIRect, #Null, SizeOf(HIRect), #Null, @current.HIRect) GetEventParameter(theEvent, #kEventParamPreviousBounds, #typeHIRect, #Null, SizeOf(HIRect), #Null, @previous.HIRect) If current\width <> previous\width Or current\height <> previous\height ResizeGadget(0, 10, 10, current\width - 20, current\height - 50) EndIf ProcedureReturn #noErr EndProcedure WindowRef.l = OpenWindow(0, 0, 0, 640, 480, "PureBasic - Live Resize", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget) If WindowRef minSize.HISize\width = 120 minSize\height = 150 maxSize.HISize\width = 1024 maxSize\height = 768 SetWindowResizeLimits(WindowRef, @minSize, @maxSize) ChangeWindowAttributes(WindowRef, #kWindowLiveResizeAttribute, #kWindowNoAttributes) EventList.EventTypeSpec\eventClass = #kEventClassWindow EventList\eventKind = #kEventWindowBoundsChanging InstallWindowEventHandler(WindowRef, NewEventHandlerUPP(@ResizeHandler()), 1, @EventList, #Null, #Null) WebGadget(0, 10, 10, 620, 430, "http://www.purebasic.com") Repeat EventID = WaitWindowEvent() Until EventID = #PB_Event_CloseWindow EndIf End
Code: Select all
Procedure LiveResizeHandler (newWidth.l, newHeight.l)
ResizeGadget(0, 10, 10, newWidth - 20, newHeight - 50)
EndProcedure
If OpenWindow(0, 0, 0, 640, 480, "PureBasic - Live Resize", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
wxl_AddLiveResizeEventHandler(WindowID(0), @LiveResizeHandler())
WindowBounds(0, 120, 150, 1024, 768)
WebGadget(0, 10, 10, 620, 430, "http://www.purebasic.com")
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
EndIf
End