|
I'm attempting to write a small tool that automatically calls a function on start-up...but my problem is I want the dialog window so be displayed first. If I call the function from the OnInitDialog() it executes it before the window is displayed.
What is the easiest way around this?
|
|
|
|
|
Here's one way:
#define UWM_SOMETHING (WM_APP + 1234)
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
ON_MESSAGE(UWM_SOMETHING, OnSomething)
END_MESSAGE_MAP()
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
...
PostMessage(UWM_SOMETHING);
return TRUE;
}
LRESULT CMyDialog::OnSomething( WPARAM, LPARAM )
{
return 1;
}
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Thanks for a quick response
I tried your suggestion but unfortunately it has the same result... The OnSomething() function is still executed before the window is displayed.
|
|
|
|
|
Which means you'll need to use a separate thread to do the work in. See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Got it, thanx
|
|
|
|
|
Maybe it will work if you overwrite the dialog's
OnActivate() member function and call your
function from there the first time it is called.
(I'm not sure where on the timeline OnActivate() gets invoked)
Steve T
|
|
|
|
|
Hello
BOOL Pump()
{
MSG msg;
LONG lIdle = 0;
CWinApp* app = AfxGetApp();
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!app->PumpMessage())
{
::PostQuitMessage(0);
return FALSE;
}
}
while (app->OnIdle(lIdle++));
return TRUE;
}
BOOL CzedusDlg::OnInitDialog()
{
...
ShowWindow(SW_SHOW);
Pump();
MessageBox(_T("It's your calculations"), _T("message"), MB_OK);
}
Andrew
|
|
|
|
|
I had a similar problem and my solution was a bit crude but worked.
First, in OnInitDialog start a time.
Second, in the OnTimer function do a find for the window by title (assuming you know this, I wrote my own function using EnumWindows for to a partial match).
Wait until the handle returned is not NULL then your window has been displayed.
Elaine
The tigress is here
|
|
|
|
|
My C++ book says that trying to store more characters then the array has space for can cause problems. What the book I have doesn't tell me is how to prevent a user from entering too many characters. The code sample is;
char name[31];
cout << " Enter your name: ";
cin >> name;
What is the best method to take text input from the user?
If only I had more time!
|
|
|
|
|
Example
#include <iostream>
using namespace std;
int main( )
{
ws( cin );
char c[10];
cin.width( 9 );
cin >> c;
cout << c << endl;
}
MSDN is your best friend.
Don't try it, just do it!
|
|
|
|
|
One way would be to accept one character at a time until either Enter is pressed or the maximum number of characters has been reached. Search for examples using getch() and getche() .
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Use a C++ type which is dynamically expandable,
std::string s;
std::cin >> s;
Which will be fine unless you have whitespace in the name, and then you would need something like (this would have been a problem with the exising code as well):
std::string s;
std::getline(cin,s);
If you wanted to get really fancy you could also use an istream_iterator<string>, but for examples this simple I don't think it really buys you anything.
|
|
|
|
|
is there any limitations on the type used? i guess this is for a school project right? if your project does not have any limitations, use the string class.
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
#include <string>
using std::string;
using std::getline;
int main()
{
string test;
cout << "name :";
getline(cin,test);
cout << "Hello " << test << endl;
return 1;
}
this effectively removes any limitiations on character size inputs, which imho, is bad. imagine you have an indian name (no offence intended) and an english name. normally indian names are longer, so if you used a larger array size, the english name wastes a lot of memory. string dynamically allocates the memory spaces, so nothing is wasted. and you don't have to explicitly deal with the memory size (i.e. no magic numbers).
lastly, you'll find that getline will require you to press return twice to get the line if u're using vc++. this is a bug in the implementation of string. follow http://www.tek-tips.com/faqs.cfm?fid=5193 to fix the bug.
hope this is clear enough.
"Learning does not make one learned: there are those who have knowledge and those who have understanding. The first requires memory, the second philosophy." - Abbe Faria, The Count on Monte Cristo
|
|
|
|
|
Yes this is a school Project. This C++ is really hard to master. I added one line and got 45 errors.
I have to take input from the user and pass to a method which takes a pointer, a char pointer. So I create and fill an array and pass the first element address to the method. I think I have most coded right except that I get a continuous scrolling at line 21.
17 char sValue[30];
18 int iData;
19 cout << " Enter a name for the Salesman \n"
20 << " limited to 29 chars:";
21 cin.get(sValue,30);
22 this->SetAgentName(sValue);
I took this directly from my book however the sample code in the book only has two lines (# 17 and # 21). There seems to be so many things that all interact to make C++ extra difficult.
Can any one tell my why my screen constantly scrolls at the line with .get?
If only I had more time!
|
|
|
|
|
ok, two things. firstly cin.get() only gets single characters, one at a time. cin.getline() will get a whole line, up to the end of the '\n' character.
i'm not sure what u're doing here.. is this a class or the main method? if u're in the main method, this-> does not have any value associated to it at all.
as i said, using a string solves a lot of problems. since u're using c++, u should use the available STLs (standard template libraries) whenever possible. using a char array in c++ is indeed foolhardy.
using the code i wrote previously, u can pass the string as a reference.
// class declaration
class myclass
{
public:
void mymethod(string&);
};
// method declaration
void myclass::mymethod(string &instr)
{
cout<
|
|
|
|
|
Ok, these lines of code are directly from the MSDN.
char line[25];
cout << " Type a line terminated by carriage return\n>";
cin.get( line, 25 );
cout << line << endl;
This will run fine when placed in my main, (first lines). However when placed in a method of a class and called, via the user selecting from a menu, the screen continuously scrolls. Do I need to clear the buffer?
Is it always this difficult to code in C++? I have been spending a couple hours just to code to take a line of text from the user.
Also what is the "compile with: /EHsc" that the MSDN shows?
If only I had more time!
|
|
|
|
|
maybe u could post more code. ur code is too cryptic for any form of debugging. esp post in detail how u called the code in the class and how the user select from a menu.
normally, a scrolling screen is due to a improper looping. in this case, it might be because u've tried to use a while loop to get the user input from the menu, until the user decides to terminate the program with a special character, right? try removing the loop first if this is the case, and debug again.
it's not difficult to code in c++ at all, just that you're not used to it. i've coded genetic algoritms, ant colony system and dijkstra's algorithm all in c++, with each algorithm averaging 1.5 weeks. i can't even begin to think of how to start my coding in VB..
"Learning does not make one learned: there are those who have knowledge and those who have understanding. The first requires memory, the second philosophy." - Abbe Faria, The Count on Monte Cristo
|
|
|
|
|
I found the fix. I needed to remove the newline character since cin.get(name, length) leaves it(the newline char) in the buffer. The line to add is a simple "cin.get(discard);" where discard is declared as a char variable. I am using a while loop for the menu. This menu was seeing the newline char constantly. Thanks for your help, I'm still trying to learn all the little things of C++ like this one.
Randy
If only I had more time!
|
|
|
|
|
ng kok chuan wrote:
...the english name wastes a lot of memory.
The word "lot" is a very subjective term. If the machine has but a few MB of physical RAM, then the unnecessary allocation of a few more bytes might matter, but given everything else that Windows' memory manager is doing, the extra bytes will definitely go unnoticed.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
yup, i guess u're right. i've been too well-trained to think lean and mean :p.. however, using strings still have their advantages, as it dynamically allocates memory. this can help to prevent some wise user from entering longer than allocated mem space.
"Learning does not make one learned: there are those who have knowledge and those who have understanding. The first requires memory, the second philosophy." - Abbe Faria, The Count on Monte Cristo
|
|
|
|
|
I'm not sure if this is the best place for this question but here it goes:
Does anyone here use MKS Source Integrity for source control? If so, does anyone know how to use their command line interface to add project members?
|
|
|
|
|
Solution to add project members:
Usage: si add options... nonmember...; options are:
--[no]retainWorkingFile Retain the non-member file (as-is) in the sandbox
-l Lock member revision
--lock Lock member revision
--onExistingArchive=[confirm|cancel|sharearchive|newarchive] The behaviour to follow if an existing archive is found
--[no]saveTimestamp Save the timestamp of the working file
--archive=value Associated archive (must exist) for the new member.
--author=value The author of the newly added member revision
--binaryFormat Format of the member's revision data/files
--changePackageId=value The associated change package ID (see documentation)
--[no|confirm]closeCP Close the associated change package(s)
--cpid=value The associated change package ID (see documentation)
--[no]createSubprojects Create one subproject per directory, as required.
-d value Description for newly created archives
--[no]defer Defer the add from taking place in the project until submitted
--deployType=value The name of the deploy type
--description=value Description for newly created archives
--descriptionFile=value The file containing the Description for newly created archives
--issueId=value The issue ID to use to find the associated change package ID (see documentation)
-r value Revision at which the non-member is to be added
--revision=value Revision at which the non-member is to be added
--textFormat Format of the member's revision data/files
--[no]unexpand Remove keywords from newly created revision
-R Select the non-members recursively
--exclude=file:pattern,dir:pattern... where "pattern" is a glob pattern
--include=file:pattern,dir:pattern... where "pattern" is a glob pattern
--[no|confirm]includeFormers Include former members
--[no|confirm]recurse Select the non-members recursively
-S value The name of the sandbox
--[no]failOnAmbiguousProject Whether to abort when multiple projects correspond to a flat project string.
--sandbox=value The name of the sandbox
-? Shows the usage for a command
-F value Read the selection from a specified file
-N Responds to all confirmations with "no"
-Y Responds to all confirmations with "yes"
--[no]batch Control batch mode (no user interaction in batch mode)
--cwd=value Act as if command executed in specified directory
--forceConfirm=[yes|no] Specify an answer to all confirmation questions
-g User interaction should happen via the GUI
--gui User interaction should happen via the GUI
--hostname=value Hostname of server
--no Responds to all confirmations with "no"
--password=value Credentials (e.g., password) to login with
--port=value TCP/IP port number of server
--quiet Control status display
--selectionFile=value Read the selection from a specified file
--settingsUI=[gui|default] Control UI for command options
--status=[none|gui|default] Control status display
--usage Shows the usage for a command
--user=value Username to login to server with
--yes Responds to all confirmations with "yes"
|
|
|
|
|
Can anyone point me to a good source/article on how to change the MFC combo box color. By changing the color I mean the background, the drop button and the scroll bar color has to be changed. I know , that it will be owner drown control,and honestly I could create by myself, but it will definitely take few days to create. So please, can anyone help me out?
|
|
|
|
|
Per MSDN:
"To change the color of the drop-down list box, create a CComboBox with an override of OnCtlColor that checks for CTLCOLOR_LISTBOX in the nCtlColor parameter. In this handler, the SetBkColor member function must be used to set the background color for the text."
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Thanks for the reply, unfortunally this will only change the color for the listbox. The drop down button color will remain unchanged. Basically, changing the color of this button is the major problem.
|
|
|
|