|
I'm sorry David.
When you say unique registered message is even better means
use RegisterWindowMessage()?
|
|
|
|
|
Anonymous wrote:
When you say unique registered message is even better means
use RegisterWindowMessage()?
That would be the one!
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
But isn't it for sending messages between applications?
I already used it which is catching Messages from Printer without really knowing it.
How am I going to let my application stop and wait for the message to coming in.. actually application is just talking to itself.
I got confused, let me clearify and see I'm right.
1) create the thread using AfxThreadBegin() when Print button is clicked. So entire GUI is still alive and user can still click on either Stop or Exit button.
2)Print the file, and wait for the message from printer. Now I'm using global bool variables stopPrinting and printNextfile to stop.
<br />
UINT theThread(...)<br />
{<br />
while(!stopPrinting) <br />
{<br />
if(printNextfile)<br />
PrintNextFile();<br />
else if(stopPrinting)<br />
break;<br />
}<br />
}<br />
it is working fine. the program is doing what I want it to do but I dont' really like it coz it takes so much of CPU time. and Dont' really know to improve it
The solution I guess was take out while loop and why dont'I just respond to message. but how to?
Using RegisterWindowMessage and SendMessage() functions will help?
if(END_DOC)
SendMessage(PRINT_NEXT_FILE);
OnPrintNextFile()
{
printNextfile();
}
So how am I going to stop or respond to Stop Button was clicked?
thanks
|
|
|
|
|
Anonymous wrote:
But isn't it for sending messages between applications?
It can also be used within the same application, whether one window is sending a message to itself, or one window is sending a message to another window. As long as you have the target window's handle, it makes no difference that it belongs to another application.
Anonymous wrote:
1) create the thread using AfxThreadBegin() when Print button is clicked. So entire GUI is still alive and user can still click on either Stop or Exit button.
So far, so good.
Anonymous wrote:
2)Print the file, and wait for the message from printer.
How does the printer signal that it is done printing?
BTW, why don't you register? It's much easier to communicate, and it's free!
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
The printer send message like window message.
here what I did
1) BlackIcePrintMessage = RegisterWindowMessage(szREGISTERMESSAGE);
where szREGISTERMESSAGE = "colorPrinter"
2)
BEGIN_MESSAGE_MAP(myApp, CDialog)
ON_REGISTERED_MESSAGE(BlackIcePrintMessage,OnPrinterMsg)
END_MESSAGE_MAP()
3)
LRESULT CSMPClientDlg::OnPrinterMsg(WPARAM wParam, LPARAM lParam )
{
..
..
}
I was using above methods without really understanding it.. I read about it but still get confused. So how can application send the message to itself using the same 3 steps?
My big question ( the most still confused) is a thread... Am I still use the infinate loop inside the thread function and watch or wait for the message coming in. or how?
|
|
|
|
|
Anonymous wrote:
So how can application send the message to itself using the same 3 steps?
It matters not to SendMessage() and PostMessage() of the origin of the message (i.e., registered or some arbitrary number like WM_APP + 5 ). Consider:
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
ON_REGISTERED_MESSAGE(BlackIcePrintMessage, OnPrinterMsg)
END_MESSAGE_MAP()
LRESULT CMyDialog::OnPrinterMsg( WPARAM, LPARAM )
{
AfxMessageBox("The printer has finished doing whatever it was doing!");
}
UINT ThreadProc( LPVOID pParam )
{
HWND hWnd = *((HWND *) pParam);
PostMessage(hWnd, BlackIcePrintMessage, 0, 0);
return 0;
}
void CMyDialog::OnPrint()
{
HWND hWnd = GetSafeHwnd();
AfxBeginThread(ThreadProc, &hWnd);
}
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Thank you very much Dave
I think I understand and let me try it.
thank you again for taking time to explain it patiently.
|
|
|
|
|
Hi pals,
I am facing a difficulty with CDC across threads.
Actually, i spawn a secondary thread to calculate the display coordinates of the strings. So i am calculating the height and width of the strings based on the font selected in the CDC. It works fine with the scroll view but the calculation goes wrong with the PrintPreview. Bcos ,SelectObject(pMyFont) is always returning NULL.
How do i solve this problem.
Help me out friends. Thanks in advance.
Kumari
|
|
|
|
|
MFC objects do not operate well across threads. There are some Knowledge base articles on MSDN that explain why. Basically they use thread local storage to map the resource handle to the C++ object pointer. So in another thread the mapping does not exist.
So always pass the resource HANDLE rather than an MFC C++ class pointer across threads. then if you want to use MFC classes in the thread you can attach the HANDLE to a thread local scope MFC object.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Pass the HDC.
Make sure the CDC is retreived by GetDC.
Make thet window class has CS_OWNDC. you get it on WM_CREATE.
you can set the GDI objects into this context once and thay persistent
couse to CS_OWNDC.
|
|
|
|
|
Hi suiram
Thanks for your response.
Yes i am passing hdc to the thread.
I tried with CS_OWNDC, But of no improvement. My problem is with the CDC of PrintPreview. What should i do now.
Please, do help me.
kumari
|
|
|
|
|
Hi suiram
Thanks for your response.
Yes i am passing hdc to the thread.
I tried with CS_OWNDC, But of no improvement. My problem is with the CDC of PrintPreview. What should i do now.
Please, do help me.
kumari
|
|
|
|
|
Any article on how to load a dll made in C# to be used in visual c++ 6. Also if this dll is capable of throwing events how do we handle these events?
Thanks
|
|
|
|
|
as every other dll!?
LoadLibrary!?
GetProcAddress!?
Don't try it, just do it!
|
|
|
|
|
I don't believe that is going to work.
|
|
|
|
|
Probably the easiest way do do it is to expose the C# code as a com object.
The architect has placed his bets,
but the odds are long
-Poster Children
|
|
|
|
|
I dont think you can create a DLL in C#. You can only build an assembly in C#. There is a difference between DLL and Managed assembly, although they share the same extension. To use the assembly from C++, as another reader pointed out convert the C# class to a COM object and use the COM object in VC++. Else you can host the CLR runtime in your VC++ app and then load your assembly there in.
|
|
|
|
|
Do a search for "hosting the CLR". As for catching exceptions, it's probably pretty similar to managed c++.
--
Joel Lucsy
|
|
|
|
|
I want to display Dialog Box from window service, but i am unable to do that
pls help
i am using domodol to show dlg box but it is not showing.
pls help me abt this
waiting for reply
I Think It will Work
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
My first question would be why would you want a UI component in a service?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
yes i want to display some infoemation to user thorugh dlg box if you know the code pls help me
I Think It will Work
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
I reiterate that this is a bad idea. Most services run on a server locked away in a closet somewhere, so if your service presented any UI elements, such as a message box, no user would be in front of the machine to see and then dismiss it. Also, any windows created would probably appear on a window station or desktop different from the one the user was sitting in front of, and thus the message wouldn't be visible to the user anyway. It sounds like you need a Service Control Program (SCP) instead.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Yeah i got the solution.
i have made my service desktop interactive.
all of my problem has been solved thanks for your concern.
now i will use winlogon notifcation package to know wheather the user is login or not
thanks any way
I Think It will Work
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
I suggest that if you write a GUI application that interogates the service. Windows services run before users login and indeed run without a desktop.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fuity and sweet. I'm jelly, what am I? - David Williams (Little Britain)
|
|
|
|
|
how a Gui application interact with service,have you any idea.
i think wheather i use socket or there is any other way
I Think It will Work
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|