|
For instance : int a = 42; CString str; int tmp;(pEdit already established) pEdit1->GetDlgItemText(str); now str holds the value the User typed which was NOT a number. but the representation of a number in character format. Now tmp = _tstoi(str); WORKS it changes the character to a number and puts it in tmp(an integer). but my question is How do I do the reverse? How to I get an integer valve into the CString(ie str)?
I've tried these functions: _itot_s, _itoa_s, and _itoa and they all give a long error message basically saying the str cannot be transfered to a char*
I know there is something that works, but I can't recall what it is.
I just want to put an integer value into a CString after I have converted one from the User's entry.
A C++ programming language novice, but striving to learn
|
|
|
|
|
Okay I think the problem is _itot excepts second argument to be either wchar_t* or char* depending whether unicode is defined or not and it cannot automatically convert from CString to char* or wchar_t*. I don't use much MFC so not sure if there are function in CString to automatically do this but you can try something like this:
int i = 42;
CString str("50");
int temp = _ttoi(str);
temp += i;
TCHAR buffer[50];
_itot(temp, buffer, 10);
str = buffer;
-Saurabh
|
|
|
|
|
works until the last statement: str = buffer; at this point buffer does indead have the value I want, but I get an Access violation error when the assignment operator in CString tries to assign buffer's value to the CString(ie str).
A C++ programming language novice, but striving to learn
|
|
|
|
|
check CString format function
CString tmp;
int a = 5;
tmp.Format("%d Hey ", a);
Hope this helps.
|
|
|
|
|
I get this error: "Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast"
A C++ programming language novice, but striving to learn
|
|
|
|
|
That should be:
CString tmp;
int a = 5;
tmp.Format(_T("%d Hey "), a);
Here's a tip:
Choose a string character type and stick with it.
The three common choices are
char (ANSI)
wchar_t (Unicode)
TCHAR (Generic - either char or wchar_t based on build configuration)
MFC uses generic types and, except for OLD APIs, so does Windows, so if you're using MFC,
generic is probably the best choice - unless you want to have to conver strings every
time you call a Windows or MFC API.
CString is also a generic type - it's either a CStringA (ANSI/char) or
CStringW (Unicode/wchar_t) depending on the build configuration.
If you choose to use the generic types, use them everywhere.
That means:
Use the Generic Text Mappings[^]
Wrap your string literals with the _T() macro
Use CSring instead of CStringA or CStringW
IMO, this stuff should be second-nature. You shouldn't have to think about it.
It's VERY worthwhile to take the time to understand it completely.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks Mark
A C++ programming language novice, but striving to learn
|
|
|
|
|
Hi,
I have the following issue:
#include <time.h>
....
struct tm tm;
if(strptime("2001-05-21", "%Y-%m-%d", &tm) == NULL)
{
//Some error processing
}
But I seem to be getting the following error when I compile, Can someone please tell me what I am doing wrong?
error C3861: 'strptime': identifier not found, even with argument-dependent lookup
|
|
|
|
|
correction
#include < time.h >
|
|
|
|
|
That is because strptime is not available in VC++. You can either try something else or use a open source version like strptime[^].
-Saurabh
|
|
|
|
|
Hi,
I created an SDI application(MFC) with an Acceletor Key (F1) that calls a Modeless Help Dialog. However, I would like to be able to select the F1 VK again so that it would close the Help dialog. This works if I move the focus from the help dialog to the main application window. Any ideas why this is happening. I do recall seeing this work if the dialog window is created using the WIN32 API CreateWindow.
Thanks
|
|
|
|
|
Try to get the KeyDown event and if it is the key you need, then call the method of the main window.
DialogBoxes doesn't share all the features of the application that called him.
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.
|
|
|
|
|
Write a program that prompts the user to enter text from the keyboard. The text is read until Ctrl+Z is entered, i.e., the end of file is reached. The program should count the frequency of each digit and of each letter of the alphabet (but it should not distinguish an uppercase letter from a lowercase letter). When the user finishes inputting text, the program should display each letter and its frequency in a table format. Also, the number of special characters (i.e. not letters nor digits) should be reported.
Hint: Declare an array of counters, one for each letter and for each digit. Use the letter and the digit itself as the subscript that determines which array element to increment. To do this the program must convert the letter and the digit to the corresponding subscript (the ASCII values of the lowercase letters are 97 – 122, the ASCII values for the uppercase letters are 65 – 90 and the ASCII values of the 10 digits are 48-57).
Example:
The following input:
Th1s 1s a test.^Z
Should produce the following result:
1 2
a 1
e 1
h 1
s 3
t 3
Special symbols:4
Additional requirements:
- the program cannot use global variables
- the program must contain at least two functions called count and printReport; formal parameters can be added to these functions (if necessary)
i need a code ASAP plz any help is appreciated. ive been working this code for days and its almost due.
|
|
|
|
|
homework ... what have you done ?
This signature was proudly tested on animals.
|
|
|
|
|
Maximilien wrote: what have you done ?
Rhetorical question?
led mike
|
|
|
|
|
You missed the following sentence: michael1201
wrote: ive been working this code for days and its almost due.
He just needs a little help: semicolons here and there.
BTW: ASAP plz!
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]
|
|
|
|
|
no...that would be "OMG what have you done?".
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
michael1201 wrote: i need a code ASAP...
Check your inbox. I sent it as fast as I could. Sorry for the delay.
"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
|
|
|
|
|
michael1201 wrote: i need a code ASAP plz
Done: visit www.cpallini.free.homework.com[^]
BTW what have you done so far. What is still missing? What are you troubles about?
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]
|
|
|
|
|
Only Days??
Most Software takes Months, (at least) so get used to it and don't give up after days. Hint: In future: Start Earlier.
Success
Bram van Kampen
|
|
|
|
|
who can tell me write a resource dll
e.g : include dialogbox,button and message loop
thanks
|
|
|
|
|
1/ Try posting a new question - you've only asked one person by replying to his post, and he might not care or know.
2/ Trying going to google, and search for "resource only dll" - there are several useful looking hits on the first page.
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
Bram van Kampen
|
|
|
|
|
Hello,
I am writing a program which can get the user-defind message from the specific program.
After the program get the message, the program will do post-processing.
If I do all action in MainFrame, the program can work. (I experimented this by pop-up a message window)
But if I want the message can be delivered to the document object from MainFrame,
then do post-processing in the document object, the program would fail.
The program would hang there and no response for any action. (Ex : close the program)
And at that time, the program which send the message even doesn't launch...
I have no idea to solve this problem. Does anyone can help me ?
My environment : Vista SP1, Visual Studio 2005 SP1, Platform SDK 2003 SP1
The MFC/SDI application is created by the wizard. I don't change the default class name.
Below is my code of MainFrm.h :
#pragma once
#include "LToolDoc.h"
#define MYWM_NOTIFYICON (WM_USER+2)
class CMainFrame : public CFrameWnd
{
protected:
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)
public:
public:
public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
public:
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
protected:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
DECLARE_MESSAGE_MAP()
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
};
and my part code of MainFrm.cpp is
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
CWnd* pWnd = AfxGetMainWnd();
if(pWnd == NULL)
return FALSE;
ASSERT_VALID(pWnd);
ASSERT_KINDOF(CFrameWnd, pWnd);
CFrameWnd* pMainFrame = static_cast<cframewnd*>(pWnd);
CFrameWnd *pActiveFrame = pMainFrame->GetActiveFrame();
if(pActiveFrame == NULL)
return FALSE;
CLToolDoc *pDoc = (CLToolDoc *)pActiveFrame->GetActiveDocument();
pDoc->TranslateMessage(pMsg);
return TRUE;
}
and the TranslateMessage() in LToolDoc is
void CLToolDoc::TranslateMessage(MSG* pMsg)
{
if(pMsg->message == USER_DEFINED_MESSAGE_1){
else if(pMsg->message == USER_DEFINED_MESSAGE_2){
else if(pMsg->message == USER_DEFINED_MESSAGE_3){
else{}
}
Thanks a lot !!!
|
|
|
|
|
What happens to all the messages that are not USER_DEFINED_MESSAGE_x?
Why use PreTranslateMessage() when MFC provides message handling for you?
It looks to me like you mark every message handled (by returning TRUE from
PreTranslateMessage() so all the system messages don't get handled.
You should return TRUE only if CLToolDoc::TranslateMessage() handles the message,
otherwise return CFrameWnd::PreTranslateMessage(pMsg).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|