|
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
|
|
|
|
|
Member 12529159 wrote: This is something a partner gave... Ahh, the classic "copy & paste" bug.
I'm usually the one to get chided for printing off code snippets and retype them line by line into my project. Consequently, I've never been a victim of this type of problem.
"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
|
|
|
|
|
Member 12529159 wrote: There are, I think, some big mistakes Yes, this will not compile, and even if it did, none of this code is going to work. You are reading a string into the array seq and then using Push to copy characters back into the same array. You are also storing everything as characters but when you use Pop, you think you are rectrieving an integer. And you assume that each string will be two digits followed by a mathematical symbol.
|
|
|
|
|
Hi all, I have a variable declared:
CMyDlg* m_pDlg1;
I initialized it as NULL and expected it to change when passed to CallDlg. But it stays as NULL before and after the call, therefore creating new modeless CMyDlg everytime it gets called (instead of bringing up the existing one the foreground).
What did I do wrong? Shouldn't m_pDlg1 point to the newly created dialog?
Please help. Thanks in advance.
void CMyApp::ActivateDlg1()
{
CallDlg(1, m_pDlg1); }
void CMyApp::CallDlg(int nType, CMyDlg* pDlg)
{
if(pDlg) pDlg->SetForegroundWindow(); else
{
pDlg = new CMyDlg(nType);
if(!::IsWindow(pDlg->GetSafeHwnd())) pDlg->Create(IDD_MY_DLG, NULL);
}
}
|
|
|
|
|
Joe Smith IX wrote: I initialized it as NULL and expected it to change when passed to CallDlg. But it stays as NULL before and after the call, therefore creating new modeless CMyDlg everytime it gets called (instead of bringing up the existing one the foreground).
1. I do not see where, how and when you set it to NULL.
2. Did you debug your code to see the "real" values of all the variables?
3. To make debugging easier for yourself you should avoid write the code in the manner
if(pDlg) pDlg->SetForegroundWindow(); but
if(pDlg)
pDlg->SetForegroundWindow();
4. how and where do you delete the m_pDlg1 pointer?
|
|
|
|
|
1. I didn't copy the whole code, just the snippet.
2. Yes, I did. That's how I could state 'it stays as NULL before and after the call'.
3. I do. Thanks.
4. Same reason as number 1 above.
Anyway, I solved it as pointed by CPallini below. I was missing the ampersand symbol to indicate passing by pointer. Thanks anyway.
|
|
|
|
|
If you want to change the passed pointer value then you have to pass its address (because, like any other kind of parameter, pointers are passed by value) ending up with a double pointer or a reference to the pointer. e.g.
void CMyApp::CallDlg(int nType, CMyDlg & * pDlg)
void CMyApp::CallDlg(int nType, CMyDlg * & pDlg)
{
}
modified 17-May-16 15:57pm.
|
|
|
|
|
Ah, you are right. To pass by address, I need the & character. It's working fine now. Thanks so much.
void CMyApp::CallDlg(int nType, CMyDlg* &pDlg)
{
}
|
|
|
|
|
I gave you a flawed code sample, sorry.
Thank you for pointing it out so nicely.
|
|
|
|
|
if I have this code :
char * s =(char*)malloc(10);
and then I write 's="test"' then s will have a different address right ?
why is this happening ?
|
|
|
|
|
You are allocating assigning the address of the string literal "test" to the pointer s thus overwriting the address returned by malloc . You should be using strcpy to copy the four characters into the allocated buffer.
[edit]
better terminology as pointed out by member below.
[/edit]
modified 17-Jun-16 4:11am.
|
|
|
|
|
or, even better, strncpy .
|
|
|
|
|
Absolutely right, but I was trying to KISS.
|
|
|
|
|
Shouldn't that be: "you are assigning the address" instead of allocating?
|
|
|
|
|
|
Member 10964099 wrote: why is this happening ? It append because it designed this way. That is how pointers work.
I recommend to read THE book "the C Language" from Kernigan & Ritchie.
The C Programming Language - Wikipedia, the free encyclopedia[^]
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Because s is a pointer.
char * s =(char*)malloc(10);
s="test"
|
|
|
|