|
You can add a UI handler for the menu item
ON_UPDATE_COMMAND_UI
and do something like
void CYourClass::OnUpdateYourMenuItem(CCmdUI* pCmdUI)
{
pCmdUI->SetText("New Menu Text");
}
|
|
|
|
|
Wanted to say, thanks for posting this. I had been scratching my head trying to figure out how to do this and was making it a far more difficult chore than it needed to be. This was the answer, so simple that I hadn't even considered it. worked perfectly by the way.
Mike - typical white guy.
"Political correctness is a doctrine, fostered by a delusional, illogical minority, and rabidly promoted by an unscrupulous mainstream media, which holds forth the proposition that it is entirely possible to pick up a piece of sh*t by the clean end."
Thomas Mann - "Tolerance becomes a crime when applied to evil."
As American as: hot dogs, apple and Sarah Palin.
|
|
|
|
|
hi to all,
need to pass a string to a void function that does not have a parameter, looks like that:
int CMyString::GetLength (void)const
{
}
in the main function, the code is follow
CMyString string1;
string1 = "Hello world!";
int nLen = string1.GetLength();// should give nLen = 11.
The class CMyString should work like the class String in this case.
Do not k now how to implement the function GetLength().
Any help will be appriciated. Thanks.
|
|
|
|
|
you don't know how to create a method in your own class ?
the class CMyString should hold a member variable that holds the buffer of some sort of the string.
just create a method that just do a strlen (if the buffer is a char* ) on the member variable.
something like :
class CMyString
{
//... some other stuff
char* m_internalBuffer;
int GetLength(){ return strlen(m_internalBuffer);};
}
|
|
|
|
|
You should (like CString , for instance does):
- define a
CMyString constructor accepting a const char * as argument. - overload the
CMyString assignment operator (= ) to accept a const char * as argument. - both of the above methods should initialize
CMyString internal data member (a character buffer, for instance). - define a
GetLenght method returning the strlen of the internal character buffer.
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]
|
|
|
|
|
susanne1 wrote: string1 = "Hello world!";
int nLen = string1.GetLength();// should give nLen = 11.
Why would you want to use a function that returned an incorrect value?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
You're so meticulous, my 5 .
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]
|
|
|
|
|
Hello,
I want to use a C++ function in order to check if a filename exists. I have already tried to use _access as well as _stat, but these functions also return true if the filename given is a fooldername instead. So how can I distinguish if it's a really a file or only a folder?
|
|
|
|
|
Erik wrote: I want to use a C++ function in order to check if a filename exists.
See PathFileExists()[^]
Erik wrote: . So how can I distinguish if it's a really a file or only a folder?
See PathIsDirectory()[^]
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Erik wrote: So how can I distinguish if it's a really a file or only a folder?
There's also GetFileAttributes() .
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hi All,
I need to create a notepad in Dialog based MFC application.I need some idea about this.
Help me......
Thanks & Regards,
Anitha
|
|
|
|
|
AnithaSubramani wrote: I need to create a notepad in Dialog based MFC application.
Creating a SDI application and deriving view class from CEditView would be better choice for this.
I hope it helps.
Regards,
Sandip.
|
|
|
|
|
Hi,
I need a example code.pls help me....
|
|
|
|
|
Does Notepad with RE[^] help?
It is advanced but you can get started.
If you want you can even follow this tutorial Creating notepad[^]
BTW:
AnithaSubramani wrote: pls help me....
No need to write this in every post.
Everyone here will help you provided you give sufficient information.
Regards,
Sandip.
|
|
|
|
|
|
AnithaSubramani wrote: I need a example code.
Open Visual Studio. Create a new SDI project. Derive the view from CEditView .
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
AnithaSubramani wrote: I need a example code
You can create a working notepad application with the App Wizard.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I want my control (CButton derived) has the same behaviour if CLICKED and DOUBLECLICKED.
Now, it is working well if CLICKED...I need to extend the functionality on DOUBLCLICK.
So, I simply added
ON_CONTROL_REFLECT_EX(BN_DOUBLECLICKED, CMyCButton::OnBnDblClicked)
In that function I want to do some similar to
BOOL CMyCButton::OnBnDblClicked(){
PostMessage(WM_COMMAND, MAKELONG(GetDlgCtrlID(), BN_CLICKED), (LPARAM) GetSafeHwnd());
return TRUE;
}
But in that way only my control receive the message BN_CLICKED , not the parent Dialog.
Please, what is the right way to send/post to the control (together to it's parent) that message?
Russell
|
|
|
|
|
Have a look at here[^]...
|
|
|
|
|
Thank you....but your solution looks work as my previus one, i.e. it is a perfect solution to manage the message inside the control, but his parent window doesn't receive the classic message BN_CLICKED
My be also I'm wronging something...
BOOL XBmpChkBtn::OnBnDblClicked(){
const MSG* pstMSG = GetCurrentMessage();
DefWindowProc(WM_COMMAND, MAKELONG(GetDlgCtrlID(), BN_CLICKED), (LPARAM) GetSafeHwnd());
return TRUE;
}
Russell
|
|
|
|
|
Please correct as
DefWindowProc( WM_LBUTTONDOWN, pstMSG->wParam, pstMSG->lParam );
|
|
|
|
|
The solution looks:
BOOL CMyCButton::OnBnDblClicked(){
GetParent()->PostMessage(WM_COMMAND, MAKELONG(GetDlgCtrlID(), BN_CLICKED), (LPARAM) GetSafeHwnd());
return TRUE;
}
or the same of:
ON_CONTROL_REFLECT(BN_DOUBLECLICKED, CMyCButton::OnBnDblClicked)
and
BOOL CMyCButton::OnBnDblClicked(){
GetParent()->PostMessage(WM_COMMAND, MAKELONG(GetDlgCtrlID(), BN_CLICKED), (LPARAM) GetSafeHwnd());
}
but I'm not sure that it is the right way to manage messages when using derived controls, I was aspecting to do everything inside the control class: that call to GetParent() looks strange to me.
any comments?
Russell
|
|
|
|
|
You posted the solution for yourself.
You are handling the conversion from BN_DOUBLECLICKED to BN_CLICKED in the button control as you desire.
But the whole purpose was to change the message to the parent from BN_DOUBLECLICKED to BN_CLICKED.
So you need to send / post the message to the parent. Which the GetParent () helps you with. If it makes it clearer for you, try this:
BOOL CMyCButton::OnBnDblClicked()
{
HWND hButton = GetSafeHwnd ();
HWND hDialog = GetParent (hButton);
::PostMessage(hDialog, WM_COMMAND, MAKELONG(GetDlgCtrlID(), BN_CLICKED), (LPARAM)hButton);
}
Ends up being the same though. I'd use SendMessage rather than PostMessage, but that's a different question.
Iain.
|
|
|
|
|
I'm according to you
Thank you
Russell
|
|
|
|
|
This is the code i used ..........To CREATE a File
and enter a default string..
...........Ive TO USE VC++ MFC
void CFileApp::OnInsert()
{
HANDLE hFile = CreateFile(_T("C:\\Documents and Settings\\MyFile.ini"),
GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Couldn't create the file!"));
else
{
// Attach a CFile object to the handle we have.
CFile myFile(hFile);
static const char sz[] = "Hockey is best!";
// write string, without null-terminator
myFile.Write(sz, lstrlen(sz));
myFile.Close();
}
}
This works.....
BUt For INI I want to ENTER DATA SECTIN-WISE....
...........
Here Data is written just like in Text files...
I need to use ...GetProfileString....
WriteProfileString..... n so on...
how do i do it??
I NEED TO MAKE A PHONE DIRECTORY USING INI FILE......
|
|
|
|