The scan code is in bits 16-23 of the lParam parameter according to the WM_CHAR documentation, so just shift and mask:
int scanCode = (lParam >> 16) & 0xff;
If you've got a character you can call OemKeyScan, which puts the scan code in the low byte:
char c='X';
int scanCode=OemKeyScan(c) & 0x0ff;