| 
 
| 
|  Author | Topic: Creating a child window  (Read 1045 times) |  |  
| 
| 
| g3nrw Junior Member
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 74
 
 | 
|  | Creating a child window « Thread started on: Jul 27th, 2014, 6:25pm »
 |  |  I am trying to create a child window, following:
 
 http://www.bbcbasic.co.uk/bbcwin/manual/bbcwing.html#fnwindow
 
 As a testbed, I am modifying DLGDEMO. The additional initialization code looks like this:
 
 Code:
 
      INSTALL @lib$+"WINLIB5A"
      WS_POPUP = &80000000
      style% = WS_CHILD + WS_VISIBLE + WS_POPUP
      child%=FN_createwindow(dlg%,"","CHILD WINDOW",style%, 20, 20, 260, 328, 200,0)
 
 Then in the code that handles the "OK" button click, I have included:
 Code:
 
 But there is no sign of a child window when I click on OK.
 
 I suspect the parameters I supplied to FN_createwindow are incorrect or inappropriate -- the documentation doesn't help here, particularly as the parameters don't seem to line up with WINAPI CreateWindow or CreateWindowEx.
 
 Where have I erred?
 
 --
 Ian
 
 
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| rtr Guest
 
 | 
|  | Re: Creating a child window « Reply #1 on: Jul 27th, 2014, 8:22pm »
 |  |  on Jul 27th, 2014, 6:25pm, g3nrw  wrote:
 The FN_createwindow function (in WINLIB5x) returns a window handle whereas the PROC_showdialog function (in WINLIB2x) takes as its parameter a pointer to a dialogue template in memory.  So these two functions are quite incompatible, and you can't use them in combination as you seem to be attempting.
 
 (Aside: The abandoned GUILIB project had as one of its objectives integrating non-dialogue child windows with dialogue controls, so the same functions could be used with both, but it wasn't to be.)
 
 If you want to show or hide a child window you can use the ShowWindow API function:
 
 Code:
       SYS "ShowWindow", child%, SW_SHOW
      SYS "ShowWindow", child%, SW_HIDE You might want to consider using a naming convention which would remind you of the data type, for example if you called it hwndChild% it would emphasise that it's a window handle, whereas simply calling it child% doesn't give any clue.  It's (arguably) a disadvantage of BASIC that it doesn't enforce type safety, in the way C++ does for example, but you can go some way by adopting naming conventions.
 
 Richard.
 
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| g3nrw Junior Member
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 74
 
 | 
|  | Re: Creating a child window « Reply #2 on: Jul 28th, 2014, 4:37pm »
 |  |  Thanks Richard.
 
 Child creation still remains elusive. Here is the complete modified DLGBASIC program:
 
 Code:
 
      REM +++++  DLGDEMO, modified to open a child window
      REM. Program to demonstrate a Dialogue Box
      INSTALL @lib$+"WINLIB2"
      BS_DEFPUSHBUTTON = &1
      CB_ADDSTRING = &143
      CB_SETCURSEL = &14E
      CBS_DROPDOWNLIST = &3
      ES_AUTOHSCROLL = &80
      ES_NUMBER = &2000
      LB_ADDSTRING = &180
      LB_GETCURSEL = &188
      UDM_SETRANGE = &465
      UDS_ALIGNRIGHT = &4
      UDS_AUTOBUDDY = &10
      UDS_SETBUDDYINT = &2
      WS_CHILD = &40000000
      WS_GROUP = &20000
      WS_VISIBLE = &10000000
  REM +++++++++++++++++++++++++++++++++++++++ new code:
      SW_SHOW = 5
      SW_HIDE = 0
      dlg%=FN_newdialog("Dialogue box", 20, 20, 160, 128, 8, 32768)
      INSTALL @lib$+"WINLIB5A"
      WS_POPUP = &80000000
      style% = WS_CHILD + WS_VISIBLE + WS_POPUP
      hwndChild%=FN_createwindow(dlg%, "","CHILD WINDOW",style%, 20, 20, 260, 100, 200,2000)
      REM +++++++++++++++++++++++++++++++++++++++
      PROC_groupbox(dlg%, "Group box", 0, 4, 4, 152, 96, WS_GROUP)
      PROC_editbox(dlg%, "Text box", 101, 12, 20, 64, 12, ES_AUTOHSCROLL)
      PROC_editbox(dlg%, "123456", 102, 82, 20, 64, 12, ES_NUMBER)
      PROC_dlgctrl(dlg%, "", 109, 0, 0, 12, 12, WS_VISIBLE OR WS_CHILD OR \
      \ UDS_AUTOBUDDY OR UDS_ALIGNRIGHT OR UDS_SETBUDDYINT, "msctls_updown32")
      PROC_combobox(dlg%, "", 103, 12, 40, 64, 60, CBS_DROPDOWNLIST)
      PROC_listbox(dlg%, "", 104, 82, 40, 64, 48, 0)
      PROC_radiobutton(dlg%, "Radiobutton 1", 105, 12, 64, 64, 10, 0)
      PROC_radiobutton(dlg%, "Radiobutton 2", 106, 12, 82, 64, 10, 0)
      PROC_checkbox(dlg%, "Checkbox", 107, 82, 82, 64, 10, 0)
      PROC_pushbutton(dlg%, "OK", 1, 12, 108, 56, 14, WS_GROUP OR BS_DEFPUSHBUTTON)
      PROC_pushbutton(dlg%, "Cancel", 2, 92, 108, 56, 14, 0)
      PROC_showdialog(dlg%)
      ON CLOSE PROC_closedialog(dlg%):QUIT
      ON ERROR PROC_closedialog(dlg%):PRINT'REPORT$:END
      SYS "SendDlgItemMessage", !dlg%, 103, CB_ADDSTRING, 0, "Combobox 1"
      SYS "SendDlgItemMessage", !dlg%, 103, CB_ADDSTRING, 0, "Combobox 2"
      SYS "SendDlgItemMessage", !dlg%, 103, CB_ADDSTRING, 0, "Combobox 3"
      SYS "SendDlgItemMessage", !dlg%, 103, CB_ADDSTRING, 0, "Combobox 4"
      SYS "SendDlgItemMessage", !dlg%, 103, CB_SETCURSEL, 0, 0
      SYS "SendDlgItemMessage", !dlg%, 104, LB_ADDSTRING, 0, "Listbox item 0"
      SYS "SendDlgItemMessage", !dlg%, 104, LB_ADDSTRING, 0, "Listbox item 1"
      SYS "SendDlgItemMessage", !dlg%, 104, LB_ADDSTRING, 0, "Listbox item 2"
      SYS "SendDlgItemMessage", !dlg%, 104, LB_ADDSTRING, 0, "Listbox item 3"
      SYS "CheckRadioButton", !dlg%, 105, 106, 105
      SYS "SendDlgItemMessage", !dlg%, 109, UDM_SETRANGE, 0, 999
      Click%=0
      ON SYS Click% = @wparam% : RETURN
      REPEAT
        WAIT 1
        click%=0
        SWAP Click%, click%
      UNTIL click%=1 OR click%=2 OR !dlg%=0
      IF click%=1 THEN
  
  
        REM +++++++++++++++++++++++++++++++++++++++ new code:
  
        SYS "ShowWindow", hwndChild%, SW_SHOW
        SYS "MessageBox", @hwnd%, "Child should be open by now", "",0
  
        REM +++++++++++++++++++++++++++++++++++++++
  
  
      ELSE
        PRINT "Cancel pressed"
      ENDIF
      PROC_closedialog(dlg%)
      END
 
 When I click on OK, the child does not appear. As before, I suspect the parameters to FN_createwindow are not correct.
 
 --
 Ian
 
 
 |  
| 
| « Last Edit: Jul 28th, 2014, 4:45pm by g3nrw » |  Logged |  
 |  |  |  
| 
| 
| rtr Guest
 
 | 
|  | Re: Creating a child window « Reply #3 on: Jul 28th, 2014, 5:57pm »
 |  |  on Jul 28th, 2014, 4:37pm, g3nrw  wrote:
 | | As before, I suspect the parameters to FN_createwindow are not correct. | 
 | 
 You're right, they're not (for example the class name is set to an empty string!), but there's a more fundamental problem.  You appear to be wanting to create the child window in a dialogue box, in which case you shouldn't be calling FN_createwindow at all but rather PROC_dlgctrl.
 
 As I tried to explain in my last reply, the routines for creating a child control in a dialogue box (which can be found in WINLIB2x) are different from - and incompatible with - the routines for creating a child window on the mainwin or other non-dialogue window (which can be found in WINLIB5x).  Mixing them won't work, or at least it won't work reliably.
 
 If you need more specific help please provide this information:
 
 Are you definitely wanting to create the child window in a dialogue box, as your code suggests?Richard.
 What kind of child window are you wanting to create?
 
 
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| g3nrw Junior Member
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 74
 
 | 
|  | Re: Creating a child window « Reply #4 on: Jul 28th, 2014, 7:05pm »
 |  |  OK, back to basics.
 
 Using DLGBASIC as a model, I have constructed a dialog box containing around 35 controls. Thanks to your ongoing patience and help, this is working very well.
 
 However, the dialog box is now becoming overcrowded, so there is a need to create dialog box #2 to display and control additional information that is only required occasionally. To invoke dialog box #2, there will be a pushbutton on the parent box.
 
 That's "all" there is to it really. (Well, almost all. I want to display a histogram in box #2, but that will be another story).
 
 --
 Ian
 
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| rtr Guest
 
 | 
|  | Re: Creating a child window « Reply #5 on: Jul 28th, 2014, 8:18pm »
 |  |  on Jul 28th, 2014, 7:05pm, g3nrw  wrote:
 | | That's "all" there is to it really. | 
 | 
 I'm rather confused.  The thread subject is 'Creating a child window' and the code snippets you have listed have confirmed that by containing a call to FN_createwindow.
 
 Yet now you seem to be saying that what you want to do is to open a second dialogue box - which you already know how to do because it's just the same as opening the first one!  So where does the child window come into it?
 
 Opening another dialogue box as a result of clicking a button is a common requirement, for example exactly that happens in the BB4W IDE (or the LBB IDE) if you click on the 'Change icon' button in the 'Compile' dialogue.
 
 'Cascaded' dialogues do not (conventionally) have a parent-child relationship - not least because you don't want the second dialogue to be constrained to be within the client area of the first.   Rather, you would normally make the second dialogue a 'modal' popup window - that's what happens in the case of the 'Change icon' dialogue as you can see for yourself.
 
 Richard.
 |  
| 
|  |  Logged |  
 |  |  |  
| 
| 
| g3nrw Junior Member
 
 
 member is offline
 
  
 
 
 
 
  
 
 Posts: 74
 
 | 
|  | Re: Creating a child window « Reply #6 on: Jul 29th, 2014, 08:32am »
 |  |  on Jul 28th, 2014, 8:18pm, Richard Russell  wrote:
 | | The thread subject is 'Creating a child window' 
 | 
 | 
 
 I included "child" in the Subject because I thought I needed a child...
 
 
 Quote:
 | | Yet now you seem to be saying that what you want to do is to open a second dialogue box 
 | 
 | 
 
 That's it exactly. I have now modified my DLGDEMO program to do just that, and it does what I expected.
 
 Case closed. Thanks again Richard.
 
 --
 Ian
 
 |  
| 
|  |  Logged |  
 |  |  |  
 |