|
As long as he's not cross-dressing across forums.
Blog link to be reinstated at a later date.
|
|
|
|
|
Hi guys, I've written an application in pure C++ and the command line and now I'd like to convert it to Windows.
I am at the very first steps in using MFC and I am wondering if anyone could be kind enough to help.
To simplify the problem, let's suppose my application is composed of 2 input edit text boxes (Box1, Box2), a button (Calculate), and 1 output textbox (Box3). What is the correct code required to display the result of the calculation (Box1+Box2) in the output textbox (Box3)?
I've read 1300 pages of the excellent Ivor Horton's Beginning C++ 2008 book....only to discover that this simple topic is not covered!!
Many thanks
jEDI
|
|
|
|
|
J_E_D_I wrote: What is the correct code required to display the result of the calculation (Box1+Box2) in the output textbox (Box3)?
Call SetWindowText() , or send the control a WM_SETTEXT message.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Thanks to both of you. I'll try it soon and let you know.
jEDI
|
|
|
|
|
in MFC you may also map the three textboxes to three integer variables and use the UpdateData mechanism see [^].
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]
|
|
|
|
|
I know that you can use the pragma comment directive in your code to link to a specific .lib file. Is it possible to also use this to pull in a .res file?
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
VCF Blog
|
|
|
|
|
Nothing in the doc's even hint at this ability, nor would it make sense for it to work based on what the pragma does.
As a workaround you might want to try creating a resource only dll that includes your res, tinker with the build options to build as a static lib, and then use the pragma to link in the static lib.
What are you trying to accomplish ?
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
I found another way around this. I have existing build .res files and I was wanting an easy way to link to them to pull it into the statically built .exe. I was hoping the pragma comment stuff could pull this off. The reason I thought this might work was because you can feed in various .lib or even .res files into the "Object/Library modules" edit in the Link settings, so I was hoping pragma comment (lib,...) would do the same trick.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
VCF Blog
|
|
|
|
|
Jim Crafton wrote: existing build .res files and I was wanting an easy way to link to them to pull it into the statically built .exe
I had the same problem. I've manually added refences to the source .rc files via the 'Resource Includes' dialog 'Compile-time directives' by adding lines like: '#include "path/res.rc"'.
So between libs i've had to add these statements as needed (i.e. one lib/dll uses resources from another), as well as in any final .exe. It's a pain, but i think the Resource Includes - Compile-time directives is the 'documented' way to do it.
By adding the #include .rc you also make it a dependent, so no risk of the .res being out of date.
How did you end up doing it ?
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
Hi there,
I am trying to populate a combo box of available com ports.
I call my openSerialport function from my init dialog function but as soon as CreateFile is executed I get an Unhandled Exception error which has the info 0xC0000005 : Access Violation.
Can anyone help???????
Code Below
InitDialog call
BOOL CPTZControlDlg::OnInitDialog()
{
int i, j, hr;
char portStr[7];
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
j=0;
for (i=0 ; i<PORTNUM ; i++)
{
hr = m_serialCtrl->OpenSerialPort(i,0);
if (hr == 0)
{
g_exists[i] = 1;
g_nComPortInd[j] = i;
g_comport[i] = j;
j++;
sprintf(portStr,"COM%d",i+1);
m_comPort.AddString(portStr);
}
else
g_exists[i] = 0;
}
return TRUE;
}
Open Serial port function
int CSerialControl::OpenSerialPort(int pcCommPortInd,int radd)
{
DCB dcb;
BOOL fSuccess;
char pcCommPort[14];
int m_nComPort;
m_nComPort = pcCommPortInd;
sprintf(pcCommPort,"COM1",pcCommPortInd+1);
m_hCom = CreateFile( "COM1",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED,
NULL
);
if (m_hCom == INVALID_HANDLE_VALUE)
{
m_hCom = NULL;
return COMMSERROR;
}
if (radd==0)
{
CloseSerialPort();
return COMMSGOOD;
}
Cheers
Jim
|
|
|
|
|
What happens if you use OPEN_EXISTING instead of CREATE_ALWAYS ?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
jimjim733 wrote: sprintf(pcCommPort,"COM1",pcCommPortInd+1);
What is the purpose of the above line?
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]
|
|
|
|
|
In addition to the "For communications resources, the dwCreationDisposition
parameter must be OPEN_EXISTING" problem...
jimjim733 wrote: if (m_hCom == INVALID_HANDLE_VALUE)
{
m_hCom = NULL;
return COMMSERROR;
}
NULL is not an invalid handle value. INVALID_HANDLE_VALUE is an invalid
handle value.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
NULL is not INVALID_HANDLE_VALUE , but (I guess) it is still is an invalid handle value.
That's said, I agree with you: he should return INVALID_HANDLE_VALUE.
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]
|
|
|
|
|
|
|
|
Mark Salsbery wrote: I knew you were going to bring that up!
MS's trap!!!
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]
|
|
|
|
|
|
If this is possible, I don't think it should be.
To borrow a phrase, "what if you could do this?"
1/ Do you think people who write viruses / trojans / rootkit / bad stuff(tm) would say to themselves "oh, it would be irresponsible of us to use MakeOurAppUnstoppable (), so we'll leave that API only for good people".
2/ You have a bug in your program, and it's in an infinite loop, guzzling memory. How do you close it to put your NewEvenShinierApp.exe?
3/ There is no (3). I'd convinced myself at (1)...
Iain.
|
|
|
|
|
Wonderful.
Good stuff for 'memorable quotes' on my blog.
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]
|
|
|
|
|
Why ? Wouldn't this be considered rude ?
|
|
|
|
|
I am not able to think of a legitimate purpose why you want to do this. Why should your process run forever? The user must have the freedom to quit any process that they want to and delete any files that they want to.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: I am not able to think of a legitimate purpose why you want to do this. Why should your process run forever? The user must have the freedom to quit any process that they want to and delete any files that they want to.
How about a software that can keep an eye on all the users logged in to your office network at any given time, and of course the users should not be able to terminate this. Trying to achive something like without using access previlages and no service, it looks he has few windows 9x clients also
|
|
|
|
|
One good use:
Anti-malware, keep the program running as a diagnostic tool.
Ps.
Ring 0, or ring 3 can't think of it.
IF you look at it from a malware writer's perspective, it would usually involve dll injection, dual processes, or creation of a driver.
Whether the code is revealed or not, malware will ALWAYS be written as will diagnostic software.
|
|
|
|