|
kialmur wrote: Is there anyway to open a console window, where cout/cin can be used, from within a a Windows forms project?
Certainly. See here and here.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Is there no way that I can just open a console and use cout/cin? No forms are open at this point. It seems like quite a complex process just to write to a console.
|
|
|
|
|
When you create a windows app that has a WinMain entry point, there isn't an easy way to create a console. That said, if you want to go the other route (create a console app that spawns your window at some point), it isn't too difficult, but does require some work as far as setting up message loops and such.
Basically, yes, you can have a window with a console. No, it isn't easy to set up.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
kialmur wrote: Is there no way that I can just open a console and use cout/cin?
Sure, if you are creating a simple console application. However, since you have a GUI application, the rules change.
kialmur wrote: seems like quite a complex process just to write to a console.
So just wrap it all up into a nice little class, and whenever you want something to be displayed in a console window, instantiate your class, and invoke a few methods. You could even skip the class part, and just put it all in a function (or three). Just call the functions whenever you want something to be displayed in a console window.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Is it possible to prevent the user of an application to use mouse & keyboard for certain operations? Im mean disabling mouse & keyboard for some parts of the program and after that re-enablig that. In VC++, please
|
|
|
|
|
why not simply ignore mouse / keyboard events ?
|
|
|
|
|
Can't you just disable the window using EnableWindow(FALSE), and re-enable it when you're done with your operation?
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
I think i wasn't clear enough. I want that the user of the app. not to be able to use mouse & keyboard to prevent altering data outside the app. That's why I need this.
|
|
|
|
|
I'm having a problem using tile view in my listview control.
It works alright if I'm not using owner data, but if I do use owner data, the listview doesn't draw the label text properly. It looks like it's not bothering to calculate the offset for the label based on the additional lines and just draws at the same spot.
Image of problem
Here are some of the relevant code snippets. Did I miss any particular step?
LVTILEVIEWINFO lvtvi = { sizeof(LVTILEVIEWINFO), LVTVIM_COLUMNS};
lvtvi.cLines = 2;
lvtvi.dwFlags = LVTVIF_AUTOSIZE;
BOOL bRet = m_view.SetTileViewInfo ( &lvtvi );
OnGetDispInfo(...)
{
:
if(pItem->mask & LVIF_COLUMNS)
{
pItem->puColumns[0] = 1;
pItem->puColumns[1] = 2;
pItem->cColumns = 2;
}
:
}
-- modified at 13:58 Monday 24th July, 2006
|
|
|
|
|
Hi,
We have a C++ MFC application GUI that in the user thread, posts a user message using "PostMessage(SET_DLG_DATA_EVENT, 0, (LPARAM)pMsg)" to the GUI's message queue. We've also added a PreTranslateMessage method which gets called by the AFX message pump (CWnd::RunModalLoop) in the GUI thread before it dispatches the message it has removed from the queue; if this PreTranslateMessage method sees the message extracted from the queue is the user message posted in the user thread, it handles it and blocks winproc from seeing the user message.
However, whenever the user message is posted while left mouse button is clicked and held in the menu bar, the posted user message somehow gets routed to the winproc and PreTranslateMessage is not called. The stack trace from CWnd::WindowProc when it gets the user message shows no CWnd::RunModalLoop (the message pump): instead I get
> mfc71d.dll!CWnd::WindowProc(unsigned int message=1234, unsigned int wParam=0, long lParam=3320176) Line 1744 C++
mfc71d.dll!AfxCallWndProc(CWnd * pWnd=0x0012fcd0, HWND__ * hWnd=0x00200610, unsigned int nMsg=1234, unsigned int wParam=0, long lParam=3320176) Line 241 + 0x1a C++
mfc71d.dll!AfxWndProc(HWND__ * hWnd=0x00200610, unsigned int nMsg=1234, unsigned int wParam=0, long lParam=3320176) Line 389 C++
mfc71d.dll!AfxWndProcBase(HWND__ * hWnd=0x00200610, unsigned int nMsg=1234, unsigned int wParam=0, long lParam=3320176) Line 209 + 0x15 C++
user32.dll!77d48654()
user32.dll!77d48723()
mfc71d.dll!_AfxMsgFilterHook(int code=0, unsigned int wParam=2083117216, long lParam=2098704) Line 817 C++
user32.dll!77d49153()
user32.dll!77d4ee88()
user32.dll!77d49196()
ntdll.dll!77f75da3()
user32.dll!77d4a4d3()
user32.dll!77d4a017()
user32.dll!77d49f5b()
user32.dll!77d4a96e()
uxtheme.dll!5ad73f9b()
uxtheme.dll!5ad8aad7()
uxtheme.dll!5ad71ae1()
uxtheme.dll!5ad71c89()
user32.dll!77d4a9a4()
user32.dll!77d4a99a()
user32.dll!77d521ec()
user32.dll!77d52311()
user32.dll!77d48654()
user32.dll!77d48723()
user32.dll!77d4a7eb()
user32.dll!77d4aa95()
mfc71d.dll!CWnd::DefWindowProcA(unsigned int nMsg=1241808, unsigned int wParam=2082654585, long lParam=274) Line 1024 + 0x20 C++
mfc71d.dll!CThreadLocal<_AFX_THREAD_STATE>::GetData() Line 177 + 0xd C++
00000001()
If the mouse button is not held down, everything works fine.
Any ideas why the user message posted to the queue is routed differently while the mouse button is held down in the menu bar (non-client area?)
thanks,
Rob
-- modified at 13:49 Monday 24th July, 2006
|
|
|
|
|
I have this code:
<br />
if (a = 1) dwID = IDC_EDIT1;<br />
if (a = 2) dwID = IDC_EDIT2;<br />
if (a = 3) dwID = IDC_EDIT3;<br />
<br />
GetString(pView, dwID);<br />
And then this function:
<br />
CString GetString(CView *pView, UINT dwID)<br />
{<br />
CString str;<br />
<br />
CWnd *pWndChild = pView->GetDlgItem( (UINT)dwID);<br />
pWndChild->GetWindowText(str);<br />
<br />
return str;<br />
}<br />
If I just called GetString(pView, IDC_EDIT1), the code works. But if I
use:
<br />
if (a = 1) dwID = IDC_EDIT1;<br />
if (a = 2) dwID = IDC_EDIT2;<br />
if (a = 3) dwID = IDC_EDIT3;<br />
I get an "unhandled exception" and it points to this code:
<br />
void CWnd::GetWindowText(CString& rString) const<br />
{<br />
ASSERT(::IsWindow(m_hWnd));<br />
Is there any way I can call
GetString(pView, dwID)
or something like this instead of
GetString(pView, IDC_EDIT1);
Please, any response any one can give me will be greatly appreciated.
Sincerely,
Danielle Brina
|
|
|
|
|
If I understand correctly, you are using a test condition for the following:
if (a = 1) dwID = IDC_EDIT1;
if (a = 2) dwID = IDC_EDIT2;
if (a = 3) dwID = IDC_EDIT3;
If that is the case, you should be using the == operator instead of the = operator.
if (a == 1) dwID = IDC_EDIT1;
if (a == 2) dwID = IDC_EDIT2;
if (a == 3) dwID = IDC_EDIT3;
It's pretty easy to confuse the assignment operator with the equals operator which is 2 consecutive equal signs.
-- modified at 13:27 Monday 24th July, 2006
|
|
|
|
|
I appreciate the reply.
The = is just a typo on my part. Im using == but I still get the error.
|
|
|
|
|
That might have been it. I take back my earlier statement.
|
|
|
|
|
DanYELL wrote: if (a = 1) dwID = IDC_EDIT1;
if (a = 2) dwID = IDC_EDIT2;
if (a = 3) dwID = IDC_EDIT3;
If a was equal to 1 , why would you want the last two statements to be evaluated?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DanYELL wrote: if (a == 1) dwID = IDC_EDIT1;
if (a == 2) dwID = IDC_EDIT2;
if (a == 3) dwID = IDC_EDIT3;
Can you show how 'a' is passed. Possibly it is not going through any of above condition and 'dwID' is having garbage value.
DanYELL wrote: CWnd *pWndChild = pView->GetDlgItem( (UINT)dwID);
and this statement is initializing pWndChild with NULL.
|
|
|
|
|
Hello, perhaps someone can answer this for me without me having to display my entire program.
I am having issues with one of my cin statements getting read in by a user's keyboard input. I am using the debugger in Visual C++ and it appears as though the compiler is skipping this cin statement and moving to the next cout statement. This seems to happen when the program is moving from one function call to another in main(). I found a fix to this by adding 2 consecutive cin statements but I know this is not the correct way to program. Has anyone had a similar experience. If so, how did you handle it.
Thanks,
HRW.
-- modified at 12:56 Monday 24th July, 2006
|
|
|
|
|
How are we expected to offer any reasonable solution without seeing the problematic code? We don't need to see all of it, just the relevant snippet.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Here is a condensed version. There are 2 functions below. Function 1 gets called before function 2. The problem appears in function 2 where I had to enter 2 cin statements. I hope it's readable as the cut and paste did not translate well.
void add_number_of_subunits (int& data)
{
char buff[1024];
unsigned int value;
int charsRead;
bool validEntry = false;
while (!validEntry)
{
cout << endl;
cout << "Please enter number of subunits: ";
cin >> buff;
if (sscanf(buff,"%u%n", &value,&charsRead)==1 && value >=1 && value <= 12)
validEntry = true;
}
data = value;
}
void add_node_at_end(data& item, int& increment)
{
char buffer[501] = {0};
cout << "Please enter the length of the protein sequence for Subunit " << increment << "> ";
cin >> buffer;
cin.getline(buffer, 500, '\n');
item.Length = buffer;
memset(buffer, 0, 501);
cout << "Please enter the protein sequence for Subunit " << increment << "> ";
cin.getline(buffer, 500, '\n');
while (buffer == "\n")
{
cout << "A sequence is required!" << endl;
cout << "Please enter a sequence." << endl;
cin.getline(buffer, 500, '\n');
}
item.Sequence = buffer;
memset(buffer, 0, 501);
item.number = item.Sequence.size();
cout << "Enter brief status on the presence of a modified N_Terminal: ";
cin.getline(buffer, 500, '\n');
item.N_Terminal = buffer;
memset(buffer, 0, 501);
cout << "Enter brief status on the presence of a modified C_Terminal: ";
cin.getline(buffer, 500, '\n');
item.C_Terminal = buffer;
memset(buffer, 0, 501);
g_DataList.push_back(item);
cout << endl;
increment++;
}
-- modified at 13:08 Monday 24th July, 2006
|
|
|
|
|
Harold_Wishes wrote: cin >> buffer; // I had to enter 2 cin statements since the compiler for whatever reason
cin.getline(buffer, 500, '\n'); // was not accepting one of them.
What compiler error were you receiving (when only one was present)?
Harold_Wishes wrote: while (buffer == "\n")
What are you hoping to accomplish with this?
If you are going to create a C++ program, quit messing around with char[] variables. Use string instead, especially since you are populating them with cin .
|
|
|
|
|
The compiler is not giving me an error per se. It's building the executable. But, when I run the executable, I am prompted to enter data in sequence with a series of multiple cout prompts and cin inputs. I have no problems when I am doing this in the first function call. But when main() makes a call to function 2 after function 1 terminates, the very first cin input in function 2 seems to get skipped (at least that is what the debugger is showing me). It does not recognize it). The debugger moves right to the next cout prompt.
If I remember correctly, I took this out of functions and slapped it out all in main() without any troubles.
|
|
|
|
|
Sans the comments, and extraneous code, this should get you real close:
void add_number_of_subunits (int& data)
{
string buff;
do
{
cout << endl;
cout << "Please enter number of subunits: ";
cin >> buff;
} while (atoi(buff.c_str()) < 1 || atoi(buff.c_str()) > 12);
data = atoi(buff.c_str());
}
void add_node_at_end(_data& item, int& increment)
{
string buffer;
cout << "Please enter the length of the protein sequence for Subunit " << increment << "> ";
cin >> buffer;
item.Length = buffer;
cout << "Please enter the protein sequence for Subunit " << increment << "> ";
cin >> buffer;
item.Sequence = buffer;
item.number = item.Sequence.size();
cout << "Enter brief status on the presence of a modified N_Terminal: ";
cin >> buffer;
item.N_Terminal = buffer;
cout << "Enter brief status on the presence of a modified C_Terminal: ";
cin >> buffer;
item.C_Terminal = buffer;
cout << endl;
increment++;
}
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
This code looks vaguely familiar ... someone else was asking about a similar problem a couple weeks ago.
Anyway, the problem you are having is that when using cin, it ignores whitespace by default (that is, it sees it, but leaves it in the buffer). This is generally a problem only when reading in strings, but can happen in certain circumstances when reading other datatypes. Basically, this is what happens:
Lets say that the following string is in the read buffer for cin: MyString\n
cin will read "MyString" into the buffer and leave the \n on the read buffer.
Now, the next cin call will see the \n and assume an empty string.
An easy way to fix the problem would be to change:
DavidCrow wrote: void add_number_of_subunits (int& data)
{
string buff;
do
{
cout << endl;
cout << "Please enter number of subunits: ";
cin >> buff;
} while (atoi(buff.c_str()) < 1 || atoi(buff.c_str()) > 12);
data = atoi(buff.c_str());
}
to be this instead:
void add_number_of_subunits (int& data)
{
int check = 0;
do
{
cout << endl;
cout << "Please enter number of subunits: ";
cin >> check;
} while (check < 1 || check > 12);
data = check;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: This code looks vaguely familiar ... someone else was asking about a similar problem a couple weeks ago.
Same person. Still using sscanf() for validation, even though you provided him an alternative!
Zac Howland wrote: int check = 0;
...
cin >> check;
I thought about this (i.e., using an int ), but since he was storing the input string for later processing, I left it as a string .
|
|
|
|
|
DavidCrow wrote: Same person. Still using sscanf() for validation, even though you provided him an alternative!
So it is. In C++, there are very few cases where using sscanf does not constitude a flaw in your implementation. This is not one of them.
DavidCrow wrote: I thought about this (i.e., using an int), but since he was storing the input string for later processing, I left it as a string.
Since he needs it to set the iterations for a loop, it is easier (and more efficient) to read it as an int and to then call itoa or sprintf or use streambufs to store it for whatever purpose.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|