|
Marwan wrote:
Stock& myStocks[i] = st;
You're assigning to an element of the array, right? Take out the Stock& because you're not declaring a new variable.
--Mike--
"Everyone has figured out what 'service pack' really means, so they had to go and change the language. Perhaps this is what Bill was talking about in the 'security is top priority' letter."
-- Daniel Ferguson, 1/31/2002
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
void Stocks:: addStock( Stock* st, int i)
{
i = numOfStocks;
Stock& myStocks[i] = st;
}
You reassign a value from an input parameter?
|
|
|
|
|
I've got a file browsing list control inside a custom Outlook Control. The problem is that when I remove all the items in the list control and fill them with a new list (as in the user selects a different folder to browse), a bunch of blank space gets left at the top. Below is a screenshot:
(dunno why this image doesn't want to display)
This seems about the same amount of space as the scroll offset before the list items were updated. I've tried a calling a bunch of functions to see if I can get rid of this, but can't. (The attemps are shown below under the //!!! part.
void
cPkpPhotoListControl::OnRightClick(NMHDR* pNMHDR, LRESULT* pResult)
{
cResId PopupMenuResId = GetPopupMenuResId();
//!!!
CListCtrl::SetWorkAreas(0, NULL);
CListCtrl::Arrange(LVA_ALIGNTOP | LVA_ALIGNLEFT);
CListCtrl::SetWorkAreas(0, NULL);
SetScrollPos(SB_VERT, 0);
if(!PopupMenuResId.IsVoid())
{
cPoint ScreenPoint;
GetCursorPos(&ScreenPoint);
//!!!!
cPoint sss = ScreenPoint;
ScreenToClient(&sss);
cWindowHelper Helper(this);
Helper.HandlePopupMenu(PopupMenuResId, ScreenPoint);
}
*pResult = 0;
}
Now I've hooked this into the right mouse click handler so I they are called whenever I hit the right mouse button (just for debugging).
I've also tried clicking the top of this space, and that point comes out as near 0 in client coordinates, so I know that white space is part of the list control. I can also drag a selection box in this white space.
Anyone have any ideas? Any other commands I can try?
Cheers,
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
Such a thing as a class prototype? Im sure there is... I need to know how to use it since I have a class that needs to derive an object from another class and use it but the other class is defined after it and if i define it before it I will hit the same problem with its class.
-- Remember your are but a lowly hair on my s*r*t*m
|
|
|
|
|
For example, the class prototype for CString would be:
class CString;
But you can only use pointers and references to a prototyped class if it's not defined yet (just declared with the prototype). So you'll have to create instances of it off the heap with the new operator, and store data members as pointers.
cheers,
swinefeaster
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
And make sure you don't use the old C casting operation on pointers prior to the class being defined. That will cause nasty problems. If you use static_cast, it will error if the class hasn't been defined.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
new CString;
my_val = CString.whatever(); ?
-- Remember your are but a lowly hair on my s*r*t*m
|
|
|
|
|
That doesn't make any sense.
in the header file (for example):
class CString;
class CStringUser
{
public:
CStringUser(void);
private:
CString* m_Member;
};
In the cpp file:
#include "StdAfx.h"
#include "CString.h"
CStringUser::CStringUser(void)
{
m_Member = new CString;
}
...but of course that's assuming "CString" is the class you want to forward declare.
Cheers,
swinefeaster
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
Hi,
I have some data in my app which is manipulated by the user which should automagically be saved upon exit, in order to be available when launching the app next time.
The amount of data is too big for storing them in the registry so I thought they could be serialized to a file.
But I want to do it without prompting the user for a filename.
Any ideas how I could achieve this?
Thanks.
Pepe
|
|
|
|
|
You could save it in the user's settings folder. For example, "c:\Documents and Settings\Matus\Application Data". But you should use the windows functions to make sure you are retrieving the right folders. I think its SHGetSpecialFolderLocation() or SHGetSpecialFolderPath().
Cheers,
swinefeaster
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
yeah, but AFAIAC the Serialize function is called by the system when the user clickes save or open in the file menu.
How can I trigger the above call without any user interaction, and how can I give the location without having to deal with CFileDialog?
Thanks
Pepe
|
|
|
|
|
Basically, CArchive just uses a CFile object as its internal file access class. The Serialize function for your object is passed a CArchive automatically by the framework, but you can do it manually also.
----------------------------------------
to serialize your data to disk:
----------------------------------------
CFile fp;
fp.Open(somefilename,CFile::modeWrite | CFile::modeCreate | CFile::shareExclusive);
CArchive ar(&fp, CArchive::store);
obj.Serialize(ar);
ar.Close();
fp.Close();
----------------------------------------
to load data from disk
----------------------------------------
CFile fp;
fp.Open(somefilename,CFile::modeRead | CFile::shareExclusive);
CArchive ar(&fp, CArchive::load);
obj.Serialize(ar);
ar.Close();
fp.Close();
----------------------------------
to automatically determine a file name
----------------------------------
Often, what I do is to save the file in the same path as the EXE, but I use the users computer name and user-name as the file name. If I want the user to be able to log in from different computers, I just use their user name.
char szAppPath[2000];
char szDrive[200];
char szDir[200];
char szComputer[2000];
char szUser[2000];
DWORD dwTempSize = 0;
CString strFileName;
memset(szAppPath, 0, 2000);
memset(szDrive, 0, 200);
memset(szDir, 0, 200);
memset(szComputer, 0, 2000);
memset(szUser, 0, 2000);
::GetModuleFileName(AfxGetInstanceHandle(), szAppPath);
_splitpath(szAppPath, szDrive, szDir, NULL, NULL);
dwTempSize = 2000;
::GetUserName(szUser, &dwTempSize);
dwTempSize = 2000;
::GetComputerName(szComputer, &dwTempSize);
strFileName = szDrive;
strFileName += szDir;
strFileName += szComputer;
strFileName += "-";
strFileName += szUser;
strFileName += ".dat";
---------------------------------------
PS. I wrote the above code from memory so there might be some typos, etc.
Matt Gullett
|
|
|
|
|
I need to allow users to run more than one instance of my app. Unfortunately I have to use Netbios functions. I have found that my app locks up the entire machine if one instance is deleting the name from the name table at the same time the other one resetting the lanas or adding the name. So I thought I could use a mutex to have the second one wait if the first one is deleting the name. Unfortunately it doesn't seem to work. Here is the code:
CMutex mutex(TRUE, "application name - Stopping or starting network stuff");
CSingleLock lock(&mutex);
lock.Lock();
The first one exectutes this and has not exited the function (so the mutex has not been deleted) when the second one executes this. The second one does not wait.
What am I doing wrong?
Cathy
Life's uncertain, have dessert first!
|
|
|
|
|
Are you checking the return state of the Lock ?
You might want to have a look at the MUTEXES sample app from MSDN to see how to use CMutex correctly.
|
|
|
|
|
Thanks. I will look at the return value to see if it failed and look at the MSDN sample. The documentation sounded pretty straitforward. I read someone's comments somewhere saying the first version of MFC's critical section class was buggy. So I thought maybe this one is too. So I was hoping to hear from someone who had used it before and could tell me whether or not it worked.
Cathy
Life's uncertain, have dessert first!
|
|
|
|
|
Actually, my first attempts with it were not successful so I just wrote my own little thing using the Win32 mutex functions. They seemed a bit more straight forward to me. The API functions used are CreateMutex, WaitForSingleObject, ReleaseMutex, and CloseHandle. They are invoked in that order.
My jokes page
|
|
|
|
|
Thanks. I will use that instead.
Cathy
Life's uncertain, have dessert first!
|
|
|
|
|
This is one of the strangest things i've seen happen. For some reason my arrays of chars seem to be holding random data that appears out of nowhere time and again..I can't explain it.
for example:
char buff[10];
char obuff[20];
memset(buff, '\0', 10);
memset(obugg, '\0', 20);
mysock.recv(buff, 10);
memcpy(obuff, buff, 10);
What does it all mean?
Stephen Caldwell
Blackfission, CEO
http://blackfission.myip.org:81
|
|
|
|
|
Have you checked if recv() succeeds? I'm not sure what class type your mysock object is, but you should probably be checking a return value. Also, break at the mysock.recv and make sure you arrays are being initialized to 0.
Are you sure your recv isn't succeeding? Just that that's the data you are getting from the socket?
cheers,
swinefeaster
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
I'm not really sure, but I think it's because you've not reserved any bytes for the null-terminator. If you create 'buff' with a size of 11 bytes (and memset all 11 bytes to zero too), I think it will all work out just fine :]
Sprudling
|
|
|
|
|
Sprudling wrote:
I'm not really sure, but I think it's because you've not reserved any bytes for the null-terminator
That was the problem, thanks Sprudling.
Stephen Caldwell
Blackfission, CEO
http://blackfission.myip.org:81
|
|
|
|
|
Sprudling is close to being right.
C/C++ uses NULL terminated strings. So when you look at a character array in the debugger or printing, if the NULL isn't there, then trash at the end of the string will be displayed.
Like Sprudling said, if you want to use the read data as a C/C++ string, then you need to add an 11th byte and then terminate it. For example:
char buff [11];
char obuff [21];
int n = mysock.recv(buff,10);
buff [n] = 0;
strcpy (obuff,buff);
No if you aren't using the data as real strings, then the NULL isn't at all required and the extra trash is just an annoyance caused by the debugger trying to display the data as a string.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Is there a good way to get the contents of another window?
i.e. Get the handle and BitBlt the contents into a buffer?
Anyhow, we do this, but are looking for more reliable ways to do this.
Specifically, here are some requirements:
1) The "window" is part of another app (any app window)
2) App window may not always be the top window or even completely on-screen.
When the window moves away from being the top window, we start losing part of it's contents due the the clipping regions from other windows or the screen edge....
any clues out there?
Thanks in advance.
|
|
|
|
|
Try giving the window in question focus, then BitBlt.
If it is off the screen get the screen dimension, the x,y, the height and width of the window and check if the window extends beyond the screen then move it and BitBlt.
Stephen Caldwell
Blackfission, CEO
http://blackfission.myip.org:81
|
|
|
|
|
I want to create one function that will be called when ever 1 of 5 static box's are clicked. I also want the ID of which ever static box was clicked to be sent over to that function. I think this would clean up my code instead of having 5 functions, 1 for each static box, that do basically the same thing. I think i have to use a WM_COMMAND thing but i dont really know how to do use it to get the desired effect. Should i just stick with five separate functions or can this be done fairly eaisly?
-Raffi
The truth about C++
|
|
|
|