|
There is some class, say Class Test{};
And let there will be a pointer Test *ptest;
How to allocate 2D array of this class pointers m_array[x][y]?
that we will be able after allocation to do
m_array[0][0] = new Test();
m_array[1][0] = new Test();
... and so on.
9ine
|
|
|
|
|
#define X_SIZE 10
#define Y_SIZE 10
class Test {
};
Test* m_Array[X_SIZE][Y_SIZE];
for (int y = 0; y < Y_SIZE-1; y++) {
for (int x = 0 ; x > X_SIZE-1; x++) {
m_Array[x][y] = new Test();
}
}
easy, isn't it ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Here's some thoughts.
1) std::vector<std::vector<Test*> > my_2D_array;
2) std::map<std::pair<int,int>,Test*> my_map;
In both these cases you would still need to use new. But you can avoid that by letting the standard container do the allocation its self, by using one of these instead:
1) std::vector<std::vector<Test> > my_2D_array;
2) std::map<std::pair<int,int>,Test> my_map;
Vector is faster, but you should reserve space for the number of rows required and then reserve space for each individual row (columns). A bit of a pain, but a simple helper function can do that for you. Or you could just encapsulate the vector of vectors in your own class and use that to access it.
Map is slower, but easier to use. You can't, nor do you need to, reserve space ahead of time. To add a new item just do this:
my_map[std::make_pair(0,0)] = Test();
Note: If the key pair already exist in the map then it is replaced by the new element. If the key pair does not exist, it is add to the map.
When using standard containers you do not have to store pointers to classes, just make the class type the type that is being stored. That way you are not responsible for the clean up and the container is responsible for most of the type safety garantees.
Oh well, I hope that gave you some help.
INTP
Use standard containers when available, unless you have a very good reason to roll your own.
|
|
|
|
|
Hi,
I was write a GINA dll that works fine on Windows XP. I use version 3 of Winlogon functions that is compatible with Windows 2000+. But when I tested this dll on Windows 2000 Advanced Server and Windows Server 2003, a problem occurred. When the message dialog with message "Preparing network connections" or "Applying computer settings" appear, this dialog remains for a long time (in fact for ever). What could be happened? Do you know?
Thanks,
Esmaeil
|
|
|
|
|
Hi
How can i at runtime replace a picture that i have inserted initially in the dialog box with another one?
/\|-||\/|/\|)
|
|
|
|
|
|
Was this of no help?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
|
Respected all
Regards!
I am a begginer in VC++ and facing problem
" I have a few bitmaps and i have to select from List Box at runtime that which bitmap has to display, how i display a bitmap while selecting from List Box at RunTime.
Hope + response.
Form
david
|
|
|
|
|
For starters, you'll need a listbox with the LBS_OWNERDRAWFIXED style.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I have downloaded a project that contains several cpp, sln, vcproj, and corresponding *.h files.
Could not open the vcproj or sln file.
I am using VC++6. How do I know which is the main cpp file? What file should I open via the IDE?
thanX
|
|
|
|
|
Anonymous wrote:
I have downloaded a project that contains several cpp, sln, vcproj, and corresponding *.h files.
Could not open the vcproj or sln file.
I am using VC++6.
Try using this tool :
VC++7 to VC++6 project converter[^] to convert and then try to open with vc6.
suhredayan There is no spoon.
|
|
|
|
|
I want to draw a string in an SDI using TextOut. But i have co-ordinates in millimeters. How can i convert them into pixels. Help needed urgently...
|
|
|
|
|
Ups!! The pixel is the basic unit of programmable color on a display or image so it's more a logical unit than a physical one, altough the physical size of a pixel depends on how you've set the resolution for the display screen:
If the display is at its maximum resolution, the physical size of a pixel will be the physical size of the dot of the display (usually .28mm but you should look to the specs of your display). If you've set the resolution to less, a pixel will be larger than the physical size of the screen's dot (the pixel will use more than one dot).
Hope it helps ...
Marc Soleda.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
Hi,
If you call 'GetDeviceCaps' on your device context you can get
the width and height, in millimeters, of your physical screen.
You can also get the resolution of the screen in pixels this way,
so you should be able to do some calculations based on these values...
Don't think you are, know you are...
|
|
|
|
|
Hi all,
I wanted to cature the screen and I found it but:
The functions I used didn't capture the Mouse Icon!
What Can I do for this problem?
Please Help me,
Cheers,
Thanks,
MILAD.
Every new thing you learn,Gives you a new personality.
|
|
|
|
|
You could draw the mouse icon yourself by using GetCursorPos, DrawIcon and GetCursor functions. This will only work by attaching your app's thread to the thread that has the window under the cursor. You can do this by using the following functions: GetCursorPos, WindowFromPoint, GetWindowThreadProcessId, GetCurrentThreadId and AttachThreadInput. It's a little messy but it works.
|
|
|
|
|
Hi dSolariuM,
This is the way to capture the entire screen
HDC hScreenDC = CreateDC("DISPLAY", NULL, NULL, NULL);
HDC hCompatibleDC = CreateCompatibleDC(hScreenDC);
HBITMAP hScreenBitmap = CreateCompatibleBitmap(hScreenDC,
GetDeviceCaps(hScreenDC, HORZRES), GetDeviceCaps(hScreenDC, VERTRES));
HGDIOBJ hPrevObject = SelectObject(hCompatibleDC, hScreenBitmap);
BitBlt(hCompatibleDC,0,0,GetDeviceCaps(hScreenDC, HORZRES),
GetDeviceCaps(hScreenDC, VERTRES),hScreenDC,0,0,SRCCOPY);
OpenClipboard(GetActiveWindow());
EmptyClipboard();
SetClipboardData(CF_BITMAP,hScreenBitmap);
CloseClipboard();
This code snipet would copy the screen snap in the clipboard.
Hope this would solve your problem.
Have fun !
Cheers,
Vishal
|
|
|
|
|
Hi,
and thanks for your reply but:
The code gave to me deosn't show the Mouse Icon,
I want the Mouse Icon in the Captured file,
Cheers,
Thanks,
MILAD.
Every new thing you learn,Gives you a new personality.
|
|
|
|
|
I need a dialog that will query the user for a user name and password, and I'd like to use the microsoft dialog that appears when you try to access a computer that's on an untrusted domain. It's got a user name combo box\edit control, a password edit control, and a 'Remember my password' check box. Too bad I can't attach a screen shot...
Is that dialog an exported class (like CFileDialog), or is there a shell command that I can use?
I'm using Visual Studio.Net 2003, on Windows XP, programming in C++;
Thanks,
Aaron
|
|
|
|
|
Yes, the dialog resource is available in one of the main system DLLs. I've seen it before but can't remember which file it's in. Why not just make your own? It'll take all of five minutes.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I have a cancel dialog for an operation that takes a while. The problem is when, in the loop, I try to change a Static control's text on the cancel dialog, it doesn't seem to erase its background (if it's showing a long file name and then a short one, the end part of the long one is still showing). I found workarounds like calling InvalidateRect on the parent dialog, but it causes a lot of flickering... I'm using the following code to process messages while in the loop:
<code>
MSG msg;
while (PeekMessage((LPMSG) &msg, (HWND) NULL, 0, 0, PM_REMOVE))
{
if (!IsDialogMessage(m_hDlgWnd, (LPMSG) &msg))
{
TranslateMessage((LPMSG) &msg);
DispatchMessage((LPMSG) &msg);
}
}
</code>
Is there anything i'm missing?
(I'm not using MFC or anything)
- thanks
|
|
|
|
|
Why not invalidate the static control itself.
After setting the new text you want.
|
|
|
|
|
Blake V. Miller wrote:
Why not invalidate the static control itself.
that was one of the first things I tried - didn't work
|
|
|
|
|
How i can insert data into ListCtrl when i clicked on TreeCtrl item
it doesn't work true with me
plz help me
|
|
|
|
|