Author Topic: Rebar Controls in Win 64  (Read 3037 times)

0 Members and 2 Guests are viewing this topic.

Arnold

  • Guest
Rebar Controls in Win 64
« on: September 04, 2018, 04:50:26 AM »
Hi Charles,

since a week I am experimenting a bit with rebar controls. They work in 32-bit, but unfortunately they fail when compiled to 64-bit. I tried several possible combinations but maybe I do something wrong. I shortened the following code a bit to point to the problem. It uses the modified dialog.inc from here:
https://www.oxygenbasic.org/forum/index.php?topic=1525.msg18825#msg18825

The statements in line 235 and line 250 do not work in 64-bit and the program crashes:
   int ok= SendMessage(hRebar, RB_INSERTBAND, -1, &rbBand)

There should be at least '0' printed if SendMessage does fail, this happens in 32-bit. I suspected -1 as the reason but using the zero based indexes does not work in 64-bit neither.

Is there a possibility to see what happens when SendMessage is applied or what the difference is in 32 and 64-bit? Perhaps I must use some different styles or omit some of the styles for REBARBANDINFO in 64-bit?

Roland

Code: [Select]
deleted
« Last Edit: September 04, 2018, 09:58:38 AM by Arnold »

Arnold

  • Guest
Re: Rebar Controls in Win 64
« Reply #1 on: September 04, 2018, 08:11:15 AM »
It seems that I found my bug. In REBARBANDINFO structure I must use:
...
dword clrFore
dword clrBack
...

Small cause, big effect. I will finish this little example.
« Last Edit: September 04, 2018, 09:59:07 AM by Arnold »

Arnold

  • Guest
Re: Rebar Controls in Win 64
« Reply #2 on: September 04, 2018, 10:02:29 AM »
This is my finished rebar example in a dialog. I did not add menu or tooltips. The example should run in 32-bit and 64-bit mode.

