Page 1 of 1

trying to understand Window IDs

Posted: Wed Aug 31, 2022 7:33 pm
by mick365
Hi,

after quite a long time i will do a restart with PureBasic.

I never used the integrated Form Designer and always coded my UI by hand.

Now i want to see, if the Form Designer can make my work easier.

i have these 2 files:

hello.pb:
MainWindow.pbf

This works:

hello.pb

Code: Select all

XIncludeFile "MainWindow.pbf"

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
MainWindow.pbf:

Code: Select all

;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;

Global Window_0

Global Text_0, Button_0

Declare ResizeGadgetsWindow_0()


Procedure OpenWindow_0(x = 0, y = 0, width = 600, height = 400)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "Main Window", #PB_Window_SystemMenu)
  Text_0 = TextGadget(#PB_Any, 10, 10, 470, 25, "")
  Button_0 = ButtonGadget(#PB_Any, 490, 10, 100, 25, "Klick mich!")
EndProcedure

Procedure ResizeGadgetsWindow_0()
  Protected FormWindowWidth, FormWindowHeight
  FormWindowWidth = WindowWidth(Window_0)
  FormWindowHeight = WindowHeight(Window_0)
  ResizeGadget(Text_0, 10, 10, FormWindowWidth - 130, 25)
  ResizeGadget(Button_0, FormWindowWidth - 110, 10, 100, 25)
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_SizeWindow
      ResizeGadgetsWindow_0()
    Case #PB_Event_CloseWindow
      ProcedureReturn #False

    Case #PB_Event_Menu
      Select EventMenu()
      EndSelect

    Case #PB_Event_Gadget
      Select EventGadget()
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure
But when i change the Window-ID from Window_0 to e.g. MainWindow i get an error:

[20:22:06] [COMPILER] Zeile 3: OpenMainWindow() ist keine Funktion, Array, Makro oder LinkedList.

What is this Window_0? Is it the Window-ID?

I thought when changing the Property "Variable" in the Form Designer from Window_0 to e.g. "MainWindow" and change the procedure call in the main code to

Code: Select all

OpenMainWindow()
this should work, but no. It only works when i call

Code: Select all

OpenWindow_0()
.

Any ideas whats wrong in my considerations?

Michael

Re: trying to understand Window IDs

Posted: Wed Aug 31, 2022 7:47 pm
by mick365
ok, tried this with MainWnd instead of MainWindow and it works. MainWindow seems to be a reserved Variable i think.

Re: trying to understand Window IDs

Posted: Wed Aug 31, 2022 10:07 pm
by mk-soft
You can also switch back to constants. Preferences -> Form -> Disable New gadget with #PB_Any.
I prefer the method with constants and I have also switched off the event management and prefer to write it myself.

PB can also create PB objects dynamically from v5.xx (#PB_Any). For this, however, the PB object id must be stored in a variable and the objects must be explicitly released before reassignment. (FreeGadget, FreeImage). They are automatically released when the programme is closed.

Code: Select all

image = CreateImage(#PB_Any, 16, 16)
; ...
FreeImage(image)
; ...
image = CreateImage(#PB_Any, 32, 32)

Re: trying to understand Window IDs

Posted: Thu Sep 01, 2022 4:37 am
by jacdelad
The designer generates its code on changes (also on switching between code-/window-view) and changes its code by itself, that's why you never should edit it by yourself (except for changing the values of some parameters, like size). There is no reserved keyword or variable or whatever called "MainWindow", the designer simply changed the name of the function of the pbf back to "OpenWindow_0(..)".

Re: trying to understand Window IDs

Posted: Thu Sep 01, 2022 10:47 am
by mk-soft
You can change property 'Variable' (constant) name of window and gadgets

MainForm.pbf

Code: Select all

;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;

Enumeration FormWindow
  #MainWindow
EndEnumeration

Enumeration FormGadget
  #Button_Ok
EndEnumeration


Procedure OpenMainWindow(x = 0, y = 0, width = 600, height = 400)
  OpenWindow(#MainWindow, x, y, width, height, "Main Window", #PB_Window_SystemMenu)
  ButtonGadget(#Button_Ok, 10, 350, 120, 40, "Ok")
EndProcedure


Re: trying to understand Window IDs

Posted: Thu Sep 01, 2022 12:08 pm
by Caronte3D
mick365 wrote: Wed Aug 31, 2022 7:33 pm I never used the integrated Form Designer and always coded my UI by hand...
The user TI-994A just updated a very basic tutorial about form designer, maybe you finds it useful :wink:
viewtopic.php?t=52246

Re: trying to understand Window IDs

Posted: Thu Sep 01, 2022 8:55 pm
by mick365
Thanks, but I stopped the experiment Form Designer and code my UI by myself, like I did in the past.