|
The problem is in either how you are creating the CWinThread, or
where in the CWinThread-derived class you are creating the CAsyncSocket.
The CWinThread MUSt be a UI thread - that means you need to create it
using the AfxBeginThread() that takes a CRuntimeClass as an argument or
if you use the CWinThread constructor/CreateThread() method, you must pass a NULL
thread proc pointer to the CWinThread constructor.
Once that's ok, you should be able to create your CAsyncSocket in the
CWinThread-derived class' InitInstance() or later (it has to be created on
that thread).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your answer; so far I have done everything correct. My UI thread is is constructed without dedicated proc pointer (to be precise, without arguments at all) and started by CreateThread().
The socket is created afterwards within the thread.
Nevertheless, my CAsyncSocket won't receive until I call at least once the AfxMessageBox. Besides, why is that at all? If the socket has a wrong message handler (let's say, the handle to some object that has no message pump), why does it suddenly get those notifications? Did the handle get exchanged? Or is the "wrong" object getting those notifications after the message box? I just do not realize why a single message box call can make everything work, and how.
- Roland
|
|
|
|
|
Even though I don't know how exactly it could result into that error, is it possible that my PostThreadMessage communication leads to the mentioned problem?
I have read that using it could lead to some messages without window handler, and the messages are dropped then... is this a field for further investigation in my case? But how should I send commands to my UI thread then!?
-- modified at 4:09 Saturday 27th October, 2007
Ok, seems like my message dispatcher is blocked until the posted message is processed. (Sounds at least like a good reason to me) And it looks like the AfxMessageBox could somehow resume the message dispatcher again... so the only questions should be how to give my sockets an own or different message pump, or how to start tasks within my thread that do not pause the message pump.
Any feedback would be great.
|
|
|
|
|
Don Rolando wrote: Ok, seems like my message dispatcher is blocked until the posted message is processed. (Sounds at least like a good reason to me) And it looks like the AfxMessageBox could somehow resume the message dispatcher again... so the only questions should be how to give my sockets an own or different message pump, or how to start tasks within my thread that do not pause the message pump.
I don't know what's going on here. What's causing this: "my message dispatcher is blocked"??
Some of the following may not apply, depending on what protocol you're using...
Which events are you specifying when you call CAsyncSocket::Create()?
If you're using CAsyncSocket::Socket() instead of CAsyncSocket::Create(),
are you calling CAsyncSocket::Bind()?
Which CAsyncSocket overrides (Onxxxx()) are being called?
For a connection-type protocol, is OnConnect() getting called?
Without your code, it's near impossible to debug
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
CAsyncSocket was desigend for a single threaded application, it could be that your problem comes from using/sharing the socket objects over different threads. How about using a single threaded application or a different socket class?
/M
|
|
|
|
|
Okay, you need to call
::PeekMessage(NULL, 0, 0, 0, PM_NOREMOVE);
to get the message pump started for your thread.
See if that helps. If not, then your thread does not have a 'primary message pump handler' and may be accumulating messages but does not know how to dispatch them. In that case, after you create the CAsynchSocket object, try to locate its hidden window and associate it as the main window of your application.
An alternative is to refactor the CAsynchSocket class to use window events for signaling instead of window messages, and your entire problem might be solved.
|
|
|
|
|
Hi,
how can I get CHtmlView session or session variables, and how can i change them.
Thanks.
|
|
|
|
|
#include<iostream>
using namespace std;
int main()
{
cout << " please choise one of these lables: " << endl << endl;
cout << " c)Carnivore p) Pianist " << endl << endl;
cout << " t)Tree g) Game ";
char ch;
cin >> ch;
while ( ch != 'c' && ch != 'p' && ch != 't' && ch != 'g' )
{
cout << " Please enter C,p,t,g " << endl << endl;
cin >> ch;
}
switch (ch)
{
case 'c' : cout << "A cat is a carnivore.\n";
break;
case 'p' : cout << "Radu Lupu is a pianist.\n";
break;
case 't' : cout << "A maple is a tree.\n";
break;
case 'g' : cout << "Golf is a game.\n";
break;
default : cout << "The program shouldn't get here!\n";
}
cin.get();
cin.get();
return 0;
}
You see!? every time you enter a number the while loop does his job and prompt the message:
" Please enter C,p,t,g ". But when i type a uppercase like G or D program terminates.
Whay while loop doesn't prompt the message?
int life()
{
in a land with no bird, no spring. My first journey was a
return 0;
}
|
|
|
|
|
pourang wrote: But when i type a uppercase like G or D program terminates.
of course it does. you aren't checking for those letters.
-- modified at 15:11 Friday 26th October, 2007
|
|
|
|
|
while ( ch != 'c' && ch != 'p' && ch != 't' && ch != 'g' )
{
cout << " Please enter C,p,t,g " << endl << endl;
cin >> ch;
}
that means if i enter 12 or G while loop show the message. And it does work for a number like 12 but not for the letter G. that's the problem
int life()
{
in a land with no bird, no spring. My first journey was a
return 0;
}
|
|
|
|
|
and now i got it right. I did not change anything but program works!!!!
int life()
{
in a land with no bird, no spring. My first journey was a
return 0;
}
|
|
|
|
|
Chris Losinger wrote: of course it does. you aren't checking for those letters.
Are you sure? The statement:
while ( ch != 'c' && ch != 'p' && ch != 't' && ch != 'g' ) should evaluate to true if c equals 'G' or 'D' , thus the loop would execute.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: Are you sure?
not any more
|
|
|
|
|
I have a tool bar in my application . i have code wirtten to disable one button on toolbar using ON_UPDATE_COMMAND_UI message. If the button gets disabled due to OnIdle message tool bar gets this message continuously and i get a flicker effect. Also due to this flicker it stops showing tool tips. for entire application. I have other tool bar buttons which have similar functionality but they work fine.
The only difference is all other buttons also have a Menu Item associated with them??
Is there any way to avoid this flicker.
|
|
|
|
|
When I'm creating dialog based applications I usually design them for resolutions of 1064x768. However, if I change to other screen resolutions (1280x1024 or 1600x1200 or ...), I would like them to grow according to the new screen size.
The first idea was to create a resource for the smallest screen resolution (800x600) and to set the FontSize according to the screen resolution during the dialogs initialization.
However, the result was not that what I expected.
The next idea was to create 3 or four different resources for different screen resolutions. This could be done easily by increasing the font size for the whole dialog.
So I created 4 different resources (Dialog800x600 (FontSize 6), Dialog1024x768 (FontSize 7), Dialog1280x1024 (FontSize 8) and Dialog1600x1200 (FontSize 10)).
In this case I have the problem that I can just start the first dialog (Dialog800x600) that was used during creation of the whole application. I think that the dialogs IDD is fix within MFC/C++ and can never be switched to another IDD.
So, does anybody have experience in creating applications that will fit for different screen resolutions?
Thanks ahead for any reply.
|
|
|
|
|
Is it really necessary to use a dialog? A simpler option would be to create an ordinary window filling the screen (remember to consider multiple screens when calling GetSystemMetrics) and then populating that window with controls. (The size of dialogs aren't actually related to pixels, but are calculated in terms of "dialog base units" (something that has to do with the size of the default font). Even if you manage to resize your dialog to fill the screen in different resolutions, the dialog will appear different depending on the user's selection for default font.)
If you really have to use a dialog, one option would be to use PostMessage(WM_SIZE, ...) in your OnInitDialog, and the on OnSize reposition the controls using the relative positions derived from the resource. Something in the line of:
<br />
BeginDeferWindowPos(...)<br />
for(i = 0; i < m_nNumCtrls; i ++){<br />
DeferWindowPos(...) <br />
}<br />
EndDeferWindowPos(...)<br />
-- modified at 19:59 Friday 26th October, 2007
|
|
|
|
|
Dialog IDD is fixed but you can change. you will have to do some changes in constructor. Go to dialog class suppose CTestDlg
Replace constructor CTestDlg(CWnd* pParentWnd = NULL) From CTestDlg(int id, CWnd *pParentWnd = NULL);
In implemention do CTestDlg::CTestDlg(int id, CWnd* pParent) : CDialog(id, pParent)
{}
When you want to display dialog. Check
if(resolution == )
{
CTestDlg testdlg(IDD_DIALOG1);
testdlg.DoModal();
}
else
{
CTestDlg testdlg(IDD_DIALOG2);
testdlg.DoModal();
}
Manish Rastogi
|
|
|
|
|
Why dont you get the size of desktop and use SetWindowPos () to change the size of the dialog in the OnInitDialog ()??
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
I am having a problem when building a solution in VC8 (2005). I am migrating a progam from VC6 to vc2005. When linking I get "error LNK2019: unresolved external symbol __imp__PrintDlgA@4 referenced in function _PopPrntPrintFile" I want to link static libraries and change to /MTd to do this. I still get these errors.
PLEASE HELP!
Thanks,
Bill
|
|
|
|
|
It seems that your project needs to a lib file are you sure you import a correct lib ?
|
|
|
|
|
I do not know if I can get the correct one. I have 2005 express. Here are the command line options used.
Compiler
/Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_VC80_UPGRADE=0x0600" /Gm /EHsc /MTd /Fp".\Debug/PopPad.pch" /Fo".\Debug/" /Fd".\Debug/" /FR".\Debug\\" /W3 /WX /nologo /c /ZI /TP /errorReport:prompt
Linker
/OUT:".\Debug/PopPad.exe" /INCREMENTAL /NOLOGO /MANIFEST /MANIFESTFILE:".\Debug\PopPad.exe.intermediate.manifest" /DEBUG /PDB:".\Debug/PopPad.pdb" /SUBSYSTEM:WINDOWS /MACHINE:X86 /ERRORREPORT:PROMPT nistpack.lib odbc32.lib odbccp32.lib kernel32.lib
I think it is the comdlg32.lob file I need, I have checked and it is in multiple pathes whihc I have included in Tools/Options.../VC++ Directories under the Libraries Tab.
Could it be that under vc6 is was a MFC?
I am reaching for anything...
Thanks,
Bill
|
|
|
|
|
are you doing a UNICODE build but linking to the non-Unicode libs (or vice versa) ?
|
|
|
|
|
I am using MFC,when I declare a X Object int class Y and a Y Object in class X,then compile Error,I know ,i have to use extern in file.h but I don't put it anywhere,please post a small code about extern to help me.Thanks everyone
|
|
|
|
|
class Y;
class X
{
Y y; <font color="Red">
};
class Y
{
X x;
}; This shows the order the compiler needs to see the declarations, regardless of
whether you use header files or not.
This will only work with object pointers, since the compiler doesn't know the size of a Y
object when it encounters the X class.
The only solution, then, is something like:
class Y;
class X
{
Y *py;
};
class Y
{
X x;
};
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Oh thanks about your question,but I'm sorry,I want to ask about include<file.h> in MFC,you can try,
If you create two class in MFC,they are X and Y,I suppose in class you have a Object X,exam X1,and in X is Y1 belong Y:
class X
{
Y Y1
}
class Y
{
X X1
}
At MFC,These two classes stay two distributed places,so At class Y you must to call include<x.h> and at class X is <include y.h="">,this is a cause to compile error,Please help me
|
|
|
|