Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC
Hello guys
 
I've faced the trouble that consist in text transferring into Edit control
I'm using SDI with Ribbon. The Edit control is on the panel
 
When I try to pass the text from My View Class by SetDlgItemText(ID_EDIT1,L"Bla-bla");
It gives no effect.
I've already tried do it in different ways
1)
::SetDlgItemText(GetParent()->GetSafeHwnd(),ID_CR_EDIT,L"adasdaasd");
also in vain
It is the merest trifle but
I don't see where the problem might be
 
I've red all articles on msdn and on web,But everywhere they just call
SetDlgItemText(CONTROL_ID,"Some text")
 
If I try run GetDlgItem(ID_EDIT1),It returns NULL. Maybe I need to catch some event in the BEGIN_MESSAGE_MAP? I don't see where the problem is.
I took Edit from toolbox and hung it on the form(like I'd do in FormConstructor in C#), then opened Properties and set a new ID.
It seems to me it's quite enough to operate with Edit control, right ?
Now I'd like to set a new value from whatever function in MyView class
 
I suppose the problem with parent class that handles Edit control events.
I've tried do
GetParent()->SetDlgItemText(ID_CR_EDIT,L"Abcd");
=No way
Now I'm trying to detect the parrent window with Spy++, but I haven't caught it yet :(
Posted 10-Oct-12 12:12pm
Edited 10-Oct-12 16:06pm
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

::SetDlgItemText(GetParent()->GetSafeHwnd(),ID_CR_EDIT,L"adasdaasd");
 
Here ID is ID_CR_EDIT, Please confirm the ID is same as that of the expected control.
 
GetDlgItem(ID_EDIT1) returns NULL, it means a window with ID_EDIT1 ID is not exists in the window.
 
Try to use Spy++ tool to identify the Parent Window and ID of the control at run time.( From Spy menu, select Find Window, Use "Finder Tool" to select your window ) and ensure the control ID is same as that you given in code. Please confirm the parent window of the control too.
  Permalink  
v3
Comments
JOHN 602 at 10-Oct-12 20:36pm
   
::SetDlgItemText(GetParent()->GetSafeHwnd(),ID_CR_EDIT,L"adasdaasd");
and ID_CR_EDIT is the same as it set in properties and of course it defined in Resource.h as #define ID_CR_EDIT 32784
Then I preset the text in properties window and try to read at runtime
CEdit* pBoxOne;
pBoxOne = (CEdit*) GetDlgItem(ID_CR_EDIT); in debug mode I see that is NULL
It returns NULL 'cause the prog begin searching the Edit control in same window. But what class handles Edit if it's on the ribbon panel. Looks like I should call it if I directly set the right class
 
I confused with all that It seems the simplest thing, but WTF ?
Santhosh_G at 10-Oct-12 20:58pm
   
Please use spy++ tyo find the parent and ID of the control.
JOHN 602 at 10-Oct-12 21:29pm
   
Ive found that window class is Afx:RibbonBar:1370000:8:10003:10
If I try do
 
HWND hTray;
 
hTray = ::FindWindow(L"Afx:RibbonBar:1360000:8:10003:10", NULL);
if(hTray)
{
 
::SetDlgItemText(hTray,ID_CR_EDIT,L"mn,m");
}
hTray returns NULL;
Santhosh_G at 10-Oct-12 21:33pm
   
This may give some information realated to Ribbon control http://stackoverflow.com/questions/4592203/find-window-handle-of-a-ribbon-button
JOHN 602 at 10-Oct-12 22:02pm
   
In that articles people say that There is no way to interact directly with the controls on the ribbon( I mean there is no way to change it's state).
But a reasonable question comes to my mind: Why is there an edit control if I can't change text in it ?? It's looks like foolishly.
I deem I've tried all the ways I found to get access to the ribbon control
CString pBoxOne;
GetParentFrame()->GetDlgItemText(ID_CR_EDIT,pBoxOne);//no use
 
What else I should try? I don't believe that there is no way to overcome this obstacle.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 395
1 DamithSL 218
2 Sergey Alexandrovich Kryukov 215
3 Dave Kreskowiak 200
4 Maciej Los 195


Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 10 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid