|
Hi,
Supposing you search in this forum a C++ STL solution
#include<iostream>
#include<strstream>
#include<string>
int main()
{
using std::cout;
using std::endl;
cout << "Enter age" << endl;
int age = -1;
std::string s;
while (age < 0)
{
std::getline(std::cin, s);
if (s.empty())
cout << "Try again!" << endl;
else if (s.find_first_not_of("0123456789") != s.npos)
cout << s << " is not a valid age. Try again!" << endl;
else
std::istrstream(s.c_str()) >> age;
const int HighestAgeEver = 122;
if (age > HighestAgeEver)
{
cout << age << "!! You are kidding. Try again!" << endl;
age = -1;
}
}
cout << "Your age is " << age << endl;
return 0;
}
cheers,
AR
Edited to handle empty input and unrealistic age
And for simpler code flow
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
modified on Wednesday, October 13, 2010 1:37 PM
|
|
|
|
|
Hi all,
I have been working on this project where i receive a stream of data over a UDP port. This Data is to be processed and the result is to be distributed to the clients. To accomplish this end i have created an ATL service along with a connection point interface. Now the actual problem is how to call the Fire_Event method as i have created a thread from the service which reads the data stream. Can someone please help me as to how can i call the fire method as the functions that reads a stream and should generate the event OnDataChange is not member of the Connectionpoint interface.
Thanks and regards,
Pratik
|
|
|
|
|
hi all,
I used vc6.0 ->Create a new Activex project, MFC ActiveX ControlWizard
I created a new button,and want to the button shows Tooltip when the mouse in the button's rect.
here is my code:
BEGIN_MESSAGE_MAP(CTestCtrl, COleControl)
//{{AFX_MSG_MAP(CTestCtrl)
ON_WM_CREATE()
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
//add Tooltip Message
ON_NOTIFY_EX( TTN_NEEDTEXTA, 0, OnToolTipNotify )
ON_NOTIFY_EX( TTN_NEEDTEXTW, 0, OnToolTipNotify )
END_MESSAGE_MAP()
BOOL CTestCtrl::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
{
TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
UINT nID =pNMHDR->idFrom; //
pTTT->lpszText ="Test";
pTTT->hinst = AfxGetResourceHandle();
return(TRUE);
}
it works well in "VC6" and "ActiveX Control Test Container",but in vb or C# or ie,it doesn't show the tooltip,
who can tell me ,how can i do for this issue.
thanks
|
|
|
|
|
Hi All
I have problems to send print in my application.
If I send print and if I change my view before ready to print, all commands will be cancelled.
I send direct to print, print setup is not showed, the view can be closed, and OpenDocumentFile doesn't show this view if command is print;
My application needs fill a graph, reading from a database, while not read all data he is not ready to print, I have a flag to do this.
See my code:
if(pDoc!=NULL)
{
dwTick=::GetTickCount();
nPrintWindowTimeout=5;
if(nPrintWindowTimeout<0)
nPrintWindowTimeout=0;
dwWaitLimit=(DWORD)nPrintWindowTimeout*1000;
if(pDoc->IsReadyForPrintWindow() || (dwTick < item.m_dwTickStart || dwTick - item.m_dwTickStart > dwWaitLimit) )
{
m_arPrintQueue.RemoveAt(0);
pDoc->SetPrinting(TRUE);
if (pDoc->GetView())
{
if (item.m_bPrintSetup == TRUE)
pDoc->GetView()->SendMessage(WM_COMMAND, ID_FILE_PRINT_SETUP);
else
pDoc->GetView()->SendMessage(WM_COMMAND, ID_FILE_PRINT);
}
pDoc->SetPrinting(FALSE);
pDoc->OnCloseDocument();
}
}
}
Somebody, can help me?
Thank you
|
|
|
|
|
Hi,
I have following block of code,
class Base
{
public:
Base()
{
cout<<"Constructor: Base"<<endl;
}
~Base()
{
cout<<"Destructor : Base"<<endl;
}
virtual void fun();
};
class Derived: public Base
{
public:
Derived()
{
cout<<"Constructor: Derived"<<endl;
}
~Derived()
{
cout<<"Destructor : Derived"<<endl;
}
void fun()
{
cout<<" in der";
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Derived obj;
obj.fun();
getche();
In above code virtual fun() is showing error that it not resolved. If i add blank body then Derived class's Fun()is called. Is it necessary to have blank body for virtual function in base class and what is reason of this.
Thanks
abm
|
|
|
|
|
Hi,
Your Base::fun() member is declared but not defined, so the linker complains.
You have to define it somewhere either as pure virtual virtual void fun() = 0; or otherwise:
virtual void Base::fun(){};
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Hi all!
Sorry for my english, I use it very rarely and have bad grammer
I tired to get moving marquee progress bar in my project. I read many articles, try different variants, but nothing work. Progress bar freezes in left side and only, what I can do, change it size, by varying range.
All, wat I do:
1. add refference into manifest file for common controls:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="XPProgress"
type="win32" />
<description>XPProgress</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*" />
</dependentAssembly>
</dependency>
</assembly>
2. change supported windows versions:
#define _WIN32_WINDOWS 0x0501
3. enable common controls:
::AtlInitCommonControls (ICC_COOL_CLASSES | ICC_BAR_CLASSES | ICC_PROGRESS_CLASS);
4. create simple dialog with progress bar:
IDD_DIALOG DIALOGEX 0, 0, 331, 44
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,137,23,50,14
CONTROL "",IDC_PROGRESS,"msctls_progress32",WS_BORDER,7,7,317,14
END
5. create dialog class:
class CDlgMain : public CDialogImpl<CDlgMain>
{
public:
enum { IDD = IDD_DIALOG };
CDlgMain(void);
~CDlgMain(void);
BEGIN_MSG_MAP(CDlgMain)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
MESSAGE_HANDLER(WM_CLOSE, OnClose)
COMMAND_ID_HANDLER(IDOK, OnOK)
END_MSG_MAP()
LRESULT OnInitDialog(UINT , WPARAM , LPARAM , BOOL& );
LRESULT OnClose(UINT , WPARAM , LPARAM , BOOL& );
LRESULT OnOK(WORD , WORD wID, HWND , BOOL& );
};
6. on button click - enable/disable marquee option for toolbar:
LRESULT CDlgMain::OnOK(WORD , WORD wID, HWND , BOOL& )
{
DWORD dwWinLong = ::GetWindowLong(GetDlgItem (IDC_PROGRESS), GWL_STYLE);
if (dwWinLong & PBS_MARQUEE)
{
::SetWindowLong(GetDlgItem (IDC_PROGRESS), GWL_STYLE, dwWinLong & (~PBS_MARQUEE));
::SendMessage(GetDlgItem (IDC_PROGRESS), PBM_SETMARQUEE, (WPARAM) 0, (LPARAM) 100);
}
else
{
::SetWindowLong(GetDlgItem (IDC_PROGRESS), GWL_STYLE, dwWinLong | PBS_MARQUEE);
::SendMessage(GetDlgItem (IDC_PROGRESS), PBM_SETMARQUEE, (WPARAM) 1, (LPARAM) 100);
}
return TRUE;
}
Result is freezed progress bar, that not moving anywhere
I discovered, than, when I change progress bar range to smaller values, visible progress line grow biger, but nowhere moves.
::SendMessage(GetDlgItem (IDC_PROGRESS), PBM_SETRANGE, 0, MAKELPARAM(0, 20));
Someone can tell me, what I do wrong, or what I miss? I read many articles in different sites and forums, but there say, that is enough to enable progress bar animation.
karuuzo
|
|
|
|
|
Hi,
You are mixing the control style, must have PBS_MARQUEE , and it's state.
Set the control style either in your DIALOG resource descriptor:
CONTROL "",IDC_PROGRESS, "msctls_progress32", PBS_MARQUEE | WS_BORDER, 23, 38, 80, 14
or in your OnInitDialog() handler:
LRESULT OnInitDialog(UINT , WPARAM , LPARAM , BOOL& )
{
CProgressBarCtrl(GetDlgItem(IDC_PROGRESS)).ModifyStyle(0, PBS_MARQUEE);
return TRUE;
}
and in your OnOK() handler switch the moving state, for instance:
LRESULT OnOK(WORD , WORD , HWND , BOOL& )
{
static bool bAnimated = false;
CProgressBarCtrl(GetDlgItem(IDC_PROGRESS)).SetMarquee(bAnimated = !bAnimated);
return 0;
}
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Sorry, not working
I already try all variants, what I can imagine - progress bar marquee definition in resource file, using WTL classes, windows messages, but nothing works.
There latest code, but progress bar still dead
LRESULT CDlgMain::OnInitDialog(UINT , WPARAM , LPARAM , BOOL& )
{
CenterWindow();
CProgressBarCtrl(GetDlgItem(IDC_PROGRESS)).ModifyStyle(0, PBS_MARQUEE);
return TRUE;
}
LRESULT CDlgMain::OnClose(UINT , WPARAM , LPARAM , BOOL& )
{
EndDialog(0);
return TRUE;
}
LRESULT CDlgMain::OnOK(WORD , WORD wID, HWND , BOOL& )
{
static bool bAnimated = false;
CProgressBarCtrl(GetDlgItem(IDC_PROGRESS)).SetMarquee(bAnimated = !bAnimated);
return TRUE;
}
IDD_DIALOG DIALOGEX 0, 0, 331, 44
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,137,23,50,14
CONTROL "",IDC_PROGRESS,"msctls_progress32",PBS_MARQUEE | WS_BORDER,7,7,317,14
END
karuuzo
|
|
|
|
|
Hi,
karuuzo wrote: Sorry, not working
What does that mean?
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Nothing shows on the progress bar. I get only this and nothing else.
karuuzo
|
|
|
|
|
I uploaded a working sample at MarqueeTest.zip (6.2 KB)
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
I try on another computer, yes - it works, but on my - no
Looks-like there are problem with my computer. I using Crystal Clear visual theme, may be this is a problem?
Thanks for all, I try do something my self.
karuuzo
|
|
|
|
|
karuuzo wrote: Looks-like there are problem with my computer. I using Crystal Clear visual theme, may be this is a problem?
Sure it's not a WTL or Windows problem
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
In your original post you showed the following line of code:
::SendMessage(GetDlgItem (IDC_PROGRESS), PBM_SETMARQUEE, (WPARAM) 1, (LPARAM) 100);
so I presume your SetMarquee() method does something similar. The LPARAM value in this call affects the speed of the marquee display: the higher the value the slower the marquee. Try setting it to zero for the default behaviour.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
CProgressBarCtrl::SetMarquee from atlctrls.h (WTL):
BOOL SetMarquee(BOOL bMarquee, UINT uUpdateTime = 0U)
{
ATLASSERT(::IsWindow(m_hWnd));
return (BOOL)::SendMessage(m_hWnd, PBM_SETMARQUEE, (WPARAM)bMarquee, (LPARAM)uUpdateTime);
}
Default is 0L
karuuzo
|
|
|
|
|
So, is it working yet or not?
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Yes. I change Windows theme to "Windows XP style" and progress bar start working.
karuuzo
|
|
|
|
|
Guys,
Iam a Fresher looking to build a project on my own as a open source. I want some tools informations which are like ProcessMonitor kind of, can any one let me know about the more tools available in C++/VC++.. Thanks in Advance.
Iam almost trying for microsoft Internship Please help me .... Please..
|
|
|
|
|
There are a couple of tools that hang out in the Back Room...
L u n a t i c F r i n g e
|
|
|
|
|
Get a copy of whole tomato visual assist, it is worth if you're on C++.
|
|
|
|
|
I'm trying to create a pop up list box to display some drawing line styles which are stored in an XML file. I want to display the line and then the name of the style (i.e., the items have strings).
So I derived a class from CListBox, added in some sizing code and the relevant DrawItem function, and dynamically CreateEx'd this to popup off a button in my test dialog app.
However, I'm not getting any owner-draw messages to my popup - it's blank! If I take off the LBS_OWNERDRAWFIXED|LBS_HASSTRINGS style the popup is correctly populated with the style name strings. I added an owner-draw list box to the dialog and re-classified it to use my listbox class, and barring some item sizing issues it draws the items the way I want them drawn.
So what am I not appreciating about the dynamically created version? Where are is WM_DRAWITEM messages going?
Cheers!
|
|
|
|
|
I can sort of make this work, by putting the owner-draw list box 'full-screen' on a borderless dialog (ick!) and then positioning that. But then I run into problems dismissing the dialog when the user clicks off it, and sorting out where the messages go. It would be nicer and neater if the dynamic way worked...
|
|
|
|
|
Hi,
I need to customize a CMFCPropertyGrid such that be able to display a simple button inside.
when user selects given grid, user can press button inside and then a dialog box will be displayed!
exactly like Folder dialog box.
how can i do this?
best regards
|
|
|
|
|
Can you pls help to How to associate CMap key value to CComboBox MFC
Thanks in advance.
|
|
|
|
|