March 28, 2024, 11:51:36 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Custom window with menu items

Started by Andy, December 10, 2017, 02:50:19 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

December 10, 2017, 02:50:19 AM Last Edit: December 10, 2017, 04:10:31 AM by Andy
I've been updating my custom window library and thought I would post a copy here for people to have a look at.

I have now simplified the menu structure so you now only have to pass some text for the menu item plus a unique control ID.

MyMenuTitle("Project",17)
MyMenuItem("PItem1",31)

MyPopupTitle("PPopup",32)
  MyPopupItem("PPopup 1",70)
  MyPopupItem("PPopup 2",71)
  MyPopupItem("PPopup 3",72)
        MyPopupEnd()

MyMenuItem("PItem2",34)
MyMenuEnd()


I've also simplified the monitoring of the custom window, which is now just one line.

      case @IDTIMER

           'All we need for the custom window.
           CheckWindow(w1,min,close) '<-- Check window for min / close / menu activity.


What you can / and can't do at the moment:

You can have icons and separators for menu items, and popup titles.
You can have multiple popups per menu title.
You can have popups in different menu titles.

You can't (at the moment) have the above for popup items, and no you can't have a popup inside a popup just yet.

Think you'll find this very easy to understand and use should you want to make your own custom window.

All variables in the library file are prefixed with the letters "cw" to avoid conflicts with any variables you might use.

Current limits:
100 menu titles, 100 popup titles, 1000 menu items.

Enjoy.

Thanks,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

December 14, 2017, 05:58:08 AM #1 Last Edit: December 14, 2017, 06:03:07 AM by Andy
Here is some more features for you.

Now you can change the menu item into a check box or radio button.

You can also change the colour of a menu item / popup title / popup item.

I think this is starting to give new life to a window's menu.

As these items are normal standard controls, you could also play around with say making some of them italics, underlined etc.... something I will put in later.

I hope someone can find a use for this.

Thanks,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

I rather like being able to colour a menu entry - that's pretty good

I notice that you can't move the window about the screen, and also the window is not resizable. Any ideas on that?

Not at all putting a dampener on the project - it was just a thought

Wondering why you are using customwindow.inc and not the customwindow.lib?

Brian

Andy

December 14, 2017, 10:51:13 AM #3 Last Edit: December 14, 2017, 10:53:07 AM by Andy
Brian,

The inlcude file uses the lib file.

No I've not got to moving and resizing windows yet, but I am on it.

Hope that helps.

I will post the above when I have had time to do it.

It is complicatey re inventing the wheel.

Thanks for the positive feedback, that helps me keep going!

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Brian,

Just looking at the moving / resizing of a window.

I'm concentrating on the moving part first, and having some success.  When you want to move a window you have to drag the window's caption - however, we don't have a normal caption here so to speak.

But I can drag my caption (a static control) and I'm starting to get the window to move with it.

When (if) I crack this, I will look at the resize problem - which I think should be a little easier.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

jalih

Quote from: Andy on December 15, 2017, 06:28:53 AM
I'm concentrating on the moving part first, and having some success.  When you want to move a window you have to drag the window's caption - however, we don't have a normal caption here so to speak.

But I can drag my caption (a static control) and I'm starting to get the window to move with it.

When (if) I crack this, I will look at the resize problem - which I think should be a little easier.

Both moving and resizing can be solved the same way: handle WM_NCHITTEST window message, check mouse cursor position inside window and return the value accordingly.

Andy

Well, got there with this now.

This now gives you the ability to create a custom window without a maximise button, which is fully movable and re-sizable - and with menu items.

All the important lines in the example are marked with a commented <--

At first glance you might need to study it a little, but if you follow my simple rules in the example you can easily build one for yourself.

Thanks again for everyone who has helped / suggested solutions.

There are one or two small things I need to correct, but I think you will agree it does exactly what it says on the tin.

Enjoy,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

I will have to look later - I keep getting the Death Stare from the Missus!

Brian

Andy

Brian,

I see you survived!

Did you get around to having a look yet, didn't think I'd get this far with it before Christmas.

I've fine tuned a couple of things and soon I'll release it, unless anyone wants something else with it that will be it I think - not easy re-inventing the wheel.

