How can I detect the existing text alignment for a CEdit control? I want to determine if the alignment is ES_LEFT or some other alignment.
I tried detecting the style in the WINDOWINFO, but this does not work.
WINDOWINFO wi;
wi.cbSize = sizeof(WINDOWINFO);
edit1->GetWindowInfo(&wi);
if (wi.dwExStyle & ES_LEFT || wi.dwStyle & ES_LEFT)
{
CString Str; // breakpoint.
}
else
{
CString Str; // breakpoint.
}
Thanks dxiv. This works for determining if left-alignment is being used or not.
if ((edit1->GetStyle() & (ES_LEFT | ES_CENTER | ES_RIGHT)) != ES_LEFT)
{
// left-alignment not used.
}
Related
I encounter a problem with CEdit textbox , the exact problem is that i unable to Set Focus to the control after creating it.
What i want to do is:
Create CEdit control temporary.
Set focus to the control.
Get the number from the control and store it in a value.
Destroy control after 10 second.
After some research on internet i couldn’t find solution to the problem , therefore i address to you.
Hope to find a solution. Thanks in advance.
i tried
editctrl.SetFocus();
DWORD dw = LOWORD(editctrl.GetDlgCtrlID()) | HIWORD(EN_SETFOCUS);
SendMessage(WM_COMMAND,(WPARAM)dw, (LPARAM)editctrl.GetHandle());
BOOL CViewsDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == 0xBB /*+*/)
{
if (!editctrl)
{
editctrl.Create(ES_NUMBER | WS_CHILD|WS_VISIBLE | WS_BORDER | WS_TABSTOP, CRect(0, 0, 100, 20), this, NULL);
editctrl.ShowWindow(SW_SHOW);
editctrl.SetFocus();
//DWORD dw = LOWORD(editctrl.GetDlgCtrlID()) | HIWORD(EN_SETFOCUS);
//SendMessage(WM_COMMAND,(WPARAM)dw, (LPARAM)editctrl.GetHandle());
telestis = e_sinplin;
SetTimer(1, 10000, NULL);
}
}
return CDialogEx::PreTranslateMessage(pMsg);
}
You need to use CDialog::GotoDlgCtrl to set focus in dialog windows.
I am writing a SDI application on Visual Studio 2012. The MFC Wizard generated two CDockablePane-derived objects. The right-side CPropertiesWnd (CDockablePane-derived) object is named m_wndProperties. I embed in m_wndProperties a CPropertySheet object with a CPageNone (CPropertyPage-derived) object captioned "HELP" like this (I use the CPropertySheet class directly). However, the real size of the CPropertySheet object is bigger.
I have tried to adjust the size of the dialog related to the CPageNone object (named m_pageNone) in the Dialog Editor. This has no effect. In the MainFrm.cpp, the only lines relating to m_wndProperties I can find are:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
.....
m_wndProperties.EnableDocking(CBRS_ALIGN_RIGHT);
DockPane(&m_wndProperties);
.....
}
.....
BOOL CMainFrame::CreateDockingWindows()
{
.....
CString strPropertiesWnd;
bNameValid = strPropertiesWnd.LoadString(IDS_PROPERTIES_WND);
ASSERT(bNameValid);
if (!m_wndProperties.Create(strPropertiesWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_PROPERTIESWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI))
{
TRACE0("無法建立 [屬性] 視窗\n");
return FALSE; // 無法建立
}
.....
}
.....
void CMainFrame::SetDockingWindowIcons(BOOL bHiColorIcons)
{
.....
HICON hPropertiesBarIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(bHiColorIcons ? IDI_PROPERTIES_WND_HC : IDI_PROPERTIES_WND), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
m_wndProperties.SetIcon(hPropertiesBarIcon, FALSE);
}
And here is the AdjustLayout() in my PropertiesWnd.cpp:
void CPropertiesWnd::AdjustLayout()
{
if (GetSafeHwnd () == NULL || (AfxGetMainWnd() != NULL && AfxGetMainWnd()->IsIconic()))
{
return;
}
CRect rectClient;
GetClientRect(rectClient);
m_PropertySheet.SetWindowPos (NULL, rectClient.left, rectClient.top, rectClient.Width (), rectClient.Height (), SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
}
And in my PageNone.cpp, I only have three functions: the default constructor, the default destructor and DoDataExchange.
My question is how can I adjust the size of m_wndProperties or m_pageNone to fit each other? Thank you very much.
I have got this working in a different way (the code is too large to give in this answer, but the main points are:
a) don't do anything in CMainFrame::OnCreate()
b) in CMainFrame::CreateDockingWindows(), after m_wndProperties.Create(), add the following code
m_PropertySheet.Create(...);
CRect rc;
m_PropertySheet.GetRect(&rc);
m_wndProperties.SetMinSize(rc.Width(), rc,Height());
m_wndProperties.EnableDocking(CBRS_ALIGN_RIGHT);
DockPane(&m_wndProperties);
ShowPane(&m_wndProperties, TRUE, FALSE, TRUE);
Your code in AdjustLayout() is plausible right, but I think during startup it will be called too early. Because the default size will be read from CWinAppEx::LoadState(), which always read the previous size from the Registry. It can probably disabled with CWinAppEx::EnableLoadWindowPlacement(FALSE). not tested.
Post a User-Defined Message at the end of InitInstance(). Or just try with a timer in CMainFrame::Create() .. SetTimer(123,2000,NULL);
void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == 123)
{
m_wndProperties.SetWindowPos(this, 0, 0, 400, 200, SWP_NOZORDER | SWP_FRAMECHANGED);
RecalcLayout();
KillTimer(123);
}
CFrameWndEx::OnTimer(nIDEvent);
}
I would like to have thin child frame borders in my MFC/MDI application. Microsoft suggests changing window styles in PreCreateWindow function and it seems like proper window style is WS_BORDER. However something like this doesn't work;
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= WS_BORDER;
return CMDIChildWnd::PreCreateWindow(cs);
}
What am I missing here?
Thanks
You can try something like this:
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style = WS_CHILD | WS_VISIBLE | WS_BORDER;
if(! CMDIChildWnd::PreCreateWindow(cs))
return FALSE;
return TRUE;
}
Its been a while i have stopped working on VC++ and now i have some project which i have again started my development on VC++.... I am having a strange issue right now the label of the control is not getting change at all here is my code for initialization of mfcoutlookbar
BOOL CMainFrame::CreateOutlookBar(CMFCOutlookBar& bar, UINT uiID, CMFCShellTreeCtrl& tree, CCalendarBar& calendar,CListCtrlBar &listctrl,int nInitialWidth)
{
bar.SetMode2003();
BOOL bNameValid;
CString strTemp;
bNameValid = strTemp.LoadString(IDS_SHORTCUTS);
ASSERT(bNameValid);
if (!bar.Create(strTemp, this, CRect(0, 0, nInitialWidth, 32000), uiID, WS_CHILD | WS_VISIBLE | CBRS_LEFT))
{
return FALSE; // fail to create
}
CMFCOutlookBarTabCtrl* pOutlookBar = (CMFCOutlookBarTabCtrl*)bar.GetUnderlyingWindow();
if (pOutlookBar == NULL)
{
ASSERT(FALSE);
return FALSE;
}
pOutlookBar->EnableInPlaceEdit(FALSE); //we dont want editing
static UINT uiPageID = 1;
// can float, can autohide, can resize, CAN NOT CLOSE
DWORD dwStyle = AFX_CBRS_FLOAT | AFX_CBRS_AUTOHIDE | AFX_CBRS_RESIZE;
CRect rectDummy(0, 0, 0, 0);
const DWORD dwTreeStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS;
//Create tree
tree.Create(dwTreeStyle, rectDummy, &bar, 1200);
//bNameValid = strTemp.LoadString(IDS_FOLDERS);
ASSERT(bNameValid);
pOutlookBar->AddControl(&tree, L"Folders", 2, TRUE, dwStyle);
//create calender
calendar.Create(rectDummy, &bar, 1201);
// bNameValid = strTemp.LoadString(IDS_CALENDAR);
// ASSERT(bNameValid);
pOutlookBar->AddControl(&calendar, L"CALLLLLL",1, TRUE, dwStyle);
//create list control bar
listctrl.Create(rectDummy,&bar,1202);
// bNameValid = strTemp.LoadString(IDS_DASHBOARD);//Dashboard to check the statistics and statical reports
// ASSERT(bNameValid);
pOutlookBar->AddControl(&listctrl, L"Some", 0, TRUE, dwStyle); //the digit represent icon
bar.SetPaneStyle(bar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
pOutlookBar->SetImageList(theApp.m_bHiColorIcons ? IDB_PAGES_HC : IDB_PAGES, 24);
pOutlookBar->SetToolbarImageList(theApp.m_bHiColorIcons ? IDB_PAGES_SMALL_HC : IDB_PAGES_SMALL, 16);
pOutlookBar->RecalcLayout();
BOOL bAnimation = theApp.GetInt(_T("OutlookAnimation"), TRUE);
CMFCOutlookBarTabCtrl::EnableAnimation(bAnimation);
bar.SetButtonsFont(&afxGlobalData.fontBold);
return TRUE;
}
if you see i am using two different controls by providing them the text label e,,g,
pOutlookBar->AddControl(&listctrl, L"Some", 0, TRUE, dwStyle);
and the other is
pOutlookBar->AddControl(&calendar, L"CALLLLLL",1, TRUE, dwStyle);
now the label "Some" and "CALLLLLL" is not being displayed i have tried everything but i dont know why its still displaying the default text of
"Calenders" and "Folders"
I have changed all the text inside String table as well ...this code is generated by Visual Studio C++ by wizard using Office 2000.
What is the mistake i am doing???
Okay finally figured out the problem is the cache , the outlookbased bar for any application save the caption and label in registry...so cleaning your solution rebuilding it again and again will not give you the right tabs captions unless you delete the registry entries for that application.
HKEY_USERS\S-1-5-21-3153867254-3211561466-2840709754-1000\Software\Local AppWizard-Generated Applications\test2
and then delete this test2 project key ....after that run your application it will display the correct label.
I am creating my textbox with these options. I can Copy / Cut / Paste / Undo, but when I hit Select All it doesn't select all. I can right click and click Select All but CTRL + A doesn't do anything. Why?
wnd = CreateWindow("EDIT", 0,
WS_CHILD | WS_VISIBLE | ES_MULTILINE | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
x, y, w, h,
parentWnd,
NULL, NULL, NULL);
Ctrl+A is not a built-in accelerator like Ctrl+C and Ctrl+V. This is why you see WM_CUT, WM_PASTE and WM_COPY messages defined, but there is no WM_SELECTALL.
You have to implement this functionality yourself. I did in my MFC app like this:
static BOOL IsEdit( CWnd *pWnd )
{
if ( ! pWnd ) return FALSE ;
HWND hWnd = pWnd->GetSafeHwnd();
if (hWnd == NULL)
return FALSE;
TCHAR szClassName[6];
return ::GetClassName(hWnd, szClassName, 6) &&
_tcsicmp(szClassName, _T("Edit")) == 0;
}
BOOL LogWindowDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN)
{
if ( pMsg->wParam=='A' && GetKeyState(VK_CONTROL)<0 )
{
// User pressed Ctrl-A. Let's select-all
CWnd * wnd = GetFocus() ;
if ( wnd && IsEdit(wnd) )
((CEdit *)wnd)->SetSel(0,-1) ;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
Note, I stole IsEdit from this page: http://support.microsoft.com/kb/145616
I point that out partly because I want to give credit, and partly because I think the IsEdit function (comparing classname strings) is dorky and I want to give blame.
You could simply use EM_SETSEL message to the textbox,
According to MSDN ,
If the start is 0 and the end is –1, all the text in the edit control is selected. If the start is –1, any current selection is deselected.
so,
SendMessage(hwndEdit,EM_SETSEL,0,-1);
Will work fine.
I tend to use MFC (forgive me) instead of Win32 so I cannot answer this definitively, but I noticed this comment added to a page on an MS site concerning talking with an Edit control (a simple editor within the Edit control):
The edit control uses WM_CHAR for
accepting characters, not WM_KEYDOWN
etc. You must Translate() your
messages or you ironically won't be
able to edit the text in the edit
control.
I don't know if this applies to BoltBait's response, but I suspect it does.
(I found this at http://msdn.microsoft.com/en-us/library/bb775462(VS.85).aspx)
You need to capture that keystroke and do the select all yourself.
Here is some C# code for use with a RichTextBox:
protected override void OnKeyDown(KeyEventArgs e)
{
// Ctrl-A does a Select All in the editor window
if (e.Control && (e.KeyCode == Keys.A))
{
this.SelectAll();
e.Handled = true;
}
}
Sorry, I don't have Win32 code for you.
The strange thing is that Ctrl+A DOES work (as select all), if you do NOT specify ES_MULTILINE
But that doesn't help if you need multiline
The MSDN documentation for ES_MULTILINE doesn't appear to say anything about this.
Could it be that something else is stealing Ctrl+A? Use Spy++ to verify that it reaches your edit control.
Why not add an accelerator for Ctrl+a to SelectAll?