|
This works for me :
srand( (unsigned)time( NULL ) ); // Initialise rand with the current time to get
// a truly random seed
int ivariable = rand() % 5 // result between 0 and 5
|
|
|
|
|
thanks
Daffy d. wrote:
int ivariable = rand() % 5 // result between 0 and
that is exactly what I needed.
I didn't know how to chance the RAND_MAX value!
You helped me a lot!
) life is fun!
Johannes
//still a newbie
|
|
|
|
|
my treeview is used to display the data stored in a database.. i made a dialog that allows the user to input information.. once the user submits the info, by clicking on the 'ok' button in the dialog, i then store the input info into the database immediately.. once new data are stored in the database, i want to refresh/redraw the tree in the treeview(the tree will display all the data in the database including the newly entered data), but i can't seem to find a way to do it.. can someone plase help me.. thank you!
|
|
|
|
|
I don't remember exactly how (I've not been doing any MFC stuff for a long time now) but you'll probably want to create a method that will query the database and add the records to the TreeView, this then gets called from other CTreeView methods, such as the one that's called when its first initialised. Once its been populated there will be a Clear() method (possibly as part of the underlying CTreeCtrl though) that will empty the TreeView so that you can then re-populate it.
However, if you're adding a single record and you know how it behaves its probably more efficient just to manually add the line into the TreeView rather than the entire db -- once it gets to a significant size it'll be quite slow (depending upon the dbms of course).
Anyway, it may be better to create a method in your CTreeView derived class that adds a single record to the TreeView, this can then be called from another method that queries the entire DB and adds each record. Then you can use this AddRecordToTree() method after your dialog closes and add the record manually, thus avoiding any database querying etc.
Sorry for being quite so vague with everything.
--
Paul
"I need the secure packaging of Jockeys. My boys need a house!"
- Kramer, in "The Chinese Woman" episode of Seinfeld
MS Messenger: paul@oobaloo.co.uk
Sonork: 100.22446
|
|
|
|
|
Hi
I would like to write an Internet explorer plugin such as the search bar of code project. However I have no clue of how about doing it! Could anyone point me to the direction eg reading or any hint about that!
Thanks
Regard,
|
|
|
|
|
|
|
How can I put a main menu created in Resource in a dialog box? And how can I crate the menu handler codes for the sub menu items?
Thank you all
|
|
|
|
|
1) Right-click on dialog template, select "Properties". If Properties dialog select menu ID from Menu combo box.
2) To handle menu items use MFC Class Wizard. If you don't use MFC, handle WM_COMMAND message.
|
|
|
|
|
If you built your menu in the resource editor of VS, you can add it in the properties of the main dialog. Or:
Add a protected member:
CMenu m_Menu;
then in OnInitDialog()
this->m_Menu.LoadMenu(IDR_MENU1);
this->m_Menu.LoadToolbar(IDR_TOOLBAR1);
<code>
this->SetMenu(&m_menu);
to handle the clicks, use class wizard and find the ID of the menu Item and handle it.
That should get you going.
Nitron
_________________________________________--
message sent on 100% recycled electrons.
|
|
|
|
|
Thank you very much.
But I have something to tell you that You used LoadToolbar method for a CMenu object. This causes an error. I think you wanted to see a toolbar (menubar) around the menu created.
Another thing:
I can't see the mnemonics of the menu items using this solution.
And finaly
Can I transfer the description (prompt) text of current menu item user selected into a status bar?
|
|
|
|
|
GurGur wrote:
But I have something to tell you that You used LoadToolbar method for a CMenu object. This causes an error. I think you wanted to see a toolbar (menubar) around the menu created.
Sorry, I'm so used to using BCMenu [^] I forgot. It's really all I use anymore .
Nitron
_________________________________________--
message sent on 100% recycled electrons.
|
|
|
|
|
Example: LoadTypeLib(...)
QuickInfo - from MSDN:
Windows NT: Use version 3.1 and later.
Windows: Use Windows 95 and later.
Header: Declared in oleauto.h.
Import Library: Link with oleaut32.lib.
QUESTION 1:
To use LoadTypeLib from a client application, do ALL of the following:
(1) Project>Add To Project>Files>oleaut32.lib
(2) #import "oleaut32.lib" (Should I include the full path?)
(3) #include "oleauto.h"
QUESTION 2:
Also, if I dont #include "windows.h", there's a whole bunch of compile time errors... why?
norm
|
|
|
|
|
Question 1:
You don't need steps 1 and 2, Instead select "Settings" from VC's "Project menu", pick "All Configurations" from the "Settings For:" drop down, select the "Link" tab, and enter oleauth32.lib into the "Object/library modules:" text box.
Question 2:
If you're using code that relies on stuff defined in windows.h then it won't work if you don't include it
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
thanks for the feedback, but how am i supposed to know that it needs windows.h if MSDN doesnt tell u that it does?
QuickInfo - from MSDN:
Windows NT: Use version 3.1 and later.
Windows: Use Windows 95 and later.
Header: Declared in oleauto.h.
Import Library: Link with oleaut32.lib.
i know only from my experience...
norm
|
|
|
|
|
my problem is I try to create a file which name is
not english in english OS.
I use GetOpenFileName() to let user select a file,
and use the returned string (ofn.lpstrfile)pass into
CreateFile() as auguemnt.
but failed.
so could someone help to solve such problem..??
as I know only windows explorer in win 2K/XP
could support different language's file name.
but still can't create file in win 2K/XP using the
procedure described above.
thanks.
|
|
|
|
|
Are you using CFileDialog? I don't think language would matter. I get a filename like this:
void MyApp::OnBrowse()
{
try
{
CFileDialog fd(false,_T("ext"), _T("*.ext"));
if(fd.DoModal() == IDOK)
this->m_szFilename = fd.GetPathName();
return;
}
catch(...)
{
AfxMessageBox("Error browsing for file!");
<code> </code>
return;
}
}
Nitron
_________________________________________--
message sent on 100% recycled electrons.
|
|
|
|
|
please
how to call MS Word Commands using DDE in Visual c++
such as [FileSave], [EndOfDoc] I managed these.
help me with the following commands please:
[EndOfLine]
create Frames
Change Font size and Colors.
|
|
|
|
|
#import "...mso9.dll" no_namespace
void dump_com_error(_com_error &e)
{
_tprintf(_T("Oops - hit an error!\n"));
_tprintf(_T("\tCode = %08lx\n"), e.Error());
_tprintf(_T("\tCode meaning = %s\n"), e.ErrorMessage());
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
_tprintf(_T("\tSource = %s\n"), (LPCTSTR) bstrSource);
_tprintf(_T("\tDescription = %s\n"), (LPCTSTR) bstrDescription);
}
struct StartUpCom
{
StartUpCom() { CoInitialize(NULL); }
~StartUpCom() { CoUninitialize(); }
} _global_com_inst;
void main()
{
IApplicationPtr pApp;
try
{
try
{
// Start up existing winmsg, if available
HRESULT hr = pApp.GetActiveObject(L"word.Application");
if (FAILED(hr))
_com_issue_error(hr);
}
catch(_com_error& e)
{
dump_com_error(e);
_tprintf(_T("NOTE: This is not a TRUE error!!\n"));
_tprintf(_T("Starting up word.exe...........\n"));
try
{
// Start up fresh instance of word
HRESULT hr = pApp.CreateInstance(L"word.Application", NULL, CLSCTX_LOCAL_SERVER);
if (FAILED(hr))
_com_issue_error(hr);
}
catch(_com_error& e)
{
dump_com_error(e);
}
}
//use pApp;
}
catch(_com_error& e)
{
dump_com_error(e);
}
}
//HKEY_CLASSES_ROOT\CLSID\{FB7FDAE2-89B8-11CF-9BE8-00A0C90A63
I am seeking...
For what?
Why did you ask me for what? I don't know!
|
|
|
|
|
Dear Ladies & Gentlemen,
A small help request from a newbie...
I would like to create a small 32 bit prog that deletes all zero byte files in the Windows directory with the extension ".tmp". The other thing is that it should not pop up a dialog frame while it is working. It should run hidden every time the computer is restarted.
I´ll guess I can enter the program path in the Windows registry key "Runservices", so it will execute on every Windows startup.
* Is there any codesample here at the board that deletes zero byte files, that I can study?
* How do I set up VC++ to make a "hidden prog" that will not bring up any screen dialogs?
Best regards,
Peter
|
|
|
|
|
1. you can just check the file size to determine zero-size files (see CFile::GetStatus, or _fstat)
2. start a new project, but make a Console app, not an MFC AppWizard app. you can use MFC, if you want. no UI at all.
-c
A conclusion is simply the place where someone got tired of thinking.
|
|
|
|
|
Thanx Chris!
I´ll guess that I have to search and make a list or table of all zero byte files found in the directory, in order to then delete them.
Do you have a nice codesample that shows how to do it?
/Peter
|
|
|
|
|
You don't need a list, just use the sample code in MSDN to iterate through files and then delete them as you find them, unless you want to offer a user prompt.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Thank you Christian, for your seuggestion.
I will try that!
|
|
|
|
|
how to set the pane frame size explicitly depending on the screen size?
|
|
|
|