|
Hello Friends
I created a Dialog based application in MFC Inherited from CFormView. I created this application on resolution 1024 X 768. But when I am opening the same application on another system with Higer Resolution then window is opening of full size in window with Extra Blank space in application other than Controls.
Can we make application size Constant or make maximize button disable so tht on Higher resolution Desktop,it will not open up with blank space ?
Or
Can we resize controls according to resolution ?
Thanks & Regards
Yogesh Sikri
|
|
|
|
|
|
I need help starting a do-while loop in my program that runs up to 10 time that asks the user to enter up to 10 scores, which include the slope and rating for the course, and calculates the handicap for each score. Any help is greatly appreciated. Here's what I have so far:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int score, slope;
double rating, handicap;
string name;
cout << "This program calculates a golfer's handicap.\n";
cout << "Enter your name: ";
cin >> name;
cout << "Hello " << name << endl;
cout << "Please enter your score: ";
cin >> score;
cout << "Please enter the course slope: ";
cin >> slope;
cout << "Please enter the course rating: ";
cin >> rating;
handicap = (score-rating) * 113 / slope ;
cout << "Your handicap is " << handicap << endl;
return 0;
}
|
|
|
|
|
think count adding a counter to count the number of scores, maybe
int scorecount = 0;
and at the end of a score 'collect', increment the counter
scorecount += 1;
then you need to add something like
do
{
}
while scorecount
around your logic - you textbooks/google should also be able to fill these gaps in for you
Question : are you sure do-while is what you really need here - what are the pitfalls with it ?
'g'
|
|
|
|
|
Thank you very much Garth. Yes my text calls for a Do-While loop that runs up to 10 times and asks the user to enter up to 10 scores, which include the slope and rating for the course, and calculates the handicap for each score. Then I'll need to use either parallel arrays or a two-dimensional array in order to store the score, slope and rating for each entry, and variables for the handicap accumulator and number of scores entered.
|
|
|
|
|
fair enough - you can see then using a counter, that you might like to use that as the array index to store the values as well - just a thought
'g'
|
|
|
|
|
Well,i'm glad to help you.It's my way to solve the problem.In my point,it's exactl solution.Thank you.
Quote: //This program calculates a golfers handicap.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int score, slope;
double rating, handicap;
string name;
int time=1;
cout << "This program calculates a golfer's handicap.\n";
cout << "Enter your name: ";
cin >> name;
cout << "Hello " << name << endl;
//Have the user to input their name, score, slope, and handicap.
do{
cout << "Please enter your score: ";
cin >> score;
cout << "Please enter the course slope: ";
cin >> slope;
cout << "Please enter the course rating: ";
cin >> rating;
//Calculate the golfers handicap
handicap = (score-rating) * 113 / slope ;
cout << "Your handicap is " << handicap << endl;
time++;
}while(time<=10);
return 0;
}
|
|
|
|
|
behavior of <dynamic_cast> with abase/derived scenario and how it is useful.thanks in advance.
|
|
|
|
|
here[^], here[^], maybe here[^] I'm sure there are examples all over the web.
|
|
|
|
|
jeron1 wrote: I'm sure there are examples all over the web. I'm sure you are pretty right.
Veni, vidi, vici.
|
|
|
|
|
dynamic_cast must be useful in parent child relation of classes. It helps to determine object type in a hierarchy.
i.e - class Base{
};
class Derived1:public Base{
void der1Fun(){}
};
class Derived2:public Base{
};
int main()
{
Base *bPtr = new derived1();
//now we want to call a derived1 function let der1Fun()
Derived1* dPtr = 0;
if( dPtr = dynamic_cast<derived1*>(dPtr) ){
dPtr->der1Fun()
}
else{
//Display the object is not of derived1 type
}
return 0;
}
I think this is why we need dynamic_cast.
|
|
|
|
|
In general I would suggest you don't use it, having to tends to suggest you have some badly designed code. Prefer inheritance and virtual functions.
Steve
|
|
|
|
|
I concur with Stephen. Almost every example I've seen is contrived. There are a few exceptions, though with some of those better design would prevent having to use it.
|
|
|
|
|
i write a class derived from CHtmlView, and write the code as below, when it run, no bar appear, and a messageBox show a string '0x80040100', what is the reason? how can i make it work. any suggestion or help are appreciated
void CXxView::OnShowBar()
{
IWebBrowser2 *pBrowser = NULL;
HRESULT hr = m_pBrowserApp->QueryInterface(IID_IWebBrowser2, (void **) &pBrowser);
if (SUCCEEDED(hr))
{
VARIANT vtBandGUID, vtShow;
vtBandGUID.vt = VT_BSTR;
vtBandGUID.bstrVal = SysAllocString(OLESTR("{30D02401-6A81-11d0-8274-00C04FD5AE38}"));
vtShow.vt = VT_BOOL;
vtShow.boolVal = TRUE;
HRESULT hrx = pBrowser->ShowBrowserBar(&vtBandGUID, &vtShow, 0);
if (FAILED(hrx))
{
CString _str;
_str.Format("0x%x", hrx);
AfxMessageBox(_str);
}
SysFreeString(vtBandGUID.bstrVal);
pBrowser->Release();
}
}
|
|
|
|
|
It is what you asked for
_str.Format("0x%x", hrx);
AfxMessageBox(_str);
"0x%x" means put a 0x in front and return the hex and hence you get 0x80040100
IWebBrowser2::ShowBrowserBar returns either S_OK status or E_FAIL see the documentation
http://msdn.microsoft.com/en-us/library/aa768268%28v=vs.85%29.aspx[^]
So it is returning E_FAIL and the value is given.
Now as to what the problem is I have suspicions on this line
vtShow.boolVal = TRUE;
Are you sure I thought these had to be lower case true or VARIANT_TRUE which is the same thing but definitely all Microsoft code I have ever seen uses VARIANT_TRUE
If that isn't it I guess there is something with the GUID implementation and talk to Microsoft.
|
|
|
|
|
thank you for your help. i use VARIANT_TRUE and true, the problem keeps the same. and i copy the guid from msdn, it also keeps the same. anyone more suggestions?
|
|
|
|
|
Hi,
I see two errors:
Leon de Boer is correct that you should set vtShow.boolVal to VARIANT_TRUE ;
I see another error... the third argument to ShowBrowserBar Function[^] should be a pointer to an empty VARIANT... not a NULL pointer.
VARIANT vtEmpty = {0};
Best Wishes,
-David Delaune
|
|
|
|
|
thank your help info. i change the variable as code below, but the problem keeps the same:
IWebBrowser2 *pBrowser = NULL;
HRESULT hr = m_pBrowserApp->QueryInterface(IID_IWebBrowser2, (void **) &pBrowser);
if (!SUCCEEDED(hr))
return;
VARIANT vtBandGUID, vtShow;
vtBandGUID.vt = VT_BSTR;
vtBandGUID.bstrVal = SysAllocString(OLESTR("{30D02401-6A81-11D0-8274-00C04FD5AE38}"));
vtShow.vt = VT_BOOL;
vtShow.boolVal = VARIANT_TRUE;
VARIANT vtEmpty = {0};
hr = pBrowser->ShowBrowserBar(&vtBandGUID, &vtShow, &vtEmpty);
SysFreeString(vtBandGUID.bstrVal);
pBrowser->Release();
|
|
|
|
|
Hi,
Your code appears to be absolutely correct. The error you are encountering could be caused by the browser control not supporting explorer bars.
Best Wishes,
-David Delaune
|
|
|
|
|
thank you for you reply.
i think the reason is as you pointed out.
my enviroment: windowsXP sp3 + IE8
|
|
|
|
|
i write a class derived from CHtmlView, and write the code as below, when it run, no bar appear, and a messageBox show a string '0x80040100', what is the reason? how can i make it work. any suggestion or help are appreciated
void CXxView::OnShowBar()
{
IWebBrowser2 *pBrowser = NULL;
HRESULT hr = m_pBrowserApp->QueryInterface(IID_IWebBrowser2, (void **) &pBrowser);
if (SUCCEEDED(hr))
{
VARIANT vtBandGUID, vtShow;
vtBandGUID.vt = VT_BSTR;
vtBandGUID.bstrVal = SysAllocString(OLESTR("{30D02401-6A81-11d0-8274-00C04FD5AE38}"));
vtShow.vt = VT_BOOL;
vtShow.boolVal = TRUE;
HRESULT hrx = pBrowser->ShowBrowserBar(&vtBandGUID, &vtShow, 0);
if (FAILED(hrx))
{
CString _str;
_str.Format("0x%x", hrx);
AfxMessageBox(_str);
}
SysFreeString(vtBandGUID.bstrVal);
pBrowser->Release();
}
}
|
|
|
|
|
I just can't understand the meaning of unique_ptr or auto_ptr, as we all know, once the parameter gets out of its scope, we won't get memory leaks. However, is it a better idea if I create the parameter on the stack rather on the heap. I don't see its advantage over normal parameters. If we really need to create parameters on the heap, then we must use '
new ' operator, right?
Here is a little code snippet:
class Base
{
public:
Base()
{
cout << "Base::()" << endl;
}
virtual ~Base()
{
cout << "~Base()" << endl;
}
virtual void iPhone()
{
cout << "I'm iPhone5s" << endl;
}
};
class Derive : public Base
{
public:
Derive()
{
cout << "Derive()" << endl;
}
virtual void iPhone()
{
cout << "I'm iPhone 6" << endl;
}
virtual ~Derive()
{
cout << "~Derive()" << endl;
}
};
void main()
{
{
auto_ptr<Base> ptr(new Derive()); ptr->iPhone();
Derive d; Base* base = &d;
base->iPhone();
}
}
|
|
|
|
|
Note: std::auto_ptr has been (mostly) replaced by std::unique_ptr .
The use of std::unique_ptr and std::shared_ptr offer better memory management (garbage control, ... ) than naked pointer (google for the difference between unique and shared).
{
Derive* p = new Derive;
}
{
std::unique_ptr<Derive> p(new Derive);
}
In all (most) cases it would be better to not use pointers at all; but when it happens, use std::unique_ptr or stdshared_ptr depending on your need.
So in your example, it could simple be :
{
Derive d;
d.iPhone();
}
In simple examples using one or the other will probably not make a difference, but in larger systems, it will.
I'd rather be phishing!
|
|
|
|
|
It's essentially meant for the cases where you do need the heap... when you're already using new/delete. It eliminates the need to call delete explicitly and prevents leaks by taking care of the deallocation automatically. That's pretty much the crux of it (I personally don't use it at all).
|
|
|
|
|
I never found it especially useful. By the time it arrived I had disciplined myself when I created code that I didn't see failures to deallocate anymore.
I did find that attempting to refactor code (others) that did have problems was at best a futile exorcize but maybe I never understood it in detail enough.
|
|
|
|