Code: OxygenBasic
  1. '====================================================================
  2. ' Rebar example in modal dialog as main.
  3. '====================================================================
  4.  
  5. $ filename "RebarDlg.exe"
  6. 'uses rtl32
  7. 'uses rtl64
  8.  
  9. '% review
  10. uses dialogs
  11.  
  12. % TB_ADDBITMAP=1043
  13. % TB_ADDBUTTONS=0x414
  14. % TB_SETBUTTONSIZE=1055
  15. % TB_AUTOSIZE=1057
  16. % TB_GETBUTTONSIZE=1082
  17. % TB_SETEXTENDEDSTYLE=1108
  18. % CCS_NODIVIDER=64
  19. % CCS_NORESIZE=4
  20. % RBS_BANDBORDERS=1024
  21. % RBS_VARHEIGHT=512
  22. % RBBIM_BACKGROUND=128
  23. % RBBIM_CHILD=16
  24. % RBBIM_CHILDSIZE=32
  25. % RBBIM_COLORS=2
  26. % RBBIM_ID=256
  27. % RBBIM_SIZE=64
  28. % RBBIM_STYLE=1
  29. % RBBIM_TEXT=4
  30. % RBBS_CHILDEDGE=4
  31. % RBBS_FIXEDBMP=32
  32. % RBBS_NOVERT=16
  33. % RBBS_BREAK=1
  34. % RB_SETBARINFO=1028
  35. % RB_INSERTBAND=1025
  36. % HINST_COMMCTRL=-1
  37. % IDB_STD_SMALL_COLOR=0
  38. % STD_FILENEW=6
  39. % STD_FILEOPEN=7
  40. % STD_FILESAVE=8
  41. % TBSTATE_ENABLED=4
  42. % TBSTYLE_BUTTON=0
  43. % TBSTYLE_FLAT=2048
  44. % TBSTYLE_TOOLTIPS=256
  45. % TB_BUTTONSTRUCTSIZE=1054
  46. % TBSTYLE_EX_HIDECLIPPEDBUTTONS=16
  47.  
  48. type TBADDBITMAP
  49.   sys       hInst
  50.   sys  nID
  51. end type
  52.  
  53. type TBBUTTON
  54.   int       iBitmap
  55.   int       idCommand
  56.   BYTE      fsState
  57.   BYTE      fsStyle
  58.   dword     dwData
  59.   sys       iString
  60. end type
  61.  
  62. type REBARINFO
  63.     UINT cbSize
  64.     UINT fMask
  65.     sys himl
  66. end type
  67.  
  68. type REBARBANDINFO
  69.     UINT cbSize
  70.     UINT fMask
  71.     UINT fStyle
  72.     uint clrFore     'COLORREF
  73.    uint clrBack     'COLORREF
  74.    char* lpText
  75.     UINT cch
  76.     int  iImage
  77.     sys  hwndChild   'HWND
  78.    UINT cxMinChild
  79.     UINT cyMinChild
  80.     UINT cx
  81.     sys  hbmBack     'HBITMAP
  82.    UINT wID
  83.     UINT cyChild
  84.     UINT cyMaxChild
  85.     UINT cyIntegral
  86.     UINT cxIdeal
  87.     sys  lParam      'LPARAM
  88.    UINT cxHeader
  89.     'RECT rcChevronLocation
  90.    'UINT uChevronState
  91. end type
  92.  
  93. macro MakeLong(lo,hi) { ( (lo) or ( (hi)<<16 ) ) }
  94.  
  95. declare sub CreateRebar (sys hParent)
  96. ==============================================
  97.  
  98. 'MAIN CODE
  99. =============================================
  100.  
  101. sys hInstance = GetModuleHandle(null)
  102.  
  103.  
  104. % ID_Rebar    = 1001
  105. % ID_Combobox = 1002
  106. % ID_Toolbar  = 1003
  107. % ID_Button   = 1004
  108. % ID_FileNew  = 1005
  109. % ID_FileOpen = 1006
  110. % ID_FileSave = 1007
  111.  
  112.  
  113. init_common_controls()
  114.  
  115. sub winmain()
  116.  
  117.   Dialog( 0, 0, 350, 200, "Rebar example in a Dialog using OxygenBasic",
  118.           WS_OVERLAPPEDWINDOW or DS_CENTER or DS_SETFONT,
  119.           10, "Arial")
  120.   Control("", ID_Rebar, "ReBarWindow32",  
  121.           WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | RBS_VARHEIGHT | RBS_BANDBORDERS | CCS_NODIVIDER,
  122.           0,0,0,0)
  123.   Control( "", ID_Toolbar, "TOOLBARWINDOW32", WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT |
  124.            WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_NODIVIDER | CCS_NORESIZE,
  125.            0, 0, 0, 0 )
  126.   DropDownList("", ID_Combobox, 0,0,0,100)
  127.   PushButton("A", ID_Button, 0,0,15,15)
  128.   LText("Clicking text of: Toolbar, Combobox, A Button will change width of Band", -1, 20,100, 250,20)
  129.   LText("Moving text of: Toolbar, Combobox, A Button will move Band",              -1, 20,110, 250,20)
  130.   LText("to the left, right, up, down",                                            -1, 20,120, 250,20)
  131.  
  132.   CreateModalDialog( null, @DialogProc, 0)
  133. end sub
  134.  
  135. winmain()
  136.  
  137. ==========================================================
  138.  
  139. function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as sys callback
  140.  
  141.   select case uMsg
  142.  
  143.     case WM_INITDIALOG
  144.       CreateRebar (hDlg)
  145.  
  146.     case WM_SIZE
  147.        sys hRebar=GetDlgItem(hDlg, ID_Rebar)
  148.        MoveWindow (hRebar, 0, 0, loword(lParam), hiword(lParam), true)
  149.  
  150.     case WM_COMMAND
  151.       select case loword(wParam)
  152.         case IDCANCEL : EndDialog( hDlg, null )
  153.         case ID_Button : mbox "Button clicked"
  154.         case ID_FileNew, ID_FileOpen, ID_FileSave : mbox "Button in Toolbar clicked"
  155.            
  156.       end select
  157.      
  158.     case WM_CLOSE
  159.       EndDialog( hDlg, null )
  160.                
  161.   end select
  162.  
  163.   return 0
  164. end function
  165.  
  166. function FillCombobox (sys hParent) as sys
  167.    sys hComboBox=GetDlgItem(hParent, ID_Combobox)
  168.    int i
  169.    for i = 1 to 10
  170.       SendMessage(hComboBox, CB_ADDSTRING, 0, "Item " + str(i))
  171.    next i
  172.  
  173.    SendMessage(hComboBox, CB_SETCURSEL, 0, 0)    'index=1, zero-based
  174.   return hComboBox
  175. end function
  176.  
  177. function FillToolbar (sys hParent) as sys
  178.    indexbase 0
  179.    ' Toolbar variables
  180.   TBBUTTON tbb[2]
  181.    TBADDBITMAP tbab
  182.  
  183.    sys hToolBar=GetDlgItem(hParent, ID_Toolbar)
  184.  
  185.    ' Set the buttons
  186.    SendMessage(hToolBar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0)
  187.     SendMessage(hToolBar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS)
  188.  
  189.     tbab.hInst = HINST_COMMCTRL
  190.     tbab.nID = IDB_STD_SMALL_COLOR
  191.     SendMessage(hToolBar, TB_ADDBITMAP, 0, &tbab)
  192.  
  193.     tbb[0].iBitmap = STD_FILENEW
  194.     tbb[0].fsState = TBSTATE_ENABLED
  195.     tbb[0].fsStyle = TBSTYLE_BUTTON
  196.     tbb[0].idCommand = ID_FileNew
  197.    
  198.     tbb[1].iBitmap = STD_FILEOPEN
  199.     tbb[1].fsState = TBSTATE_ENABLED
  200.     tbb[1].fsStyle = TBSTYLE_BUTTON
  201.     tbb[1].idCommand = ID_FileOpen
  202.  
  203.     tbb[2].iBitmap = STD_FILESAVE
  204.     tbb[2].fsState = TBSTATE_ENABLED
  205.     tbb[2].fsStyle = TBSTYLE_BUTTON
  206.     tbb[2].idCommand = ID_FileSave
  207.  
  208.     SendMessage(hToolBar, TB_SETBUTTONSIZE, 0, MAKELONG(28, 28))
  209.     SendMessage(hToolBar, TB_ADDBUTTONS, countof(tbb), &tbb)
  210.     SendMessage(hToolBar, TB_AUTOSIZE, 0, 0)
  211.  
  212.     return hToolBar
  213. end function
  214.  
  215. sub CreateRebar (sys hParent)
  216.    REBARINFO rbi
  217.    REBARBANDINFO  rbBand
  218.    RECT rc
  219.  
  220.    sys hRebar=GetDlgItem(hParent, ID_Rebar)
  221.    
  222.    ' Initialize and send the REBARINFO structure
  223.   rbi.cbSize = sizeof(REBARINFO)
  224.    rbi.fMask = 0
  225.    rbi.himl = 0
  226.    if SendMessage(hRebar,  RB_SETBARINFO, 0, &rbi) = 0 then
  227.      mbox "Cannot SendMessage RB_SETBARINFO"
  228.    end if  
  229.    
  230.    ' Initialize REBARBANDINFO for all rebar bands
  231.   rbBand.cbSize     = sizeof(REBARBANDINFO)
  232.    rbBand.fMask      = RBBIM_COLORS    |    ' clrFore and clrBack are valid
  233.                       RBBIM_CHILD     |    ' hwndChild is valid
  234.                       RBBIM_CHILDSIZE |    ' cxMinChild and cyMinChild are valid
  235.                       RBBIM_STYLE     |    ' fStyle is valid
  236.                       RBBIM_ID        |    ' wID is valid
  237.                       RBBIM_SIZE      |    ' cx is valid
  238.                       RBBIM_TEXT      |    ' lpText is valid
  239.                       RBBIM_BACKGROUND     ' hbmBack is valid
  240.   rbBand.fStyle     = RBBS_NOVERT     |    ' do not display in vertical orientation
  241.                       RBBS_CHILDEDGE  |
  242.                        RBBS_FIXEDBMP
  243.    rbBand.hbmBack    = 0
  244.  
  245.    sys hToolbar = FillToolbar(hParent)
  246.    dword dwBtnSize = SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0)
  247.  
  248.    rbBand.clrFore    = BLUE
  249.    rbBand.clrBack    = YELLOW
  250.    rbBand.lpText     = "Toolbar"
  251.    rbBand.hwndChild  = hToolbar
  252.    rbBand.wID        = ID_Toolbar
  253.    rbBand.cxMinChild = 150 'rbBand.cxIdeal
  254.   rbBand.cyMinChild = hiword(dwBtnSize)
  255.    rbBand.cx         = rbBand.cxIdeal
  256.  
  257.    ' Insert band into rebar  
  258.   if SendMessage(hRebar, RB_INSERTBAND, -1, &rbBand) = 0 then mbox "Cannot RB_INSERTBAND hToolbar"
  259.    
  260.    sys hCombobox = FillCombobox(hParent)
  261.  
  262.    rbBand.clrFore    = RED
  263.    rbBand.clrBack    = GREEN
  264.    rbBand.lpText     = "ComboBox"
  265.    rbBand.hwndChild  = hCombobox
  266.    rbBand.wID        = ID_Combobox
  267.    GetWindowRect (hCombobox, &rc)
  268.    rbBand.cxMinChild = 150
  269.    rbBand.cyMinChild = rc.Bottom - rc.Top
  270.    rbBand.cx         = rbBand.cxIdeal
  271.  
  272.    ' Insert band into rebar
  273.   if SendMessage(hRebar, RB_INSERTBAND, -1, &rbBand) = 0 then mbox "Cannot RB_INSERTBAND hCombobox"
  274.  
  275.    sys hButton1=GetDlgItem(hParent, ID_Button)
  276.    rbBand.clrFore    = BLACK
  277.    rbBand.clrBack    = GRAY
  278.    rbBand.lpText     = "A Button   "
  279.    rbBand.hwndChild  = hButton1
  280.    rbBand.wID        = ID_Button
  281.    GetWindowRect (hButton1, &rc)
  282.    rbBand.cxMinChild = 50
  283.    rbBand.cyMinChild = rc.Bottom - rc.Top
  284.    rbBand.cx         = rbBand.cxIdeal
  285.    if SendMessage(hRebar, RB_INSERTBAND, -1, &rbBand) = 0 then mbox "Cannot RB_INSERTBAND hButton1"  
  286.  
  287. end sub
  288.  

