Page 1 of 1

[Windows PB 4.00] Win32 API

Posted: Fri Jun 15, 2007 5:12 am
by ..::Origin::..
Hi, I'm having 3 issues/questions revolving around the Win32 Api...

My first one is abit of an interesting one, i have a Parent Window and a Child Window... When a user tries to resize a child window, it decides to center itself in the middle of the container gadget, See for yourself:

Code: Select all

 OpenWindow(0, 5, 5, 800, 600, "test",  #PB_Window_ScreenCentered | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_TitleBar )
 CreateGadgetList(WindowID(0))
 ContainerGadget(0, 10, 10, 780, 580, #PB_Container_Single) : CloseGadgetList()
 
 OpenWindow(1,0,0,500,500,"Test2",#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_TitleBar)
 SetParent_(WindowID(1),GadgetID(0))

 Repeat
   Event = WindowEvent()
   Delay(16)
 Until Event = #PB_Event_CloseWindow 
Also, how would i be able to still have the Parent Window active and a child one active at the same time?

_______

Last question;

Is there a simple way to get the position of the last item created in a Tree Gadget?

Thanks for reading.

Posted: Fri Jun 15, 2007 6:39 am
by Heathen
you just have to reorganize the code

Code: Select all

 OpenWindow(0, 5, 5, 800, 600, "test",  #PB_Window_ScreenCentered | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_TitleBar )
 OpenWindow(1,0,0,500,500,"Test2",#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_TitleBar)
 SetParent_(WindowID(1),GadgetID(0))

 CreateGadgetList(WindowID(0))
 ContainerGadget(0, 10, 10, 780, 580, #PB_Container_Single) : CloseGadgetList()
 

 Repeat
   event = WindowEvent()
   Delay(16)
 Until event = #PB_Event_CloseWindow 

Posted: Fri Jun 15, 2007 7:02 am
by ..::Origin::..

Code: Select all

 OpenWindow(0, 5, 5, 800, 600, "test",  #PB_Window_ScreenCentered | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_TitleBar )
 OpenWindow(1,0,0,500,500,"Test2",#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_TitleBar)
 SetParent_(WindowID(1),GadgetID(0))

 CreateGadgetList(WindowID(0))
 ContainerGadget(0, 10, 10, 780, 580, #PB_Container_Single) : CloseGadgetList()
 

 Repeat
   event = WindowEvent()
   Delay(16)
 Until event = #PB_Event_CloseWindow 
How so? If i reorganise the code it simply wont imbed the window because "Gadget 0" (the handle to imbed the window to) doesn't even exist yet. :roll:

Posted: Fri Jun 15, 2007 8:36 am
by Trond

Code: Select all

OpenWindow(0, 5, 5, 800, 600, "test",  #PB_Window_ScreenCentered | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_TitleBar ) 
CreateGadgetList(WindowID(0)) 
ContainerGadget(0, 10, 10, 780, 580, #PB_Container_Single) : CloseGadgetList() 

OpenWindow(1,0,0,500,500,"Test2",#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_Invisible)
SetWindowLong_(WindowID(1), #GWL_STYLE, GetWindowLong_(WindowID(1), #GWL_STYLE) | #WS_CHILD)
SetParent_(WindowID(1),GadgetID(0)) 
HideWindow(1, 0)

Repeat 
  Event = WindowEvent() 
  Delay(16)
Until Event = #PB_Event_CloseWindow
But you should use a MDI gadget for this.

Posted: Fri Jun 15, 2007 9:59 am
by ..::Origin::..
Only problem with using an MDI Gadget is that it really hates SplitterGadgets and doesn't like to function correctly. (For example, i contiually get invalid memory accesses on program exit, and maximizing a window inside the mdi gadget does the same thing.)

There should be a way around this, but i've yet to have found it. (I beleive i know of one program which found a way around it)

Posted: Fri Jun 15, 2007 2:32 pm
by netmaestro
Only problem with using an MDI Gadget is that it really hates SplitterGadgets and doesn't like to function correctly
Please explain this hatred as I only see love and devotion:

Code: Select all

#Main = 0
#MDIChild = 1
flags = #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget
OpenWindow(#Main, 0, 0, 640, 480, "MDIGadget", flags)
CreateGadgetList(WindowID(#Main))
CreateMenu(#Main, WindowID(#Main))
  MenuTitle("MDI windows menu")
    MenuItem(0, "self created item")
  
MDIGadget(0, 0, 0, 0, 0, 0, 2, #PB_MDI_AutoSize)

quit = 0
Repeat
  ev = WaitWindowEvent()
  Select ev
  
    Case #PB_Event_CloseWindow
      If EventWindow() = #Main
        quit = 1
      Else
        CloseWindow(EventWindow())
      EndIf
      
    Case #PB_Event_Menu
      AddGadgetItem(0, #MDIChild, "child window")
      SmartWindowRefresh(#MDIChild, 1)
      CreateGadgetList(WindowID(#MDIChild))
        ButtonGadget(2,0,0,0,0,"Button 1")
        ButtonGadget(3,0,0,0,0,"Button 2")
        h = WindowHeight(#MDIChild) : w = WindowWidth(#MDIChild)
        SplitterGadget(4,10,10,w-20,h-20,2,3,#PB_Splitter_Separator)
      UseGadgetList(WindowID(#Main)) 
      
    Case #PB_Event_SizeWindow
      If EventWindow() = #MDIChild
        h = WindowHeight(#MDIChild) : w = WindowWidth(#MDIChild)
        ResizeGadget(4,10,10,w-20,h-20)
      EndIf
  EndSelect
    
Until quit

Posted: Fri Jun 15, 2007 3:11 pm
by Heathen
..::Origin::.. wrote:

Code: Select all

 OpenWindow(0, 5, 5, 800, 600, "test",  #PB_Window_ScreenCentered | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_TitleBar )
 OpenWindow(1,0,0,500,500,"Test2",#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_TitleBar)
 SetParent_(WindowID(1),GadgetID(0))

 CreateGadgetList(WindowID(0))
 ContainerGadget(0, 10, 10, 780, 580, #PB_Container_Single) : CloseGadgetList()
 

 Repeat
   event = WindowEvent()
   Delay(16)
 Until event = #PB_Event_CloseWindow 
How so? If i reorganise the code it simply wont imbed the window because "Gadget 0" (the handle to imbed the window to) doesn't even exist yet. :roll:
I guess I didn't understand your question...

Posted: Fri Jun 15, 2007 3:32 pm
by Trond
Please explain this hatred as I only see love and devotion:
It was written in the holy book, chapter "MDIGadget()", verse 4.

Posted: Sat Jun 16, 2007 5:19 am
by ..::Origin::..
Trond wrote:
Please explain this hatred as I only see love and devotion:
It was written in the holy book, chapter "MDIGadget()", verse 4.
No, it was Verse 7 acctualy.

Code: Select all

Solved
Compile and try to maximize the Child Window.

Posted: Sat Jun 16, 2007 5:33 am
by netmaestro
You can't have a splitter moving/sizing an entire MDI gadget, it's too highlevel. It just isn't something you can do. Normal child controls like buttons, containers, listicons, etc., that's all you can split.

[edit] Actually, this is covered in the doc as well:
PB help for MDI Gadget wrote:You can only put this gadget directly on a window, you can NOT put it inside a ContainerGadget(), SplitterGadget() or PanelGadget().

Posted: Sat Jun 16, 2007 5:38 am
by ..::Origin::..
Hmm... ok, thanks will have to rethink my UI.

Also, anyone have any idea's for my third question?
Is there a simple way to get the position of the last item created in a Tree Gadget?
Thanks for help so far everyone.

Posted: Sun Jun 17, 2007 3:09 am
by netmaestro
I don't know if it qualifies as simple, but it's pretty straightforward if you're familiar with subclassing. In this code, the Treeview procedure logs the index and text of every item added as it happens:

Code: Select all


Procedure TreeProc(hwnd, msg, wparam, lparam)
  
  Protected oldproc = GetProp_(hwnd, "oldproc")

  Select msg
  
    Case #TVM_INSERTITEM
      *tvis.TV_INSERTSTRUCT = lparam
      item_index  =  *tvis\item\lparam
      item_text.s =  PeekS(*tvis\item\pszText)
      Debug "Added at index " + str(item_index) + " : " + item_text
    
    Case #WM_NCDESTROY
      RemoveProp_(hwnd, "oldproc")
        
  EndSelect
  
  ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
  
EndProcedure


 If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    TreeGadget(0, 10, 10, 160, 160)                                         ; TreeGadget standard
    oldproc = SetWindowLong_(GadgetID(0), #GWL_WNDPROC, @TreeProc())
    SetProp_(GadgetID(0), "oldproc", oldproc)
    
    For a = 0 To 10
        AddGadgetItem(0, -1, "Normal Item "+Str(a), 0, 0) ; if you want to add an image, use 
        AddGadgetItem(0, -1, "Node "+Str(a), 0, 0)        ; ImageID(x) as 4th parameter
        AddGadgetItem(0, -1, "Sub-Item 1", 0, 1)    ; These are on the 1st sublevel  
        AddGadgetItem(0, -1, "Sub-Item 2", 0, 1)
        AddGadgetItem(0, -1, "Sub-Item 3", 0, 1)
        AddGadgetItem(0, -1, "Sub-Item 4", 0, 1)
        AddGadgetItem(0, -1, "File "+Str(a), 0, 0) ; sublevel 0 again
    Next
    Repeat 
      ev = WaitWindowEvent()

    Until ev = #PB_Event_CloseWindow
  EndIf
I can't think of a simpler way off the top of my head, but it's possible I've missed something obvious.