|
ashwiny wrote: could anyone tell me briefly how this code is working?
Which part exactly?
"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
|
|
|
|
|
Hi,
I'm trying to paint a Bitmap in my dialog. Got as far as:
CWnd* pWnd =GetDlgItem(IDC_LOGO);
if(pWnd){
CDC* pDC=pWnd->GetDC();
CBitmap Bmp;
Bmp.LoadBitmap(IDB_LOGO);
pDC->SelectObject(&Bmp);
// What Next to Paint it
}
My Bitmap painting skills are very seldomly excersised, and got a bit rusty as a result.
Bram van Kampen
|
|
|
|
|
create a compatible dc using pDC.
select the Bmp in this compatible dc.
at last pDC->Bitblt(......compatible dc);
|
|
|
|
|
ccpptrain is right,
using CImage is much simple
CImage img;
img.LoadFromResource(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_LOGO));
img.BitBlt((HDC)pDC, 0, 0);
|
|
|
|
|
|
Thanx
I Never Knew that, but you can actually import a static Bitmap Resource direct into MS5++.
Actually that was all I was looking for.
Regards
Bram van Kampen
|
|
|
|
|
I create a thread in a very simple app, that way:
<br />
HWND hWnd = CreateWindow(...);<br />
<br />
DWORD _tid;<br />
if((CreateThread(NULL, 0, msgprocessing, hWnd, 0, &_tid)) == NULL) {<br />
error();<br />
}<br />
I need tu run message processing in the thread to catch msg's for hWnd window, but it won't work. Everything else is coded correctly. Any ideas why
|
|
|
|
|
Hi,
have you tried to create the window in the thread that needs to catch the messages?
This should work.
codito ergo sum
|
|
|
|
|
Hi,
U can create window in thread. The message of that window will pass though the PreTransalte and MessageLoop of the application .
If needed i hope u can implement you own message loop(in the thread itself) after the creation of window.
I do not know if the implementation of message loop in the thread will causue any problem withe the main message loop of the application.
Prasanth Vijay
|
|
|
|
|
U can use PeekMessage() message for implementing the message catching loop.
See the help in MSDN.
If u have time, Plz have look on CWInApp::Run() or CWinThread::Run() in the MFC message implementation. This will give very good idea on the messaeg loop implemenattion.
Thanks
Prasanth Vijay
|
|
|
|
|
I used the PeekMessage and tried to create the window in the secondary thread, but still not working. So I placed the whole code, here (sorry for the comments, they are not in ENG)
|
|
|
|
|
Im wanting to allocate a button on a form to connect to an IP address on my network through TCP. A seperate button will send an ASCII code e.g "l" to the IP address and a third button will disconnect from the TCP connection. Im having trouble trying to do this using TcpClient in Visual C++ (express edition 2008 version). The main problem Im having is trying to seperate code for just connecting to the tcp conection, then having a seperate part of code to write to the data stream and a third part that just disconnects from the tcp connection.
|
|
|
|
|
|
Howdy out there...
I was wondering if anyone had some good guidelines for creating services.
Currenly I have a UI and and engine hooked together... The communicate a lot, and I'd like to split the engine off of the UI and make a service.
But, I was wondering if there were any good guidelines on this topic?
Thanks in advance!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</a>
|
|
|
|
|
I guess most important, is the first sentence here:
Services (Windows)[^]
The service shouldn't have any UI.
Other than the service control code, interprocess communication is the
only major change you should need.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Is there an "easy IPC"?
Or, do I need to invent a protocol for myself over whatever carrier I use (named pipes, tcp, etc...)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</a>
|
|
|
|
|
The easiest I know of is .NET remoting You can do IPC with regular class method calls
with that - very nice.
Unfortunately, managed code is not always an option, so pipes and sockets I guess
is the next easiest (AFAIK).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
One last question about services in general.
In transition my app to a service -- I wonder what limitations I can run into. I know now to have UI in the service.
Can I assume there's no limiation to having a window? There's parts of the code that use this for some inter-thread communication. Personally, I hate using a window, but it's something I am stuck with.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</a>
|
|
|
|
|
I don't know of any limitations beyond what's mentioned in the programming considerations here[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm trying to figure out how to place a loop in this program that will take input from the user after each iteration, ask to continue, and restart or exit the program. I've tried everything, I just don't know how to do it. Will someone please take a look at this code and maybe put the loop statements in the right spots? I'm really lost and I just need this one example done so I can understand it and move on. Thanks.
#include <iostream>
int getMonth();
// Precondition: User will enter birth month
// Postcondition: Returns 1 <= birth month <= 12
int getDay();
// Precondition: User will enter birth day
// Postcondition: Returns 1 <= birth day <= 31
int getSign(int month, int day);
// Precondition: 1 <= month <= 12, 1 <= day <= 31
// Postcondition: Returns integer corresponding to astrological sign for
// given month and day starting with Capricorn = 1.
int main()
{
using namespace std;
int month;
int day;
//
// Get birth month and day.
//
month = getMonth();
day = getDay();
//
// Determine and print the user's sign
//
cout << "Your sign is ";
// --------------------------------
// ----- ENTER YOUR CODE HERE -----
// --------------------------------
switch (month)
{
case 1:
if (day <= 19)
cout << "Capricorn.";
else
cout <<"Aquarius.";
break;
case 2:
if (day <= 18)
cout << "Aquarius.";
else
cout <<"Pisces.";
break;
case 3:
if (day <= 20)
cout << "Pisces.";
else
cout <<"Aries.";
break;
case 4:
if (day <= 19)
cout << "Pisces.";
else
cout <<"Taurus.";
break;
case 5:
if (day <= 20)
cout << "Taurus.";
else
cout <<"Gemini.";
break;
case 6:
if (day <= 20)
cout << "Gemini.";
else
cout <<"Cancer.";
break;
case 7:
if (day <= 22)
cout << "Cancer.";
else
cout <<"Leo.";
break;
case 8:
if (day <= 22)
cout << "Leo.";
else
cout <<"Virgo.";
break;
case 9:
if (day <= 22)
cout << "Virgo.";
else
cout <<"Libra.";
break;
case 10:
if (day <= 22)
cout << "Libra.";
else
cout <<"Scorpio.";
break;
case 11:
if (day <= 21)
cout << "Scorpio.";
else
cout <<"Sagittarius.";
break;
case 12:
if (day <= 21)
cout << "Sagittarius.";
else
cout <<"Capricorn.";
break;
}
// --------------------------------
// --------- END USER CODE --------
// --------------------------------
cout << endl;
cout << "Do you want to continue? (Y/N)\n";
}
int getMonth()
{
using namespace std;
int month;
cout << "Enter the month of your birthday (1-12): ";
cin >> month;
while ((month < 1) || (month > 12))
{
cout << "Month must be between 1 and 12; please re-enter: ";
cin >> month;
}
return month;
}
int getDay()
{
using namespace std;
int day;
cout << "Enter the day of your birthday (1-31): ";
cin >> day;
while ((day < 0) || (day > 31))
{
cout << "Day must be between 1 and 31; please re-enter: ";
cin >> day;
}
return day;
}
|
|
|
|
|
Probably you miss the right locations for the code placeholders.
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
|
|
|
|
|
not very helpful.
thanks anyway.
|
|
|
|
|
It was just an hint: if you want a loop then you have to widen its scope, i.e. move the upper placeholder up and the lower placeholder down:
int main()
{
using namespace std;
int month;
int day;
char answer;
do
{
month = getMonth();
day = getDay();
cout << "Your sign is ";
switch (month)
{
case 1:
if (day <= 19)
cout << "Capricorn.";
else
cout << "Aquarius.";
break;
}
cout << endl;
cout << "Do you want to continue? (Y/N)\n";
cin >> answer;
} while (answer=='y' or answer=='Y');
}
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
|
|
|
|
|
int main()
{
char YesNo = 'Y';
while (YesNo == 'Y' || YesNo == 'y')
{
...put all your loop code here...
cout << endl;
cout << "Do you want to continue? (Y/N)\n";
cin >> YesNo;
}
return 0;
}
Maybe something like that will work?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
that just creates an endless loop in the console window, repeating "Your sign is ", or the sign, depending on where it is placed?
|
|
|
|