trying to understand Window IDs

You need some new stunning features ? Tell us here.
User avatar
mick365
New User
New User
Posts: 3
Joined: Wed Aug 31, 2022 7:11 pm

trying to understand Window IDs

Post 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
PureBasic 6.0.0 LTS on Windows and MacOS (Apple Silicon)
User avatar
mick365
New User
New User
Posts: 3
Joined: Wed Aug 31, 2022 7:11 pm

Re: trying to understand Window IDs

Post by mick365 »

ok, tried this with MainWnd instead of MainWindow and it works. MainWindow seems to be a reserved Variable i think.
PureBasic 6.0.0 LTS on Windows and MacOS (Apple Silicon)
User avatar
mk-soft
Always Here
Always Here
Posts: 5398
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: trying to understand Window IDs

Post 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)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
jacdelad
Addict
Addict
Posts: 1477
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: trying to understand Window IDs

Post 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(..)".
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
mk-soft
Always Here
Always Here
Posts: 5398
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: trying to understand Window IDs

Post 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

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Caronte3D
Addict
Addict
Posts: 1053
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: trying to understand Window IDs

Post 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
User avatar
mick365
New User
New User
Posts: 3
Joined: Wed Aug 31, 2022 7:11 pm

Re: trying to understand Window IDs

Post by mick365 »

Thanks, but I stopped the experiment Form Designer and code my UI by myself, like I did in the past.
PureBasic 6.0.0 LTS on Windows and MacOS (Apple Silicon)
Post Reply