I've got a c++ win32 (non MFC) dialog based app with a custom control
that listens to WM_KEYDOWN,WM_KEYUP for keypress/releases to
behave like a synth keyboard - so i NEED keyup events.
Thing is, it's BEEPING! (a "default beep" type beep)
In my custom control i've tried returning 0, returning 1 and
calling the default message handler - STILL beeps.
I tried with and without calling TranslateMessage() in my msgloop.
STILL BEEPS!
Can anybody help meee?
Here's my custom control - pretty basic:
(KeyMap and Canvas are my own classes, but are pretty simple and DON'T BEEP)
struct {key k; ubyte nt;} KyNt [] = {
{'z', M_NT(M_C,0)}, {'x', M_NT(M_D,0)},
{'c', M_NT(M_E,0)}, {'v', M_NT(M_F,0)},
{'b', M_NT(M_G,0)}, {'n', M_NT(M_A,0)},
{'m', M_NT(M_B,0)}, {',', M_NT(M_C,1)},
{'.', M_NT(M_D,1)}, {'/', M_NT(M_E,1)},
{'s', M_NT(M_Db,0)}, {'d', M_NT(M_Eb,0)},
{'g', M_NT(M_Gb,0)}, {'h', M_NT(M_Ab,0)},
{'j', M_NT(M_Bb,0)}, {'l', M_NT(M_Db,1)},
{';', M_NT(M_Eb,1)},
{'q', M_NT(M_C,1)}, {'w', M_NT(M_D,1)},
{'e', M_NT(M_E,1)}, {'r', M_NT(M_F,1)},
{'t', M_NT(M_G,1)}, {'y', M_NT(M_A,1)},
{'u', M_NT(M_B,1)}, {'i', M_NT(M_C,2)},
{'o', M_NT(M_D,2)}, {'p', M_NT(M_E,2)},
{'[', M_NT(M_F,2)}, {']', M_NT(M_G,2)},
{'\\', M_NT(M_A,2)},
{'2', M_NT(M_Db,1)}, {'3', M_NT(M_Eb,1)},
{'5', M_NT(M_Gb,1)}, {'6', M_NT(M_Ab,1)},
{'7', M_NT(M_Bb,1)}, {'9', M_NT(M_Db,2)},
{'0', M_NT(M_Eb,2)}, {'=', M_NT(M_Gb,2)},
{BSP_KEY, M_NT(M_Ab,2)}
};
struct CtlKbd {
public:
void Init ()
{
TRC("CtlKbd::Init bgn");
MemSet (& _wc, 0, sizeof (_wc));
_wc.lpszClassName = "KBD";
_wc.lpfnWndProc = WinProc;
_wc.cbSize = sizeof (WNDCLASSEX);
_wc.hCursor = ::LoadCursor (0, IDC_ARROW);
if (::RegisterClassEx (& _wc) == 0)
DieWn ("CtlKbd::CtlKbd RegisterClassEx");
TRC("CtlKbd::Init end");
}
private:
WNDCLASSEX _wc;
static LRESULT CALLBACK WinProc (HWND hwnd, UINT msg, WPARAM w, LPARAM l)
{ static bool foc = false;
static ubyte oct = 4;
static ubyte vel = 100;
switch (msg) {
case WM_LBUTTONDOWN:
::SetFocus (hwnd);
return 0;
case WM_SETFOCUS:
foc = true; ::RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE);
return 0;
case WM_KILLFOCUS:
foc = false; ::RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE);
return 0;
case WM_PAINT:
{ PAINTSTRUCT p;
Canvas c (::BeginPaint (hwnd, & p));
c.SetBg (foc ? 0 : 255, foc ? 255 : 0, 0);
c.Text (0, 0, "in");
::EndPaint (hwnd, & p);
}
return 0;
case WM_ERASEBKGND:
return 0;
case WM_KEYDOWN: case WM_KEYUP:
{ KeyMap km;
key k;
ubyte i;
TrkEv e;
char buf [900];
if ((l & 0x80000000) || (!(l & 0x40000000))) if (k = km.Map (w)) {
for (i = 0; i < BITS (KyNt); i++)
if (k == KyNt [i].k) {
e.ctrl = (ubyte)(KyNt [i].nt + oct*12);
e.valu = (l & 0x80000000) ? 0 : vel;
if ((l & 0x80000000) == 0) e.valu |= 0x80;
e.chan = 0;
sprintf (buf, "kbd ctl: $%02X $%02X\n", e.ctrl, e.valu);
DBG(buf);
break;
}
}
return 0;
}
}
return ::DefWindowProc (hwnd, msg, w, l);
}
};
|