|
I'm not much of C++ programmer but am just putting together a very simple Dialog in Visual C++ 6.0.
It's one button and two Edit Boxes. From the first I get user input and the second I use for user feedback.
To the press button message handler I have added a function that is looping and for each loop I'd like to update the message in the second Edit Box.
The code looks something like this:
void CAppGUIDlg::OnButton1()
{
CAppGUIDlg::DoSomething();
}
void CAppGUIDlg::DoSomething()
{
int *string;
int max;
char *tmpStr = "";
int total = 0;
max = atoi(m_editStr1); //Get Edit Box 1 value
while (total < max )
{
//Do something with value from Edit Box 1
sprintf(tmpStr,"User message %i", total/1024);
UpdateData(false);
m_editStr2 = _T(tmpStr); //feedback the result to Edit Box2
Sleep(200);
UpdateData(false);
}
}
What will happen is that Edit Box 2 will not be updated until the loop is finished. Is there a simple way to update it within every loop?
|
|
|
|
|
Either:
Do each thing in a different thread.
Or (more simply for this case)
Pump messages in your loop.
Change your loop to:
while (total < max )
{
//Do something with value from Edit Box 1
sprintf(tmpStr,"User message %i", total/1024);
UpdateData(false);
if(!PeekAndPump())
break;
m_editStr2 = _T(tmpStr); //feedback the result to Edit Box2
Sleep(200);
UpdateData(false);
}
Then add this function to your class:
BOOL PeekAndPump()
{
MSG dlgMsg;
if (::PeekMessage (&dlgMsg, NULL, 0, 0, PM_NOREMOVE))
{
if (!AfxGetApp ()->PumpMessage ())
{
::AfxPostQuitMessage (0);
return FALSE;
}
return TRUE;
}
LONG lIdle = 0;
while (AfxGetApp ()->OnIdle (lIdle++));
return FALSE;
}
|
|
|
|
|
Exactly what I was hoping for. Thanksa lot Diddy!
|
|
|
|
|
No problem
|
|
|
|
|
if you want to send a message to an edit box just use SetDlgItemText function and you have only 2 parameters in MFC VC++.
gabby
|
|
|
|
|
Wont help.
If your looping around in that one function, you can do what you want to the other edit box, it wont redraw until you return from that function and contine to pump messages.
|
|
|
|
|
I AM pretty sure it works.
gabby
|
|
|
|
|
Try it - it doesnt.
Yes SetDlgItemText changes the text - though really its the Win32 way of doing things. The way he has done it with UpdateData basically calls SetDlgItemText anyway under the hood - just using the DDX/DDV map to work out what to map to what.
But just like UpdateData, SetDlgItemText will set the text after the loop has returned. If you are processing a message spinning in a loop then no other messages will come through when you are doing that (specifically, WM_PAINT's) until you return from that loop. Hence, yes u have changed the text in the edit box with SetDlgItemText but the edit box wont redraw until your function returns.
|
|
|
|
|
By updating the edit control (either by using SetDlgItemText() or UpdateData() ) every 200 ms, none of the updates will be seen except for the last one after the loop terminates.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I'm trying to determine the font size used for menu's. I've tried retrieving the NONCLIENTMETRICS structure which contains the right font name but the wrong size. My system is configured to use 8pt font but the height field of the menu LOGFONT structure in the NONCLIENTMETRICS structure is always set to 0xfffffff5 which equates to -11 or an 11pt font. Can anyone tell me what I'm doing wrong?
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
You are mixing up typographical point with pixels, most likely.
A typographical point, 1 72th of an inch, is the measure normally used for fonts - in the "real world". A pixel is a picture element, one of the small dots on your monitor.
The size of a typographical point in pixels is decided by the manufacturer of the screen(driver). But it is not a one-to-one correspondance, as you've noticed.
Negative pixels heights means "don't include external leading in the font height". Leading is yet another typographical term, meaning the space between lines (that were created by adding slices of lead - thus the name).
You can see the difference by creating two fonts, one with the height -12 and one with 12. You'll see that the 12-pixel font is smaller than the -12, it is reduced by the leading.
You can convert between the formats by getting the number of pixels per inch vertically from a CDC , calling GetDeviceCaps( LOGPIXELSY ) . Then, divide the result with 72 to get the height of a typographical point. Note that you'll need to use floating point for this, or multiply the pixels per inch with some suitably large value.
Finally, the -11 is the value you should use as a font height in a call to a CreateFont with the MM_TEXT mapping. The value sounds very reasonable, BTW.
Now you know more than you ever wanted to know about font heights
|
|
|
|
|
Sounds like you know a lot about fonts, maybe you could post an article covering the basics for us beginners?
Roger Allen - Sonork 100.10016
Strong Sad: I am sad I am flying
Who is your favorite Strong?
|
|
|
|
|
I will consider it - IME this, together with printing (where it normally starts to give trouble, even to experienced developers) and mapping modes are normally hopelessly uncharted areas in our community...
|
|
|
|
|
Thanks for the detailed explanation. The bit I was missing was the calculation to get from pixels to point size. If I'd looked at the help for LOGFONT I wouldn't have needed to ask the question. That'll teach me for trusting my memory!
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
I know this isn't strictly a Visual C++ Q, but I haven't had much luck else where )
Has anyone ever managed to combine the VS.NET CD distribution (7 CD version, 2002 Enterprise Archect) onto one DVD?
I have created a network install, as per readme file, and everything works fine from the HDD. Copy that onto a DVD, try to install, the install starts, gets about 6% through - then starts asking for me to "Insert CD1".
I don't suppose anyone has ever managed to do this? Long shot I know.
Ta.
|
|
|
|
|
I was wondering how to design a complete form from within resource editor and then make it scroll. I can get the form to scroll but the problem is that i cannot place the controls outside of the forms viewable area. The application is dialog based as it is an iterface to a database that i designed Thanx!!
|
|
|
|
|
If you create a doc/view app, and select CFormView as the view-class, you get scrolling automatically.
|
|
|
|
|
I forgot to mention the application is dialog based as it is a user interface to a database that i made. thanx
|
|
|
|
|
|
How do i access and display a dxf object with the Visual C++ 6 api tools for Maya?
|
|
|
|
|
I want to save a struct contains points of char into a file,but actually the strings that the points point to don't be contained in the struct,how can I do?
|
|
|
|
|
You just save the contents of the strings. If you need to share strings between several instances of the struct (or other structs), you can devise some kind of id-mechanism instead.
|
|
|
|
|
Hi, I want to develop an application in Visual C++ 6 which will run the default internet connection.
Any ideas about how to do that, without running the internet explorer?
Thanks in Advance
Regards,
Dimitris
|
|
|
|
|
check MSDN for : Establishing a Dial-Up Connection to the Internet and InternetAutodial function.
InternetAutodial(INTERNET_AUTODIAL_FORCE_ONLINE,hWnd);
|
|
|
|
|
Hi guy;
Try to add an Web Browser control to your project. Add an Active control to the project. do Project->Add->Components and controls. Add the control and configure it to dial a connection in none is present.
Krugger
|
|
|
|