| NS Basic/Desktop Enhancements February 05, 2008 Copyright 2008 NS BASIC Corporation |
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
2.5.2
2.5.1
2.5.0
AddObject "CommandButton::visible=0", "cb1", 10, 10, 100, 24
To add a module to a project, choose either Add Module from the Project menu or right click on the project in the Project Explorer. Modules are added to your program in the order they appear in the Project Explorer. If you want to change the order in which they are compiled, right click on the project in the Project Explorer.
Internally, the modules are added to the project code in the order specificed before compilation. You can put DIM statements, subroutines, functions and code into a module. If you would like to see the actual code that will be compiled, save the project as a txt file and open it in NotePad.
Running a program with modules is the same as one without. If you choose Start under the Run menu, a .nsd file will be produced that combines your main project code with all your modules.
AddObject "Window", "win1", -1, -1, -1, -1All windows created are children of the main window (named "Output"). The Output window must persist for the duration of the program. Any number of windows may be created below the Output window. The windows will behave like the Output window and can be moved anywhere on the screen, even behind the Output window.
Always use the six-argument form of AddObject to create a subwindow. Using the seven-argument form to create a window underneath a window is not recommended.
Everything that works with the Output window works with subwindows, with the exception that if the output window is closed, the subwindows will go away as well. The ParentHwnd property of a subwindow returns the Hwnd of the Output window.
All subwindows are initially invisible when created. This allows a window to be populated with forms and other controls with a minimum of flashing. When a window is populated, use the Show method or the Visible property to show it.
The x, y, width, and height are given in screen pixel coordinates. If any parameter is -1, the Windows default will be used.
A window may now have several forms of different sizes. Only one of the forms should be visible at one time. You can use the show method or the visible property to show and hide forms.
When you show or hide a form, or you set the width or height of the single visible form, the output window will automatically resize to fit the single visible form.
Example:
addobject "Form", "fm1", 0, 0, 400, 300
addobject "Form", "fm2", 0, 0, 600, 400
fm2.visible = false
fm1.caption = "Form 1"
fm2.caption = "Form 2"
addobject "CommandButton", "cb1", 10, 10, 70, 17, fm1
cb1.text = "Show form 2"
addobject "CommandButton", "cb2", 10, 10, 70, 17, fm2
cb2.text = "Show form 1"
sub cb1_click
fm1.hide
fm2.show
end sub
sub cb2_click
fm2.hide
fm1.show
end sub
You can also change the size of a form by setting its width or height
properties. This will also cause the window to resize if the form is
the one visible form:
Example:
addobject "Form", "fm1", 0, 0, 400, 300
addobject "CommandButton", "cb1", 10, 10, 70, 17, fm1
cb1.text = "Make it big"
addobject "commandButton", "cb2", 10, 30, 70, 17, fm1
cb2.text = "Make it small"
sub cb1_click
fm1.width = 600
fm1.height = 400
end sub
sub cb2_click
fm1.width = 400
fm1.height = 300
end sub
You can also have windows that can be resized by the user by dragging
the corner or edges. A form has four properties: MinWidth, MaxWidth,
MinHeight, and MaxHeight. You can set these properties to provide the
minimum and maximum width and height of the form for dragging.
If you set the minimum width, you must also set the maximum width. The same goes for height. When a window is dragged, it will automatically resize the only visible form. Your program will get a Resize message for the form.
Example:
addobject "Form", "fm1", 0, 0, 400, 300
fm1.minWidth = 200
fm1.maxWidth = 800
addobject "CommandButton", "b1", 10, 10, 380, 20, fm1
b1.text="A resized button"
sub fm1_Resize
b1.width = fm1.width - 20
end sub
There are some caveats with resized windows. When a window is expanded,
Windows only draws the exposed portion of the window. This is good,
because it minimizes flicker. However, if there is a feature on the
main form that needs to be redrawn when expanded, such as when the form
has a border or an image, the entire form needs to be redrawn.
This must be done in your Resize subroutine. Simply set a property that would cause a redraw.
Example:
addobject "Form", "fm1", 0, 0, 400, 300
fm1.caption = "Form 1"
fm1.borderStyle = 1
fm1.minWidth = 200
fm1.maxWidth = 800
sub fm1_Resize
fm1.backColor = fm1.backColor
end sub
This can cause undesirable flashing when expanding or shrinking a window,
but it works. It's best, however, not to have any elements that need to be erased on most resizable windows.
The Output object in has a new read-only propery: HWnd. This returns the parent window of the Output window. It is useful for many system routines that require a window. The following example displays a popup menu on NSBasic CE, using the Output.HWnd property.
AddObject "CommandButton", "cb1", 10, 10, 100, 20
cb1.caption = "Menu"
Declare "Function CreatePopupMenu Lib ""Coredll"" () As Long"
Declare "Function AppendMenu Lib ""Coredll"" Alias "AppendMenuW"" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As String) As Long"
Declare "Function TrackPopupMenuEx Lib ""Coredll"" (ByBal hMenu As Long, ByVal un As Lont, ByVal n1 As Long, ByVal n2 As Long, ByVal hWnd As Long,lpTPMParams As Long) As Long"
Const TPM_RETURNCMD = $H100&
Const MF_ENABLED = &H0&
Const MF_STRING = &H0&
Const MF_GRAYED = &H1&
Const MF_SEPARATOR = &H800&
Sub cb1_Click
Dim ret
Dim hMenu
hMenu = CreatePopupMenu
AppendMenu hMenu, MF_ENABLED Or MF_STRING, 1, "Option 1"
AppendMenu hMenu, MF_ENABLED Or MF_STRING, 2, "Option 2"
AppendMenu hMenu, MF_ENABLED Or MF_STRING, 3, "Option 3"
AppendMenu hMenu, MF_GRAYED Or MF_SEPARATOR, 4, ""
AppendMenu hMenu, MF_ENABLED Or MF_STRING, 5, "Fuhgettaboutit"
ret = ShowPopupMenu(0, 0)
MsgBox ret
End Sub
You must use the HWnd property because under Windows Mobile 5,
attempting to display a popup menu using Output.Hwnd causes undesirable
results. This appears to be unique to Mobile 5 and does not occur on
earlier devices.
You can also present popup windows under NSBasic Desktop by using the Output.Hwnd property, provided that the appropriate core DLL is installed on the system.
If you are writing code that is to run under both NSBasic CE and NSBasic Desktop, you can take advantage of the fact that Output.HWnd is always 0 under NSBasic Desktop.
2.1.0
2.0.1
2.0.0
2.0.0 Documentation
AddObject "TextBox::Visible=0:Text=""My Text Box"" ","tbMyTextBox",10,10,100,100
Use strings and constants as values; True and False are not recognised.
addobject "Window", "win", 10, 10, 100, 100 addobject "Form", "fm", 0, 0, 200, 200, win