|
I have been trying to make a 2d array of pictureboxes but it seems like a can't figuer it out.
I have been trying to do like this but it does work.
PictureBox* Array2d[][]= new PictureBox* [][];
|
|
|
|
|
This should create a 4x3 array of PictureBox objects:
PictureBox **pb = new PictureBox*[4];
for (int x = 0; x < 4; x++)
pb[x] = new PictureBox[3];
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Then how would you acces them ?
and thanks
|
|
|
|
|
Like any two-dimensional array:
pb[2][0] = ???; would assign a value to the following "cell" of the array:
-------
| | | |
-------
| | | |
-------
|#| | |
-------
| | | |
-------
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
|
Avoid raw arrays. I would use CArray or vector, eg., (in your case substitute PictureBox for int)
// ***************************************
// Example: Dynamic Multidimensional Array
// ***************************************
// We want both array dimensions to be allocated dynamically and
// to be able to reference an element as x[i][j]
// Here's how to do it...
// ***********
// MFC Version
// ***********
// Array of ints
typedef CArray <int, int> CIntArray;
// Array of arrays of ints
typedef CArray <CIntArray, CIntArray&> CMultiIntArray;
void TraceDynamicArray(const unsigned int rows, const unsigned int columns)
{
CMultiIntArray aTest;
// Allocate number of rows
aTest.SetSize( rows );
// For each row
for (int row = 0; row < aTest.GetSize(); row++)
{
// Allocate number of columns
aTest[row].SetSize( columns );
// For each column
for (int column = 0; column < aTest[row].GetSize(); column++)
{
// Assign a value
aTest [row] [column] = 10 * row + column;
// Trace it
afxDump << aTest [row] [column] << "\t";
}
afxDump << "\n";
}
}
// ****************************
// Standard C++ Library Version
// ****************************
// Array of arrays of ints
typedef vector<vector<int> > CMultiIntArray;
void TraceDynamicArray(const unsigned int rows, const unsigned int columns)
{
CMultiIntArray aTest;
// Allocate number of rows
aTest.resize( rows );
// For each row
for (int row = 0; row < aTest.size(); row++)
{
// Allocate number of columns
aTest[row].resize( columns );
// For each column
for (int column = 0; column < aTest[row].size(); column++)
{
// Assign a value
aTest [row] [column] = 10 * row + column;
// Trace it
cout << aTest [row] [column] << "\t";
}
cout << "\n";
}
}
// Example usage: Standard C++ Library version
int main(int argc, char* argv[])
{
TraceDynamicArray(3,5);
return 0;
}
// For rows = 3, columns = 5, produces output...
// 0 1 2 3 4
// 10 11 12 13 14
// 20 21 22 23 24
Kevin
|
|
|
|
|
"Avoid raw arrays. I would use CArray or vector."
Why?
I am kind of new in c++ and thanks.
|
|
|
|
|
See http://www.artima.com/intv/goldilocks.html[^]
Basically, we should all be using the modern, high-level features of C++. They are safer, more robust, easier to use (after a bit of acquaintance) and often just as efficient as the low-level stuff.
Have a look at Stroustrup's comments and papers on this. See also Paul McKenzie's posts at codeguru.com.
Stroustrup: "The problem with the C way is that if you write code C-style, you get C-style problems. You will get buffer overflows. You will get pointer problems. And you will get hard to maintain code, because you're working at a very low level. So the cost is in development time and maintenance time."
Kevin
|
|
|
|
|
|
i got a problem that i can't hook java application by VC++. So please give me documents or sample source code if you have this solution huh. Thanks for all. I'm waiting for all of you.
|
|
|
|
|
I am creating a server application using CAsyncSocket , i am able to recieve information from a client , how could i send reply back to connected client , at present i am able to accept only one client how could i make it for multiple clients...
this is code that i had written...
here async is a class derived from CAsyncSocket....
void async::OnAccept(int nErrorCode)
{
if( recvsocket==NULL )
recvsocket = new async;
//Create the new connection
if( Accept( *recvsocket,NULL,NULL ) == 0 )
{
return;
}
CAsyncSocket::OnAccept(nErrorCode);
}
here i declared recvsocket as
async* recvsocket;
in the async class....
void async::OnReceive(int nErrorCode)
{
char *pBuf = new char[1025];
int iBufSize = 1024;
int iRecv, iErrCode;
CString strRecv, Emsg;
iRecv = Receive(pBuf,iBufSize);
if (iRecv == SOCKET_ERROR)
{
iErrCode = GetLastError();
Emsg = "Error found! Error code: " + iErrCode;
AfxMessageBox(Emsg);
}
else
{
pBuf[iRecv] = NULL;
strRecv = pBuf;
AfxMessageBox(strRecv);
/* if (recvsocket->Send(pBuf,iBufSize) == SOCKET_ERROR)
{
AfxMessageBox("Send Error");
}
else
{
AfxMessageBox("sended");
}
*/
}
CAsyncSocket::OnReceive(nErrorCode);
}
Thank u.
Prasanna
|
|
|
|
|
I had to create a Win 32 dll in C++ to be able to link it to Clarion.
I usually use C# and don't know C++ very well.
This dll works fine but I am struggling to interface to my C# web service from this C++ dll.
I have added my Web service to the Project as a web reference.
In the dll I can see the web service name space but not the procedures in that service.
Is it possible top link from a C++ dll to a C# web service ?.. If possible How??
Thanks
Max
|
|
|
|
|
How get IContextMenu for several files from different folders ?
XZ
|
|
|
|
|
I wanna set real time priority to my application.
At first a loader program runs myapp. Then I want to get the process id using exe name. With exe name i must be able to set its priority to REALTIME.
My concept may sound correct but i dont know how to program it. Anybody can help me;P
|
|
|
|
|
|
If you have control over the loader program you can use CreateProcess() to launch your application and use REALTIME_PRIORITY_CLASS in the creation flag.
Otherwise use SetPriorityClass() within your application to REALTIME_PRIORITY_CLASS - this will ensure that your application runs at Realtime priority always.
I would be carefull when creating programs that run at realtime as they *will* hog the processor and you can easily prevent other applications from responding.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
I tried...but it doesn't work. I am in VC6. Does this stuffs work under VC6? In the loader program i am using the below code,
STARTUPINFO suInfo;
PROCESS_INFORMATION procInfo;
CString m_Process;
m_Process.Format(_T("%s\\my.exe"),curDir);
memset (&suInfo, 0, sizeof(suInfo));
suInfo.cb = sizeof(suInfo);
::CreateProcess(m_Process,
NULL, // can also be NULL
NULL,
NULL,
FALSE,
REALTIME_PRIORITY_CLASS,
NULL,
NULL,
&suInfo,
&procInfo);
if (procInfo.dwThreadId == NULL)
{
AfxMessageBox("nope");
}
else
{
::SetThreadPriority(&procInfo.dwThreadId,THREAD_PRIORITY_HIGHEST);
}
When I check in process viewer the class priority is "Very High", the thread priority remain "normal". Also when a thread runs in "my.exe" it's not given the highest priorities, i am free to access other programs.
|
|
|
|
|
Manikandan wrote:
i am free to access other programs
You will always be able to access other programs even with Realtime priority set.
NOTE: Running under windows you can not set the application to have exclusive use of the processor.
I am puzzled, why would you want to do this?
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
Hi Ant, my application is time sensitive. even mouse move will affect its normal operation. This is why i have to suspend other programs when my exe run a thread.
Actually i found a standalone program in the net that list out all the running programs (I give you the link asap). When i set the priority to real time (24). I found my program running fine while i cant even access the mouse.
But i want to do this programmatically.
|
|
|
|
|
Manikandan wrote:
But i want to do this programmatically
I would have thought that my suggested launching would have worked. If I think of anything else you could try I will let you know.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
Well, just a notice - Windows are not realtime OS, if you really need the RT features (for RT controlling a device or something like that) you better to go by some specialized RT OS or get some RT plugin for NT that replaces the standard scheduler.
Even if you set the process realtime priority and thread realtime priority the time scheduler can interrupt your process and will do it usually in the worsest possible time.
|
|
|
|
|
hi thanks for you idea,
i did a google search with the string "Real Time plug in for NT" but i couldn't come across any windows compatible plug in's.
would you please refer me one
|
|
|
|
|
just googled for "RealTime NT"
and got some results
|
|
|
|
|
Hi all,
Apologies if this has already been covered but I could find it anywhere.
The problem that I have is that a piece of software that I am working on used a lot of arrays and matrices (i.e. float* and float**), the problem that we where having was that the program was leaking memory like there was no tomorrow (about a meg every 10secs) and the program was crashing at 'innocent' parts of the code.
After spending quite a while trying to solve these errors I decided to go at it with a sledge hammer and change all of the arrays and matrices to STL vectors (i.e. vector for the arrays and a vector <vector> for the matrices). I've now finished making the changes and the program no longer leaks memory or crashes, however it now runs at about 50% slower. I've changed where the vectors are created so that they are only created once. This has improved things quite a lot however it is still noticibly slower about 10%, does anyone have any other easy optimisation methods that I can implement.
I've left the way that the program accesses the data the same using the [] and [][] brackets.
Any thoughts or suggestions will be gratefully received!
Andy
|
|
|
|
|
Hi,
If the type is known (in your case float) you could write your own vector class.
Do the maintance (new/delete) in there and use the good old (double if necessary) arrays.
Vector classes are always quite slow. If speed is primary you should use arrays.
hope this helps...
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|