|
|
When using rand() from the standard cstdlib include files, how often should you seed the number generator?
Do you need to seed every time you use the rand() function, or just once at the start of the application?
Also, is srand((unsigned)time(0)); adequate for seeding purposes, or is something more complex a better idea?
|
|
|
|
|
Once. Otherwise you could seed it with the same time value which would result in the same number multiple times which is probably not what you wanted.
|
|
|
|
|
Iam having a MDI application.
I have two queris.
1. How to add the menu in childframe
2. For different child how i can add the different menu.
Thanks in davance.
Regards
Lavate Mallikarjun Avanna
|
|
|
|
|
In one project I used different Views with different Menus according to which was the active one. I did it creating the menus in the resource editor and then in the MyApp files (.h and .cpp) creating different CMultiDocTemplate one for each type of view, saying which menu was owned by which view.
BOOL CFPSApp::InitInstance()
{
AfxEnableControlContainer();
.
.
.
.
pDocTemplate = new CMultiDocTemplate(
IDR_FPSIITYPE,
RUNTIME_CLASS(CFPSDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CFPSView));
AddDocTemplate(pDocTemplate);
.
pParamRegMatTemplate = new CMultiDocTemplate(
IDR_VIEWTYPE,
RUNTIME_CLASS(CFPSDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CParamRegView));
AddDocTemplate(pParamRegMatTemplate);
.
}
this option is good when you know for sure how your project is going to be structured. There are other options to load/unload menus dinamically. If you use it you will have to load/unload the menu in the OnInitialUpdate and when your view loses and wins the focus another time. With the other way I have explained all is done automatically.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Hi
is it possible to show a single item's text in multiple line in a combo box?
Thanks
|
|
|
|
|
Hi sheshidar,
I really do not know if that's possible, but I would start by modifying Xiao Wu Guang's Multi Column ComboBox[^]. Hope this helps!
Best regards,
Mihai Moga
|
|
|
|
|
sheshidar wrote: is it possible to show a single item's text in multiple line in a combo box?
No. What exactly are you trying to accomplish?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
My dao database application is not working on customers PC until I install VC++ there.
Application has no problem itself, problem is some functionalities are missing from OS, which may be problems of missing dll files or COM registers - I don't know why.
I posted similar question before and got no right answer, I hope I am luck this time.
How do you install dao database apps?
Thanks
|
|
|
|
|
|
includeh10 wrote: My dao database application is not working on customers PC until I install VC++ there.
Are you trying to deploy a debug build? Your symptom might be related to this. If you are trying to deploy release build and still having problems, make sure the libraries files for any libraries you use are in your installation package (i.e. MFC, STL, ATL, etc...).
In my deployment .msi, I'll usually include the redistributable components for any dependencies. Depending on your version of Visual C++, these redistributables might be in .exe format or .MSM files.
If targeting a specific Windows OS, assume there is no other software installed except the OS and whatever version of IE you require (for IE api specific functions). For example, to support NT 4.0, you would probably want to include the redistributable for MDAC you are targeting and the WMI redistributable (if using any of it's functionality), runtime libraries for Visual C++, library redistributables for MFC, STL, ATL and any additional libraries your app uses like zlib, GDI+, etc...
All too often, you can get false positives that your software will deploy properly if you have Visual Studio or MS Office installed on your test deployment box. You should build a clean OS installation (For each OS you support) and ghost it so you can reimage the machine over and over as you refine your installation packages.
Expect to put a reasonable amount of time into ensuring the installation .msi has everything your app needs. If the Visual Studio Installer cannot give you the option you need, you can use ORCA.EXE (in the Windows Resource Kits and the Windows SDK) to build .msi databases from scratch or apply post compile options to a Visual Studio Installer .msi. It can be a bit tedious and subject to error if you don't document what post compile changes you need to make so document each step so it can be repeated for each new version.
Hope that helps.
|
|
|
|
|
One of our applications and a couple of our installers need to be able to
determine whether or not certain programs are running. They do that using
FindWindow(), as in this article: http://support.microsoft.com/kb/88167.
The problem is, Vista came along and bit us in the butt, because one of the
programs that we need to detect is actually a service, and our detection
routine no longer detects whether or not that is running.
Is there a more reliable way to detect whether or not a program or service
is running that works across session boundaries and doesn't involve a whole
lot of pain. It should not involve .NET or anything else that has to be
installed onto an XP or Win2k system in order for it to work. (This is a
requirement for the installer; we don't want the installer to have any
prerequisites that are not present out of the box on our earliest supported
OS, which is Win2k in the version of our programs that we're currently in the
process of getting into beta. Also, as we are using Visual Studio 6 for the
development of that version, the solution must be compatible with that (i.e.,
using only Win32 API and/or MFC calls).)
Rob Holstein (BSc)
Software Developer
Delta Controls, Inc.
|
|
|
|
|
What about using CreateMutex() to create a named mutex?
A named mutex is system-wide in scope and can be obtained
atomically by any process.
You can use code similar to the following. The same code can be used
to prevent more than one instance of an app and to detect if it's running already...
HANDLE hMutex;
hMutex = ::CreateMutex(NULL, TRUE, _T("Global\\MutexNameUniqueToSomeApplication"));
if (hMutex)
{
DWORD err = ::GetLastError();
if (ERROR_SUCCESS == err)
{
}
else if (ERROR_ALREADY_EXISTS == err)
{
}
}
... (at exit)
if (hMutex)
::CloseHandle(hMutex);
*edit*<br />
Bug fix - thanks Randor!
Mark Salsbery
Microsoft MVP - Visual C++
modified on Saturday, July 19, 2008 1:19 PM
|
|
|
|
|
Excellent suggestion Mark, one minor bugfix:
The original poster implied that the application should be visible across session boundries.
hMutex = ::CreateMutex(NULL, TRUE, _T("Global\\MutexNameUniqueToSomeApplication"));
In order for the mutex to be globally accessible it should be prefixed with a proper namespace.
Further Reading:
Kernel Object Namespaces[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Excellent David, thanks!
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In order to determine if specific applications are running during our installs, we simply try renaming it (or the directory that contains it).
For example, if I know the app is located in
C:\Program Files\MyApp\
in our installer, we rename C:\Program Files\MyApp\ to C:\Program Files\~MyApp\
If it succedes, we rename it back and continue (since windows wont let you move/rename/delete something that is currently running).
If it fails, we popup a message saying that the application is currently in use and to exit it and try the install again.
It isn't "pretty" by any means, however, this works in every version of windows available.
|
|
|
|
|
This isn't pretty, as you've said. In Vista it will be even less so as the user will not have permission to rename a file in the "Program Files" folder. Also, what happens if your program crashes or is terminated before it renames the folder back to its original name?
Steve
|
|
|
|
|
we have our installs elevate themselves when they run so admin rights are not a problem (user must know an admin password or have an admin account to install).
The crash issue would be a problem but since nothing happens between the two commands, it isn't much of a probability. about the only way this would happen is if windows crashed because we renamed a file we check...which shouldn't ever happen
|
|
|
|
|
An excellent suggestion with one minor flaw: It seems that it doesn't work for services. Even with the service running, I found that it is still possible to rename the executable. (I haven't tried it, but it might be the same with DLLs that the system is configured to use (e.g. a Web server).)
Rob Holstein (BSc)
Software Developer
Delta Controls, Inc.
|
|
|
|
|
I found out why you can rename the executable of a service even while the service is running. Apparently, when a service is installed, Windows takes a copy of the executable and runs that whenever the service is running, so the original file is never in use when the service runs.
Rob Holstein (BSc)
Software Developer
Delta Controls, Inc.
|
|
|
|
|
If all of the programs you need to detect are yours, you could use the solution provided by Mark S. You'd need to modify all of them to create a mutex and check for all of the mutexes.
Another solution would be to get a list of all processes running using the CreateToolhelp32Snapshot() function. I've used this under Win98, 2000, and XP. I can't say about Vista.
This will give you the names of the .exe files that are running, including services. You'll need to know the executable name (not full path) in order for this to work.
Hope that helps.
BDF
A learned fool is more a fool than an ignorant fool.
-- Moliere
|
|
|
|
|
Using Visual C++ 6.0 MFC in SDI application
I have a window that displays a drawing and also displays a modeless dialog window. When a user clicks on a button in the modeless dialog, I want to display a different drawing along with the modeless dialog window again. But I don't understand how to update the drawing immediately. I have a routine that gets called when the user clicks on the button, but if I simply use Invalidate(0), or UpdateWindow(), the new drawing isn't displayed until I do something on the drawing. So I'm assuming that the Invalidate(0) or UpdateWindow() are updating the modeless dialog window and not my drawing window. But I don't understand how to tell it to update my drawing window.
Thanks!
|
|
|
|
|
Well, assuming you dialog is child of the drawing window, whenever the button is clicked on the dialog you may call the updating functions on dialog's parent, for instance:
CMyDialog::OnBtnClick()
{
CWnd * pParentWnd = GetParent();
if (pParentWnd)
{
pParentWnd->Invalidate(FALSE);
pParentWnd->UpdateWindow();
}
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I'm using the famous XListCtrl class in my app and currently have checkboxes as one of the subitems to indicate a state (Disabled/Enabled).
What I am currently doing is changing the background colour of a list item when Disabled is set - this works.
What I would like to be able to do is change the colour of the currently selected line (default is blue) to Red.
This is a side effect I am experiencing as when I set the disabled state of the current item in the list, the colour of the selected item is still blue based upon selection.
Any advice?
Thanks.
|
|
|
|
|
I have an Application that I have made a Set class called HPDset that is based from CRecordSet to connect to an ODBC database and am trying to make it work in the mainfrm class of my application. It works fine in the view class but when I add the pointer definition i get a bunch of wierd errors. It also says HPDset is undefined, but I have included the header file in mainfrm.h.
class CMainFrame : public CFOPMDIFrameWnd
{
DECLARE_DYNAMIC(CMainFrame)
public:
CMainFrame();
public:
HPDset* m_pSet;
CStringArray m_UndoString;
CStringArray m_RedoString;
|
|
|
|