Aurel

  • Guest
Re: Rebar Controls in Win 64
« Reply #3 on: September 04, 2018, 10:19:33 AM »
Hi Arnold
May I ask you why you use dialogs instead of window?

Arnold

  • Guest
Re: Rebar Controls in Win 64
« Reply #4 on: September 04, 2018, 11:36:26 PM »
Just to show that it is possible to create resources using in-memory templates. This is possible with modal and modeless dialogs. It is also possible to build resources with a resource editor such as Resed.exe, compile the resulting .rc file with GoRC.exe into a .res file, and link this file to an Oxygenbasic created .dll or .exe with LinkRes2Exe.exe. I have done this in previous projects.

But there is no problem with CreateWindow(Ex) to create the child windows, see e.g. \examples\WinGui\Controls.o2bas. If WinUtil.inc is used then this should happen in sub WndProc in the case of a WM_CREATE message. However, I have no idea how to create the controls with awinh.inc.

Aurel

  • Guest
Re: Rebar Controls in Win 64
« Reply #5 on: September 05, 2018, 09:04:53 AM »
Quote
However, I have no idea how to create the controls with awinh.inc.

Is that possible ?
With awinh.inc it is really easy to create any control.
In older version of compiler i don't have any trouble but with latest i have
because Charles made some internal changes in o2.

