|
Josh Gray wrote: I'd try changing "\n" to std::endl
This is not related to the OP, but I think there is a tendency to overuse std::endl, I suspect that somehow people think it is more C++ish. The big difference is that std::endl, as well as outputting a new line character, flushes the stream's buffer. For a few random output lines this doesn't matter, but for writing normal files use '\n' and let the stream's buffer do what it is supposed to do. The exception is when you use file-based debugging - here endl is essential as it ensures that in the case of a crash the last line of the file is actually written to disk.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
cp9876 wrote: This is not related to the OP, but I think there is a tendency to overuse std::endl, I suspect that somehow people think it is more C++ish. The big difference is that std::endl, as well as outputting a new line character, flushes the stream's buffer. For a few random output lines this doesn't matter, but for writing normal files use '\n' and let the stream's buffer do what it is supposed to do. The exception is when you use file-based debugging - here endl is essential as it ensures that in the case of a crash the last line of the file is actually written to disk.
Thanks I didnt know that. I always thought the advantage was that it would put the correct line ending for the platform you are running on.
|
|
|
|
|
I am having a more-than-momentary lapse of reason... I want to use the PostMessage( ) function to pass a window handle (CWnd) from one app to another.
In the caller, i have something like this:
CWnd hWnd;
static CWnd *pWnd;
pWnd = FindWindow("RecvApp",0);
pWnd->PostMessage(WM_CONNECT_APP, hWnd, 1);
In the receiver application ("RecvApp"):
CWnd *pWnd_Caller;
ON_MESSAGE(WM_CONNECT_APP, OnMakeConnection)
LRESULT CMainFrame::OnMakeConnect(WPARAM wParam, LPARAM lParam)
{
if (lParam == 1)
m_View->PostMessage(WM_CONNECT_APP, wParam, lParam);
}
wParam->PostMessage(WM_ADD_ENTITY, 0, 0);
I want to use the window handle of the caller to post a message back to itself based upon parameters gathered in the receiver app...
(caller) PostMessage (to receiver)
(receiver) assign values, do its stuff...
(receiver) PostMessage (to caller - new values)
In short, I need to know how to pass and use/dereference (etc...) the CWnd handle I am passing around.
Thanks.
Johnny
|
|
|
|
|
You can't pass a CWnd object or a pointer to one. You can pass the HWND that is wrapped by the CWnd
object though.
To obtain the HWND from a CWnd you can use
The HWND cast operator
HWND hWnd = (HWND)MyCWnd;
Use CWd::GetSafeHwnd()
HWND hWnd = pMyCWnd->GetSafeHwnd();
On the receiving end, to get a CWnd from an HWND you can
Create a temporary CWnd object using CWnd::FromHandle()
CWnd *pCWnd = CWnd::FromHandle(hWnd);
For an object that needs to persist, use CWnd::Attach()
pCWnd = new CWnd(); <br />
pCWnd->Attach(hWnd);
Cast an HWND to (WPARAM) or (LPARAM) when passing with PostMessage().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
john john mackey wrote: wParam->PostMessage(WM_ADD_ENTITY, 0, 0);
instead of CWnd* send actual HWND by using CWnd::GetSafeHwnd() method and on Receieving end using CWnd::Attach attach that Hwnd to CWnd Pointer!
sending CWnd* is creating problem because the Pointer Address can't be accesible two application!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief
|
|
|
|
|
Hi all, quick question. I dont know how to save to a buffer in C++ only in C with sprintf().
Can anyone tell me how to print to a buf with C++? Thanx in advance!
|
|
|
|
|
dellthinker wrote: I dont know how to save to a buffer in C++
dellthinker wrote: tell me how to print to a buf with C++
Save...print... what to what kind of buffer?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
dellthinker wrote: Hi all, quick question. I dont know how to save to a buffer in C++ only in C with sprintf().
sprintf also available in c++ too. are talking abt std::string class
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief
|
|
|
|
|
|
Hello,
I am storing a card number 9999999999 in the database as hexa format 0x09090909090909090909,
i have to send it to the controller in a pack of 5 binary (in hexa Format), meaning 0x02540BE3FF
any sample code appreciated.
With Rgds,
Anil
|
|
|
|
|
__int64 llValue = _tstoi64(_T("9999999999"));
Send low-order 5 bytes of llValue
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Wait, I missed half of this earlier...
AnilUnni wrote: I am storing a card number 9999999999 in the database as hexa format 0x09090909090909090909
Wouldn't ASCII have been easier?
I guess you need to convert those "hexa format" (why the "0x"??) digits to ascii then convert to binary.
Is this homework?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hi -
I've been working on a large multi-threaded VC++ 6.0/MFC application for some years and use ODBC as the main database service provider to a backend database in SQL Server 2000.
For one client's application, though, we notice that the ODBC connection disappears from time to time (their database generally resides on a different machine) and the application crashes when it makes a database request over a handle that's gone bad. As the application has recently started transporting real money, this is unacceptable and I need to know the answers to two questions:
1. Is it possible for the ODBC driver to alert me when it determines that a connection has died, rather than leaving me find out the hard way? The application is idle perhaps 98% of the time and a temporary outage caused by a resurrect-on-connection-death is going to affect the performance far less than a system crash.
2. If there is no answer to (1), is there an alternative to ODBC that will give me this functionality - either something (a) that is stateless and which will allow me to query, read and write the database without requiring handles or (b) or which has a fast connect, so that I can make a connection every time that I need to do something or (c) something that doesn't crash when the connection is lost? You can assume that I'm going to continue using VC++ 6.0/MFC for the foreseeable future.
thanks folks,
- robin.
|
|
|
|
|
1) I don't think so, i don't recall any callback functionality, nor do i believe the connection is 'live', i think it is like (is?) a TCP/IP connection.
2)
a)
i)Rewrite the app as a client-server system that can handle caching data while the server is offline.
ii) See if any of the SQL server replication (pub-sub) services can help you.
b) You say that a reconnect would be acceptable, in that case i would suggest turning on connection pooling and reconnecting each time. If there are a lot of requests in a short period then a connect request will receive an existing connection from the pool (fast), if not then a full connect will happen (slower).
c) Why not test the connection before you use it ? If bad reconnect. There shouldn't be any reason for the app to crash.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
cmk wrote: c) Why not test the connection before you use it ? If bad reconnect. There shouldn't be any reason for the app to crash.
I've done this in another module for this application, but it's unreliable because (AFAIR) the code which checks if the database handle is alive (it does a "SELECT GETDATE()") generally crashes if the HDBC is dead. Doesn't do it all the time, which is why I've written it this way. Catching 25% of problems is better than catching none at all.
I might try the connection pooling method and see how I get on with that. It's certainly goin to give better results than I've been getting to date.
Thanks for your help
|
|
|
|
|
Hi
I need to subclass Command Prompt window but CP window's WndProc is Zero , therefore i can not call DefWndProc
I do subclassing window using global hook
Thanks for your ideas
|
|
|
|
|
There is no windows message loop for command prompt applications, so no message queue and no routing of messages to a WndProc.
You could use a hidden window though.
What are you trying to do ?
|
|
|
|
|
I mean window of CMD.exe , i think CMD.exe is a window application , it has window handle , window class , ... , an program can use most of window related functions with Command Prompt window
I use global hook to subclass all top-level windows , in their subclassed WndProc i will send useful messages to main program written in .NET , main program will do something such as : adding title button + system menu , managing window . Would you like to try it ?
|
|
|
|
|
In a new MFC application, I obtain positional data from an eternal source, but would like to generate a Google Earth type image with this data. Perhaps updated a few times per second.
I have looked at Global Majic ActiveX controls (Digital Map), but are they any others that are out there?
I did think of Microsoft's Flight Simulator, it that an option?
Many thanks,
Andy.
|
|
|
|
|
Hi,
Is there any built in separator control in MFC?
Best Regards,
Mushq
Mushtaque Ahmed Nizamani
Software Engineer
Ultimus Pakistan
"English is my second language; please excuse any grammatical or spelling mistakes"
|
|
|
|
|
pDC->MoveTo (100,0);
pDC->LineTo (100,100);
will draw a line, separating two parts of a DC....?
I feel fairly sure that's not what you are after though. Can you explain your question differently?
If it's for putting a line in a dialog box, I just use a static control, with the sunken flag, and make its width (or height) equal to zero.
Iain.
|
|
|
|
|
Iain thanks for reply, i want this sort of separator in some of my dialogs.
http://i9.tinypic.com/5ytbbsj.jpg[^]
Best Regards,
Mushq
Mushtaque Ahmed Nizamani
Software Engineer
Ultimus Pakistan
"English is my second language; please excuse any grammatical or spelling mistakes"
|
|
|
|
|
Use Spy++ to find out what sort of control that is. I'd hazard a guess that it's a static control, one DLU in height.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
That is the method I described in my previous post. Use the dialog editor, and put a box on your dialog (static control).
Drag it to the width you want, and sent the style to sunken.
Move the top to the position you want, then drag the bottom up. Voila - 1 reeeeeally thin box = line / separator.
Iain.
|
|
|
|
|