|
std::numeric_limits<int>::min()
std::numeric_limits<int>::max()
|
|
|
|
|
Thanks for your help !
I still have a problem though :
I do :
#include <limits>void main()
{
int LowerLimit=std::numeric_limits<int>::min();
}
And I get these errors when I compile :
warning C4003: not enough actual parameters for macro 'min'
error C2589: '(' : illegal token on right side of '::'
error C2059: syntax error : '::'
I'm using VS 6.
Any idea ?
Thanks !
Jerome
|
|
|
|
|
First time I posted, the forum removed my <int> - I forgot to check the checkbox "Do no treat <'s as HTML tags".
I should be:
#include <limits>
LowerLimit=std::numeric_limits<int>::min();
its a template class - you can use it for any primitive data type, eg.
std::numeric_limits<float>::min();
std::numeric_limits<double>::max();
|
|
|
|
|
<small><b>Rowan Seymour wrote:</b></small>
<i>I forgot to check the checkbox </i>¨
So did I !!!
Here is the line I have in my code :
int LowerLimit=std::numeric_limits<int>::min();
and the errors I get :
warning C4003: not enough actual parameters for macro 'min'
error C2589: '(' : illegal token on right side of '::'
error C2059: syntax error : '::'
It looks like 'min' has many definitions, but the namespace should do it, right ?
I don't see what I'm doing wrong !
Jerome
|
|
|
|
|
|
yes, and using namespace std !
strange....
|
|
|
|
|
Try the following program:
#include <limits>;
#include <iostream>;
int main()
{
int LowerLimit=std::numeric_limits<int>::min();
int UpperLimit=std::numeric_limits<int>::max();
std::cout << LowerLimit << '\n'
<< UpperLimit << std::endl;
}
Don't use any other include statements.
|
|
|
|
|
min is a Win32 macro computing minimum of two parameters. It intererferes with the numeric_limits<>::min() function. The similar example is min(x, y) and max(x, y) function in <algorithm> , so in stl header files distributed with VC are defined as _cpp_min and _cpp_max . But there isn't any similar definition in numeric_limits.
You can use the INT_MIN , INT_MAX macros from limits.h . The numeric_limits class is only a STL wrapper around these macros.
HTH.....Robert-Antonio
|
|
|
|
|
INT_MIN, SHRT_MIN, SCHAR_MIN, SCHAR_MAX, UCHAR_MAX, SHRT_MAX, USHRT_MAX, INT_MAX, UINT_MAX - all defined in ANSI-C and C++, including VS6, see limits.h
Bernd
|
|
|
|
|
Sure. Just use sizeof() in a standard (2**n - 1) calculation to get the most -ive and most +ive number that can be stored in an int . Imho, that's the real programmatic way of figuring this out.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Dear All,
Code project people has helped me a lot during my initial career by flooding me with useful solutions & valuable comments to my doubts. Thanks a lot for that.
I have another small question. I am developing an application in which I am running an executable (the job of this exe is to move some files from one location to the other, etc.). This exe is built using "Win32 Console application" provided in Visual C++ Version 6.0
When I run the application, it calls my exe, and this running exe shows its console window and performs its required operation successfully and close downs decently. BUT I DONOT WANT THAT CONSOLE WINDOW TO BE DISPLAYED DURING MY APPLICATION.
I cannot change the application since I don’t have the code for that, but I can easily do the same for my exe. So can any body please tell me how to hide the console window or console should not be displayed.
Regards,
Rohit Dhamija
|
|
|
|
|
In VB, it would be simple:
Shell "foobar.exe", vbHide
modified on Monday, August 30, 2010 6:46 AM
|
|
|
|
|
See the Console class on my website www.xfcpro.com, under the freestuff section for the full code, but here is a sample of what you need to do.
HWND Console::GetConsoleWindow9X()
{
HWND hWndConsole = NULL;
TCHAR szTempTitle[_MAX_PATH];
TCHAR szTempOldTitle[_MAX_PATH];
if(GetConsoleTitle(szTempOldTitle, _MAX_PATH) > 0)
{
WCHAR szBuff[_MAX_PATH];
memset(&szBuff, 0, _MAX_PATH);
GUID obGuid;
CoCreateGuid(&obGuid);
StringFromGUID2(obGuid, szBuff, _MAX_PATH);
wsprintf(szTempTitle, "%ws", szBuff);
SetConsoleTitle(szTempTitle);
Sleep(50);
if((hWndConsole = FindWindow(_T("tty"), szTempTitle)) == NULL)
if((hWndConsole = FindWindow(_T("ConsoleWindowClass"), szTempTitle)) == NULL)
hWndConsole = FindWindow(NULL, szTempTitle);
SetConsoleTitle(szTempOldTitle);
}
return hWndConsole;
}
void Console::ShowConsoleWindow(bool bHide )
{
HWND hWndConsole = NULL;
#if(_WIN32_WINNT >= 0x0500) // Windows 2000 and later only
hWndConsole = GetConsoleWindow();
#else
hWndConsole = GetConsoleWindow9X();
#endif
ShowWindow(hWndConsole, (bHide) ? SW_SHOW : SW_HIDE);
iLastErrorCode_ = XFC_SUCCESS;
}
regards,
Dark Angel
|
|
|
|
|
Thanks Dear,
I am developing my application only for Windows2000 (no Win9x systems)
So I there any simpler way out for my doubt ??
Thanks a lot.
Regards,
Rohit Dhamija
|
|
|
|
|
Hi Rohit,
For Windows 2000 just add the following function to your code and call it at the start of your application.
void ShowConsoleWindow(bool bHide )
{
ShowWindow(GetConsoleWindow(), (bHide) ? SW_SHOW : SW_HIDE);
}
Then to hide the console window, call:
<code>
ShowConsoleWindow(true);
and to show it again (if necessary):
<code>
ShowConsoleWindow(false);
best wishes,
Dark Angel
|
|
|
|
|
Hello,
in my application I use the activex component msflxgrd.ocx. I use it in a dialog and in a view. At a PC without visual c++ installed I only can see the component in the dialog not in the view. I copy the component in C:\Winnt\system32, and I register it.
Do I need some dll or library?
Thank you.
|
|
|
|
|
Hi,
I need to simulate the process OS detecting the device when is it connected to system thru USB port and loads a driver. OS should treat my application as a device and load its driver..plz any one help me out this .
|
|
|
|
|
hi ,
i have the following problems... would be gratefulif you could kindly give me some suggestions.....
1)i have a dialog based application in which i have to implement a scroll view .. can i use CSrollView(i suppose i cant)..if not how do i do it..if yes then how do i do it
2)i have to capture the entire image irrespective of being within the viewable region or not ....how do i go about it....
plesae help...
Thanking you.
Satadru
|
|
|
|
|
1) to use Views in a Dialog there is a splended article in MSDN with sample code that should help
( but i can't figure out why you have to use CScrollView it doesn't provide anything else other than scrolling support
you can use scroll bars on the dialog instead)
2)if that image is not completely displayed than you cannot capture it (it would be like , you give the application ur DC and ask it to paint on it )
but you can try to get that window's DC and Bitblt (might work)
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
hi ,
thanks for the help cud u please tell me which article is that.... i have another problem..
from my main dialog iam creating another dialog and popping it....from this second dialog i have to access members of the main dlg ... how do i go about it ... i have tried DYNAMIC_DOWNCAST but it isnt working in my compiler ... any way ouy...
Thanking you.
Satadru
|
|
|
|
|
class CAnotherDlg .....
{
CDialog *m_pPrevDlg;
}
CFirstDialog :: OnInitDialog()
{
CAnotherDialog dlg;
dlg.m_pPrevDlg = this;
dlg.DoModal();
}
now whenever you use the m_pPrevDlg just cast it and use it
((CFirstDialog*)m_pPrevDlg)->FireAway();
(Don;t forget to include the firstdialog.h )
as for not finding the article it is by Paul dilascia and it show how to use CHTMLView in a dialog
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
Hello guys,
I am still having trouble to catch "Enter" (Return) key press from a PC keyobard in my app. I think the problem mainly comes from the fact that the app has a parent dialog with serveral embedded child dialogs (only one child dialog is shown at a time on the app window, different child dialog is shown using ShowWindow(SW_SHOW), ShowWindow(SW_HIDE).
Preferrably, I want the child dialogs to catch the "Enter" key press. So what I did, was first, "return 0" in the parent class' OnInitDialog() and set the focus to the appearing child's DDX control, say a CButton, in the child class' OnShowWindow().
With the above method, I can get the focus set (using SetFocus()) to each desired CButton in the child dialogs and I can cycle through the buttons (if there are multiple) in each shown child dialog using arrow keys. However, none of the buttons will not respond to "Enter" key, but only "Spacebar" key to perform OnBnClicked() function. If I "tab" to the button that belong to the parent dialog, pressing the "Enter" key will call the OnBnCliked(). Can anyone explain why?
Also, I tried to see if the Enter key is caught in the child class by overriding its OnOk() or OnKeyDown() but the key pressed doesn't seem to go through them either.
|
|
|
|
|
i don't understand you! but i think this may be help you:
BOOL CMyCTIDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_KEYDOWN)
if(pMsg->wParam==VK_ESCAPE||pMsg->wParam==VK_RETURN)
return true;
return CDialog::PreTranslateMessage(pMsg);
}
|
|
|
|
|
Thanks alot for the reply, taiozi.
And apologies for the badly phrased post, I wrote that in a rush. I have rewritten it. Would appreciate if you could give it one more read and see if you can understand it now
However, the PreTranslateMessage() you mention here might be what I am looking for, I will try that in my child dialogs' classes. Will report back.
Thanks again
|
|
|
|
|
Thanks tiaozi,
with your help (the code), I can correctly catch the Enter key press(VK_RETURN) and tell if it's caught by the parent dialog or the embedded child chialog. Now I realise when the app was initially load, the key press is always caught by the parent, although a button in the child dialog has been highlighted (here I'd think so the focus is set to the child dialog?).
Do you know how I can correctly set the focus to child dialog when the app is loaded? I've tried two different ways, none of them seem to work.
One is to place pChildDlg->SetFocus() in the parent class' OnInitDialog(). pChildDlg is the pointer to the child dialog that is showing.
Two is to place SetFocus() in the child class' OnShowWindow(), whether to the child itself (thus this->SetFocus(); ) or a control (in my case, to a CButton). Here as I mentioned earlier, when I SetFocus() to the CButton, I can see the button is highlighted as the app window is initially loaded. But when I hit "Enter" key, this input message is still caught by the parent?
|
|
|
|