|
-
August 10th, 2010, 03:17 PM
#1
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
-
August 10th, 2010, 10:16 PM
#2
Re: Stop text overwrting in a edit box
Code:
if editbox_text == ""
case id_b0:
editbox_text = "0"
case id_b1:
editbox_text = "1"
Last edited by zaryk; August 10th, 2010 at 10:19 PM.
-
August 11th, 2010, 02:38 AM
#3
Re: Stop text overwrting in a edit box
Sorry to be annoying but this doesnt make sence to me
-
August 11th, 2010, 03:39 AM
#4
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"?
Best regards,
Igor
-
August 11th, 2010, 08:33 AM
#5
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
-
August 11th, 2010, 12:12 PM
#6
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
-
August 11th, 2010, 12:15 PM
#7
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
-
August 11th, 2010, 01:13 PM
#8
Re: Stop text overwrting in a edit box
 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
-
August 11th, 2010, 01:39 PM
#9
Re: Stop text overwrting in a edit box
Yes i understand storing it but how do i update with 0 and 1 together?
-
August 11th, 2010, 01:47 PM
#10
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.
Best regards,
Igor
-
August 11th, 2010, 02:10 PM
#11
Re: Stop text overwrting in a edit box
 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
-
August 11th, 2010, 04:13 PM
#12
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.
-
August 11th, 2010, 05:43 PM
#13
Re: Stop text overwrting in a edit box
 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
-
August 12th, 2010, 03:00 AM
#14
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;
}
-
August 12th, 2010, 03:05 AM
#15
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???
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|