|
|
Hi guys
I'm trying to do something similar to a sports results tray info, and I was thinking to get the results from a web page to later show them in the tray.
There is an easy way to get part of text from an html page programatically?
Best Regards
Dr.pi
|
|
|
|
|
Yes, you can use IE automation. Search MSDN for IHTMLDocument .
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Another idea..
In the past I have used the following function to pull HTML code from a url.. I then parse the HTML code and pull out the info I want.. Not sure if this is what your looking for but here's some code..
CString strUrl,
strBuff,
strError;
CInternetSession mysession;
CStdioFile* remotefile;
char httpbuff[4096];
int numbytes;
strUrl = _T("HTTP://www.someurl.com/index.htm");
strError = _T("SUCCESS");
TRY
{
remotefile = mysession.OpenURL(strUrl,1,INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_RELOAD);
while (numbytes = remotefile->Read(httpbuff, sizeof(httpbuff)-1))
{
httpbuff[NULL];
strBuff += (CString)httpbuff;
}
mysession.Close();
remotefile->Close();
delete remotefile;
}
CATCH_ALL(error)
{
TCHAR szCause[4096];
error->GetErrorMessage(szCause,4096,NULL);
strError.Format("%s",szCause);
}
END_CATCH_ALL;
if(!strError.CompareNoCase(_T("SUCCESS")))
{
}
else
{
}
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
Please if there is someone who knows how to pass an input parameter to a query for selecting data from a view with parameter.
I have a "MS Access" View called "Income" and this view has a parameter pDate.
The SQL used to create the View is something like this:
SELECT AVG(TROL) AS MROL, AVG(TEURO) AS MEURO, AVG(TUSD) AS MUSD
FROM Total
WHERE date > pDate;
pDate is a parameter.
I have a class CDBIncome : public CRecordset
and a recordset
CDBIncome rsIncome;
I don't know how to pass the pDate parameter to rsIncome;
If somebody knows how to do this, please write the code to do this.
Code for DoFieldExchange(CFieldExchange* pFX)
and code for query. And anything I should know.
Thank you.
|
|
|
|
|
|
I have tried to add this code to
DoFieldExchange(CFieldExchange* pFX)
{
..............................
pFX->SetFieldType( CFieldExchange::inputParam );
RFX_Text( pFX, _T("[pDate]"), m_dateDate );
}
I have declared
CString m_dateDate;
CDBIncome::CDBIncome(CDatabase* pdb)
: CRecordset(pdb)
{
//{{AFX_FIELD_INIT(CDBMedie)
m_MROL = 0.0;
m_MEURO = 0.0;
m_MUSD = 0.0;
m_nFields = 3;
m_nParams= 1;
//}}AFX_FIELD_INIT
m_nDefaultType = snapshot;
}
and
{
CDBIncome rsIncome(&theApp.m_DB);
rsIncome.m_dateDate = ...(my date to pass as parameter)
rsIncome.Open();
}
But i get this error to few parameters and everything i try i receive errors
|
|
|
|
|
Here's one way:
CString CDBIncome::GetDefaultSQL()
{
CString strQuery;
strQuery.Format("SELECT AVG(TROL) AS MROL, AVG(TEURO) AS MEURO, AVG(TUSD) AS MUSD FROM Total WHERE date > '%s'", m_strSomeDateValue);
return strQuery;
}
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thanks, it does the work, but this isn't a parametrized query.
I want to know how to pass parameters to a view.
|
|
|
|
|
Ahh, that's a different request! You'll want to read this article.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
For a technical drafting program, i need to draw truetype fonts with total control on their height : for example i want a text of exactly 10mm high.
The problem is in interpretation of height; for truetype fonts, this height is made of 3 arts : Descent (part under the baseline), Ascent (part over the baseline), InternalLeading (some space above the character). All these values are returned by pDC->GetTextMetrics() when you have selected a font in the pDC.
In my case, when i say i want a font 10 mm high, it means a font whose characters above the baseline (such as digits) will be 10 mm high. This convention is used by programs such as Autocad, MicroStation, ...
For creating a CFont object, you have to fill a LOGFONT struct with the properties of the font, such as font name, height, weight, ... But as said before, the height specified here include descent + ascent + leading. Here is how i try to get what i want :
CFont *pOldFont, newfont;
TEXTMETRIC Metrics;
LOGFONT lf;
double HcarFromFont, HcarWanted;
memset(&lf, 0, sizeof(LOGFONT));
strcpy(lf.lfFaceName, "Arial");
// HcarWanted is the required height (say 10 mm) converted in pixels;
// the height must be specified in logical units, which are pixels because the the current mapMode is MM_TEXT.
HcarWanted = 10 /* mm */ * ConversionFactor; // ConversionFactor translates mm in pixels
// set the height - this is just a first try :
lf.lfHeight = - (long)HcarWanted; // note the minus sign, this is normal (see doc. for LOGFONT)
... // set others font properties
newfont.CreateFontIndirect(&lf);
pOldFont = pDC->SelectObject(&newfont);
pDC->GetTextMetrics(&Metrics); // get metrics (in pixels) for the font just created
// read the current height for ascent part :
HcarFromFont = Metrics.tmAscent - Metrics.tmInternalLeading;
// here is the trick : the height of the ascent part is of course smaller than the required height;
// so i correct the total height (lf.lfHeight) so that the ascent part grows up to the required height :
lf.lfHeight = (long) (lf.lfHeight * (HcarWanted / HcarFromFont));
// example : let's say that HcarWanted is 100 pixels and that GetTextMetrics()
// returned HcarFromFont = Metrics.tmAscent - Metrics.tmInternalLeading = 60;
// so the new lf.lfHeight is multiplied by * 100/60 = 1.66
newfont.Detach();
newfont.DeleteObject();
newfont.CreateFontIndirect(&lf); // recreate the font with the corrected height
pDC->SelectObject(&newfont);
// the following lines just check that the new height of the ascent part is very near of the required height :
pDC->GetTextMetrics(&Metrics);
HcarFromFont = Metrics.tmHeight - Metrics.tmInternalLeading;
Problem : the resulting height on screen is near the required height but there is still an error up to 20 %; for a same specified height, some fonts are smaller, some are bigger.
JPG
|
|
|
|
|
Have you considered working in a different mapping mode, for example, MM_LOMETRIC ?
If you want to implement printing, using such a device-independent mapping mode will seriously simplify your code.
One thing that will bite you is that MM_LOMETRIC has the y axis increasing from the bottom of the screen to the top, unlike MM_TEXT which is the other way round. By default, the (0, 0) position is still in the top left of the window.
You can implement zooms and pans simply by modifying the window and viewport extents.
For more information, see Mapping Modes and Translations[^].
|
|
|
|
|
I have made tests with 2 mapping modes :
on screen : mapmode = MM_TEXT : 1 logical unit = 1 pixel
when printing : mapmode = MM_LOMETRIC : 1 logical unit = .1 mm
The problem stays independently of the map mode; i don't think it's a problem
of map mode, since for a same mapmode and a same lfHeight (in the LOGFONT struct),
the effective height of the text will vary with the font.
And my problem is not only that the height changes with the font : for a given font i want that the height of the 'ascent' part of the font is precisely 10 mm, and i can't get that. For example i want digits (these characters have no descent part) of exactly 10 mm.
(Of course i don't set lfHeight = 10, but i apply a factor converting mm to pixels; i know this factor is correct, i use it for drawing lines).
|
|
|
|
|
Hi,
I far as I can remember there is something like a negative height. When the height in the logfont structure is positive it is the height with the leading, when the height is negative it the cell height. But I do not know if it's just the ascending or the ascending+descending.
I vaguely remember that the TEXTMETRICS structure has members for ascent descent and so on.
So for your code the line
HcarFromFont = Metrics.tmAscent should do what you need;
Regards
G. Steudtel
|
|
|
|
|
yes indeed I use a negative lfHeight, it means that height is the character height (ascent + descent, including an internal leading); a positive lfHeight would mean the cell height (= character height + external leading).
G. Steudtel wrote:
HcarFromFont = Metrics.tmAscent should do what you need
so I presume I write :
lf.lfHeight = -HcarWanted; // first try : HcarWanted = 10 mm (in pixels)
font.CreateFontIndirect(&lf);
pDC->SelectObject(&font);
pDC->GetTextMetrics(&Metrics);
HcarFromFont = Metrics.tmAscent;
lf.lfHeight = -HcarFromFont;
font.CreateFontIndirect(&lf);
But don't forget that CreateFontIndirect(&lf) will consider lf.lfHeight as the total character height, how can it known it's meant to be the ascent height ?
Or is there something i didn't grasp ?
Nevertheless I did test the above code : it does not work : the font is now much too small; suppose the initial height was 10 mm : say 6 mm for ascent and 4 mm for descent; so with the 2nd assignment of lfHeight, i will ask a font whose total height is 4 mm.
|
|
|
|
|
Hi,
Sorry that I made it too short. Off course if you take a smaller value you get a smaller font. The fault is by me for not thinking any further.
Two approaches:
1) In a loop increase the height of the font until tmAscent becomes 10.
2) HcarFormFont = INeededHeight*Metrics.tmHeight/Metrics.tmAscent; with iNeededHeight being a constant of 10 ( or what ever height you need).
I'm not so sure about the calculation but the ratio of height to ascent should be the factor to increase the height of the font. Also you should do some casting to double and back to integer to minimize rounding errors. But basically the second method seems reasonable.
Regards
G. Steudtel
|
|
|
|
|
In my first code, i did a similar interpolation that the one you suggest.
HcarFormFont = INeededHeight*Metrics.tmHeight/Metrics.tmAscent.
Nevertheless, using your formula or mine, the results are very near, and on screen the font looks either too small, either too big (it depends of the font).
Note that, curiuously, after having set the height with the interpolation formula, if i request again the metrics with GetTextMetrics(), i see that the height of ascent part is now equal (or very near) to the initial height i requested. So the formula seems to work, and yet on screen that's not OK...
Thanks,
JPG
|
|
|
|
|
For any office document and many other documents as well, you can edit the document's set of properties by right clicking the document's icon, and selecting the summary prop-page. There are for instance etries like "Document title", "Comments" and "Keywords".
In my code, I would like to access this information. That is, given a filename, I want to check if the correspondning file has an entry "Comments" and reads its value.
Can anyone with this knowledge share some hints or, even better an example?
Regards // Jonas Pettersson
|
|
|
|
|
|
Thanx Michale for your help! It got me almost there... I have now extracted the information I wanted from all the Office documents in my application.
The thing is that I also need to do the same thing for a bunch of JPEG-files. Reading the article You proposed, I understand that IStorage and IPropertySetStorage only applies for compund documents, such as the Word documents You helped me inspect. The JPEG files aalso have properties like this - is there another way to access their properties ? Or is their properties stored elsewhere than in the file?
Once again, thank you
Jonas Pettersson
|
|
|
|
|
Hello all, I'm an engineering student looking to go into control systems engineering and automation.
And just because I'm so interested in the field, I've started working on a ride control system (theme park ride) model written entirely in c++. I've designed and written the code for the vehicle, zone, and track objects.
Now,
My current plan is to have ride vehicle motion be powered by a near-infinite loop, with the program going from zone to zone checking zone status and advancing vehicles if certain conditions are met.
Heres a quick outline of how it basically works
Say we have a vehicle, called veh1. veh1 is located at zone 1 on the track. Now, zone 1 has its own characteristics such as integers timeinzone and zoneclearance. timeinzone is the minimum number of milliseconds the vehicle has to spend in the zone before it is able to advance to the next zone. zoneclearance is the number of zones that must be unoccupied ahead of the current zone for the vehicle to be advanced. So, back to veh1, the control loop checks zone 1, sees that veh1 is present, checks how long veh1 has been there (time at zone entry is also stored), and if a move is to be made, it checks the following zones (to comply with zoneclearance) before it gives the go for veh1 to move.
Every zone can have different values and requirements for advancement. There are also certain maximum values and vehicle safety zones that will return errors or stop all vehicle motion if they are intruded.
And, the help I need
I dont think the way i'm doing it right now is very efficient. I was wondering if there was another method to go about this. Keep in mind that I know only console c++, ZERO MFC.
In a perfect world, each vehicle would almost be its own pseudo-sub-program, and evaluate the conditions on its own. Can I do this in C++? There would be several vehicles, in a predefined environment, and they would decide "on their own" what the next logical move would be and send the information to the main control or user console. User intervention would only be required on errors, and all vehicles could send messages to the console, or even to a log file. It would be somewhat event-driven. I suppose its a level of artificial intelligence too. Except that there will be several "robots."
Any help or comments would be appreciated. Even the "YOU SHOULDNT BE WRITING THIS IN C++" comment is welcomed, just tell me what language you feel would be better.
|
|
|
|
|
All signs seem to point to mfc, to use multithreading and event handling.
Comments?
Looks like I'm going to have to bite the bullet here and learn mfc. Any recommendations? Advice? Books? Sites?
|
|
|
|
|
immanis wrote:
All signs seem to point to mfc, to use multithreading and event handling.
Comments?
[/EDIT Because I did not see that you answert yourself]
Here it goes:
If you have to learn anyway, what about a real framework?
wxWindows, QT if you wants to stay platform independent.
.NET or WTL/ATL if being tied to microsoft platforms is OK.
Biggest question I see here is:
Is Windows capable of doing this near-realtime type of stuff? Or would you better look into a different OS? Client server connected via HTML to have the best of both worlds?
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
From the computing standpoint, the overall strategy for a system like this is typically: 1) collect current state data, 2) evaluate system conditions, 3) provide control output. The collection of data from your vehicles and zone sensors already seems to be handled, so you should know what variables you have that define the system "state." The output of control back to the vehicles or to zone-changing controllers is also a finite set of items, and you should know what those are and how they contribute to the system state.
The logic for evaluating the current system state to determine what the next state should be can be described by ... a state transition scheme. Whether this is a large and cumbersome diagram, or a set of "rules," doesn't really matter. In the field of artificial intelligence, you can create a set of if...then rules to describe input conditions that affect output control, and this is a perfectly good method of determining your logic.
When it comes to programming all of this, sure, you could use a rule-based interpretive kind of language, or code the logic into methods within a class, distinguishing of course between vehicle objects, zone objects, input sensor objects, output controller objects, etc. The overall control of these objects, and their interaction, may become a bit messy, depending on how your control logic is formed, because many times the control logic spans many objects and any individual object may not have visibility over the state of other objects. Coordinating the interaction of these separate objects that need visibility of other objects' state can be tricky, and another approach may make more sense.
If you want each object to retain its independence and be an instance of a class, then you will need other classes that have visibility over all these other objects - the "business rules" class, for example. This is where you would put the control logic.
While timing is another consideration, typical Windows environments are able to keep up with a continual stream of inputs and outputs. But, if you depend on microsecond level timing, then Windows may not be the best choice, as the "real time" aspect isn't there. You don't have precise control over process timing, so by definition Windows isn't "real-time." It may be fast enough to keep up, which then makes it operate in "real-time," but this depends on how tight your time frame is.
Is any of this dependent on MFC? No. There are much larger issues to consider. If there is going to be a user interface, either for monitoring or control, then MFC would certainly provide some answers. But, again, there are other issues to consider.
That's my two cents worth.
Dave
"You can say that again." -- Dept. of Redundancy Dept.
|
|
|
|
|
David Chamberlain wrote:
typical Windows environments are able to keep up with a continual stream of inputs and outputs.
As far as I have heard from the engineers in our company, their main problem with windows is not the typical reaction time. With a modern CPU and memory you can get good typical reaction times, but you still have outliers where reaction is much slower.
Depending on the problem, this may be a knockout criterion.
So, while windows may provide a good typical reaction, it can not not guarantee a maximum reaction time.
But I am not an expert in real time programming (not at all) so please ignore me
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|