LB Booster
« Maximising the main window »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:17am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Maximising the main window  (Read 1092 times)
RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx Maximising the main window
« Thread started on: Oct 12th, 2015, 4:32pm »

Here is a useful bit of code for maximising the main window that I found on LB Conforums all the way back in March 2004. The code was posted initially by Scott Bannon and was updated for Windows 32bit code by Ken Lewis, Snr.

Code:
open "user32" for dll as #user

calldll #user, "GetActiveWindow",_
mainwinhandle as ulong     'returns handle of mainwin

calldll #user, "ShowWindow",_
mainwinhandle as ulong,_         'mainwindow handle
_SW_SHOWMAXIMIZED as long,_    'flag for maximize
result As long

close #user
wait
 


I do quite a bit of programming in "console" mode requiring the main window to be open. This saves having to click the maximise button on the main window when it opens.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Maximising the main window
« Reply #1 on: Oct 12th, 2015, 4:46pm »

on Oct 12th, 2015, 4:32pm, RNBW wrote:
Here is a useful bit of code for maximising the main window that I found on LB Conforums all the way back in March 2004.

That was presumably before LB made it unnecessary to open the 'common' DLLs such as user32. These days you can safely omit the open and close statements:

Code:
calldll #user32, "GetActiveWindow",_
  mainwinhandle as ulong     'returns handle of mainwin

calldll #user32, "ShowWindow",_
  mainwinhandle as ulong,_       'mainwindow handle
  _SW_SHOWMAXIMIZED as long,_    'flag for maximize
  result As long
wait 

And if you don't mind it being LBB-specific you can get the mainwin handle more easily using BBC BASIC code:

Code:
!mainwinhandle = @hwnd%

calldll #user32, "ShowWindow",_
  mainwinhandle as ulong,_       'mainwindow handle
  _SW_SHOWMAXIMIZED as long,_    'flag for maximize
  result As long
wait 

Richard.
User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx Re: Maximising the main window
« Reply #2 on: Oct 12th, 2015, 6:21pm »

Thank you Richard. That works very well.

Another issue in the main window you could help me with:

How do I dictate the font I use in the main window and can I change it in different parts of the program.

Ray
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Maximising the main window
« Reply #3 on: Oct 12th, 2015, 9:12pm »

on Oct 12th, 2015, 6:21pm, RNBW wrote:
How do I dictate the font I use in the main window and can I change it in different parts of the program.

http://lbb.conforums.com/index.cgi?board=compatibility&action=display&num=1420991703

But I'm sure the LB fraternity would want me to advise you not to do it. The mainwin is primarily intended for debugging, rather than as a user interface.

Richard.
User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx Re: Maximising the main window
« Reply #4 on: Oct 12th, 2015, 10:24pm »

Richard

Thank you for the link. That works fine, with one or two little quirks that were mentioned in the link, but these are minor and it looks as though you have solved the mouse problem with INPUT.