Blame me... i never finished ControlDemo with awinh.inc
and not finish fixing newer version awinh037.inc.

However ..here is one example:

Code: [Select]
$ Filename "ListView.exe" ' o2
include "RTL32.inc"
include "awinh037.inc"
INT win,wx=0,wy=0,ww=600,wh=400,wstyle = WS_MINMAXSIZE
INT button0,b0ID=100,listv,lvID=1000, col1,col2
win=SetWindow("GUI o2 :ListView:by Aurel",wx,wy,ww,wh,0,wstyle)
'crete button-----------------------------------------------------------------------
button0 = SetButton(win,180,4,120,26,"Close Window [X]",0x50001000,0x200,b0ID)

'create ListView --------------------------------------------------------------------
listv = SetListView (win, 20, 60, 300 , 300 ,"COL:0", 150, 0, 0x200, lvID)
'add column
col1= AddListViewColumn (listv, 1, 150, "COL:1"  , 0)
'add [0] column items
'add listview item {AddLVI hwnd, pos, text, icon}
AddListViewItem (listv, 0, "item_0", 0)
AddListViewItem (listv, 1, "item_1", 0)
AddListViewItem (listv, 2, "item_2", 0)
AddListViewItem (listv, 3, "item_3", 0)
AddListViewItem (listv, 4, "item_4", 0)

'------------------------------------------------------------------------------------
Wait()  'message loop
'------------------------------------------------------------------------------------
'func main
Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callback
SELECT hwnd
CASE win
Select wmsg

