|
I know that. But have you actually used your debugger to check that they are both valid at the time of your SendMessage call? Is selPos >= 0, and selEnd > selPos && < editTextLen()?
|
|
|
|
|
The selPos and selEnd had actually referred to the precise character index of the selected text. Thanks.
|
|
|
|
|
As per Richard said debug the dam thing because there is something wrong with a value and you are asking us to guess what.
However something obvious to me which you have not explained you have two different string pointers in the above lpWStr1 and lpWstr0 and since there is something wrong with selPos or selEnd which you haven't debugged is this related as no explaination of these???
In vino veritas
|
|
|
|
|
programmingalholic wrote: Below is code that sends the EM_SETSEL message to the Edit control.
int selPos = (int)(pInitialFound - lpWStr1) + 1;
int selEnd = selPos + (lstrlenW(lpWStr0));
SendMessage(hwndEdit, EM_SETSEL, selPos, selEnd);
And what are the actual values of selPos, selEnd, and the length of the text in hwndEdit edit control?
|
|
|
|
|
|
the actual value of selPos and selEnd just represent as what they are, both contained int value that denoted character index. To hwndEdit, the return value of GetWindowTextLengthW just not false ( other values than 0 ).
|
|
|
|
|
programmingalholic wrote: ...to make it locates the searched text enter from the another Edit control. This is very unclear. Are you wanting to select text (EM_SETSEL ), or get the text that is selected (EM_GETSEL )? These are two separate problems, requiring two separate messages.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
modified 20-May-16 9:27am.
|
|
|
|
|
I want to select text in the Edit control and make it has visual effect that represents the highlight of selected text. But how does WM_SETSEL come? It was undefined in the edition of my Visual Studio.
Any suggestion please??
modified 19-May-16 13:03pm.
|
|
|
|
|
programmingalholic wrote: But how does WM_SETSEL come? Do you mean how is it used?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
programmingalholic wrote: WM_SETSEL There is no such message.
|
|
|
|
|
The default behaviour of edit controls is showing the selection only when the control has the focus. From your description I assume that another control (the search input field or a button) has the focus when you try to set the selection.
But there is an option to show the selection even when the edit control does not have the focus: ES_NOHIDESEL[^].
Unfortunately the style can't be changed once the control exists. You have to set it when creating the edit control. If it is defined as static resource, set the option there (e.g. using the resource editor). For dynamically created edit controls pass the flag in the style parameter when calling CreateWindow or CreateWindowEx .
|
|
|
|
|
That's 100% right !! It had to do with ES_NOHIDESEL style, I had succeeded tap into it. However, thanks to all members of this community that had posed attention to my problem.
|
|
|
|
|
Hello Friends
I am creating 100s of buttons in Window application.I used naming like IDB_BUTTON1, IDB_BUTTON2..... IDB_BUTTON100.And assign variable m_button1.
Now, I want to convert string (m_button+ ID) to m_button1 of CButton type.
Regards
|
|
|
|
|
You cannot normally do that, generated resource IDs are numbers. You can use strings to refer to resources but it requires a detailed knowledge of resource files and the rc compiler. This also begs the question, why do you need so many buttons?
|
|
|
|
|
So many buttons are requirement of Application.
Actually, I tried with Macro. But ,again I need to use Variable value to identify 100 buttons tht macro doesn't consider variable.
I used like
#define CONCAT(ID,NUMBER) ID##NUMBER
And IN Code
for(int num =0; num < 100; num++)
CONCAT(m_Button,num)
So, this one fails.
|
|
|
|
|
Like I said, you cannot do it, as resource ids are integer values.
And chances are if the application needs 100 buttons, then there is something wrong with the design.
|
|
|
|
|
I beg to disagree on some grid based applications I routinely get up over 200 buttons but there are tricks which I will discuss with him.
In vino veritas
|
|
|
|
|
I suspect you need all the buttons for something like I have done which was a grid display for a process plant control switches for pumps and the like.
What you can do is attach a text string as either a property of the button handle via "SetProp" or alternative set the string as
a resource using RT_STRING to the ID of the button and use FindResourceEx to pull back the string matching the button ID. The
String resources are stored in sections of up to 16 strings per section so you will need to provide a function to pull it back.
Here is a sort of normal code for pulling back a string resource
String Resources | Ruminations[^]
The SetProp way is easier but can only be created in the WM_CREATE of the button creation, or just after the CreateWindowEx call creating the button and so needs a little more setup work than a string resource list.
In vino veritas
|
|
|
|
|
How are you creating all these buttons?
Anytime I need more than a few of the same type, I create them dynamically and add their references to a collection. You then reference them via an "index" (which is the equivalent of an ID).
|
|
|
|
|
I think control array will help you.
void CControlArrayDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_BUTTON1, m_CtrlButton[0]);
DDX_Control(pDX, IDC_BUTTON2, m_CtrlButton[1]);
}
|
|
|
|
|
Hello, I am trying to code a program which evaluates expressions in reverse polish notations. For now, it should work only with numbers and operands ( +, -, * and / ).
Here is the code I have written:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <conio.h>
#define MAX 41
int t, i, v1, v2;
int top = -1;
char seq[40];
char rpn[40];
char fin[40];
int main()
{
printf("introduce the numbers and opreands in rpn \n");
fgets(seq,40,stdin);
t=strlen(seq);
for (i=0;i<=t;i++)
if (isdigit(seq[i]))
{
Push(rpn, seq[i]);
}
if (ispunct(seq[i]));
v1=pop(rpn);
v2=pop(rpn);
if (seq[i] = '+');
push(fin, v1+v2);
if (seq[i] = '-');
push(fin, v1-v2);
if (seq[i] = '*');
push(fin, v1*v2);
if (seq[i] = '/');
push(fin, v1/v2);
printf(fin);
}
int isempty() {
if(top == -1)
return 1;
else
return 0;
}
int isfull() {
if(top == MAX)
return 1;
else
return 0;
}
int peek() {
return seq[top];
}
int pop() {
int data;
if(!isempty()) {
data = seq[top];
top = top - 1;
return data;
}else {
printf("Could not retrieve data, Stack is empty.\n");
}
}
int push(int data) {
if(!isfull()) {
top = top + 1;
seq[top] = data;
}else {
printf("Could not insert data, Stack is full.\n");
}
}
There are, I think, some big mistakes i can't solve by myself, since im a beginner in programming. I have searched for a solution on the internet, but i don't truly understand them.
The idea of my code is that the user types some numbers and operands like this: 2 3 +. In this case, the program should add 2 and 3 in a stack and when it reads and operator, pop the lasts 2 numbers on the pile and do the corresponding opperation.
When i build it I have this errors:
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
C:\Users\Jordi\Documents\RPN.o:RPN.c|| undefined reference to `Push|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
modified 17-May-16 13:03pm.
|
|
|
|
|
Unless this is a fragment, it seems like you have done no effort to actually implement push and pop.
strlen (the usual one) is from string.h which you should therefore include.
|
|
|
|
|
You are right, sorry, I even forgot to put them in the code! This is something a partner gave and explained to me. There are some functions i dont even use. It's because I understand it i didn't put in here. My bad.
The full code looks like:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <conio.h>
#define MAX 41
int t, i, v1, v2;
int top = -1;
char seq[40];
char rpn[40];
char fin[40];
int main()
{
printf("introduce the numbers and opreands in rpn \n");
fgets(seq,40,stdin);
t=strlen(seq);
for (i=0;i<=t;i++)
if (isdigit(seq[i]))
{
Push(rpn, seq[i]);
}
if (ispunct(seq[i]));
v1=pop(rpn);
v2=pop(rpn);
if (seq[i] = '+');
push(fin, v1+v2);
if (seq[i] = '-');
push(fin, v1-v2);
if (seq[i] = '*');
push(fin, v1*v2);
if (seq[i] = '/');
push(fin, v1/v2);
printf(fin);
}
int isempty() {
if(top == -1)
return 1;
else
return 0;
}
int isfull() {
if(top == MAX)
return 1;
else
return 0;
}
int peek() {
return seq[top];
}
int pop() {
int data;
if(!isempty()) {
data = seq[top];
top = top - 1;
return data;
}else {
printf("Could not retrieve data, Stack is empty.\n");
}
}
int push(int data) {
if(!isfull()) {
top = top + 1;
seq[top] = data;
}else {
printf("Could not insert data, Stack is full.\n");
}
}
|
|
|
|
|
Just move them to above main then. Or use forward declarations.
|
|
|
|
|
Keep in mind that the c/c++ is case sensitive. I'm looking at this line in particular.
Push(rpn, seq[i]);
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|