Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working in an old c++ application where the UI is created completely dynamic. I have a framework which helps me in creating the UI. None of the edit box in this application is scrollable. So when i type characters having lon width like 'W', it doesn'e allow even the maximum allowed character limit, because the scroll property ES_AUTOHSCROLL is not enabled. I coded it to enable this property using the function SetWindowLong(). When i use SPY++ to verify this, it has got this property set. But still my edit box is not horizontally scrollable. Can anyone help me with this?
Posted

See the notes at the beginning of the documentation[^].
 
Share this answer
 
Comments
Resmi Anna 7-Aug-13 9:06am    
I did follow the document. but it is still not working. can anyone tell me how to enable the ES_AUTOHSCROLL style for an edit control dynamically?
Richard MacCutchan 7-Aug-13 13:11pm    
You obviously did not follow the document because it explicitly states that you cannot enable this feature after the control has been created.
pasztorpisti 8-Aug-13 8:49am    
As the linked documentation states, it can not be enabled and the same is true for most of the window styles in the WinAPI. If you want to enable it at runtime then create a compound control: A panel that has 2 child controls, 2 editboxes that completely cover the panel. One of the editboxes has ES_ATOHSCROLL enabled while the other doesn't. You make only one of these editboxes visible and you change visibility as needed. You can still provide a single HWND, the HWND of the panel to the other parts of the framework. In the code of the panel you may have to write together the framework and the currently active editbox. Implement this only if it is really needed.
As Richard says some of the edit controls styles cannot been changed if the control still exist. But you can replace the control by a new one. If the control handles (HWND) are stored by the program you have to replace the by the new handle. Please don't try this solution with MFC classes.

snippet:
C++
typedef void (*FNCHANGESTYLE)(long&,long&);
HWND replacecontrol(HWND h,const int idc,FNCHANGESTYLE fnchange)
{
  HWND      hwnd;
  HWND      prev;
  RECT      rc;
  POINT      pt = {0,0};
  HINSTANCE  hinst;
  long      style;
  long      exstyle;
  TCHAR      text[256];
  TCHAR      scls[256];
  HFONT      hfont;
  int        focus;

  hwnd    = GetDlgItem(h,idc);

  // control not exist
  if(!IsWindow(hwnd)) return 0;

  prev    = GetWindow(hwnd,GW_HWNDPREV);
  hinst   = (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE);
  style   = GetWindowLong(hwnd,GWL_STYLE);
  exstyle = GetWindowLong(hwnd,GWL_EXSTYLE);
  focus   = hwnd == GetFocus();
  hfont   = (HFONT)SendMessage(hwnd,WM_GETFONT,0,0);

  ClientToScreen(h,&pt);
  GetWindowRect(hwnd,&rc);
  GetClassName(hwnd,scls,sizeof(scls)/sizeof(scls[0]));
  GetWindowText(hwnd,text,sizeof(text)/sizeof(text[0]));

  DestroyWindow(hwnd);
  fnchange(style,exstyle);

  // create the new one
  hwnd = CreateWindowEx
  (
    exstyle,
    scls,
    text,
    style,
    rc.left-pt.x,
    rc.top-pt.y,
    rc.right-rc.left,
    rc.bottom-rc.top,
    h,
    (HMENU)idc,
    hinst,
    0
  );

  // apply the font
  SendMessage(hwnd,WM_SETFONT,(WPARAM)hfont,1);
  // adjust z-order
  SetWindowPos(hwnd,prev,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
  // set focus if needed
  if(focus) SetFocus(hwnd);
  return hwnd;
}

void modES_AUTOHSCROLL(long& style,long& exstyle)
{
  style ^= ES_AUTOHSCROLL;
}

void modES_PASSWORD(long& style,long& exstyle)
{
  style ^= ES_PASSWORD;
}

void changestyle(HWND hdlg)
{
  HWND    hwnd;
  HWND    htxt;

  hwnd = replacecontrol(hdlg,101,modES_AUTOHSCROLL);
  hwnd = replacecontrol(hdlg,103,modES_PASSWORD);

}

Good luck.
 
Share this answer
 
Have you set ES_MULTILINE flag ?
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900