|
Hi Freinds,
I have combobox control in my mfc application. Here I am adding an item with an empty string and 2 more item with some txt.
if i am navigating through the items, if empty string get selected, it draws a dotted boundary, but when other item is getting selected, dotted boundary of empty string is not getting cleared. So basically I can see 2 items selected at the same time.
please help me out.
Regards,
Amrit
|
|
|
|
|
You could just intercept the DrawItem call and for any empty string simply clear the lpDrawItemStruct->rcRect manually and then pass all the calls thru to the normal drawitem. lpDrawItemStruct has everything you need to know what to draw
lpDrawItemStruct->itemID it the string number
lpDrawItemStruct->itemState & ODS_SELECTED will tell give you if it is selected or not.
lpDrawItemStruct->rcRect is the area to draw in
In vino veritas
|
|
|
|
|
Hi
If have a class member say CFont cf; which is a member of My CDialig derived class which I create on the heap via new
Does storage for cf get allocated when I do the new for the CDialog derived class
Thanks
|
|
|
|
|
Yes, storage for class members will be allocated when the object is created. In the case of class objects (such as your CFont object) their constructor will be called to create them. You can see this happen by stepping through the code in the debugger.
|
|
|
|
|
Code source de FIFO,LIFO,SJF,Round Robin en langage C?
|
|
|
|
|
Hi,
Is it that time of year again? Sorry, we have past our own exams, and are not going to sit yours. I suggest you read a few books on the subject.
Regards and Success
Bram van Kampen
|
|
|
|
|
What about a little study ?
and a little work by yourself ?
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
|
Is the first method correct for all the platforms?
I describe the three methods in the following code:
#include <stdio.h>
#include <iostream>
using namespace std;
#define YMAX 6
#define XMAX 4
void print_data2d(float *matriz[XMAX],int max1,char *method);
void print_data2d(float (*matriz)[XMAX],int max1,char *method);
void print_adress(float (*matriz)[XMAX],int ymax,char *method);
void print_adress(float *matriz[XMAX],int ymax,char *method);
void print_data2d(float *matriz,int ymax,int xmax,char *method);
void print_data2d(float **matriz,int ymax,int xmax,char *method);
int main()
{
int x,y;
float *matriz1_m=new float[XMAX*YMAX];
float (*matriz1)[XMAX]=(float (*)[XMAX]) &matriz1_m[0];
float (*matriz2)[XMAX]=new float[YMAX][XMAX];
float *matriz3[YMAX];
for (y=0;y<YMAX;y++)
matriz3[y]=new float[XMAX];
float **matriz4 = new (float*[YMAX]);
for (int y = 0; y < YMAX; y++)
matriz4[y] = new float[XMAX];;
for (y=0;y<YMAX;y++)
for (x=0;x<XMAX;x++)
{
matriz1[y][x]=matriz2[y][x]=matriz3[y][x]=matriz4[y][x]=(y+1)*1000.0f+x;
}
print_data2d(&matriz1[0][0],YMAX,XMAX,"Values 1st method");
print_data2d(matriz3,YMAX,XMAX,"Values 3rd method");
print_data2d(matriz4,YMAX,XMAX,"Values 4th method");
print_data2d(matriz1,YMAX,"Values 1st method");
print_data2d(matriz2,YMAX,"Values 2nd method");
print_data2d(matriz3,YMAX,"Values 3rd method");
print_data2d(matriz4,YMAX,"Values 4rd method");
print_adress( matriz1,XMAX,"Adress 1st method");
print_adress( matriz2,XMAX,"Adress 2nd method");
print_adress( matriz3,XMAX,"Adress 3rd method");
print_adress( matriz4,XMAX,"Adress 3rd method");
long size=sizeof(float)*XMAX*YMAX;
printf("\nMinimum =%li",size);
size= (sizeof(float) + (long) (&matriz1[YMAX-1][XMAX-1]) ) - (long) &matriz1[0][0];
printf("\nArray 1 =%li",size);
size= (sizeof(float) + (long) (&matriz2[YMAX-1][XMAX-1]) ) - (long) &matriz2[0][0];
printf("\nArray 2 =%li",size);
size= (sizeof(float) + (long) (&matriz3[YMAX-1][XMAX-1]) ) - (long) &matriz3[0][0];
printf("\nArray 3 =%li",size);
size= (sizeof(float) + (long) (&matriz4[YMAX-1][XMAX-1]) ) - (long) &matriz4[0][0];
printf("\nArray 4 =%li",size);
delete matriz1_m;
delete[] matriz2;
for (int y=0;y<YMAX;y++)
delete matriz3[y];
for (int y=0;y<YMAX;y++)
delete matriz4[y];
printf("\n\n=== END ===");getchar();getchar();
return 1;
}
void print_adress(float (*matriz)[XMAX],int xmax,char *method)
{
cout << "\n============= INI DIR "<< method << "=============\n";
int x,y;
for (y=0;y<YMAX;y++)
{
for (x=0;x<xmax;x++)
cout << ((long) (&matriz[y][x]) - (long) (&matriz[0][0])) << '\t';
cout <<endl;
}
cout << "\n============= END DIR "<< method << "=============\n";
}
void print_adress(float *matriz[XMAX],int xmax,char *method)
{
cout << "\n============= INI DIR "<< method << "=============\n";
int x,y;
for (y=0;y<YMAX;y++)
{
for (x=0;x<xmax;x++)
cout << ((long) (&matriz[y][x]) - (long) (&matriz[0][0])) << '\t';
cout <<endl;
}
cout << "\n============= END DIR "<< method << "=============\n";
}
void print_data2d(float *matriz[XMAX],int maxy,char *method)
{
cout << "\n============= INI VAL "<< method << "=============\n";
long y,x;
for (y=0;y<maxy;y++)
{
for (x=0;x<XMAX;x++)
{
cout << matriz[y][x] <<'\t';
}
cout <<endl;
}
cout << "============= FIN VAL "<< method << "=============\n";
}
void print_data2d(float (*matriz)[XMAX],int maxy,char *method)
{
cout << "\n============= INI VAL "<< method << "=============\n";
long y,x;
for (y=0;y<maxy;y++)
{
for (x=0;x<XMAX;x++)
{
cout << matriz[y][x] <<'\t';
}
cout <<endl;
}
cout << "============= FIN VAL "<< method << "=============\n";
}
void print_data2d(float **matriz3,int ymax,int xmax,char *method)
{
cout << "\n============= INI VAL "<< method << "=============\n";
long y,x;
for (y=0;y<ymax;y++)
{
for (x=0;x<xmax;x++)
{
cout << matriz3[y][x] <<'\t';
}
cout <<endl;
}
cout << "============= FIN VAL "<< method << "=============\n";
}
void print_data2d(float *matriz1,int ymax,int xmax,char *method)
{
cout << "\n============= INI VAL "<< method << "=============\n";
long y,x;
for (y=0;y<ymax;y++)
{
for (x=0;x<xmax;x++)
{
cout << matriz1[y*xmax+x] <<'\t';
}
cout <<endl;
}
cout << "============= FIN VAL "<< method << "=============\n";
}
modified 30-Apr-16 5:09am.
|
|
|
|
|
Hi,
Four Questions:
1st: What do you mean by 'Different Platforms' It's all standard CPP, Standard Libraries, etc. Should work on any machine that supports a CPP Compiler to ISO Standards.
2nd: Does it Work! (I Don't see any obvious errors at a Glance, but a First Glance can be deceiving in this game, which is the reason we do debugging. I am not willing to do that for you, but I'll offer Help if you encounter a Difficulty.)
3rd: What are you trying to prove, apart from that there is more than one way to skin a Cat (or in this case, write a piece of Code) Otherwise, Did you provide a Crude Example of a Bigger Problem, but you are trying to touch the basics, by simplifying the problem, (and sometimes by Abstracting the problem, hiding the real issues that you try to discuss). For Instance, did you abstract the concept of MFC Classes down to Floating Point Variables.
4th: If it all works, Why pose the question in the first place. (In other words, What was the real question!)
Kind Regards
Bram van Kampen
modified 29-Apr-16 21:35pm.
|
|
|
|
|
You are right, the second method of course works and is my preferred method as long as I do not need a loop to create and delete it, but I have to be careful when sending the array to a function.
Thank you to advise that the first one fits with iso standard.
|
|
|
|
|
You seem to have yourself very confused on pointer dereferencing and memory allocation. You are trying to assign "right way" to something that has nothing to do with the language but what is essentially about memory ownership.
Your version 3 is mongrel of a thing and NOT CLASSICAL AT ALL. Look carefully at what it is which is an array of pointers on the stack if within a function or on the heap if globally assigned and into which you place allocated memory. YUCK writing any function via pointer reference to access that abomination would be fun and dangerous it's not necessarily a persistent structure unless defined globally.
So how about I give you 4 WHICH IS ACTUALLY THE CLASSICAL VERSION
float **matriz3 = new (float*[YMAX]);
for (int y = 0; y < YMAX; y++)
matriz3[y] = new float[XMAX];;
float **matriz3 = (float**)malloc(YMAX * sizeof(float*));
for (int y = 0; y < YMAX; y++)
*matriz3[y] = (float*)malloc(XMAX *sizeof(float));
So now you have another one and all of them are perfectly fine within the contexts of what they were designed to do although 3 is of very limited use locally. You would need to take care passing a reference to your version 3. Method 4 is usable anywhere and someone needs to take responsibility to delete/free the allocated memory blocks.
Whats different is 1 and I think 2 allocate all the memory together in one big contiguous block, 3 & 4 don't do that they have a pointer block which points to memory blocks for each row array and those blocks can be all over the place in physical memory. Structurally they are both 2D float arrays but there is differences in there internal memory layout. Versions 3 & 4 will never produce anything that looks like version 1 without a lot of luck with memory allocation.
I won't comment on 2 because I have a feeling it may be compiler dependent C++11 seems to say it will be a contiguous block but I am not sure all compilers will do it if they are not C++11 compliant.
The two structures also do no use the same amount of memory take a 2x2 matrix. Version 1 simply allocates memory for 4 floats. Version 3 & 4 allocate 2 pointers and then 2 floats allocated into each pointer. So if your floats are 4 bytes and your pointers are 4 bytes, version 1 allocates 16 bytes of memory and version 3&4 allocate 8+16=24bytes.
Technically the access to version 1 is faster but it has the considerable downside that as the structure gets larger the chances of finding that amount of contiguous memory block size becomes difficult. Version 3 & 4 can go to much larger size and are more likely to still work at larger sizes that version 1.
So you asked:
Is the first method correct for all the platforms? Yes but that is only one way to make a 2D float array don't expect that to work for other methods on any platform.
Your overloaded functions are correct for 1, 3 & 4 ... I am still wary of 2 you might need to do some checking
void print_data2d(float *matriz,int ymax,int xmax,char *method);
void print_data2d(float **matriz,int ymax,int xmax,char *method);
There is some danger in that overloading that the use of an "&" will give you the wrong one. Consider a version 1 array and I went to print it.
float *matriz; print_data2d (&matriz, .... );
See what happens there .... matriz is a float* .. &matriz is a float** .. so the call takes the second form and probably crashes and burns.
I think for safety you need to do a bit of typecasting
In vino veritas
modified 30-Apr-16 1:42am.
|
|
|
|
|
Thank you leon de boer, I included the 4th method and modified the comment at printf_data2d, I will check the last part of the post.
|
|
|
|
|
Can I point out that if you really want portability with C++11, we do this and there is nothing your code can do with this as it uses the standard vector library
#include <vector>
using namespace std;
#define YMAX 6
#define XMAX 4
vector<vector<float>> matrix1(YMAX, vector<float>(XMAX));
matrix1[0][0] = 3.6f;
matrix1[1][2] = 4.0f;
matrix1[5][3] = 8.0f;
float f = matrix1[1][2];
The really cute part is it can be used on any standard type
vector<vector<string>> stringmatrix(YMAX, vector<string>(XMAX));
stringmatrix[0][0] = "hello at 0,0";
stringmatrix[1][2] = "this one";
stringmatrix[5][3] = "hello at 5,3";
string whatdidwesay = stringmatrix[1][2];
In vino veritas
modified 30-Apr-16 9:29am.
|
|
|
|
|
Our MFC Server application send huge real time data of size 900000bytes using CSocket (TCP/IP Sockets) via serialization continuously every 2 second to the MFC Client.
But After a few minutes, the application gets slowed down.
Is there any specific ways or methods of send/receive huge data continuosly via Csocket.
How to send the big data every interval in a better way.
|
|
|
|
|
Increase Baudrate of CSocket and reduce data chunk size while communication.. big data if reduced to small data chunks with sequence added in the data packet may help in faster data transfer across systems.. look in windows provided CSocket for more info
|
|
|
|
|
Can i get more information in this regard...reducing to small data chunks with sequence added in the data packet.
How many data chunks could be done for 900000bytes of data.
Please give me the steps or some example and detail.
|
|
|
|
|
create a struct data structure similar to:
struct myPacket{
int uwSeq;// sequencing starts from 1 upto 879
int maxSeqCount;// when this reaches 879 reaset to 1
char myData[1024];//Small Chunk
unsigned int uwcrcData;//CRC of uwSeq,myData
}stSmallChunk;
send stSmallChunk data packet and validate at other end using CRC recieved seqs.
FYI: 1024*879 small chunks =900096 Bytes
-Shyam Kodase
|
|
|
|
|
reduce time interval to 500ms interval upto 4 subiteration in 1st iteration.. (which in effect will result in 2s interval) and after 4th subiteration append all data at client side.
|
|
|
|
|
Hi,
I am looking for an article about dialing a phone number directly from my database (i.e. as in Call Centre), Via CPP Code. I do not seem to be able to filter the article count down to less than 3700, mostly altogether unrelated. Anyone a Hint or Idea?
Thanks and Regards
Bram van Kampen
|
|
|
|
|
Is this a desktop or a mobile app?
"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
|
|
|
|
|
Hi Dave,
It is an MFC42/CPP Desktop Application I want to Auto Dial from, to establish a Voice Connection. I.e.: I want staff to contact selected customers, via de Phone Number we have on our DB. As a Laundrette, we have an issue with customers forgetting they left stuff in. I'm writing an MFC Application for staff to deal with this during quiet times. Automatic dialling helps to prevent mis-dials, and protects our phone bill against misuse.
Thanks + Regards,
Bram van Kampen
modified 29-Apr-16 18:45pm.
|
|
|
|
|
Bram van Kampen wrote: It is an MFC42/CPP Desktop Application... And how is it connected to the phone?
"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
|
|
|
|
|
Hi David,
Thanks for your reply.
I am planning to connect Via a "RealTech" Dial up Modem Card, or Equivalent. All my XP Computers have one, or something similar, by a different manufacturer. I also harvested about half a dozen. The Installation software is typically part of WinXP.
The XP Default installation is that specific and unspecified features may not be available. However, I seek only Voice Contact, on an Out Dialling only Connection.
I have also a number of Installation disks for older Real Tech Modems which I bought in the past. I suppose that any and all of them can do a basic Function, Dialling out, and thereafter managing a Voice Based conversation. All Computers we currently have, have also a form of sound processing card.(Very Basic in most cases) I assume that this can be used to get the Voice Aspect realised for a phone connection.
Al I am ultimately interested in is, getting an outgoing Voice Connection.
We have NO requirement at all, to deal with in coming calls.
Thanks for your Reply,
Looking forward to your response
Bram van Kampen
modified 1-May-16 20:46pm.
|
|
|
|
|
Bram van Kampen wrote:
I am planning to connect Via a "RealTech" Dial up Modem Card, or Equivalent. Okay, you'll need to look into connecting to the cards via the CreateFile("COM3", ...) function. Then you'll send the appropriate AT commands to the open port.
Also check out the TAPI.
"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 3-May-16 9:08am.
|
|
|
|
|