|
can you reformat the listing so it is easier to read ? (use the > < buttons below )
also, use srand to regenerate the random number generator (look in msnd for a full example)
Maximilien Lincourt
"Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
|
|
|
|
|
Some of the most immediate problems are your #includes aren't correct. Also (unless you have a custom stdlib.h) there is a typo - your first include should be stdlib, not cstdlib. the #includes should look like #include <stdlib.h> (actually, you probably had it correct, but because they look like HTML tags to the server processor, they got stripped). Also namespace is a C++ specific feature but in C++ you can't have locally defined functions (your int nrand(int n). You'll need to break out your nrand and call it from your main.
Create a NRand class and header file and save them in their own source files. #include the header in your main source file. Then you'll need to call the class with an integer. I didn't even look at the logic contained in your loop. Try to get a good compile and then check back in!
|
|
|
|
|
Look at my modification:
#include <cstdlib>
#include <iostream>
using namespace std;
int nrand (int n)
{
int x = RAND_MAX / n;
int r;
do r = rand() / x;
while (r >= n);
cout<<r;
return r;
}
void main()
{
}
Allan
|
|
|
|
|
Hint: if you have a space before and after the < > they get not deleted by the stupid HTML-interpreter at CP.
I did find a few things in your program.
First:
In your main() , you need to seed the random-generator, or you will get the same list of random numbers over and over. Use srand() for that. You can find an example how to do it in the MSDN.
Second:
You should do the cout in your main, after the call to your nrand -function. Separates the logic in natural parts: nrand() gets you a number, but does not say what to do with it, and main() uses the number to do whatever must be done, but does not bother how to generate it.
Third:
Your main sould be of return type int , and you do return 0; if all went well, otherwise something different (right now cant see why you would want to return anything other than 0.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
Thanks all,
I will work with your suggestions.
Dave
"The man who reads nothing is better educated than the man who reads nothing but newspapers."- Thomas Jefferson
|
|
|
|
|
Hi, how can I implement a windows like IntelliSense which does not steal the focus of the activated windows. Could you help me. Thank you!
|
|
|
|
|
That would be a tool tip window. Create it with the WS_EX_TOOLWINDOW and WS_EX_TOPMOST extended styles, and the WS_POPUP style. Then to show the window, use SetWindowPos() inserting it after HWND_TOPMOST and using the SWP_NOACTIVATE and SWP_SHOWWINDOW flags.
WNDCLASS WndClass = {0};
WndClass.hInstance = hInstance;
WndClass.lpnfWndProc = ::DefWndProc;
WndClass.style = CS_SAVEBITS;
WndClass.hIcon = NULL;
WndClass.hbrBackGround = (HBRUSH)(COLOR_INFOBK + 1);
WndClass.lpszClassName = _T("MyToolTipClass");
::RegisterClass(&WndClass);
HWND ToolTip = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
_T("MyToolTipClass"),
_T(""),
WS_POPUP | WS_BORDER,
[EDIT] 0, 0, 0, 0, [/EDIT]
NULL,
NULL,
hInstance,
NULL);
SetWindowPos(ToolTip,
HWND_TOPMOST,
position.x,
position.y,
width,
height,
SWP_NOACTIVATE | SWP_SHOWWINDOW);
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Thank you very much for your help! I will try it.
|
|
|
|
|
I am developing an MFC SDI program that needs to know what the screen res is because it needs a res of is 1024x768 or above to show its UI child windows properly. How would I get the size of the screen resolution that the user has set? Thanks.
bneacetp
|
|
|
|
|
You can use the GetDeviceCaps function retrieves device-specific information for the specified device. Visit the MSDN for its reference.
|
|
|
|
|
|
use..
DEVMODE devmode;
::EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &devmode)
width =devmode.dmPelsWidth;
height =devmode.dmPelsHeight;
u r done with the screen resolution..
cheers
Himanshu
|
|
|
|
|
::GetSystemMetrics(SM_CXSCREEN)
::GetSystemMetrics(SM_CYSCREEN)
Gets the same values as GetDeviceCaps.
|
|
|
|
|
Hello,all
How control the size of a window meta file(WMF) when paste it into a richedit?
example:
//write a WMF and put it into the clipboard.
void copy()
{
CMetaFileDC * m_pMetaDC = new CMetaFileDC();
CRect rc(0,0,20000,20000);
m_pMetaDC->CreateEnhanced(GetDC(),_T ("c:\\test.wmf"),&rc,"name");
//drawing the lines in the DC.....
HENHMETAFILE hMF= m_pMetaDC->CloseEnhanced();
//copy to the clipboard
OpenClipboard();
EmptyClipboard();
::SetClipboardData(CF_ENHMETAFILE,hMF);
CloseClipboard();
}
//then paste the file in a CRichEditView.
void CMyView::PasteIt()
{
GetRichEditCtrl()->Paste();
//clear the clipboard
OpenClipboard();
EmptyClipboard();
CloseClipboard();
}
In windows2000, I can control the size of the metafile with the third parameter of the function CreateEnhanced().But in Win98, the parameter have no effect on the program. Why? How control the size in win98?
Thanks a lot.
Yes,Free Code project~~~~
|
|
|
|
|
Oh,I've got it.
With CF_METAFILEPICT.
Yes,Free Code project~~~~
|
|
|
|
|
Hi,
I am writing a third-party filepacker/launcher for a small game engine. I have completed the launcher and filepacker, but because it is third-party, there are certain undesirable aspects that I would like to improve upon, and I was wondering if anybody here had any suggestions.
Essentially, as it is, the game engine leaves all of its files (models, bitmaps etc) open in the game directory. Obviously it's a good idea to pack these so that players can't just open the bitmaps and find out what is to come in later levels (ruining the "surprise"). However, the engine needs all of the files present in order to run (or rather, it needs some files present; others it loads when they are called in-game).
Thus (remember that I have no access to any of the game code - not that I am a good enough coder for that anyway - but am just writing an external packer), for my file-packer, I have had to resort to zipping the files (all game files, executable and all) up with password protection (using the excellent ZipArchive library from www.artpol-software.com), and then having the launcher extract the files to a temporary directory on the hard-drive when started and run the game from there (the files are deleted when the game closes). This means that most players will never see the files, which is certainly better than nothing. However, anybody can easily find the files by alt-tabbing out of the game and searching the hard-drive (and it also means that more hard-drive space is required). (The insecurity of the packer means that it won't appeal to many of the other developers using the engine - who will be the main users of my program - whose chief priority is protecting their files from each other...)
I was wondering if anybody here had any suggestions of how I could better protect these files. I had thought of trying to extract and run them from memory, but this seems an almost impossible task, and besides which, it would consume precious memory that the game requires to run (as I understand it).
The packer and launcher have been written using the Windows API, the ZipArchive library, and *no* MFC. I have hacked my way through the programming (with a lot of help from people here), but I am still a novice at C++, so if anybody does have any suggestions, I would be really grateful if you could explain it as simply as possible and tell me where to look for examples of what I need to do.
That's probably a lot to ask, and it's probably impossible anyway, but it's worth a shot!
Any suggestions would be really appreciated.
Many thanks,
KB
|
|
|
|
|
Have a look at www.flipcode.com, there are heaps of examples of how to solve these problems, and more with filepackers. I think the Code-Of-The-Day sample at the moment is a filepacker, but the archives have some good examples as well.
From what I can remember most of the suggestions are about unzipping to memory, using a secondary thread. The idea being that before you know you are going to need something, you send a request to the unpacker, which queues the request and saves the memory block which you can get later. If the memory hasn't loaded, then you have to wait.
Sorry about the bad explanation, but the people on the flipcode message boards have heaps more experience on this stuff.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Thanks! I've been looking at flipcode at their packer code, still trying to work it out.
(Any more suggestions still welcome.)
Cheers,
KB
|
|
|
|
|
How to add a default bitmap to the picture control?
Thanks
rapace
|
|
|
|
|
hi...
you can use like that;
CStatic my_Static=(CStatic*)GetDlgItem(IDC_STATIC...);
myStatic.SetBitmap( ::LoadBitmap(NULL, MAKEINTRESOURCE(.....)) );
Good Work....
|
|
|
|
|
|
Is there a way to create an MHT file from my program? It is my understanding that it is a multipart mime object, but I don't know how to create that either. Thanks for the help.
Darroll Walsh
|
|
|
|
|
Hey guys,
i wondered if anyone knows how to use this new screen in windows xp, which is used while the os is changing settings (e.g.: background-color, power off screen,...)
using: visual studio 6.0
greets ckr
|
|
|
|
|
Hi, I have MFC application with splitter window that divides client area to two views, both are CListView-derived classes. Because I want to keep columns to have stable proportions all the time, I'm catching CMyListView::OnSize() and executing this code:
void CMyFileView::OnSize(UINT nType, int cx, int cy)
{
int my_cx = cx;
INT iWidth = 0;
RECT viewRect;
::ZeroMemory(&viewRect, sizeof(RECT));
GetClientRect(&viewRect);
INT iViewLen = viewRect.right - viewRect.left;
CMultiColumnSortListView::OnSize(nType, cx, cy);
// disable horizontal scroll bar
GetListCtrl().ShowScrollBar(SB_HORZ, FALSE);
INT iColWidth = 0;
if (cx != old_cx)
{
GetListCtrl().ShowWindow(SW_HIDE);
for (INT i = 0; i < (COLUMN_NUM - 1); i++)
{
iColWidth = viewRect.right * COLUMN_WIDTHS[i];
iWidth += iColWidth;
GetListCtrl().SetColumnWidth(i, (viewRect.right * COLUMN_WIDTHS[i]));
}
GetListCtrl().SetColumnWidth((COLUMN_NUM - 1), (iViewLen - iWidth));
GetListCtrl().ShowWindow(SW_SHOW);
}
}
old_cx = cx;
}
I call ShowWindow() in order to stop flickering, it helped. The problem is, calling ShowWindow() deselectes selected item (selected before with SetItemState()). I tried to call SetItemState() again after ShowWindow(SW_SHOW), but it doesn't work as expected, it highlights item, but it doesn't select and focus it 100% (it just draw grey rectangle aroung the item, but doesn't display dark blue rectangle which appears in normal case).
Does somebody know what to do to select and focus the item again successfully?
Thanks for any suggestion.
|
|
|
|
|
Hey everybody..
I'm writing code that will display a popup menu when a user clicks an item in a listview control. In order to have the popup display right underneath the mouse cursor, I need to know the x.y position of where the user clicked in the list.
I've searched the help, but turned up nothing, is there a GetMousePos() type function kicking around?
Thanks.
Mike.
|
|
|
|
|