You want to see just how many people want to hide the max box - well it's done.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

Yes, all in one piece - I think it was because I was f*rting about on my PC, while she was writing Christmas cards!

Been for haircut this morning, visiting a neighbour this afternoon, whose wife died last week, a good friend of ours

Will get to it today

Brian

Andy

December 19, 2017, 04:11:00 AM #10 Last Edit: December 19, 2017, 04:58:50 AM by Andy
This is the final version of the custom window.

I've made it even more simple to use, and put more documentation into the example program.

Thanks again every one.

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

December 19, 2017, 05:00:53 AM #11 Last Edit: December 19, 2017, 05:08:23 AM by Brian Pugh
Andy,

Before I try this one, I noticed that if you resize the window, and resize over the title bar text, the text gets broken up, and is only recovered if you click somewhere in the title bar

Also, where are you setting the font and size for the title bar and menu items?

Brian

Edit: I am getting these errors on the new build:

Compiling...
customwindowFinal.iwb
File: C:\Users\Public\Documents\IWBasic\projects\MouseOverControls5\customwindowFinal.iwb (121) Error: Undefined function RegisterControls
File: C:\Users\Public\Documents\IWBasic\projects\MouseOverControls5\customwindowFinal.iwb (143) Error: wrong number of parameters in CheckWindow. Should be 3 but 1 given.
File: C:\Users\Public\Documents\IWBasic\projects\MouseOverControls5\customwindow.inc (110) Warning: See previous declaration
File: C:\Users\Public\Documents\IWBasic\projects\MouseOverControls5\customwindowFinal.iwb (146) Error: Undefined function MoveTheWindow
File: C:\Users\Public\Documents\IWBasic\projects\MouseOverControls5\MouseOverControls.inc (35) Warning: Unreferenced variable 'f1'
Error(s) in compiling C:\Users\Public\Documents\IWBasic\projects\MouseOverControls5\customwindowFinal.iwb


Andy

December 19, 2017, 05:08:50 AM #12 Last Edit: December 19, 2017, 05:18:35 AM by Andy
Brian,

Sorry for the errors - you beat me to it - I was just updating the zip file - please download it again and copy the usual lib and inc files to your IWBDev folders.

Have downloaded it myself now just to check - everything is okay at my end now.

Hopefully with this final version the text problem should be solved.

The library sets the window's caption to Arial, font size 10, BUT - if you look at the example program I have changed the colour and style of the caption because it's only a static control and it's easy to do now.

You can of course change the font, weight etc as well.

Andy.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Nope, not working for me - same errors

Brian

Andy

December 19, 2017, 05:31:58 AM #14 Last Edit: December 19, 2017, 06:29:57 AM by Andy
Brian,

C:\Users\Public\Documents\IWBasic\projects is where the examples for IWB are stored.

You have the old version - the sub routine CheckWindow now only has one parameter which is in the customwindow.inc file.

sub CheckWindow(window WinIn),int


The sub routines "RegisterControls" and "MoveTheWindow" are also in there.

The location on my PC where the include / lib files should reside is:

C:\IWBDev\Include
C:\IWBDev\Libs

Try copying the inc and lib files to these locations (overwrite the other versions).

The menu titles, items, popup titles, popup items font style and sizes are set with the sub routine "MyMenuEnd()".

But again, because these are just ordinary controls you can again set the font, style, weight etc of these items in the ordinary way.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Duh! I still had the old .inc and .lib files in the folder where the example program is!

Anyway, how do you set the font for the menus? I've set the caption font and size

And it still messes the caption text up when you resize the window

Brian

Andy

December 19, 2017, 07:41:13 AM #16 Last Edit: December 19, 2017, 07:45:39 AM by Andy
Brian,

For menu items etc, just do this:

'Because the caption is just a static control, we can play around with it's appearance.
'Here I'm changing it's colour, but you could make it italic, underlined etc...
SETCONTROLCOLOR w1,caption,rgb(65,105,225),rgb(255,255,255)
SETFONT w1,"Arial",10,700,@SFITALIC|@SFUNDERLINE,caption

