Author Topic: Question about MAKELONG  (Read 1625 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
Question about MAKELONG
« on: June 06, 2018, 11:12:49 AM »
Hi Charles,

this is the definition of MSDN for the MAKELONG macro:
#define MAKELONG(a, b) \ 
    ((LONG) (((WORD) (a)) | ((DWORD) ((WORD) (b))) << 16))

The macro creates an unsigned 32-bit value from two 16-bit values.

In Oxygenbasic I try this with:
macro makelong(wlow, whigh) {dword wlow | dword (whigh<<16)}

and I am totally unsure if this is correct.

I use this macro with the example below in line 84:
   SendMessage(hwndTrack, TBM_SETRANGE,  true, makelong(0,750))

The app seems to work correctly (also compiled to 64-bit), but does the macro match the definition of MSDN?

Roland

Code: OxygenBasic
  1. 'http://zetcode.com/gui/winapi/customcontrols/
  2. 'slightly modified
  3.  
  4. $ filename "BurningControl.exe"
  5.  
  6. 'uses rtl32
  7. 'uses rtl64
  8.  
  9. uses WinUtil
  10.  
  11. % GCLP_HBRBACKGROUND= -10
  12. % TRACKBAR_CLASS="msctls_trackbar32"
  13. % ICC_BAR_CLASSES=4
  14. % COLOR_3DFACE=15
  15. % COLOR_BTNFACE=15
  16. % TBM_SETRANGE=1030
  17. % TBM_SETPAGESIZE=1045
  18. % TBM_SETTICFREQ=1044
  19. % TBM_GETPOS=1024
  20. % TBM_SETPOS=1029
  21. % SWP_NOZORDER=4
  22. % PS_NULL=5
  23. % DT_CENTER=1
  24. % TBS_NOTICKS=16
  25. % TBS_FIXEDLENGTH=64
  26.  
  27. macro makelong(wlow, whigh) {dword wlow | dword (whigh<<16)}
  28. macro RGB(r,g,b) {r+(g<<8)+(b<<16)}
  29.  
  30. int g_pos = 150
  31. % EDIT_ID = 1000
  32.  
  33. 'Register Common Controls
  34. INITCOMMONCONTROLSEXt iccex
  35. iccex.dwSize=sizeof(iccex)
  36. iccex.dwICC= ICC_BAR_CLASSES
  37. InitCommonControlsEx(&iccex)
  38.  
  39. sys hInstance=inst
  40. MainWindow 400,250,WS_OVERLAPPEDWINDOW
  41.  
  42. function WndProc(sys hwnd, uint uMsg, sys wParam, lParam) as sys callback
  43.  
  44.     static sys hwndTrack, hwndBurn, hEdit
  45.     WNDCLASSEX wc
  46.  
  47.     select uMsg
  48.  
  49.         case WM_CREATE
  50.             SetWindowText(hwnd,"Burning control")
  51.             'Adjust color of MainWindow
  52.            SetClassLongPtr(hwnd,GCLP_HBRBACKGROUND, GetSysColorBrush(COLOR_3DFACE))
  53.            
  54.             'Custom control  
  55.            wc.cbSize        = sizeof(WNDCLASSEX)
  56.             wc.lpszClassName = strptr "BurningControl"
  57.             wc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE)
  58.             wc.style         = CS_HREDRAW
  59.             wc.lpfnWndProc   = @PanelProc
  60.             wc.hCursor       = LoadCursor(0, IDC_ARROW)
  61.             if not RegisterClassEx(&wc) then
  62.               MessageBox(null, "BurningControl Registration Failed!", "Error!",
  63.               MB_ICONEXCLAMATION or MB_OK)
  64.               return 0
  65.             end if            
  66.  
  67.             hwndBurn = CreateWindowEx(
  68.                 WS_EX_STATICEDGE,
  69.                 "BurningControl",
  70.                 null,
  71.                 WS_CHILD | WS_VISIBLE,
  72.                 0,0,0,0,
  73.                 hwnd, 1, null, null)
  74.            
  75.             'Slider control
  76.            hwndTrack = CreateWindowEx(
  77.                 0,
  78.                 TRACKBAR_CLASS,
  79.                 null,
  80.                 WS_CHILD | WS_VISIBLE | TBS_FIXEDLENGTH | TBS_NOTICKS,
  81.                 40, 25, 150, 25,
  82.                 hwnd, 2, hInstance, null)
  83.  
  84.             SendMessage(hwndTrack, TBM_SETRANGE,  true, makelong(0,750))
  85. '            SendMessage(hwndTrack, TBM_SETRANGE,  true, makelong(100-10, 1500\2))
  86.            SendMessage(hwndTrack, TBM_SETPAGESIZE, 0,  20)
  87.             SendMessage(hwndTrack, TBM_SETTICFREQ, 20, 0)
  88.             SendMessage(hwndTrack, TBM_SETPOS, true, 150)  
  89.  
  90.             'Edit control
  91.            hEdit = CreateWindowEx(
  92.                 WS_EX_CLIENTEDGE,
  93.                 "edit",
  94.                 "",
  95.                 WS_CHILD | WS_VISIBLE | ES_READONLY,
  96.                 40, 70, 60, 25,
  97.                 hWnd, EDIT_ID, hInstance, null)
  98.             g_pos = SendMessage(hwndTrack, TBM_GETPOS, 0, 0)
  99.             SetWindowText(hEdit, str(g_pos))
  100.    
  101.         case WM_SIZE
  102.             SetWindowPos(hwndBurn, null, 0, hiword(lParam)-30, loword(lParam), 30, SWP_NOZORDER)
  103.  
  104.         case WM_HSCROLL
  105.             g_pos = SendMessage(hwndTrack, TBM_GETPOS, 0, 0)
  106.             SetWindowText(hEdit, str(g_pos))
  107.             InvalidateRect(hwndBurn, null, true)            
  108.        
  109.         case WM_CLOSE
  110.             DestroyWindow(hwnd)
  111.        
  112.         case WM_DESTROY
  113.             PostQuitMessage(0)
  114.        
  115.         case else
  116.             return DefWindowProc(hwnd, uMsg, wParam, lParam)
  117.            
  118.     end select
  119.    
  120.     return 0
  121. end function
  122.  
  123. function PanelProc(sys hwnd, uint msg, sys wParam, lParam) as sys callback
  124.  
  125.     sys hBrushYellow, hBrushRed, holdBrush
  126.     sys hPen, holdPen
  127.     sys hFont, holdFont
  128.     PAINTSTRUCT ps
  129.     RECT rect, rect2
  130.  
  131.     string cap[]={"75","150", "225","300","375","450","525","600","675"}
  132.  
  133.     sys hdc
  134.     int till
  135.     int gap, full
  136.     int i
  137.  
  138.     select msg  
  139.  
  140.     case WM_PAINT
  141.    
  142.         hdc = BeginPaint(hwnd, &ps)
  143.  
  144.         GetClientRect(hwnd, &rect)
  145.  
  146.         till = (rect.right / 750.0) * g_pos
  147.         gap = rect.right / 10.0
  148.         full = (rect.right / 750.0) * 700
  149.        
  150.         hBrushYellow = CreateSolidBrush(RGB(255, 255, 184))
  151.         hBrushRed = CreateSolidBrush(RGB(255, 110, 110))
  152.  
  153.         hPen = CreatePen(PS_NULL, 1, RGB(0, 0, 0))
  154.         holdPen = SelectObject(hdc, hPen)
  155.  
  156.         hFont = CreateFont(13, 0, 0, 0, FW_BOLD, 0, 0, 0, 0,
  157.                     0, 0, 0, 0, "Tahoma")
  158.  
  159.         holdFont = SelectObject(hdc, hFont)
  160.        
  161.         if (till > full) then      
  162.             SelectObject(hdc, hBrushYellow)
  163.             Rectangle(hdc, 0, 0, full, 30)
  164.             holdBrush = SelectObject(hdc, hBrushRed)
  165.             Rectangle(hdc, full, 0, till, 30)
  166.         else        
  167.             holdBrush = SelectObject(hdc, hBrushYellow)
  168.             Rectangle(hdc, 0, 0, till, 30)
  169.         end if
  170.  
  171.         SelectObject(hdc, holdPen)
  172.  
  173.         for i = 1 to 9
  174.           MoveToEx(hdc, i*gap, 0, null)
  175.           LineTo(hdc, i*gap, 7)
  176.  
  177.           rect2.bottom = 28
  178.           rect2.top = 8
  179.           rect2.left = i*gap-10
  180.           rect2.right = i*gap+10
  181.  
  182.           SetBkMode(hdc, TRANSPARENT)
  183.           DrawText(hdc, cap[i], len(cap[i]), &rect2, DT_CENTER)
  184.         next i
  185.  
  186.         SelectObject(hdc, holdBrush)
  187.         DeleteObject(hBrushYellow)
  188.         DeleteObject(hBrushRed)
  189.  
  190.         DeleteObject(hPen)
  191.  
  192.         SelectObject(hdc, holdFont)
  193.         DeleteObject(hFont)
  194.                    
  195.         EndPaint(hwnd, &ps)
  196.  
  197.     case else
  198.         return DefWindowProc(hwnd, msg, wParam, lParam)  
  199.  
  200.     end select
  201.  
  202. end function
  203.  

Charles Pegge

  • Guest
Re: Question about MAKELONG
« Reply #1 on: June 06, 2018, 11:49:00 AM »
Hi Roland,

Thanks for the demo!

I make it:

Code: [Select]
macro MakeLong(lo,hi) { ( (lo) or ( (hi)<<16 ) ) }

This macro is not fussy about integer types, and will support lo hi as expressions.


Arnold

  • Guest
Re: Question about MAKELONG
« Reply #2 on: June 06, 2018, 10:51:48 PM »
Hi Charles,

I always forget that O2 can apply expressions in macros, thank you for this solution. If necessary I think this construct can be useful for some other macros of this kind too, like MakeLParam, MakeWParam, MakeLResult.

Roland