|
Erik wrote: That means I use Findwindow when I start my program...
You should be using a mutex instead. FindWindow() could potentially cause a deadlock situation.
Erik wrote: Instead, I should post some kind of message telling the running instance that I want to open a file instad, this is what I haven't figured out yet.
Are you referring to PostMessage() ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I had a similar problem. I searched CP for "single instance", and the first article that came up was:
Limiting an application to a single Instance - the MFC way[^]
I fixed a small (but pretty nasty) buf in the demo program, and all is good. Read the article, and some of the comments for more information.
Good luck,
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
We are having Host application which sends file data streams 64 bytes at a time continuously to target through TCP/Ip connection. while sending data if LAN cable is disconnected Target is executing recv(). it is not blocking at recv(). is there any means of getting connection status before executing recv()?
|
|
|
|
|
nvshree87 wrote: is there any means of getting connection status before executing recv()?
What is wrong with calling recv() and evaluating a possible error code with WSAGetLastError() ? There are for example WSAECONNABORTED and WSAECONNRESET to signal an interrupted TCP stream.
/M
|
|
|
|
|
Hi All,
I Tried to change the default icon in MFC by going to the toolbox and editing it and i built the solution.
When i run the application there is no change happening...
I tried searching in the internet .... but i am not able to find anything
So somebody pls tellme howto do it...
Regards,
Hari
|
|
|
|
|
try Resource Files folder ..in your project directory ..its possible to change it
|
|
|
|
|
Can u please be a bit more detailed ...
I opened the directory and the resources folder and CLicked on the icon which says MFC and changed it and built it again ...
But no Luck... it still not working
|
|
|
|
|
You should change the proper image type icon (The application bar shows the 16x16 one).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hey ,
There are 3 16x16 which one should i change!!!
Thanks to Both For the Quick reply
|
|
|
|
|
You should actually change all the images of the icon.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
When we lauch the dialog it actually shows a 32x32 (16 colors) i changed that and it works ...
Thanks,
Hari
|
|
|
|
|
Hi All,
Can anybody give me an example to get the drives of a client pc from a server pc using NetServerDiskEnum.Please specify the first argument i.e LPWSTR servername.
Thanks,
Abinash Mohanty
|
|
|
|
|
Abinash Mohanty wrote: Can anybody give me an example to get the drives of a client pc from a server pc using NetServerDiskEnum.
Was this[^] impossible to find?
|
|
|
|
|
Thanks for your reply.But if I run this example on my pc it retrieves the drives of my pc.Suppose I want to retreive the drives of a pc having name for eg. abc which is connected through LAN to my pc. Please tell me the first parameter of NetServerDiskEnum .
Regards,
Abinash
|
|
|
|
|
Abinash Mohanty wrote: Please tell me the first parameter of NetServerDiskEnum .
Did you read the documentation on the link I gave you?
|
|
|
|
|
|
I am new to multithreading and my application doesnot compile. It is a Dialog Based Applicationin MFC with only one ButtonCtrl
Here's the code
UINT ThreadFunc(LPVOID pParam)
{
MessageBox("Thread Started");
return 0;
}
void CAppDlg::OnButtonClkRunThread()
{
AfxBeginThread(ThreadFunc, this);
}
Where am I going wrong?
Manmohan Bishnoi
|
|
|
|
|
Usually compiler errors are pretty informative, so have a look at it.
I guess the error occurs in
Manmohan29 wrote: MessageBox("Thread Started");
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
try this ...
UINT ThreadFunc (LPVOID lpParam)
{
::MessageBox(0,L"Thread Started",L"",1);
return 0;
}
void CAppDlg::OnButtonClkRunThread()
{
::AfxBeginThread (ThreadFunc,this);
}
|
|
|
|
|
Manmohan29 wrote: doesnot compile
And what does the compiler say? Be specific.
To add to it,
Manmohan29 wrote: UINT ThreadFunc(LPVOID pParam)
{
MessageBox("Thread Started"); //----> BAD idea!
return 0;
}
void CAppDlg::OnButtonClkRunThread()
{
AfxBeginThread(ThreadFunc, this);
}
Because if your main thread becomes busy into something, the newly spawned thread as well would block for displaying the message. This is because you are using a function (MessageBox from MFC) that would make use of the default message pump of your application.
In other words, if you add a Sleep(3000); after AfxBeginThread, the message from your thread would probably be displayed after this sleep period only!
I see you're just starting to learn, but threading has such "gotchas", that you'll learn along the way. Lesson learned today: It isn't a great idea to use something within a worker thread, that may in turn use the default message pump of the application (in a blocking fashion).
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
NEW CODE :-
UINT CThreadDlg::ThreadFunc(LPVOID pParam)
{
return 0;
}
void CThreadDlg::OnBnClickedBthread()
{
// TODO: Add your control notification handler code here
AfxBeginThread(ThreadFunc, this);
}
ERROR :-
------ Build started: Project: Thread, Configuration: Debug Win32 ------
Compiling...
ThreadDlg.cpp
d:\manmohan\visual c++\thread\thread\threaddlg.cpp(162) : error C3867: 'CThreadDlg::ThreadFunc': function call missing argument list; use '&CThreadDlg::ThreadFunc' to create a pointer to member
Build log was saved at "file://d:\Manmohan\Visual C++\Thread\Thread\Debug\BuildLog.htm"
Thread - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Manmohan Bishnoi
|
|
|
|
|
Manmohan29 wrote: UINT CThreadDlg::ThreadFunc(LPVOID pParam) //---> Here is the problem!
{
return 0;
}
void CThreadDlg::OnBnClickedBthread()
{
// TODO: Add your control notification handler code here
AfxBeginThread(ThreadFunc, this);
}
The thread function should be a global function (not a member function of any class), or it must be a static member function of any class. Try this instead:
in your header file:
static UINT CThreadDlg::ThreadFunc(LPVOID pParam);
in the source file:
UINT CThreadDlg::ThreadFunc(LPVOID pParam){
OutputDebugString(_T("*********** Entered thread function ***********\n"));
return false;
}
Watch the output window of your debugger to see the text printed from your thread.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Manmohan29 wrote:
UINT CThreadDlg::ThreadFunc(LPVOID pParam)
This member has to be declared as 'static'.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
My previous answer to you is updated after you edited your post to include the code. Check it.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Thanks, It works great.
Manmohan Bishnoi
|
|
|
|