CASE WM_COMMAND
controlID = LoWord(wParam) 'get control ID
notifyCode = HiWord(wParam) 'get notification message

Select controlID
       
CASE b0ID 'button 0 ID
If notifycode = 0
CloseWindow(win)
EndProgram()
End If

End Select
CASE WM_CLOSE
CloseWindow(win)
EndProgram()
End Select
END SELECT
RETURN Default
END FUNCTION
 

Of course this is for 32bit and you must have awinh037.inc  in same folder
it is in attachment.
« Last Edit: September 05, 2018, 09:22:44 AM by Aurel »

Arnold

  • Guest
Re: Rebar Controls in Win 64
« Reply #6 on: September 05, 2018, 10:52:34 PM »
This does not look like a rebar. It does not feel like a rebar. It does not act like a rebar. It is not a rebar. And according to your specification it is for 32-bit. So this example does not fit to this topic.

However, it seems you have no idea how to use awinh.inc to create rebar controls, though there are examples that show how this works. Search in Internet for: msdn how to create rebar controls.

Aurel

  • Guest
Re: Rebar Controls in Win 64
« Reply #7 on: September 05, 2018, 11:37:18 PM »

However, it seems you have no idea how to use awinh.inc to create rebar controls

Arnold
You said u have no idea how to use awinh in first place....right?
Rebar is as any other control and i don't need to search internet for that .
I have example for rebar-control written in Emergence basic so it should be easy to add them
into awinh.inc ...hehe i am not from yesterday with winapi-s.  ;D
Ok

Aurel

  • Guest
Re: Rebar Controls in Win 64
« Reply #8 on: September 06, 2018, 12:26:26 AM »
WOW wow wow
ReBar is a huge thing and that will take time
i just look into Controlpack - plenty of functions
I will see ... ::)

Aurel

  • Guest
Re: Rebar Controls in Win 64
« Reply #9 on: September 06, 2018, 05:03:10 AM »
For start i will do this:

Code: [Select]
Function SetReBar (byval _rhwnd as INT,byval _rebtext as string,byval _rebx as INT,byval _reby as INT,byval _rebw as INT, byval _rebh as INT, byval _rFlag as INT,byval _ext as int, byval _rebID as INT) as INT
 hReBar = CreateWindowEx(WS_EX_TOOLWINDOW, "ReBarWindow32", _rebtext, WS_CHILD | WS_VISIBLE | WS_BORDER, 0, 0, 100, 50, _rhWnd, _rebID, 0, 0)



Function = hReBar
End function

Charles Pegge

  • Guest
Re: Rebar Controls in Win 64
« Reply #10 on: September 06, 2018, 05:10:51 AM »
Hi Roland,

Thanks for your Rebar examples. I am currently working on the self-compiled o2 versions, which will confine number literal parameters to 32bits, preventing sign extension into the upper bits. This solves the negative dword problem. 64bit literals are very rarely used as a parameter, but they can still be passed by expressing type:

foo(sys -10)

Arnold

  • Guest
Re: Rebar Controls in Win 64
« Reply #11 on: September 06, 2018, 10:27:46 AM »
Hi Charles,

I do these little examples because otherwise I can not help with developing the O2 language. I hope that this way you will find some problems that need to be considered. Unfortunately, currently there seems to be little interest in solving small or larger tasks with O2 (Aurel is an exception). I am convinced that most tasks of Rosetta Code can be easily solved with Oxygenbasic. Maybe this is one of my next projects.

Roland

JRS

  • Guest
Re: Rebar Controls in Win 64
« Reply #12 on: September 06, 2018, 11:08:54 AM »
I offen question my efforts towards Script BASIC. Either BASIC is dead or we are unfortunate to have lazy programmers as forum members.

I appreciate ALL your contributions to the Oxygen Basic project!

Aurel

  • Guest
Re: Rebar Controls in Win 64
« Reply #13 on: September 06, 2018, 01:14:46 PM »
Quote
(Aurel is an exception)
Thanks man...
when i have time it's not a problem   :)

Aurel

  • Guest
Re: Rebar Controls in Win 64
« Reply #14 on: September 06, 2018, 01:21:53 PM »
Quote
we are unfortunate to have lazy programmers

John
..that depends on how you look on things
we have real life and work and many other things to do
yeah maybe we are lazy when i look for example qb64 forum
there is always something new but looks to me that members there reinventing  the wheel
all the time ...
i don't know... ::)