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
zaryk
August 10th, 2010, 10:16 PM
if editbox_text == ""
case id_b0:
editbox_text = "0"
case id_b1:
editbox_text = "1"
gaar321
August 11th, 2010, 02:38 AM
Sorry to be annoying but this doesnt make sence to me
Igor Vartanov
August 11th, 2010, 03:39 AM
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"?
gaar321
August 11th, 2010, 08:33 AM
Yeah thats it i want in to contain 10 but when you press one or the other they overwrite eachother
MrViggy
August 11th, 2010, 12:12 PM
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
gaar321
August 11th, 2010, 12:15 PM
Im sorry but i follow example better could you please give me a snippet
thanks in advance
Paul McKenzie
August 11th, 2010, 01:13 PM
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
gaar321
August 11th, 2010, 01:39 PM
Yes i understand storing it but how do i update with 0 and 1 together?
Igor Vartanov
August 11th, 2010, 01:47 PM
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.
Paul McKenzie
August 11th, 2010, 02:10 PM
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
gaar321
August 11th, 2010, 04:13 PM
I am using Edit_SetText and Edit_GetText put i dont know how to Concatenate a char and a string.
Paul McKenzie
August 11th, 2010, 05:43 PM
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.
#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
gaar321
August 12th, 2010, 03:00 AM
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.
// Calc.cpp : Defines the entry point for the application.
//
// 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;
// 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;
//
// 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
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
);
//
// 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:
I think i have posted this is the wrong place should this be in VC++ because thats what i am using???
Paul McKenzie
August 12th, 2010, 05:11 AM
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:
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
Igor Vartanov
August 12th, 2010, 05:52 AM
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? ;)
gaar321
August 14th, 2010, 06:11 PM
* bump *
gaar321
August 16th, 2010, 02:01 PM
Bump
MrViggy
August 16th, 2010, 02:26 PM
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
gaar321
August 16th, 2010, 02:28 PM
Sorry about that
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.