LPARAM
The LPARAM data type is a 32-bit signed integer value. It is used to pass data to window procedures as part of a window message. The meaning of this parameter depends on the specific window message being processed.
Type Definition
typedef long LPARAM;
Remarks
LPARAM is a parameter that can be used to send information to a window procedure. The specific data contained within an LPARAM varies greatly depending on the message being sent. For instance:
- In the
WM_KEYDOWNandWM_KEYUPmessages, LPARAM contains information about the key that was pressed or released, including its scan code, extended-key flag, context code, previous key-state flag, and transition-state flag. - In the
WM_MOUSEMOVEmessage, LPARAM contains the x-coordinate of the mouse cursor, specified in screen coordinates, in its low-order word. The y-coordinate is in its high-order word. - In the
WM_COMMANDmessage, LPARAM contains the identifier of the menu item, control, or accelerator.
Developers must consult the documentation for each specific window message to understand the precise interpretation of its LPARAM value.
Example Usage (Conceptual)
// Example of handling WM_KEYDOWN (simplified)
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_KEYDOWN: {
// Extract scan code from LPARAM
UINT scanCode = (lParam >> 16) & 0xFF;
// Extract extended-key flag
BOOL isExtendedKey = (lParam >> 24) & 0x01;
if (wParam == VK_SPACE) {
OutputDebugString(L"Spacebar pressed!\n");
}
// ... other key handling
break;
}
// ... other messages
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
Note: The interpretation of LPARAM is message-dependent. Always refer to the specific message documentation for accurate usage.