|
Hello, the codegurus around the world.;)
One possibility is that "return" in customerinfo() and in customerdisplay();
I think that "return" ends this program.
int main()
{
customerinfo();
cout << "After customerinfo() << endl;
customerdisplay();
cout << "After customerdisplay() << endl;
getch ();
return 0;
}
We can always put cout to find which lines is reached if we don't have the debugger.
But, I think that you use VC 6.0?
Last, I didn't check your code in detail, and basically, try to do your homework by yourself.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
You're gonna kick yourself....
The new function to write out the file looks like this:
void customerdisplay()
{
infile.open ("orders.txt");
while (!infile.fail())
{
infile >> order.phone_num >> order.name >> order.address >> order.city >> order.state >> order.zip >> order.credit_limit >> order.customer;
cout << order.phone_num << order.name << " " << order.address << " " << order.city << " "
<< order.state << " " << order.zip << " " << order.credit_limit << " "
<< order.customer << endl;
}
infile.close ();
return;
}
You were reading in the number BEFORE reading it for the first time, and again AFTER you read the whole schmeer at the end of a 'while' iteration. Some other points:
This only works if each input string has no spaces in it, otherwise it tries to seperate by spaces. A better way would be to read a line at a time and cut it up using you own token ( TAB maybe, \t ) and therefore maintain things like an address which will usually have 2 or three 'words' in it.
This also only works if the phone number is a number, not a string. If you're going to save as a number, it's best to make sure you've been given one.
Christian
The early bird may get the worm, but it's the second mouse that gets the cheese.
|
|
|
|
|
I've got a CListCtrl in a dialog that selects a row. The problem is that the selection disappears when I click on a another control in the dialog and the focus moves there. How can I make the CListCtrl continually show the selected row, without going to custom draw, etc?
Thanks.
Peter
|
|
|
|
|
modify the List Control to use LVS_EX_SHOWSELALWAYS, eg
void MyDialog::OnInitDialog ()
{
...
m_myList.SetExtendedStyle (m_myList.GetExtendedStyle() | LVS_EX_SHOWSELALWAYS);
...
}
hope this is what you need
nb
|
|
|
|
|
Thanks, that pointed me in the right direction. It doesn't quite work that way, so I need to do something like this:
CMyDialog:OnInitDialog...
CRect rcWin;
m_ListCtrl.GetWindowRect(&rcWin);
ScreenToClient(&rcWin);
DWORD nStyle = m_ListCtrl.GetStyle();
UINT nID = ::GetWindowLong(m_ListCtrl.m_hWnd,GWL_ID);
long nExStyle = m_ListCtrl.GetExtendedStyle();
m_ListCtrl.DestroyWindow();
m_ListCtrl.Create(nStyle | WS_BORDER | LVS_SHOWSELALWAYS, rcWin, this, nID);
m_ListCtrl.SetExtendedStyle(nExStyle | WS_EX_WINDOWEDGE);
Still haven't figured out how to get the standard 3-d border on the listcontrol. Tried all sorts of WS_ and WS_EX_ but it doesn't seem to go. May have to leave it that way.
Peter
|
|
|
|
|
Instead of re-creating the window, select the 'show selection always' option in the list control properties in dialog editor.
> Still haven't figured out how to get the standard 3-d border on
> the listcontrol. Tried all sorts of WS_ and WS_EX_ but
> it doesn't seem to go
Are you creating your list control programatically (CListCtrl::Create), or in dialog editor?
Tomasz Sowinski
http://www.shooltz.com.pl
|
|
|
|
|
Yes, that's exactly what I was looking for. Thanks!
Peter
|
|
|
|
|
Hi All!
Doing some work with SQL Server, getting out this horrendous datatype called DB_NUMERIC - Converting DB_NUMERIC to anything useful looks like a nightmare. It is a decimal value stored as an array of 16 bytes, + a sign, + a precision. I particularly need to convert it to a string ... can anybody help me???
Thankyou, and happy coding
NB
|
|
|
|
|
for anyone else in this situation:
I just solved the prob, you need to use IDataConvert ... look it up in MSDN
cheers
NB
|
|
|
|
|
Okay, so I have this multi-threaded app. It shows a dialog with a 'Start' button on it. You click start, it starts a thread. That thread in turn starts a user specified number of other threads that do actual work and block when they finish( See CThread::WaitForEnd() ).
The problem is, if I specify a large number of threads, some of them never end. i.e. Start 100 threads, wait until they stop (WM_TIMER sets a mutex protected BOOL), the debug window shows 0xNNNN exited etc. but locks up before they all exit (i.e. 80 will but the last 20 won't). Task manager says there are still threads open ( 10, 20, 30 etc. ). What on earth would cause this behaviour??? Can anyone help?
NB: I got it to do an unhandled exception on a call to WaitForSingleObject() in CThread::WaitForEnd(). I can't reproduce it however so I don't know if it has anything to do with the problem...
UINT CDlgBlah::ThreadProc()
{
CThread* arrThreads = new CThread[ dwThreadCount ];
hMutex = CreateMutex( NULL, FALSE, NULL );
for( DWORD dw = 0; dw < dwThreadCount; dw ++ )
{
arrThreads[ dw ].m_rnd = rand() % RAND_MAX;
arrThreads[ dw ].Begin()
}
for( dw = 0; dw < dwThreadCount; dw ++ )
arrThreads[ dw ].WaitForEnd(); // ##### Stops here
// ##### Never gets here
AfxGetMainWnd()->SendMessage( UWM_SHOWRESULTS ); // Update display (safe?)
return 0;
}
class CThread : public CObject
{
public:
CThread();
virtual ~CThread();
BOOL Begin( void );
void WaitForEnd( void );
void DoWork( void );
static UINT ThreadProc(LPVOID pObj);
int m_rnd;
private:
CWinThread* m_pThread;
}
BOOL CThread::Begin()
{
m_pThread = AfxBeginThread( ThreadProc, this );
return m_pThread != NULL;
}
UINT CThread::ThreadProc( LPVOID pObj )
{
CThread* pThread = (CThread*)pObj;
pThread->DoWork(); // Do some work
return 0;
}
void CThread::WaitForEnd()
{
WaitForSingleObject( m_pThread->m_hThread, INFINITE );
}
void CThread::DoWork()
{
srand( rnd );
while( StillWorking() ) // WaitForSingleObject in here etc.
Sleep( rand() % 250 )
}
|
|
|
|
|
When sending from threads, do not use SendMessage().
This can block. Use PostMessage(), this won't block.
If you want to ensure you don't wait too long when sending, use SendMessageTimeout().
I recommend PostMessage(), its what I use and I haven't had any problems.
Stephen Kellett
|
|
|
|
|
Hi, All!!
Who know: how could be established connection between your application and some of the Windows standart progs (like gettin' notification message when user has made double-click on some form fields in IExplorer, e.t.c) means that I know nothing about internal structure of the programm?
Thanks!
|
|
|
|
|
Read Programming Windows Applications by Jeffrey Richter
|
|
|
|
|
In my project, I declared a toolbar button structure TBBUTTON as
TBBUTTON button;
and loaded up some bitmap buttons dynamically into the toolbar by using toolBarCtrl.InsertButton( 0, &button ); in a for loop.
Then I set TBBUTTON's state and style as
button.fsState = TBSTATE_ENABLED;
button.fsStyle = TBSTYLE_BUTTON;
The problem now is that only 2 out of 10 buttons are being displayed on the toolbar. The rest of the buttons somehow got hidden in the bar.
By resize the window a little bit or toggle toolbar(show/hide), all the buttons get showed up. Obviously all the buttons are loaded up properly at run time but some buttons are just stay back invisible. If I drag and move the window around rather than tweaking the window size, those buttons are still hiding in the background.
Any thoughts what might caused this problem? Any suggestions on how to resolve that?
Thanks,
Allision
|
|
|
|
|
In my message map...
BEGIN_MESSAGE_MAP()
...
ON_WM_????
END_MESSAGE_MAP
what is the message used to tell a window to assert the OnRecieve method of a CAsyncSocket object.
|
|
|
|
|
Hello, the codegurus around the world.;)
You need the good book about Socket programming. But, the book about Socket sometimes
use the basic of WinSock, not CSocket or CAsyncSocket class.
I got this code from some Wrox book about MFC, but I forgot this titile.
Define the following the message map entry at CYourAsyncSocket class.
#ifndef WM_SOCKETEVENT
#error You must define 'WM_SOCKETEVENT' as a WM_USER message.
#endif
#ifndef ON_WM_SOCKETEVENT
#define ON_WM_SOCKETEVENT() \
{ WM_SOCKETEVENT, 0, 0, 0, AfxSig_vwwh, \
(AFX_PMSG)(AFX_PMSGW)(void (AFX_MSG_CALL CWnd::*)(UINT, UINT, SOCKET))OnSocketEvent },
#endif
Now, we can use this message function at some Dialog;
// some Dialog header file
afx_msg void OnSocketEvent(UINT nEvent, UINT nErroCode, SOCKET hSocket);
BEGIN_MESSAGE_MAP(CWinFingerDlg, CDialog)
................
ON_WM_SOCKETEVENT ()
END_MESSAGE_MAP()
...................
CMyDialog::OnSockeEvent (UINT nEvnet, UINT nErroCode, SOCKET hSocket)
{
}
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
do you know, how can create MFC application, where buttons will have same style as button "start" (button have icon and caption)
|
|
|
|
|
Yes, try my CButtonST class.
You can find it here: http://www.codeproject.com/buttonctrl/cbuttonst.asp
Let me know if it can help you, bye!
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://members.tripod.com/~SoftechSoftware/index.html
|
|
|
|
|
Thank you,
Can you tell me, how can I draw icon in all controls ?
LB
|
|
|
|
|
If the control supports owner-drawing so this is the way. Else you have to develop a custom control. Bye!
SoftechSoftware
Davide Calabro'
davide_calabro@yahoo.com
http://members.tripod.com/~SoftechSoftware/index.html
|
|
|
|
|
How do you create a 8 bit/pixel bitmap on the fly useing CBitmap? For example, suppose I just wanted a blue 1000x1000 pixel bitmap but did not want to create it as a resource. (System settings are 32 bits/Pixel) When I try this with CreateBitmap/BitBlt everything seems to succeed but I get only a black output. I can create an appropriate bitmap on the fly if I use the system settings (32bpp) but I would really like a smaller bitmap. I can also create and display a monochrome bitmap with the logic I have, so I know the DC, size and everything is correct. Is the issue that I am inheriting the system palette for the bmp but that I actually need to create my own palette with the appropriate colors? I other words, that the bit values do not refer to the appropriate colors in the palette? I have played around with creating a palette, but to no avail.
|
|
|
|
|
The problem is that you cannot select your bitmap into a DC to draw on it unless your system is running at 8BPP, because a CBitmap is a DDB. You probably want to look into DIBSections, which can be any bit depth and still loaded into any DC and drawn onto. Chris wrote a DIBSection wrapper which is on the site, or you can use paintlib ( which I use ) from www.paintlib.de
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
|
How to update one class's member variable from another class. I have a control bar on the left (CLeftDlg class) and working aarea on the right (CRightDlg). How to update m_strComment (member of CRightDlg) from CLeftDlg.
How to call a non-static member function CRightDlg::Refresh() from CLeftDlg.
Please HELP !!!!!!!
|
|
|
|
|
Your common thread is to call AfxGetMainWnd for SDI/MDI or AfxGetApp otherwise (don't forget to cast it to your specific class ), and then you can get whatever you want from there.
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|