About Lo, hi, loword, hiword
Cardinal is a 4-byte unsigned integer. First, let's look at the number of examples:
Cardinal examples: |
4277991664 |
By byte: |
Fourth byte |
Third byte |
Second byte |
First byte |
Binary: |
11111110 |
11111100 |
11111000 |
11110000 |
Hexadecimal: |
Fe |
FC |
F8 |
F0 |
Decimal: |
254 |
252 |
248 |
240 |
Divided by two bytes: |
High dual |
Two lower |
Binary: |
1111111011111100 |
1111100011110000 |
Hexadecimal: |
FEFC |
F8f0 |
Decimal: |
65276 |
63728 |
// You can use the lo function to extract its low byte (that is, the first byte) const C: Cardinal = 4277991664; begin showmessagefmt ('% d ', [Lo (c)]); {240} end;
// Actually, the lo function is not used. You can use byte type conversion to obtain the first byte const C: Cardinal = 4277991664; begin showmessagefmt ('% d ', [byte (c)]); {240} end;
// The Hi function is used to obtain the high byte. In fact, it is used to obtain the second byte const C: Cardinal = 4277991664; begin showmessagefmt ('% d', [HI (c)]); {248} end;
// If you want to get the lower two digits, it seems that there should be a loword function; it does, but it is not a function, it is just a alias for the word type. const C: Cardinal = 4277991664; begin showmessagefmt ('% d', [loword (c)]); {63728} showmessagefmt (' % d ', [word (c)]); {63728} end;
//HiwordThe function is to extract the const C: Cardinal = 4277991664; begin showmessagefmt ('% d ',[Hiword(C)]); {65276} end;
Loword andHiwordPurpose:
For example, the mouse position is stored in the Message Parameter lparam of a mouse message. lparam is 4 bytes, and its low-two-digit storage is X and the high-two-digit storage is y...
In this example:
ProgramProject1;UsesWindows, messages; {custom process for wm_lbuttondown message call}ProcedureOnlbuttondown (H: hwnd );VaRBrushhandle: hbrush; rect: trect;BeginGetclientrect (H, rect); {get client rectangle} brushhandle: = createsolidbrush (RGB (255, 0, 0); {create red brush} fillrect (getdc (H), rect, brushhandle); {fill customer zone} deleteobject (brushhandle); {Delete brush}End; {Custom process for wm_lbuttonup message call}ProcedureOnlbuttonup (H: hwnd );VaRRect: trect;BeginGetclientrect (H, rect); {obtain the rectangle of the customer region} invalidaterect (H, @ rect, true); {invalidate the customer region and force re-painting}End; {Custom process for wm_mousemove message call}ProcedureOnmousemove (H: hwnd; lparam: integer );VaRPT: tpoint; Buf:Array[0 .. 255]OfChar;BeginPT. x: = loword (lparam); {the lower two digits in lparam are X coordinates} PT. y: = hiword (lparam); {the height two digits in lparam are Y coordinates} wvsprintf (BUF, '% d, % d', @ pt ); {format to buffer} setwindowtext (H, Buf); {display in title}End;FunctionWndproc (WND: hwnd; MSG: uint; wparam: integer; lparam: integer): integer;Stdcall;BeginResult: = 0;CaseMSGOfWm_lbuttondown: onlbuttondown (WND); {message with the left mouse button pressed} wm_lbuttonup: onlbuttonup (WND); {message with the left mouse button lifted} wm_mousemove: onmousemove (WND, lparam ); {cursor-moving message, coordinate position in lparam} wm_destroy: postquitmessage (0 );ElseResult: = defwindowproc (WND, MSG, wparam, lparam );End;End;FunctionRegmywndclass: Boolean;VaRCLS: twndclass;BeginCls. Style: = cs_hredrawOrCs_vredraw; Cls. lpfnwndproc: = @ wndproc; Cls. cbclsextra: = 0; Cls. cbwndextra: = 0; Cls. hinstance: = hinstance; Cls. hicon: = 0; Cls. hcursor: = loadcursor (0, idc_arrow); Cls. hbrbackground: = hbrush (color_window + 1); Cls. lpszmenuname: =Nil; Cls. lpszclassname: = 'mywnd'; Result: = registerclass (CLS) <> 0;End; {Program entry}ConstTit = 'new form'; Ws = ws_overlappedwindow; X = 100; y = 100; W = 300; H = 180;VaRHwnd: thandle; MSG: tmsg;BeginRegmywndclass; hwnd: = createwindow ('mywnd', tit, WS, X, Y, W, H, 0, 0, hinstance,Nil); Showwindow (hwnd, sw_shownormal); updatewindow (hwnd );While(Getmessage (MSG, 0, 0, 0 ))Do BeginTranslatemessage (MSG); dispatchmessage (MSG );End;End.