|
For overriding the user agent, I am wondering if I actually need to do this from within the BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e) method. If the user clicks on a link from within the browser control, the Navigate method is not exercised. Would it be possible to modify the DWebBrowserEvents2_BeforeNavigate2Event.header variable in this case? Or is there a better solution to this? In the case of modifying the header field of the event, what would need to be done for marshaling etc.? Would I need to declare an unmanaged type for the event class itself in order to modify its header field?
|
|
|
|
|
Give it a try. Since the parameters are pointers to VARIANTs that is a SAFEARRAY you would marshal these using UnmanagedType.SafeArray and declare the parameters as a string[] (which is already a reference type). You can try to change the data in there but whether or not the WebBrowser uses it after firing the BeforeNavigator2 event is another question.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Still looking into the user agent. I've also tried seeing if it's somehow possible to override the window.navigator.userAgent DHTML property, to no avail. The BeforeNavigate2 method by default has a "null" value for the header property of the event (i.e. AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event.headers == null ). So, I don't think that changing it or setting it there will make a difference (although I haven't tried yet, as I'm still trying to figure out how to write the code for marshaling). And since we aren't using the Navigate method (rather, relying on the user to click on links), I don't see how to modify the user agent, yet. We'll figure something out... I guess I need help from an IE SDK guru. Dunno.
The reason that we're trying to hide the browser window (question #1 from before) during document loading is that we need to rescale the page, by setting the body.style.zoom property once the page has loaded. This begs the question of whether or not it's possible to just automatically set the zoom property somehow (in advance), without having to invoke it once the page is loaded (which is what we're doing now, after DocumentComplete). It would be nice to be able to just have the zoom property "preset", without having to invoke it after the fact, so that the page is always scaled, even during loading (if that's even possible). Maybe this is more of a DHTML question, I don't really know.
Also, in the alternative where you suggest to put another control on top of the browser while it's loading, what exactly did you have in mind? We don't want the browser to "flash" or anything between pages.
Thanks for your help so far, it's been quite informative!
|
|
|
|
|
I've been doing some more investigation to try to see how to avoid my IE web browser from showing the layout while a page is downloading, so that it waits until DocumentComplete before displaying the page.
I've noticed that in C++ world, there's a flag DLCTL_SILENT that can be set on the pvarResult in IDispatch::Invoke. This flag says "No user interface will be displayed during downloads." Needless to say, this caught my attention. (If someone out there knows offhand that this is in fact *not* doing what I hope it's doing, please chime in.)
My problem now is that I can't figure out how to properly implement this in my C# application. Any ideas?
Thanks.
David
|
|
|
|
|
When I enable VisualStyles in my Application I loose all the images on all the toolbarbuttons of my app in runtime. The problem is solved when I disable visualstyles.
This only happens in runtime as I can see the images perfectly in the designer.
I'm currently using bmps 24x24 pixels and
24 BPP. Transparent color of the ImageList is set to White.
Anybody knows why this is happening?
|
|
|
|
|
Are you calling Application.DoEvents after Application.EnableVisualStyles and before Application.Run ? If you don't, problem like this will arise due to timing issues. A bare-bones entry-point should look like this (for example):
static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new Form1());
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks a lot Heath, that solved the problem
|
|
|
|
|
Maybe I wasnt clear enough in my last thread:
I want to use the API function SendMessage in my .NET CF apllication.
I use the following code to get the handle of my TextBox window:
[DllImport("coredll.dll")]
internal extern static IntPtr GetCapture();
this.Capture = true;
hwnd = GetCapture();
this.Capture = false;
I want to send messages in order to extend the functionality of my TextBox.
I use:
[DllImport("coredll.dll")]
internal extern static int SendMessage(IntPtr Hwnd, int Msg, int WParam, int LParam);
SendMessage(this.hwnd, (int)0x0300/*WM_CUT*/, 0, 0);
This does not cut the text in my TextBox.
I have read all through the .NET CF and could not find the reason for this.
Any other p/invoke I use works fine (like GetCapture) but the SendMessage doesnt.
Please help...
Thanks.
avivhal
|
|
|
|
|
Seems kind of convoluted. Are you just trying to move some text from a textbox to the clipboard?
Anyway, if you are doing this in an event handler that may be the problem; have you tried PostMessage() instead?
Matt Gerrans
|
|
|
|
|
Thanks for the answer.
I tried PostMessage as well. It does not work.
I do not do it in an event handler of a menu.
My goal is to create a more robust editor then TextBox(that’s all there is in the .net CF, no RichTextBox). Therefore I build an extended TextBox with cut,copy,paste and more.
My other problem is that when I try to add text programmatically:
int len = textBoxTerminal.Text.Length;
textBoxTerminal.SelectionStart = len;
textBoxTerminal.SelectionLength = len;
textBoxTerminal.SelectedText = (string)StringToAdd;
the caret always positions itself in the beginning of the TextBox's Text.
I can reposition it to the end and scroll, but this causes the TextBox to flicker. I thought PostMessage will help solving this, but I cannot test it for the Since PostMesage does not work for me.
Hope you have an answer for this...
Thanks.
avivhal
|
|
|
|
|
What is the return code for SendMessage ? Check this against the errors in winerror.h.
You should also set the DllImportAttribute.CharSet field to CharSet.Auto . There is actually no SendMessage function, but SendMessageA (ANSI) and SendMessageW (Wide-char, or Unicode). The Windows .NET CE platform is actually Unicode, so you could P/Invoke SendMessageW and set DllImportAttribute.EntryPoint to "SendMessageW" (since DllImportAttribute.ExactSpelling is not supported for the .NET CF).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Neither DllImportAttribute.CharSet nor SendMessageW worked.
I did get it to work though (somehow)...
I took the declarations I have of SendMessage(I have a few overloads) :
[DllImport("coredll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
and wrapped them in a separate class.
Then I called them as this class's static members and it works!
I do not understand why would this solve the problem though...?
Maybe the problem was that they were members of a TextBox (Form) derived class and this caused congestion problems with the Form’s own messages?
I wish I had the OS source code so I could check this;)
avivhal
|
|
|
|
|
How were you doing it before? C# does not support functions - only methods. They would've had to have been members of a class before or else you couldn't have even compiled your source file.
BTW - those last two parameters are process-dependent types and should be IntPtr . If you're needing to pass pointers to structs or char arrays (strings), you can define overloads that would amount to a pointer, such as simply string or ref MyStruct . int is an Int32 in C# and will always be 32 bits. If you ever hope to port this - whether the source or binary - you'll need to change it anyway.
External methods must always be static, too, but you declared them statically before, did you not?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
They were static members of the my TextBoxEx class before.
All I did was build a new class and pass the methods to be static members of the new class. then call them as the new class methods.
e.g. if my old class was Aclass and the new Bclass then in Aclass I call:
Bclass.SendMessage(...);
I have a few overloads such as
[DllImport("coredll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, String lParam);
[DllImport("coredll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, byte[] lParam);
that take addresses (pointers). I only use :
[DllImport("coredll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
to call with 0 lparam and wparam thus:
Bclass.SendMessage(this.Handle, (int)ClipboardMessage.WM_UNDO, 0, 0);
I probably should use 2 pointers (IntPtr) instead and lock the IntPtr for the GC before calling this method?
Thanks,
Aviv.
avivhal
|
|
|
|
|
On what class they're defined shouldn't matter, but perhaps some of your overloads were conflicting.
With value types - like int - you do not need to pin them (see the GCHandle class, BTW). Reference types may be moved by the GC on the heap, but it depends how the message handler uses the data; you may not need to pin the memory. Strings are reference types but this data is typically used synchronously with SendMessage (PostMessage , on the other hand, is a different story). When passing addresses of reference objects (as IntPtr , or just a GCHandle which works, too, as well as a HandleRef ) you should pin them.
For robust code, never use fixed-size integers for the WPARAM and LPARAM . Always use IntPtr . For 0, just use IntPtr.Zero and to wrap an int or long use new IntPtr(int) or new IntPtr(long) , respectively.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Can anyone tell me how to print text and images within a rich text box?
Thanks,
Sterling
|
|
|
|
|
|
I'm trying to use p/invoke in the .NET CF in order to create copy,paste and other operations.
I use the following code:
[DllImport("coredll.dll")]
internal extern static int SendMessage(IntPtr Hwnd, int Msg, int WParam, int LParam);
SendMessage(this.hwnd, (int)ClipboardMessage.WM_CUT, 0, 0);
I noticed that the desired operation never happens! All other p/invoke I use work fine. Only the SendMessage does not work (I tried many other like WM_CHAR,WM_VSCROLL and more, nothing works)
Thanks.
avivhal
|
|
|
|
|
I have enabled the xp styles for a windows application with Application.EnableVisualStyles() and seted to all the controls that have a FlatStyle property to FlatStyle.System .
The problem apears at a CheckedListBox , the CheckBox 'es that it contains doesn't take the style and it doesn't have a FlatStyle property. I didn't manage to find a property for the items (CheckBox 'es) that it contains, all I've found was a string that represented an item (a string item).
Can anybody help me?
I hope you understand...
By the way... visit http://nehe.gamedev.net[^]
|
|
|
|
|
The CheckedListBox does use the ComboBox control - it draws checkboxes using ControlPaint.DrawCheckBox , which doesn't take advantage of the Theme API.
To accomplish what you want you'll have to extend the CheckedListBox and override OnDrawItem , using the DrawItemEventArgs.Graphics to get an HDC (handle to a device context), draw the checkbox you want using the Theme API, then release the HDC :
public XPCheckedListBox : CheckedListBox
{
protected override void OnDrawItem(DrawItemEventArgs e)
{
IntPtr hdc = e.Graphics.GetHdc();
e.Graphics.ReleaseHdc(hdc);
}
} To draw a themed checkbox you'll need to P/Invoke the Theme APIs, which you can read about at http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/userex/refentry.asp[^]. For help with P/Invoke signatures, see http://pinvoke.net[^].
Be sure to read about the Theme API because it's not a simple set of APIs.
Also note that in .NET 2.0 themes should be (it's still beta, so nothing's set in stone till release) encapsulates. For documentation about these set of classes in .NET 2.0 Beta1, see http://msdn2.microsoft.com/library/System.Windows.Forms.VisualStyles.aspx[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am trying to write a spellcheck application in C#.NET, that will utilize ASPELL to detect, whether the text entered in a textbox is valid or not. I don't want to use word.dll because that means the user has to have Microsoft word installed in his/her machine. There is one such project over here, but I don't really understand how it works. Is there a simple way to do this? Somebody suggested integrating ASPELL to my code, but I have no idea how to do that. Can somebody help me out?
|
|
|
|
|
I need that Regex won't return match if the string starts with another substring, for example "abc".
In detail, "abcde " shouldn't match, but "abg ", "gbc " and "afcgr " should match.
I know the [^abcde] syntax that works for characters, but I couldn't figure out way for substrings.
It is possible to do this with Regex?
I need it to be done through Regex, not String class methods.
Thanks.
|
|
|
|
|
|
I think you missed the point.
"abc" should not match.
I want to match any combination of three characters, except the above sequence.
I can do it as well with two chars. For example, if i want to match anything except "ab", i can use (?:a[^b])|(?:[^a].) .
But when it comes to three or more characters, i find no way. Maybe I miss something.
Thanks.
|
|
|
|
|
"[^(abcd)]+" seems to be working
a better way would be: "^(?!abcd).+"
(I'm not sure if (?!x) is a valid expression in the C# Regexes)
|
|
|
|
|