SETFONT w1,"Arial",10,700,@SFITALIC|@SFUNDERLINE,1 '<-- This (menu title "File").
SETFONT w1,"Arial",10,700,@SFITALIC,6 '<-- This (menu item "Exit").
setcontroltext w1,6,"       Exit" '<-- This - you'll have to play around with the spacing before the text.

starttimer w1,100 '<-- Start the timer.


The lines marked with "<-- This." - just set the font / style etc as you would for any control id.

Don't get the same problem with the caption - I will have to look into it for you.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

December 20, 2017, 12:26:28 AM #17 Last Edit: December 20, 2017, 12:41:48 AM by Andy
Brian,

Does the caption text mess up with the new example program unchanged?


autodefine "off"

$Include "MouseOverControls.inc" '<-- Must include this file.
$include "customwindow.inc"      '<-- Must include this file.

'Your window, call it what you want...
window w1

'Your program icon, you choose...
'Size 26 x 28.
uint progicon = loadimage(getstartpath + "progicon.jpg",@IMGSCALABLE)

'Your menu item icon images, if you want any...
'Size must be 20 x 20!
uint hIcon = LoadImage(getstartpath + "WAV.ico", @IMGICON)
uint hIcon2 = LoadImage(getstartpath + "WAV2.ico", @IMGICON)

'Control range for NON menu item / title / separator controls
'This will diable any controls that might be overlapped by menu
'items when the menu is clicked - but here I'm simply disabling
'all other controls.

cwMyControlsBeginAt = 100
cwMyControlsEndAt = 200

'Some constants used for minimise / close / window caption controls.
'But you can call them anything you like...
const min     = 500
const close   = 501
const caption = 502

'Open a normal window but without a caption and allow sizing.
openwindow w1,10,20,600,400,@NOCAPTION|@SIZE,0,"",&w1_handler

CreateBorder(w1,progicon) '<-- Show a program icon and sub class the caption control for tracking.

'Some normal IWB controls, you choose.....
CONTROL w1,@BUTTON," This is an Exit button",10,250,250,25,0x50000000,100
CONTROL w1,@STATIC," This is a static",10,200,200,20,SS_NOTIFY,101

'===============================================================
' Menu items (if you want some, create after other controls!)...
'
' Each menu titles / item / separator must
' have a unique ID control number.
'===============================================================

MyMenuTitle("File",1) '<-- Menu ID for "File" is 1.
MyMenuItem("FItem1",2) '<-- Menu item belongs to Menu ID 1, and control ID 2.
   MySeparator(3)
MyMenuItem("FItem2222222222222",4,hIcon) '<-- Menu item belongs to Menu ID 1, and control ID 4.
   'NOTE:- The above menu item has an icon, loaded by passing an option uint (of the icon).
   MySeparator(5)
MyMenuItem("Exit",6)
MyMenuEnd() '<-- End the menu title for MeunID 1 - No control ID needed.

MyMenuTitle("Edit",10) '<-- Menu ID for "Edit" is 10.
MyMenuItem("EItem1",11,0,0,rgb(255,255,255),rgb(150,150,150))
MyMenuItem("EItem2",12)

MyPopupTitle("EPopupT1",13) '<-- Start a popup menu, ID is 13.
  MyPopupItem("EPopup 1",14) '<-- Popup item 1, ID is 14.
  MyPopupItem("EPopup 2",15)
  MyPopupItem("EPopup 3",16,0,0,rgb(255,255,255),rgb(60,179,113))
  MyPopupItem("EPopup 4",17)
   MyPopupEnd() '<-- End the popup title for Popup ID 13 - No control ID needed.

   MyMenuItem("EItem3",20,0,0,rgb(255,255,255),rgb(150,150,150))

   MySeparator(21)

MyPopupTitle("EPopupT2",22,hIcon2,0,rgb(255,255,255),rgb(255,160,122))
  MyPopupItem("EPopup 21",23)
  MyPopupItem("EPopup 22",24)
  MyPopupItem("EPopup 23",25)
  MyPopupItem("EPopup 24",26)
   MyPopupEnd()

   MySeparator(30)

