|
An array variable is basically just a pointer to a block of memory. In other words, it's already a pointer, so you can just return it:
return pArray;
Just make sure that your pArray variable is a member of your class, so that it hangs around longer than the scope of the function that returns it.
class A
{
private:
CString array[10];
...
public:
CString* GetArray()
{
return array;
}
};
void foo()
{
A a;
CString* array = a.GetArray();
CString strCopyOfFirstElement = array[0];
CString& strLastElement = array[9];
}
Regards,
Alvaro
If you want to get to the top, prepare to kiss a lot of bottom. -- despair.com
|
|
|
|
|
Alvaro
Thanks for the help. Your suggestion worked. I'm still a little confused on pointers and excatly how they work. I guess what you are saying is that since its already a pointer all I have to do is pass it and nothing special just view it as an array from my calling function.
One other question. Do I need to destroy that pointer after I pass it, to release that memory?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Alvaro
Thanks. Your suggestion worked. One other question do I need to delete that pointer? So that is doesn't take up memory?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
This topic is often the subject of much debate. Some folks claim that if your application is intended to run for days/weeks/etc (e.g., service), it needs to be as clean as possible so that a "slow" memory leak does not eventually turn into a big problem. If, on the other hand, your application is only used a few times, and only exists for a few minutes when it is used, a memory leak here and there is harmless as the OS will return to the memory manager any memory owned by your application once your application terminates.
My take on the subject is it's always nice to clean up dynamically allocated memory, regardless of whether the OS cleans up behind you or not.
|
|
|
|
|
Tom Wright wrote:
CString pArray[10];
...
..
return * pArray;
Is this right?
if you did this in one of ur member function, then it is quite nonsense.
just keep the array as global/member variable or use the pointer (allocate the number as u like) and then retun the address...
regards,
CodeTheDreams();
|
|
|
|
|
I would like to import, display and print PDF or postscript documents (whichever would be easier) as a background for my forms. Is there a decent C++ library out there?
Regards,
BB
|
|
|
|
|
|
Hey Friends
Can someone suggest how to Get Pointer to Main Menu in case of MDI Application.
I am Using Code Like this
CMenu *pMenu;
CFrameWnd *pFrame;
pFrame = (CFrameWnd *)(::AfxGetApp()->m_pMainWnd);
pFrame = pFrame->GetActiveFrame();
pMenu = pFrame->GetMenu();
The above code dose'nt works when Caled from a PropertyPage(ie pMenu is NULL)
Pl Help.
|
|
|
|
|
Anonymous wrote:
pFrame = pFrame->GetActiveFrame();
Remove this line and it should work. In a MDI app this returns the active child frame, which doesn't own the menu.
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
Hi, I wrote a dll to retrieve data from a table of a web page. That works fine. But there are also tables protected by some Javescript code. The scriptcode get's the login/password and makes a "document.login_form.submit()". How could I emulate this behavior within my dll. To give GetHttpConnection() the login/password parameter doesn't work, because the page isn't direct protected. There shouldn't be any interaction. Thanx, Norbert
Norbert Behrens, Gruenheider Weg 36, 12589 Berlin, Germany
|
|
|
|
|
Hi
I've made a clistctrl + subclassed it to add more functions.
My list-view looks like this:
Employee Nr Name Age School
1 MyStupidName 15 SKL(BUTTON)
..
All fields are not editable + added some extended styles (gridlines, full row select).
If you click on the button, a dialog should appear with another listcontrol displaying all schools. After selecting a school + pressing ok, the name of the school should appear before the button.
The form is already made with all schools in the list, and when you press ok, it returns the name of the school. So that part is ok.
But how do i insert such a button into a listcontrol at the correct place of every line?
Hope someone knows how to get this done.
Just edited:
and i use VC5
Greetings
Jens
|
|
|
|
|
You may have to resort to owner-drawing the cell in question.
|
|
|
|
|
if you don't want to ownerdraw...
take a look here in CP about a recent article on how to create more than one button dinamically.
Moreover there's another article here or in codeguru (I don't remember very well) about editing a listctrl and the author creates a combobox inside a cell... (you could create dynamically some buttons inside the desired cells...)
Hope this helps...
NOTE:
if you ownerdraw, or if you do this other solution, derive a CListCtrl and place the code there, you'll be able to reuse tha class wherever you want to.
|
|
|
|
|
I have a CSpinButton control buddied to a CEdit, and that is fine for changing a numeric value.
The problem is that I want an even which occurs and will generate an action.
I have tried UDN_DELTAPOS, but this shows the value of the CSpinButtonCtrl before it is changed by the up/down event.
Also, when I try accessing the value of the text in the CEdit box, I get an exception.
Any ideas ?
Thanks.
Elaine
The tigress is here
|
|
|
|
|
Trollslayer wrote:
The problem is that I want an even which occurs and will generate an action
What do you mean ?
Trollslayer wrote:
Also, when I try accessing the value of the text in the CEdit box, I get an exception.
Easiest way to fix that will be to post your code.
~RaGE();
|
|
|
|
|
Hi,
I'm creating an MDI App containing non rectangular dialog.
It seems to work well because I can see my bitmap and the region seems to be well defined. My problem is that the removed part of my dialog is supposed to allow me to see my app background. Unstead, I see my desktop. Also, when I'm resizing, the removed part of my dialog dont refresh.
I have redefined OnPaint() and OnCreate(), OnEraseBkGround()
int BitmapDlgBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialogBar::OnCreate(lpCreateStruct) == -1)
return -1;
// Load the image
m_hBmp = (HBITMAP)LoadImage(GetModuleHandle(NULL), "C:\\Bitmap.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if(m_hBmp == NULL)
{
AfxMessageBox(_T("Error opening the Bitmap!"));
return 0;
}
// create a compatible device context
// for the bitmap. we will use this
// DC when painting the image onto
// the background of the window.
//CDC* dc = GetDC();
//m_hBitmapDC = CreateCompatibleDC( dc->m_hDC );
//ReleaseDC( dc );
//m_hOrigBmp = (HBITMAP)SelectObject( m_hBitmapDC, m_hBmp );
HDC dc = ::GetWindowDC(this->m_hWnd);
m_hBitmapDC = ::CreateCompatibleDC( dc );
::ReleaseDC(this->m_hWnd, dc);
m_hOrigBmp = (HBITMAP)SelectObject( m_hBitmapDC, m_hBmp );
// convert image to region. assume a magenta transparency color.
m_imageWidth = 0;
m_imageHeight = 0;
WindowRegion rgn;
HRGN hBmpRgn = rgn.CreateRegionFromImage( m_hBmp, RGB(255,0,255), m_imageHeight, m_imageWidth );
m_imageWidth = rgn.m_dwWidth;
m_imageHeight = rgn.m_dwHeight;
// resize the window with its height/width based on that of the bitmap.
SetWindowPos( NULL, 0, 0, rgn.m_dwWidth, rgn.m_dwHeight, SWP_NOZORDER | SWP_NOMOVE );
// finally, ask Windows to force the
// window to take on the shape of the
// region.
// note: the System owns the region
// after this call so there is no need
// to release it manually.
SetWindowRgn( hBmpRgn, FALSE );
return 0;
}
void BitmapDlgBar::OnPaint()
{
if ( GetUpdateRect(NULL,FALSE) )
{
PAINTSTRUCT ps;
ZeroMemory(&ps,sizeof(ps));
CDC* dc = BeginPaint(&ps);
BitBlt( dc->m_hDC, 0, 0, m_imageWidth,
m_imageHeight,
m_hBitmapDC,
0, 0, SRCCOPY);
EndPaint(&ps);
}
}
Any Ideas?
Regards
Everything's beautiful if you look at it long enough...
|
|
|
|
|
Create a function that does the specialized drawing you do in OnCreate(). Call that same function in OnPaint().
Kuphryn
|
|
|
|
|
Hi,
Thanks for the reply,
I'm not sure of what your telling me...Can you explains a bit?
Thanks
Everything's beautiful if you look at it long enough...
|
|
|
|
|
Hi,
I am posting again due to no one replied before to my post.
I have created a very simple activeX using VC++. When I add the ocx file to a web page, using microsoft activeX control pad, I can edit the properties I have created and send values to them, but if I want to send values using the <param /> tag, so the values will be send when the page is loaded, then nothing happend.
Can anyone please help?
"Learn from the mistakes of others.
You can't live long enough to make them all yourself."
"Failure doesn't mean I'm a failure, It does mean I have not yet succeeded;
Failure doesn't mean that I should give up, It does mean that I should try harder;
Failure doesn't mean that I will never make it, It does mean that I need more practice".
Thank you for helping.
|
|
|
|
|
Hi
I have this project that I'm working on. It's a SDI with a CFormView an it contains a Tabctrl which again contains a dialog for each tab. Every dialog, which is created dynamically, contains some dynamic buttons an other controls!
So my question is how do I create the messages for the controls to react on?
I dont know if my question is clear enough but ask if there is any doubt.
Thanks in advance!
Frank
|
|
|
|
|
Maybe this link[^] can be a beggining to answer your question.
~RaGE();
|
|
|
|
|
How do I dismiss a popup menu tracked on a tray icon after my callback has created the menu?
Inside the client it's easy:
GetMenu()->TrackPopupMenu(
uFlag,
ipMouse.x,
ipMouse.y,
this);
But it does not work for the tray!!!
This does not work either:
HWND hWndTB = ::FindWindow("Shell_TrayWnd", NULL);
::TrackPopupMenu(
GetMenu()->GetSafeHmenu(),
uFlag,
ipMouse.x,
ipMouse.y,
0,
hWndTB,
NULL);
???
Must be something like killing the menu modal loop I guess.
Regards Michael Mogensen /dk.
Regards Michael Mogensen /dk.
|
|
|
|
|
Try setting the forground window to the window of your app, showing the menu and then posting a null message to your window...
pWnd->SetForegroundWindow();
pMenu->TrackPopupMenu( ... );
pWnd->PostMessage( WM_NULL );
There are 10 kinds of people - those that get binary and those that don't.
|
|
|
|
|
THANX'! It worked - perfect!
Michael Mogensen.
|
|
|
|
|
Hello,
how can i embbed a dialog in a my mainframe window?
Thanks, Mark
|
|
|
|
|