Hello,
I am using an OpenFileDialog to allow the user to pick the logo of their company. It works just fine, but I would like to set the View Menu option to Thumbnail instead of the users default (which for me is List). Does anyone know how to do this? I tried using intellisense to see what I could find to no avail, and I have severely limited internet access here.
Thanks
Wow, what a complete and total pain. I guess they figured no one would want to be able to set that very easily. Thanks a lot for the code. I know nothing of these things, so I am going to use this example to learn more about this. Thanks again.
I did a bunch of google searches and compiled a few bits of knowledge from this article and that article to find what I needed to make it work.
Once you get down to it, its actually pretty simple.
The basic problem is the only way to show an openfiledialog, is to call its showdialog method, but once you do that, your program's code is haulted until the dialog closes. This makes it hard to get the window handle of the dialog, because its not created until you call the ShowDialog method, so you can send a message to it to change the view.
This is why you have to filter out messages that are sent to the main form, that are basically saying "a dialog opened, here is its handle" so you grab that, and use it to send your messages to the dialog.
This is why you have to filter out messages that are sent to the main form, that are basically saying "a dialog opened, here is its handle" so you grab that, and use it to send your messages to the dialog.
Is that why I can see it flash a list view for a moment before switching to the chosen view?
Probably, I actually didn't see any flash on my box, but I am running a pretty fast machine here.
I think its actually possible to capture a different message, instead of the WM_ENTERIDLE, there are other messages that fire when a Dialog is opened, perhaps the WM_ACTIVATE, however I figured that fires well more often than WM_ENTERIDLE, although I suppose you could set a boolean value to true right before you call ShowDialog() and set it to false after the dialog closes. Then check to see if the boolean is true before even bothering to filter the wndproc message. That way your app won't spend time trying to look for the dialog when its not open, but the main form gets a windowsmessage that you filter on. If you want I can update the code later to reflect this.
If Me.MessageSent = False Then
SendMessage(LvwHandle, WM_COMMAND, DirectCast([Enum].GetValues(GetType(DialogViewType)).GetValue(3), DialogViewType), IntPtr.Zero)
Me.MessageSent = True
End If
so that it would only send the message once. Without it the mouse was flickering, celltips were sporatic, and I was a little leary of the whole thing. Like I said, I have no idea how this stuff works, but it works great now.
Oh, yeah. When I was testing I found that if my OpenFileDialog has no Title, this won't work. It doesn't have to have any specific title, just anything will do. Thanks again.
P.S. Only sending the message once also allows the user to override this setting and view the folder the way they want to.
Last edited by 18experience; Feb 28th, 2007 at 01:48 PM.