MyPopupTitle("EPopupT4",31)
  MyPopupItem("EPopup 41",32)
  MyPopupItem("EPopup 42",33)
  MyPopupItem("EPopup 43",34)
  MyPopupItem("EPopup 44",35)
   MyPopupEnd()

MyMenuEnd()

MyMenuTitle("Resource",40) '<-- Menu ID for "Resource" is 40.
MyMenuItem("RItem1",41,0,2) '<-- Menu item belongs to Menu ID 40, and control ID 41.
   ' 0 denores no icon, 2 donotes a radio button.

MyMenuEnd()

MyMenuTitle("Project",50)
MyMenuItem("PItem1",51,0,1)
   ' 0 denores no icon, 1 donotes a checkbox.

MyPopupTitle("PPopup",52)
  MyPopupItem("PPopup 1",53)
  MyPopupItem("PPopup 2",54)
  MyPopupItem("PPopup 3",55)
   MyPopupEnd()

MyPopupTitle("PPopup2",60)
  MyPopupItem("PPopup 21",61)
  MyPopupItem("PPopup 22",62)
  MyPopupItem("PPopup 23",63)
   MyPopupEnd()

MyMenuItem("PItem2",70)
MyMenuEnd()

MyMenuUpdate(w1) '<-- Finally update the menu.

'=============================================
' End of your custom menu, if you wanted one.
'=============================================

RegisterControls() '<-- Register the min / close / caption controls for tracking....

'Because the caption is just a static control, we can play around with it's appearance.
'Here I'm changing it's colour, but you could make it italic, underlined etc...
SETCONTROLCOLOR w1,caption,rgb(65,105,225),rgb(255,255,255)
SETFONT w1,"Arial",10,700,@SFITALIC|@SFUNDERLINE,caption

'SETFONT w1,"Arial",10,700,@SFITALIC|@SFUNDERLINE,1 '<-- This.
'SETFONT w1,"Arial",10,700,@SFITALIC,6 '<-- This.
'setcontroltext w1,6,"       Exit" '<-- This - you'll have to play around with the spacing.

starttimer w1,100 '<-- Start the timer.

waituntil w1 = 0
end

sub w1_handler(),int

SELECT @MESSAGE

CASE @IDCREATE
  centerwindow w1
           CreateCaption(w1,caption,"This is my window's caption.",min,close) '<-- Routine to create our custom caption.
   
      case @IDTIMER '<-- Must include this section.
           Trackwindow(w1) '<-- Keep track of window / controls incase they are moved /resized.
           CheckWindow(w1) '<-- Check window for min / close / menu activity.

   case @IDSIZECHANGED '<-- Must include this section.
           MoveTheWindow() '<-- Move the window.

      CASE @IDCONTROL

         SELECT @CONTROLID

             case 100 'An exit button if you like...
                if @NOTIFYCODE = 0
                   closewindow w1
                   CloseCaption() '<-- Deletes the min / close images and un-subclasses the cation control.
deleteimage progicon,@IMGSCALABLE
deleteimage hIcon,@IMGICON
deleteimage hIcon2,@IMGICON
                   end
                endif

             'Menu titles selection,(File / Edit / Resource etc)...
             'Detect when a menu title is clicked so we can show the menu items.

             case 1 'File
                if @NOTIFYCODE = 0
                    MenuClicked(w1,1)
                endif

             case 10 'Edit
                if @NOTIFYCODE = 0
                    MenuClicked(w1,10)
                endif

             case 40 'Resource
                if @NOTIFYCODE = 0
                    MenuClicked(w1,40)
                endif

             case 50 'Project
                if @NOTIFYCODE = 0
                    MenuClicked(w1,50)
                endif

             'Menu item selection...
             case 2 'A menu Item click - do something....
                if @NOTIFYCODE = 0
                   HideAllMenuItems(w1) '<-- Hide the menu items.
                   openconsole
                   print
                   print
                   print "  Menu item control 2 clicked...."
                   print
                   print "  Press any key to close console window."
                   print
                   do:until inkey$ <> ""
                   closeconsole
                endif

             case 6 'File - Exit, do something....
                if @NOTIFYCODE = 0
                   closewindow w1
                   CloseCaption() '<-- Deletes the min / close images and un-subclasses the cation control.
