Archived

This topic is now archived and is closed to further replies.

ELS1

Edit Beep when Subclassing?? Why?

Recommended Posts

ELS1    127
im processing VK_RETURN in my Edit Control, but for some strange reason, it beeps everytime it recieves that message. Everything else works though. I tried fixing this by making my control Multi-Line, but thats just a 'cheap' was of fixing it, plus you can paste text that has several lines, and i do not want that. Is there any way to get rid of that annoying beep sound? Thanks. This is what I have.
   
#include "Win32Console.h"

// RGB Arrays

int RGB_BACKGROUND[3] = {0, 0, 0} ;
int RGB_FOREGROUND[3] = {255, 255, 255} ;

// Edit Controls

static HWND ConsoleScreen, EditBox ;

// Edit WNDPROC

static WNDPROC EditWndProc ;

// EditProc Callback

LRESULT CALLBACK EditProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
	switch(iMsg)
	{
	case WM_KEYDOWN:
		switch(wParam)
		{
			case VK_RETURN:
				ProcessCommand(ConsoleScreen, EditBox) ;

			break ;
		}
	}

	return CallWindowProc(EditWndProc, hwnd, iMsg, wParam, lParam) ;
}

// WndProc Callback

LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
	LOGBRUSH LogicalBrush ;
	HBRUSH HBrush ;
	TEXTMETRIC TM ;
	HDC DeviceContext ;

	switch(iMsg)
	{
		case WM_SIZE:
			DeviceContext = GetDC(hwnd) ;
		
			GetTextMetrics(DeviceContext, &TM) ;
			MoveWindow(ConsoleScreen, 0, 0, LOWORD(lParam), HIWORD(lParam) - TM.tmHeight + TM.tmExternalLeading, TRUE) ;
			MoveWindow(EditBox, 0, HIWORD(lParam) - TM.tmHeight + TM.tmExternalLeading, LOWORD(lParam), TM.tmHeight + TM.tmExternalLeading, TRUE) ;

			ReleaseDC(hwnd, DeviceContext) ;

			return 0 ;
		case WM_CTLCOLORSTATIC:
		case WM_CTLCOLOREDIT:
			LogicalBrush.lbStyle = BS_SOLID ;
			LogicalBrush.lbColor = RGB(RGB_BACKGROUND[0], RGB_BACKGROUND[1], RGB_BACKGROUND[2]);
			HBrush = CreateBrushIndirect(&LogicalBrush) ;

			SetTextColor((HDC) wParam, RGB(RGB_FOREGROUND[0], RGB_FOREGROUND[1], RGB_FOREGROUND[2])) ;
			SetBkMode((HDC) wParam, OPAQUE);
			SetBkColor((HDC) wParam, RGB(RGB_BACKGROUND[0], RGB_BACKGROUND[1], RGB_BACKGROUND[2])) ;

			return (LRESULT) HBrush ;
		case WM_DESTROY:
			PostQuitMessage(0) ;
		
			return 0 ;
	}
 
	return DefWindowProc(hwnd, iMsg, wParam, lParam) ;
}

// WinMain Function

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	char* ClassName = "Can2Soft::Console32" ;
	HWND hwnd ;
	MSG msg ;
	WNDCLASSEX WClass ;

	WClass.cbSize = sizeof(WClass) ;
	WClass.style = CS_HREDRAW | CS_VREDRAW ;
	WClass.lpfnWndProc = WndProc ;
	WClass.cbClsExtra = 0 ;
	WClass.cbWndExtra = 0 ;
	WClass.hInstance = hInstance ;
	WClass.hIcon = LoadIcon(hInstance, IDI_APPLICATION) ;
	WClass.hIconSm = LoadIcon(hInstance, IDI_APPLICATION) ;
	WClass.hCursor = LoadCursor(NULL, IDC_ARROW) ;
	WClass.hbrBackground = CreateSolidBrush(RGB(RGB_BACKGROUND[0], RGB_BACKGROUND[1], RGB_BACKGROUND[2]))  ;
	WClass.lpszMenuName = NULL ;
	WClass.lpszClassName = ClassName ;

	RegisterClassEx(&WClass) ;

	hwnd = CreateWindow(ClassName, "Console32", WS_OVERLAPPEDWINDOW, 0, 0, 400, 250, NULL, NULL, hInstance, NULL) ;
	ConsoleScreen = CreateWindow("edit", "Type /commands for available commands.\r\n", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_READONLY, 0, 0, 0, 0, hwnd, (HMENU)EDIT1, hInstance, NULL) ;
	EditBox = CreateWindow("edit", "EditBox", WS_CHILD | WS_VISIBLE , 0, 0, 0, 0, hwnd, (HMENU)EDIT2, hInstance, NULL) ;
			
	SetFont(ConsoleScreen, "Verdana", 15) ;
	SetFont(EditBox, "Verdana", 15) ;
 
	EditWndProc = (WNDPROC) SetWindowLong(EditBox, GWL_WNDPROC, (LONG)EditProc) ;

	ShowWindow(hwnd, iCmdShow) ;
	UpdateWindow(hwnd) ;

	while(GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg) ;
		DispatchMessage(&msg) ;
	}

	return (int) msg.wParam ;
}    
Edited by - ELS1 on March 19, 2002 11:58:40 AM

Share this post


Link to post
Share on other sites
daerid    354
Change this


  
switch(wParam)
{
case VK_RETURN:
ProcessCommand(ConsoleScreen, EditBox) ;
break ;
}


to


  
switch(wParam)
{
case VK_RETURN:
ProcessCommand(ConsoleScreen, EditBox);
return 0;
}


The reason is that you''re still processing the VK_RETURN in the default edit window procedure. That''ll give you a beep.

Share this post


Link to post
Share on other sites
ELS1    127
still gives me a beep.

i remember when i used to program in VB, it gave me the same error...and i remember doing something like KeyAscii = 0 so it wouldnt beep...but i dunno...

Share this post


Link to post
Share on other sites
daerid    354
herm... try returning 1

or

try handling VK_RETURN in WM_CHAR instead.

I know I've done exactly what you're trying to do. I think I handled VK_RETURN in WM_CHAR, and then not calling the default proc. That did it, i'm almost positive.

[edited by - daerid on March 19, 2002 1:34:42 PM]

Share this post


Link to post
Share on other sites
ELS1    127
quote:
Original post by daerid
herm... try returning 1

or

try handling VK_RETURN in WM_CHAR instead.

I know I've done exactly what you're trying to do. I think I handled VK_RETURN in WM_CHAR, and then not calling the default proc. That did it, i'm almost positive.

[edited by - daerid on March 19, 2002 1:34:42 PM]


it worked! thanks a lot bro. this is what i did


    
LRESULT CALLBACK EditProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch(iMsg)
{
case WM_CHAR:
switch(wParam)
{
case VK_RETURN:
ProcessCommand(ConsoleScreen, EditBox) ;

return 0 ;
}
}

return CallWindowProc(EditWndProc, hwnd, iMsg, wParam, lParam) ;
}


[edited by - ELS1 on March 19, 2002 1:45:41 PM]

Share this post


Link to post
Share on other sites