How can hidden input change content of the edit controls

Hello.I'm trying to whrite code that depending on entered character ,change the content of the edit controls.The problem is that entered values must be hidden.On the dialog window must be displayed only edit controls .How can I do this.
Subclass the edit control.
Would you explain?
Windows edit controls represent an instantiation of one of several predefined Window Classes. Other examples of predefined controls would be list boxes, combo boxes, labels (static), progress bars, etc. Every window in Windows is a member or instantiation of some Window Class, and, and one of the most important fields or 'members' of the WNDCLASSEX object is the WNDCLASSEX::lpfnWndProc member.

When someone hits a key on the keyboard, that keystroke will be received in the Window Procedure of an edit control - if the edit control has the keyboard focus. The Window Procedure for the edit control will receive WM_CHAR and WM_KEYDOWN messages. It is those messages that you want to get at. For example, if someone presses the letter 'a' and you want a 'b' instead to show up in the edit control, then you'll want to intercept the WM_CHAR message and translate the 'a' into a 'b'.

The way you do this is by 'subclassing' the edit control. Windows contains a function named SetWindowLong()/SetWindowLongPtr(), and if the GWL_WNDPROC define is used as a parameter, it allows you to intercept the messages bound for the internal Window Procedure within Windows of the edit control, and substitute your own. That is how you an modify the behavior of the edit control (or any control). Do a search for 'Window Subclassing', and you should find examples of it.
I've learnt a lot about subclassing , but my code doesn't work as I want.
The idea is depending on entered character in edit control3 to increase the value of edit control1 or edit control2.Here is the code:


#include "stdafx.h"
#include "table6.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name

// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK MyEditProc(HWND ,UINT ,WPARAM ,LPARAM);
INT_PTR CALLBACK Table(HWND, UINT, WPARAM, LPARAM);
WNDPROC g_pOldProc;
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_TABLE6, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TABLE6));

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}



//
// FUNCTION: MyRegisterClass()

ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TABLE6));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_TABLE6);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

return RegisterClassEx(&wcex);
}


BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOGBAR), hWnd, Table);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Message handler for table box.


INT_PTR CALLBACK Table(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);

HWND hMyEdit;


switch (message)
{
case WM_INITDIALOG:
SetDlgItemInt(hDlg,IDC_EDIT1,0,FALSE);//initially print 0 in EDIT1
SetDlgItemInt(hDlg,IDC_EDIT2,0,FALSE);//initially print 0 in EDIT2
SetDlgItemText(hDlg,IDC_EDIT3,""); //clear EDIT3
hMyEdit= GetDlgItem(hDlg,IDC_EDIT3);
g_pOldProc = (WNDPROC)SetWindowLong(hMyEdit,GWL_WNDPROC,(LONG)MyEditProc);//call subclass proc for EDIT3
return (INT_PTR)TRUE;

case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BUTTON1:
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;

break;

}
}
return (INT_PTR)FALSE;
}
// subclass Edit Proc for EDIT3
LRESULT CALLBACK MyEditProc(HWND hDlg,UINT Message,WPARAM wParam,LPARAM lParam)
{
TCHAR chChar;
int *home , *guest;
home = new int;
guest = new int;
switch(Message)
{
case WM_CHAR:
chChar=(TCHAR)wParam;//if 'h' is entered in EDIT3 then EDIT1 display home+1
if(chChar=='h')
{
*home = GetDlgItemInt(hDlg,IDC_EDIT1,NULL,FALSE);
*home+=1;
SetDlgItemText(hDlg,IDC_EDIT1,"");
SetDlgItemInt(hDlg,IDC_EDIT1,*home,FALSE);
}

else if(chChar == 'g')//if 'g' is entered in EDIT3 then EDIT2 display guest+1
{
*guest = GetDlgItemInt(hDlg,IDC_EDIT2,NULL,FALSE);
*guest+=1;
SetDlgItemText(hDlg,IDC_EDIT2,"");
SetDlgItemInt(hDlg,IDC_EDIT2,*home,FALSE);
}
SetDlgItemText(hDlg,IDC_EDIT3,"");// clear entered character and wait for new
delete home;
delete guest;
}
return CallWindowProc(g_pOldProc,hDlg,Message,wParam,lParam);
}
It would help if you would use code tags fitipaldi, so that others could look at decently formatted code.

I did look at your code though, and suspect this might be your problem in your subclass procedure MyEditProc ...

if(chChar=='h')

Since chChar is defined as a TCHAR, if you are doing a wide character build, it won't make a satisfactory comparison of a wide character against an ansi character. I'd recommend you try this instead ...

if(chChar==L'h')

Or, even better yet ...

if(chChar==_T('h'))



Topic archived. No new replies allowed.