|
Michael Imamura wrote:
Of course, the strongest random number generators are ones which use a random natural source rather than an algorithm.
On Windows, use CryptGenRandom . This uses the process ID, thread ID, milliseconds since boot, current local time, the high-precision performance counters accessed by QueryPerformanceCounter , a hash of the environment block, some of the processor's internal counter registers, and various of the system's running counters (things like bytes transferred per second, context switches per second). Information from Writing Secure Code, Second Edition (Michael Howard & David LeBlanc, MS Press).
|
|
|
|
|
I want to create a slider control by command. I have done following but it doesn't appears in the dialog
<br />
CSliderCtrl m_createslider;<br />
const RECT rc = {20,200,500,60};<br />
m_createslider.Create (WS_TABSTOP|WS_CHILD|WS_VISIBLE|TBS_AUTOTICKS |TBS_TOOLTIPS|TBS_RIGHT|TBS_BOTTOM , <br />
rc, this, IDC_MYSLIDER);<br />
m_createslider.ShowWindow(SW_SHOW);<br />
Please tell me why.
vhunghl
|
|
|
|
|
Where did you put this code?
If you put it in OnInitDialog(), the slider will be destroyed when you exit this function because m_createslider goes out of scope. Declare m_createslider as a member of your dialog class.
|
|
|
|
|
I have declared folowing
<br />
class CexplDlg : public CDialog<br />
{<br />
public:<br />
CexplDlg(CWnd* pParent = NULL);
<br />
enum { IDD = IDD_EXPL_DIALOG };<br />
<br />
protected:<br />
virtual void DoDataExchange(CDataExchange* pDX);
<br />
<br />
protected:<br />
HICON m_hIcon;<br />
<br />
virtual BOOL OnInitDialog();<br />
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);<br />
afx_msg void OnPaint();<br />
afx_msg HCURSOR OnQueryDragIcon();<br />
DECLARE_MESSAGE_MAP()<br />
public:<br />
CSliderCtrl m_createslider; <br />
};<br />
|
|
|
|
|
I have called waveOutReset command and then waveOutClose command, but it doesn't happen MM_WOM_DONE event.
vhunghl
|
|
|
|
|
Hi,
This might sound a bit silly as this is not supposed to be a question in the VC++ forum. Nevertheless, I hope I can get an answer from somebody
How to find whether a file already exists in a folder?
Regards and thanks in advance
Deepak Samuel
|
|
|
|
|
WIN32_FIND_DATA wsd;
HANDLE hFind = FindFirstFile(pszFileName, &wsd);
if(hFind != NULL)
{
//the file does exist
}else{
MessageBox(NULL, "Error", "The specified file does not exist.",MB_OK);
}
FindClose(hFind);
|
|
|
|
|
Open up "My Computer" and double-click the folders to the right directory...
I take it you're asking about file existance from an fstream point of view. If you're looking if "foo.txt" exists you can do something like the following:
ifstream fin( "foo.txt" );
if ( fin )
{
}
else
{
}
You could also use the ios flags ios::nocreate and ios::noreplace with an ofstream object:
ofstream fout( "foo.txt" ios::noreplace )
if ( fout )
{
}
else
{
}
||
ofstream fout( "foo.txt" ios::nocreate )
if ( fout )
{
}
else
{
}
Hopefully that helped a little.
Always Fear the Man with Nothing to Lose
Jeryth
|
|
|
|
|
From MSDN Library
/* ACCESS.C: This example uses _access to check the
* file named "ACCESS.C" to see if it exists and if
* writing is allowed.
*/
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
void main( void )
{
/* Check for existence */
if( (_access( "ACCESS.C", 0 )) != -1 )
{
printf( "File ACCESS.C exists\n" );
/* Check for write permission */
if( (_access( "ACCESS.C", 2 )) != -1 )
printf( "File ACCESS.C has write permission\n" );
}
}
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt__access.2c_._waccess.asp
|
|
|
|
|
I'm new to operator overloading so this may come off as a stupid question, but I'll risk it. I'm making a simple BlackJack game and have two ENUM s that I want operators to work on. Here's a little of what I'm working with:
enum SUIT { CLUB, DIAMOND, SPADE, HEART };
void operator++( SUIT &suit )
{
switch( suit )
{
case( CLUB ):
suit = DIAMOND;
break;
case( DIAMOND ):
suit = SPADE;
break;
case( SPADE ):
suit = HEART;
break;
case( HEART ):
suit = CLUB;
break;
default:
;
}
}
The '--' operator looks nearly identical. I keep getting a compile error C2676: binary '++' : 'SUIT' does not define this operator or a conversion to a type acceptable to the predefined operator. Where's my problem coming from? Also, any ideas for tricks to overload the '+' & '-' operators without having to make a very long switch ?
Always Fear the Man with Nothing to Lose
Jeryth
|
|
|
|
|
Your code seems to work fine in VS.NET 2K3:
SUIT f = CLUB;
++f; Are you trying to use the postfix version of operator++ ? If so, you need to add another function with a dummy int parameter:
SUIT operator++(SUIT &suit,int){
SUIT old = suit;
++suit;
switch( old ) {
case( CLUB ):
return DIAMOND;
break;
case( DIAMOND ):
return SPADE;
break;
case( SPADE ):
return HEART;
break;
case( HEART ):
return CLUB;
break;
default:
return DIAMOND;
}
}
- Mike
|
|
|
|
|
No it was prefix and I'm on 2K3 as well. However your code had a return on it. I understand the purpose of the return here, postfix == fetch value THEN increment, does the prefix need one too?
Always Fear the Man with Nothing to Lose
http://www.dragonfiresoft.com
Jeryth
|
|
|
|
|
You can choose to have a return or not on the prefix, but to maintain the standard semantics of prefix increment it really should return a value. So, the declaration for the function changes to:
const SUIT &operator++(SUIT &suit) and just add
return suit; to the end of the function.
For reference, here's the test program I'm using:
enum SUIT { CLUB, DIAMOND, SPADE, HEART };
const SUIT &operator++(SUIT &suit) {
switch( suit ) {
case( CLUB ):
suit = DIAMOND;
break;
case( DIAMOND ):
suit = SPADE;
break;
case( SPADE ):
suit = HEART;
break;
case( HEART ):
suit = CLUB;
break;
default:
;
}
return suit;
}
SUIT operator++(SUIT &suit,int){
SUIT old = suit;
++suit;
return old;
}
int _tmain(int argc, _TCHAR* argv[]) {
SUIT f = CLUB;
SUIT v = ++f;
return 0;
} Note the fixed postfix increment... I blame insufficient caffeine when I replied earlier
- Mike
|
|
|
|
|
Hi Jeryth
You cannot redefine the meaning of an operator when applied to built-in data types. Your SUIT enum is nothing but an ordinary int. I think that this is your problem...
greets,
Jason
|
|
|
|
|
That's what I thought as well, enum s get referenced to as int s for boolean and conditional arguments. I'm not sure but I think .NET changed that. When I hadn't overloaded any operator I still got an error saying no operator existed that returned an appropriate type.
Always Fear the Man with Nothing to Lose
DragonFire Software
Jeryth
|
|
|
|
|
I have a dialog based app which is launching a process and then waiting for it to finish. The problem is that if I click on the parent window before the child process window displays then it seems to get the focus and is on top of the child window when it finally does display.
How can I make it so that child window will always be displayed on top of the launching app's window? regardless of mouse clicks or anything else the user might do
(I don't have access to the source code for the child process, so can't make any mods there)
|
|
|
|
|
Make your child dialog as modeless and then add the following codes in your child dialog initDialog handler
CRect rect;
GetWindowRect( rect );
::SetWindowPos(
m_hWnd ,
HWND_TOPMOST,
rect.left,
rect.top,
rect.Width(),
rect.Height(),
SWP_SHOWWINDOW
);
It basically set your child windows on top most in the z-order of the windows.
Hope this helps.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Hi,
I've been having a problem with CTabCtrls:
I've derived a class from CTabCtrl which will load in the setup of controls from a file and put them on to their respective tabs. The problem comes with tooltips, the controls are created ok, but the controls have no tooltips.
I've called EnableToolTips(TRUE) to enable tooltips (within the new class) and set up a message handler for the TTN_NEEDTEXT message, and the handler fills in the structure ok. If the controls are created on a dialog (without the CTabCtrl) the tooltips work ok, its' only if the controls are in the CTabCtrl that they don't work...
Any Ideas?
Thanks in advance.
Andy Vincent
andyvinc at hotmail dot com
|
|
|
|
|
Your CTabCtrl probably should route Mouse Messaeges to active control inside of it. You can do it in PreTranslate message handler for CTabCtrl if it's subclassed...
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
Has anyone had any experience creating an XML editor (even a rudimentary one) from scratch? And I don't mean one of the 'editors' wherein a treeview is used and the text for each element is represented by a node. I'm not even concerned about parsing ability (I've already created a parser). I just wondered if anyone had come up with a good architecture that would allow one to identify the element in which the caret is currently positioned in a contiguous display of the whole instance's text.
Sorry if this isn't clear!
things could always be worse...
|
|
|
|
|
Yeah, I know this is probably a dumb question, but how do you create .lib files? I have some classes that I would like to convert to class libraries. Any help that would point me in the right direction would be appriciated. I tried searching around for it, but nothing useful. It seems like such a standard thing, but I can't find anything on it.
Thanks
|
|
|
|
|
If you run Visual Studio .NET 2002/2003, just choose a new project of type "Win32". Then select "static library" in the project wizard. You're ready to go.
--
The coolest game in the world: NHL Hockey[^]
|
|
|
|
|
Thanks. That was easy
|
|
|
|
|
You could do the same in Visual C++ 6.0 not just VS.NET
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
I have a sort of Service which resides in a dll. Whenever something happens in the system the functions from this DLL are called. Now my question is, i am trying to make a sort of control panel thing where i can set options that the DLL code will abide by, and when the control panel is closed these options will be saved. Also, the DLL code must be able to pass information to this control panel to display some status and other data. My question is, how can i let these communicate? Do i just use FindWindow() from the DLL code to get the window handle and access it that way? But i thought maybe this is too... heavy or whatever i should call it, like if the DLL functions are suddenly called a lot by the system then it would always do a findwindow first, wouldn't that slow things down too much? Anyways, i don't know. Thats why i'm asking
Thanks in advance
Kuniva
--------------------------------------------
|
|
|
|