Rich Edit Control in raw Win32 - windows

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.

Related

using #ifdef inside "Windows Form Designer generated code" in C++ CLI with VS2010

Good afternoon,
I am having an issue trying to conditionally comment out some code sections and objects inside code that is generated by Windows Forms Designer.
If I simply comment out these objects, the designer will show no issues with the code and will display what I am working on
If I comment out with #ifdef and #endif in the code, the designer gives me
"C++ CodeDOM parser error: Line: 358, Column: 1 --- Unexpected token for a 'term' "
and will not display the UI I am working on. However the code will compile just fine without errors.
Is there a way to conditionally comment out sections of the designer code in the Form.h file?
Thanks,
-D
Do not edit designer-generated code. If your change works then it is not going to live long, wiped out when the designer re-generates the code. And the real problem, the designer code parser can only understand the kind of code it generates itself. It is not a full-blown compiler, it doesn't know beans what #ifdef might mean. Which is what the error is trying to tell you.
If you need conditional changes then you need to make them in form's constructor, after the InitializeComponent() call. You can remove or add controls and change their properties as needed.

How to change the title/caption of MFC SDI documentless application

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.

Win32 WinAPI EditBoX styles

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

How to host activex control for to render html on window using Visual c++ (x64) application

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 ??

Debugging XAML databinding in Visual Studio 2012

In the Silverlight 5 beta I could debug databinding directly in XAML. Where is this feature in Visual Studio 2012 (RC)? Can I do this with WPF, WinRT and/or Silverlight? If so how? When I set a breakpoint on a binding expression application, I get the message that the breakpoint will not be hit because no source code is associated with this line.
Update:
It works in Visual Studio 2012 (RC) for Silverlight 5 applications but not for WPF applications. Please don't tell me, that this feature does not exist for WPF!
Sorry to tell you but this feature DOES NOT exist in WPF XAML nor does it exist in WinRT XAML. I can't find an official source for WPF, but here is a pretty official one for WinRT (http://social.msdn.microsoft.com/Forums/en-US/toolsforwinapps/thread/fae53937-cb47-45da-b740-49f75f8d36e9/) he insinuates pretty strongly that this was an effort spearheaded purely by the Silverlight team and can possibly be expected in future versions of WPF and WinRT.
So far the best debugging techniques I've seen are as follows:
1) WinRT & WPF: Output Window
Using the output window with the proper options enabled, make sure Tools->Options->Debugging->Output Window->Data Binding = "Warning" or something else useful...
2) WinRT & WPF: Use a converter
Using a converter and just setting a break point inside the converter. Or you can build/use something similar to how WinRT XAML Toolkit does: http://winrtxamltoolkit.codeplex.com/.../WinRTXamlToolkit.Debugging/Converters/BindingDebugConverter.cs
3) WinRT: Use DebugSettings.BindingFailed
App.Current.DebugSettings.IsBindingTracingEnabled = true;
App.Current.DebugSettings.BindingFailed += (s, e) =>
{
// debug the failed binding here
};
see: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.debugsettings.bindingfailed for more information
4) WPF: Use PresentationTraceSources.TraceLevel Attached Property
Gives you a verbose output of the binding, see: http://msdn.microsoft.com/en-us/library/system.diagnostics.presentationtracesources.tracelevel.aspx for more information.
I realize this is an older question, but I couldn't find a good source of information for everything XAML, found this answer off a search engine and noticed it was still lacking an answer. It doesn't help that there are technically 3 versions of XAML going by the same moniker. So here's the dump of everything I found while investigating debugging bindings. Enjoy, hope it helps someone... -ck

Resources