[Windows PB 4.00] Win32 API

Just starting out? Need help? Post your questions and find answers here.
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

[Windows PB 4.00] Win32 API

Post 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.
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post 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 
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

Post 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:
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

Post 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)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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
BERESHEIT
Heathen
Enthusiast
Enthusiast
Posts: 498
Joined: Tue Sep 27, 2005 6:54 pm
Location: At my pc coding..

Post 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...
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Please explain this hatred as I only see love and devotion:
It was written in the holy book, chapter "MDIGadget()", verse 4.
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

Post 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.
Last edited by ..::Origin::.. on Sat Jun 16, 2007 5:39 am, edited 1 time in total.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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().
Last edited by netmaestro on Sat Jun 16, 2007 5:51 am, edited 1 time in total.
BERESHEIT
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

Post 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.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
Post Reply