deleteimage progicon,@IMGSCALABLE
deleteimage hIcon,@IMGICON
deleteimage hIcon2,@IMGICON
                   end
                endif

          endselect
     
      'Note - the close window is not used / needed anymore
      'as we are not using any of the window's min / max / close buttons.
      'case @IDCLOSEWINDOW
     
    endselect

RETURN 0
EndSub



Also, what font and size are you changing the caption to?

I've tried moving and resizing the window every which way and I don't get any problems here at my end.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

Just compiled and run your above code. I had only changed the font on my test, from Arial to Segoe UI. Unfortunately, it still messes the caption text up if you resize the window over the text, and then resize back again. Clicking in the titlebar area restores the text

I have not altered your test code in any way this morning

Brian

Egil

Andy,
Finally came around to test your code today. I am impressed!

The resize  caption text messup can easily be fixed by redrawing the caption after resize.

I fixed it by adding three lines to the code you posted today,  but I'm sure this can be done in several ways:
   case @IDSIZECHANGED '<-- Must include this section.
MoveTheWindow() '<-- Move the window.

' The new lines goes here:
CreateCaption(w1,caption,"This is my window's caption.",min,close) '<-- Routine to create our custom caption.
SETCONTROLCOLOR w1,caption,rgb(65,105,225),rgb(255,255,255)
SETFONT w1,"Arial",10,700,@SFITALIC|@SFUNDERLINE,caption



Support Amateur Radio  -  Have a ham  for dinner!

Andy

Brian,

I changed the font to Segoe UI - but I still can't get it to mess up i.e. it works fine for me.

I hope Egil's suggestion works for you - otherwise I'm a little stumped at your problem.

Egil,

Thanks for the encouragement!, greatly appreciated, it's taken weeks now to get this far.
Also thanks for the suggestion for Brian, I hope it helps him.
By the way, it's nice to see you around again!

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Egil

December 21, 2017, 01:49:11 AM #21 Last Edit: December 21, 2017, 04:59:49 AM by Egil
This morning I experimented a little. Ended up with this code change:

   case @IDSIZECHANGED '<-- Must include this section.
MoveTheWindow() '<-- Move the window.

CreateCaption(w1,caption,"This is my window's caption.",min,close) '<-- Routine to create our custom caption.
CreateBorder(w1,progicon) '<-- Show a program icon and sub class the caption control for tracking.
SETFONT w1,"Arial",10,700,@SFITALIC|@SFUNDERLINE,caption
SETCONTROLCOLOR w1,caption,rgb(65,105,225),rgb(255,255,255)


The problem occours if you reduce the width so much that the actual with becomes less than the width of the bitmaps plus text length. When the width becomes smaller than that, both the text and the bitmaps are scrolled down, and when the windows again is made wider, remains of the scrolled bitmaps and text is left behind.
Maybe it can be avoided by modifying the CreateCaption  function, or hard program a minimum accepted resize width.


Thanks for sharing your ideas.

Egil

Support Amateur Radio  -  Have a ham  for dinner!

Andy

Thanks Egil,

That's interesting, I have code that can stop the window from being resized to small, I will have a look at it as soon as I get home.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Egil

Andy,

Was in a hurry when I posted this morning, and the result was a lot of typos. But guess you understood what I meant.

Egil
Support Amateur Radio  -  Have a ham  for dinner!

Andy

December 21, 2017, 06:34:29 AM #24 Last Edit: December 21, 2017, 06:40:10 AM by Andy
Egil,

I understood you loud and clear!

With this update we can restrict the minimum size a window can be, i.e the user can resize it small until it reaches the size X and Y you specify.

The new section in the handler is this:


           case WM_GETMINMAXINFO '<-- Must include this section.
                   WindowMinSize(420,300) '<-- Min X / Min Y size of the window - here 420 across, 300 down.

   case @IDSIZECHANGED  '<-- Must include this section.
                  MoveTheWindow() '<-- Move the window.


Don't forget to copy the inc and lib files to:

C:\IWBDev\Include
C:\IWBDev\Libs

Otherwise you need to use Egil's suggestion.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.