I have no concerns about what the LB fraternity think about the use of the mainwin as a console. As a user, I can use the program's capabilities in the way it meets my requirements. I haven't written the program as a GUI (I'm working on it) and the mainwin meets my requirements.

Ray

User IP Logged

AAW
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx Re: Maximising the main window
« Reply #5 on: Oct 13th, 2015, 10:04am »

on Oct 12th, 2015, 9:12pm, Richard Russell wrote:
http://lbb.conforums.com/index.cgi?board=compatibility&action=display&num=1420991703

But I'm sure the LB fraternity would want me to advise you not to do it. The mainwin is primarily intended for debugging, rather than as a user interface.

Richard.


I don't know who is in the fraternity, but I do not offer that advice. I suggest that people use either a GUI or the main window, but not both in the same program. The mainwin is intended to replicate the old-style console. GUIs provide event-driven programs. They don't mix well. I do use the mainwin to document debugging messages during development of a GUI program, then disable it when the program is finished.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Maximising the main window
« Reply #6 on: Oct 13th, 2015, 11:34am »

on Oct 13th, 2015, 10:04am, AAW wrote:
The mainwin is intended to replicate the old-style console.

If by "old-style console" you literally mean the scrolling 'teletype' interface provided by MS-DOS, Unix/Linux, the command processor in Windows etc. then certainly the mainwin is in most respects an acceptable substitute (I might question the way it shares settings with the IDE in LB/JB). If the program requires only a basic UI of that sort then using the mainwin is fine and I didn't mean to discourage it - although I might argue that (in LBB) you would be better off compiling the program as a true console application.

However what I suspect many people who try to use the mainwin for their I/O are really wanting is something akin to the interface provided by old BASICs such as QBASIC, BBC BASIC, Spectrum BASIC etc. These typically provide both text and graphics output, with control over font, color etc. They also support things like testing the keyboard without waiting, which is important for simple games etc. LB/JB doesn't provide that sort of traditional interface; if you need anything beyond a basic text console you are forced to move to a fully-fledged event-driven GUI (e.g. a graphics window) which can make it difficult to port code from older BASICs and which some people find difficult to adapt to.

What I was really advising the OP against was taking advantage of the fact that 'behind the scenes' the LBB mainwin does have all these traditional capabilities, which can be accessed using embedded BBC BASIC statements (e.g. to change the font and color, draw graphics etc.). It can be tempting to go down this route instead of learning how to write a proper GUI program, but I would argue that it's not in the 'spirit' of Liberty BASIC to do so. But of course it's entirely up to the user how he uses the language, and to the extent that LBB supports these features he is free to use them, with the proviso that there may well be side-effects from mixing Liberty and BBC code.

Richard.
User IP Logged

AAW
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx Re: Maximising the main window
« Reply #7 on: Oct 14th, 2015, 3:42pm »

Good points, Richard. Yes, the mainwin is for plain text entry only.

Back in QBasic days, I recall quite a few published attempts to create a graphical user interface, similar to a Window (before Windows existed.) wink

I use the mainwin to test routines before I insert them into a GUI program. It's a great way to test loops, file handling, logic, math, etc.
User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx Re: Maximising the main window
« Reply #8 on: Oct 15th, 2015, 09:29am »

Alyce

I'm sorry, but you appear to have a very short sighted view of the usefulness of the mainwin, or indeed how it should be used.

As a Chartered Builder and a Project Manager, I know that in resolving any problem it is necessary to know what you are trying to achieve and to look at the tools, skills and capabilities you have available.

In Liberty Basic and LB Booster, you have a mainwin, which can be used for both text and GUI based solutions (although I must admit I do tend to use it for text based solutions) and you also have the ability to create windows, dialog boxes and various gadgets. These all look very nice on the screen, but one of the problems you may have is the requirement to provide your solution in hard copy. GUI is not very good at producing high quality hard copy.

This is where I use the mainwin. You can code your program so that in addition to producing a GUI layout, it also produces copy onto the mainwin (in the way that you would if you were using a non-GUI solution). This will enable you to set out the solution as you would wish to see it in hard copy (eg producing calculations for steel beams, etc). You can check this layout to ensure it is how you want it. You can then set up the same code but using LPRINT instead of PRINT to produce hard copy. A crisp high quality output.

If you subsequently, decide that you have thoroughly debugged you code and have the confidence that you will be able to get the correct hard copy, then you can introduce NOMAINWIN. You may wish to do this if you are producing a commercial programme, but most people are not. The mainwin sits in the background and the windows etc that you create sit on top of it.

Whilst, it may not be the way that you would wish to use the mainwin, it can provide solutions for others and its use should not be discouraged.

I would suggest to anyone using LB or LBB to check out all the possible interface uses and decide themselves how they wish to use them. Always remember that coding is simply a means to achieve a solution. Constraints prevent innovation.

Ray
User IP Logged

AAW
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx Re: Maximising the main window
« Reply #9 on: Oct 15th, 2015, 10:56am »

Ray, you do not appear to understand my cryptic posts. First, Richard said that the "fraternity" claimed the mainwin is only for debugging. I disagreed with that advice, hence my response. I further gave examples of my own use of the mainwin, which pretty much matched your own use.

I field many questions from absolute beginners. I advise them to use a GUI or the mainwin, but not both in the same program because novices can be quite confused. See the thread on writing a compiler on the Community Forum. The member there issued a "nomainwin", then wrote code that relied on the mainwin for input and display. He did not understand why he got nothing when he ran his code. It is folks like this who do well to use one or the other and not mix them.

Experienced programmers such as yourself can certainly use any tools in any way that suits their needs. My advice is generally for complete novices.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Maximising the main window
« Reply #10 on: Oct 15th, 2015, 10:58am »

on Oct 15th, 2015, 09:29am, RNBW wrote:
This will enable you to set out the solution as you would wish to see it in hard copy (eg producing calculations for steel beams, etc). You can check this layout to ensure it is how you want it. You can then set up the same code but using LPRINT instead of PRINT to produce hard copy. A crisp high quality output.

An alternative approach, not involving the mainwin, is to preview your hardcopy output in a (normally) invisible graphics window, and then send it to the printer using the GUI print command. This method makes it easier to combine text and graphics on the same page, allows you to center text automatically (using LPRINT you will probably need to use trial-and-error) and supports colored text (which with LPRINT requires API calls).

It's true that in LBB the print quality can suffer using this approach (because it uses a bitmap rather than a metafile) but that can be overcome by making the graphics window large enough. Here's an example of what I mean, using a large invisible window to give 600-dpi equivalent quality (LBB only; it doesn't work properly in LB):

Code:
    PaperWidth = 7.0   ' Printable width in inches
    PaperHeight = 10.0 ' Printable height in inches
    DotsPerInch = 600  ' Equivalent DPI quality
    
    WindowWidth = PaperWidth * DotsPerInch
    WindowHeight = PaperHeight * DotsPerInch
    stylebits #preview, 0, _WS_VISIBLE, 0, 0
    open "Printer Preview" for graphics_nf_nsb as #preview
    
    title$ = "My centered page title"
    #preview "font Arial 0 200 underscore"
    #preview "stringwidth? title$ stringwidth"
    #preview "place ";(WindowWidth-stringwidth)/2;" ";500
    #preview "color blue"
    #preview "\"; title$
    #preview "print ";WindowWidth
    close #preview 

Richard.
« Last Edit: Oct 15th, 2015, 11:02am by Richard Russell » User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx Re: Maximising the main window
« Reply #11 on: Oct 15th, 2015, 12:52pm »

Alyce
Your comments are noted and understood.

Richard
The sort of formatting that I am thinking about requires the positioning of text on a page, which I do using the old fashioned TAB and USING. I tend to use mono fonts and there are several that are quite good looking these days. They make it easier to line up numbers, for example and I don't normally have a need for different colours. However, I can see that for some purposes graphics window could be the way to go.

is there a way to control the position of text and numbers in a graphics window?

Ray
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Maximising the main window
« Reply #12 on: Oct 15th, 2015, 4:27pm »

on Oct 15th, 2015, 12:52pm, RNBW wrote:
is there a way to control the position of text and numbers in a graphics window?

Far more easily than you can using LPRINT! I listed a code example which automatically centres a string, by calculating the coordinates at which it needs to be drawn. You can use a similar technique to draw subscripts and superscripts, align text in columns (even when it is proportional spaced) etc.

Whenever accurate positioning is important a graphics window is the way to go. Even if you can get close to what you want using LPRINT, the chances are that switching to a different printer will upset your careful alignment (for example if the resolution or page margins are different, which will almost certainly be the case).

Really the only good use of LPRINT I can think of is when you want the text to 'flow' from one line to the next and/or from one page to the next when necessary. In other words rather than determining the page layout yourself you want the PC to do it automatically according to the sizes of the paper, margins and text.

Richard.
User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx Re: Maximising the main window
« Reply #13 on: Oct 15th, 2015, 7:26pm »

Richard
I hear what you are saying, but we will have to agree to disagree on this. I've been using the LPRINT method from DOS and, although it may now seem old fashioned I know it works using mono fonts and with TAB and USING. I can print out exactly as I want to whatever printer I want and I have used dot matrix, ink jet and laser printers.

What is not always possible its changing the sizes of the print.

Many years ago (good god it's over 30 years ago), I wrote a program for my employer designing structural beams. It was designed in such a way that the hard copy output (to a dot matrix printer) would be the same as if it had been produced by hand. This avoided having to have the program approved by countless Building Control Departments. This was done using LPRINT, etc. At that time there was no other way and I've used it ever since.

It should be said the program outlasted me by several years as I left structural design behind and went into project management.

I hope that explains why I am such a 'stick-in-the-mud' on this subject.

Ray
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls