Stop text overwrting in a edit box
Hello
could you please help me on how i could stop text overwriting in a edit box when SendMessage() is used for example: case ID_B0 which holds the value 0 how could you keep that in the edit box if you then pressed the button ID_B1 which holds the value 1
Re: Stop text overwrting in a edit box
Code:
if editbox_text == ""
case id_b0:
editbox_text = "0"
case id_b1:
editbox_text = "1"
Re: Stop text overwrting in a edit box
Sorry to be annoying but this doesnt make sence to me
Re: Stop text overwrting in a edit box
The same to your original explanation. :)
What does "overwriting" means? You press "0" button, your edit box receives "0", then you press "1", your edit box should eventually contain what? "1"? or "01"? or "10"?
Re: Stop text overwrting in a edit box
Yeah thats it i want in to contain 10 but when you press one or the other they overwrite eachother
Re: Stop text overwrting in a edit box
You either need to store the data in the text box in a variable in your class, or before you update the box (after a button has been pressed), you read the text out of the box; append the new data; update the text box.
Viggy
Re: Stop text overwrting in a edit box
Im sorry but i follow example better could you please give me a snippet
thanks in advance
Re: Stop text overwrting in a edit box
Quote:
Originally Posted by
gaar321
Im sorry but i follow example better could you please give me a snippet
1) Get the data from the text box.
2) Concatenate that data onto a string that you have stored somewhere (I don't care where -- you know this, not us).
3) Update the text box with this string.
So what don't you understand?
Regards,
Paul McKenzie
Re: Stop text overwrting in a edit box
Yes i understand storing it but how do i update with 0 and 1 together?
Re: Stop text overwrting in a edit box
Look, your edit box holds the string. You want to append another character to a string. This is called concatenation. You get the string from edit box, append corresponding character to it and update the edit box content with the resultant string.
Re: Stop text overwrting in a edit box
Quote:
Originally Posted by
gaar321
Yes i understand storing it but how do i update with 0 and 1 together?
Do you know what concatenation is? If so, do you know how to change what's in a text box programatically? If so, then what are you having trouble with?
Regards,
Paul McKenzie
Re: Stop text overwrting in a edit box
I am using Edit_SetText and Edit_GetText put i dont know how to Concatenate a char and a string.
Re: Stop text overwrting in a edit box
Quote:
Originally Posted by
gaar321
I am using Edit_SetText and Edit_GetText put i dont know how to Concatenate a char and a string.
What is "Edit_SetText" and "Edit_GetText"? Those are not Windows API functions.
Secondly, how did you get as far as writing any program that deals with strings? Are you cherry-picking examples off the web, without learning the tools (i.e. the language) used to create such programs? You are not going to get far using that approach to learn.
Code:
#include <string>
#include <iostream>
using namespace std;
int main()
{
string s = "0";
string s1 = "1";
// concatenation
s += s1;
cout << s; // this will print "01" on the console
}
Regards,
Paul McKenzie
Re: Stop text overwrting in a edit box
Right okay this is starting to make sence i know how to do concatenation.
What i am coding is nothing to with a console app.
I am trying to apply 10 in a win app e.g.
Code:
// Calc.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "Calc.h"
#include <Richedit.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
HWND Box;
HWND B0;
HWND B1;
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
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_CALC, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CALC));
// 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()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
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_CALC));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_CALC);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
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);
Box = CreateWindow("edit","", // Default text.
WS_VISIBLE | WS_CHILD | SS_RIGHT, // the styles
100,100, // the left and top co-ordinates
100,100, // width and height
hWnd, // parent window handle
(HMENU)ID_EDIT, // the ID of your combobox
hInstance, // the instance of your application
NULL
);
B0 = CreateWindow("button","0",WS_VISIBLE | WS_CHILD | WS_BORDER, // the styles
50,50, // the left and top co-ordinates
20,20, // width and height
hWnd, // parent window handle
(HMENU)ID_B0, // the ID of your combobox
hInstance, // the instance of your application
NULL
);
B1 = CreateWindow("button","1",WS_VISIBLE | WS_CHILD | WS_BORDER, // the styles
300,300, // the left and top co-ordinates
20,20, // width and height
hWnd, // parent window handle
(HMENU)ID_B1, // the ID of your combobox
hInstance, // the instance of your application
NULL
);
if (!hWnd)
{
return FALSE;
}
Edit_SetReadOnly(Box,TRUE);
ShowWindow(hWnd, nCmdShow);
ShowWindow(Box,nCmdShow);
UpdateWindow(hWnd);
UpdateWindow(Box);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
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_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
case ID_B0:
Edit_SetText(Box,"0");
break;
case ID_B1:
Edit_SetText(Box,"1");
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 about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
Re: Stop text overwrting in a edit box
I think i have posted this is the wrong place should this be in VC++ because thats what i am using???
Re: Stop text overwrting in a edit box
Quote:
Originally Posted by
gaar321
Right okay this is starting to make sence i know how to do concatenation.
What i am coding is nothing to with a console app.
You're missing my point, and the reason you are asking endless questions on something that is so simple (and probably will be asking more basic C++ questions in the future).
The first thing you should be learning is the language. You obviously did not do that. What I showed you could be used in any application type, since it shows how you do concatenation using C++.
You are using C++, right? So what I showed you is basic C++ usage, something you will find in any C++ book. Let's take your code:
Code:
#include "stdafx.h"
#include "Calc.h"
#include <Richedit.h>
#include <string>
std::string currentEditText;
//...
case ID_B0:
Edit_SetText(Box,"0");
currentEditText += Edit_GetText(Box,"0"); // gets the text and concatenates it onto the current text.
break;
case ID_B1:
currentEditText += "1";
Edit_SetText(Box, currentEditText.c_str());
Something like this is what you should be doing. Whether this works exactly as you're describing, I don't know since I have no idea what Edit_SetText/Edit_GetText do or what they return.
Seriously, if you want to learn how to program, you don't take examples off the web and not know anything about how to logically put together your own functions/programs, and worse, not know basic C++ syntax and rules.
Regards,
Paul McKenzie
Re: Stop text overwrting in a edit box
Code:
case ID_B0:
Edit_SetText(Box,"0");
break;
case ID_B1:
Edit_SetText(Box,"1");
Okay, let's see what happens. You program a reaction to button press as setting some predefined (!) text. Every SetText call overwrites the edit box content. Entirely. Please read this twice.
To append another chunk (whatever it is, digit or something) you have to read the current edit box content to a buffer, append your chunk to that buffer and only then apply the new buffer content to edit box with SetText. Now, does this ring any bells to you? ;)
Re: Stop text overwrting in a edit box
Re: Stop text overwrting in a edit box
Re: Stop text overwrting in a edit box
Quote:
Originally Posted by
gaar321
Right okay this is starting to make sence i know how to do concatenation.
What i am coding is nothing to with a console app.
I am trying to apply 10 in a win app e.g.
What is your question? You just said that you understand concatenation, and from previous posts you imply that you understand how to populate an edit box. :confused:
Viggy
Re: Stop text overwrting in a edit box