How to create an EditBox using Win32 WinAPI so that it looks like the one you would get by placing an editBox in a VS designer in for example Visual C# or VB (with a nice top border etc.)? Here is an image of how it looks like and how it is when dropped in a designer:
I have tried this code:
hWndTextBox = CreateWindow(L"EDIT", L"My default text",
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL ,
10,10,200,20,
hWnd,
(HMENU) ID_TEXTBOX,
hInst,
NULL);
But that one does not look like the box created in some .NET IDE designer. I have enabled visual styles in my Win32 application and I am using VS 2010 under Win7. I want it to look like the second one.
I must be missing some of the styles. I hope
Yup, you must use CreateWindowEx() so you can specify WS_EX_CLIENTEDGE instead of WS_BORDER. And use WM_SETFONT to set a decent TrueType font instead of the default Terminal.
To create such effect you need to subclass the Editbox control and override the WM_PAINT and WM_ERASEBKGND messages.
For info about subclassing see: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633570(v=vs.85).aspx#subclassing_window
Related
I have created a window application using Visual Studio 2017 template. CreateWindowEx expands to CreateWindowExW. I create an edit window this way:
LoadLibrary(TEXT("Msftedit.dll"));
hwndEdit = CreateWindowEx(
0,
MSFTEDIT_CLASS,
TEXT("Type here"),
WS_VISIBLE | WS_CHILD ,
100,
100,
100,
30,
gHwnd,
NULL,
hInst,
NULL);
MSFTEDIT_CLASS is defined as L"RICHEDIT50W" in Richedit.h This topic contains advice that I should use RICHEDIT_CLASSA (version 2.0). How to achieve it ?
Currently there are four versions for rich edit control:
Rich Edit Version 1.0
Rich Edit Version 2.0
Rich Edit Version 3.0
Rich Edit Version 4.1
The original specification for rich edit controls is Microsoft Rich Edit 1.0; the current specification is Microsoft Rich Edit 4.1.
It is suggested to use latest version for new application.
More detailed information about features supported on different versions you can refer to official document.
I want to create a Xamarin Forms Editor Control that changes its height when it gets filled(Adds a new line when space in previous line finished). I'm only interested in WinPhone and Android Platfroms.
The Editor itself doesn't support such property.
I know that the Android native control (EditText) supports it (Not sure about the WinPhone variant, TextBox). But I'm not sure how to implement it.
It will be very helpful if someone can explain me how to create the renderers for these platforms.
Edit
I found this partial solution, it kind of works fine but it is not so natural(as for example EditText in Android).
class RoundedEditor : Editor
{
public RoundedEditor()
{
this.TextChanged += (sender, e) => { this.InvalidateMeasure(); };
}
}
I'll be glad if someone will provide a better solution.
Edit 2
Here are the results of how it works now:
UWP
Writing first line:
pressing enter:
The previous line is not showed completely as I would like.
Android
In android it actually works great:
You will have to implement a custom Android EditText, and then use it for your XamarinForms control (by implementing a custom renderer for it)
Take a look at this implementation of resizable EditText:
https://github.com/ViksaaSkool/AutoFitEditText
You'd have to translate it to C# obviously, but its a great start point.
I can't find a working solution to change the title of my MFC SDI application. I don't use document/view. I need to change the title according to internal state of the applicaiton.
I've tried CMainFrame::SetWindowText from my main app module in InitInstance - with no luck.
I've tried to change CMainFrame::m_strTitle member variable and call OnUpdateFrameTitle(TRUE) after that - still no luck.
Inside OnTimer procedure - calling AfxGetMainWnd()->SetWindowText(_T("title from OnTimer")); - it does not work either.
What am I missing? That should be a common and simple task, shouldn't it?
EDIT: I'm sorry, it seems SetWindowText is working, just need to properly compile my app.
That's all my fault.
Overwrite CMainFrame::PreCreateWindow.
Clear the style FWS_ADDTOTITLE
cs.style &= ~(LONG)FWS_ADDTOTITLE;
Now it should be possible the window caption in any way you like.
The Default window caption is taken from the string resource with the ID AFX_IDS_APP_TITLE.
I am trying to render a html file in my own create window using Visual c++(x64). I have done every thing I just need some mechanism to display html file in my own window.I have html file contents stored in a buffer (and i am sure about that because i have the same html code in my buffer which I can see when I open that file in notepad, so the only thing i have to do is to get a way to render that html file in my window)
On a random search on google i have been aware that i need to host an activex control but i don't know how to do that.Yes ofcourse there are some samples availble on internet but they are not for Visual c++ (x64 MFC application).
What i have in mind is that
(1.) i will create a dialog using-
HINSTANCE g_hInst2 = NULL;
m_hwndPreview= CreateDialogParam( g_hInst2,MAKEINTRESOURCE(IDD_HTML_DIALOG), m_hwndParent,(DLGPROC)DialogProc, (LPARAM)this);
//I have not implemented the part below (its just idea that what should i do?? please correct me
// if my idea is wrong)I have not implemented it because when i create dialog using CreateDialogParam(...) when i debug it i get m_hwndPreview=0000000000000
// and once if m_hwndPreview is done successfully i have assumed the code below in my
// mind to achieve my target. please correct me if i am wrong ??
CWebBrowser2 * pBrowse = (CWebBrowser2 *) GetDlgItem(IDC_EXPLORER1);
COleVariant sLoc("http://localhost");
pBrowse->Navigate2(sLoc, NULL, NULL, NULL, NULL);
//after that
if (SUCCEEDED(hr))
{
ShowWindow(m_hwndPreview, SW_SHOW);
UpdateWindow( m_hwndPreview );
}
Am i right ??
Please answer the two questions (1.) Why m_hwndPreview=00000000000 ?? because i have created a dialog(IDD_HTML_DIALOG) using resource editor and inserted a activex contol (Microsoft web browser) and it is done succesfully because i can see in my file resource.h (I have #define IDC_EXPLORER1 1046) so its sure that it has been done.
There may be some problem in g_hInst2. i don't undersatnd it properly.
(2.) Is my approach to achieve my target is correct ?? if i _hwndPreview is done succesfully then the code which i have assumed will work or not ?? is my approach correct ??
Is the documentation for Rich Edit Controls really as bad (wrong?) as it seems to be? Right now I'm manually calling LoadLibrary("riched20.dll") in order to get a Rich Edit Control to show up. The documentation for Rich Edit poorly demonstrates this in the first code sample for using Rich Edit controls.
It talks about calling InitCommonControlsEx() to add visual styles, but makes no mention of which flags to pass in.
Is there a better way to load a Rich Edit control?
http://msdn.microsoft.com/en-us/library/bb787877(VS.85).aspx
Here's the only code I could write to make it work:
#include "Richedit.h"
#include "commctrl.h"
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_USEREX_CLASSES; //Could be 0xFFFFFFFF and it still wouldn't work
InitCommonControlsEx(&icex); //Does nothing for Rich Edit controls
LoadLibrary("riched20.dll"); //Manually? For real?
hWndRichEdit = CreateWindowEx(
ES_SUNKEN,
RICHEDIT_CLASS,
"",
WS_BORDER | WS_VISIBLE | WS_CHILD,
2, 2, 100, 24,
hWnd, (HMENU) ID_RICH_EDIT, hInst, NULL);
Using MFC, RichEdit controls just work.
Loading with InitCommonControlsEx() - ICC_USEREX_CLASSES doesn't load RichEdit AFAIK, you don't need it as it only does the 'standard' common controls, which don't include richedit. Apparently you only need to call this to enable 'visual styles' in Windows, not to get RichEdits working.
If you're using 2008, you want to include Msftedit.dll and use the MSFTEDIT_CLASS instead (MS are rubbish for backward compatibilty sometimes).
The docs do suggest you're doing it right for Win32 programming.
Many years ago, I ran into this same issue, and yes, the answer was to load the .dll manually. The reason, as far as I can remember, is that the RichEdit window class is registered in DllMain of riched20.dll.
Isn't there an import library (maybe riched20.lib) that you can link to. Then you won't have to load it "manually" at run time. That's how all the standard controls work. VS automatically adds a reference to user32.lib when you create a project.
I think you have to call CoInitializeEx before you create any of the common controls.
The LoadLibrary is not needed. If you link with the correct .lib file the exe-loader will take care of such details for you.