Alright so first im coding in C using the win32 api, no mfc, no .net, no wxwidgets.
I've created a window with the WC_TABCONTROL class, and have added tabs to it, everything works fine except... I need to have content in each tab, I got the impression from msdn that I needed to create a dialog for each page, and then load the dialog when the user selects a tab. Only problem with this is my main window isnt a dialog, so making the dialog box for the tab fit perfectly is not working too good.
So I'm wondering if there's a better way to do this? I thought about just hiding and showing different controls per tab but that doesn't seem like a good idea.
What I'd like is when my application starts it will resize the window and the tab control to the minimal size needed to fit all the tabs (3-4 tabs), and the window isn't going to be resizable which I guess simplifies things a little bit. I did this by following the example on msdn (Loading each dialog box into memory, looping thru each one and setting a RECT to the minimal size needed then resizing everything), problem is that the size is in dialog box units and I can't convert it to pixels because I don't have a HWND to the dialog box yet.
Basically my question is what is the best way to manage controls on a window with a tab control. So if I have a tab control and the user changes from tab1 to tab2, I want different controls to be displayed to the user.
The basic idea that MSDN is getting at is to have the controls for each tab within their own HWND. The benefit of this is that you can hide/show all the controls within a HWND by hiding/showing that parent HWND. This means that going from one tab to another is just a case of hiding one container HWND, and showing another, which is simpler and more elegant than having to hide/show groups of controls. (It also keeps the dialog handler code for each pane separate, which is usually what you want.) Both approaches are allowed, though: it's often more convenient to create a dialog, but you are not required to.
These container HWNDs don't have to be dialogs, but using a dialog means that windows will populate the contents from a .rc file for you and handle keyboard tabbing automatically. If you create your own HWND, you'll have to do this yourself. You could take a hybrid approach: start off with a dialog, but add your own controls in the WM_INITDIALOG handler if you need to, and even handle WM_SIZE to do custom layout so that the controls fit better.
If you go the create-your-own-HWND route, look up IsDialogMessage() for a simple way to add keyboard tabbing support to your own HWND; and also check out the WS_EX_CONTROLPARENT style so that tabbing between the tabs themselves and the controls in the container HWND work.
Re: "problem is that the size is in dialog box units and i cant convert it to pixels because i dont have a HWND to the dialog box yet." - you may be able to use CreateDialog to create the dialog as invisible - omit WS_VISIBLE from the .rc file - then you can measure/resize as appropriate before you show it.
Related
Scenario: I have one more more WPF applications opened. I cannot change the source code of these apps. My purpose is Whenever user clicks any control (button, combobox, textbox etc.) on these apps, I want to know which control / element is clicked, and log it. Simply obtaining the name of the element would be enough like so: "App1 - button3 is clicked." or "App2 - button1 is clicked". If possible, I want to achieve this for both Winforms and WPF apps, but WPF is more important.
Any way to do accomplish this in the background is OK.
I tried examining and using source codes of snoopwpf (Since it is able to detect the element under the mouse cursor by pressing CTRL+SHIFT), but I wasn't able to achieve my purpose. I could not get the elements in different AppDomains. (AppDomainHelper.GetAppDomains() also returns null)
I looked a little into pywinauto module, however couldn't find such a functionality.
I have a window with a popup that pops when an item in a listview is double clicked.
It centers to the main window and looks really nice floating there.
The problem is when the user moves the main window or selects another program, and the popup floats on top of other stuff.
I would like to have something like a popup, meaning that it floats on top of other elements in the window, but sticks with the main window when it moves (stays centered), and doesn't float on top of other programs.
Can I make a popup act like this, or is there a better way to do it?
Popups will not move while the window is resized or moved. Because, Popups/Context menus are not the part of Visual Tree. You have to use Adorner for this. I will suggest to read this four part series for a quick start on Adorner.
It's possible that an Adorner will fit your needs in this case better than a popup. Adorners can float above your window, too. There are a few differences, mainly that an adorner is bound to a UIElement (which include windows).
If you are willing to use a third-party/open source (MS-PL) option, the Extended WPF Toolkit has a ChildWindow control.
It's technically not a separate window, but it appears to be a separate window to the user.
I have not found a way to make Popups stop doing that in WPF
As an alternative, you can create a UserControl which acts like a Popup.
Usually I host the content section of the app along with the Popup within a Canvas control, and when IsPopupOpen gets changed to True I set the popup Visibility = Visible.
I have a Windows Forms form in C#.
It is just like a regular Windows GUI application. However I am facing problems making the different components on the form resize themselves according to the window size. I mean I do not exactly know which property of the component is to be changed.
I have a tabPage in the form. The tabPage contains a splitcontainer which has 2 panels in it.
The left panel contains a treeView and the right panel has components like radio buttons, textboxes, comboBox and buttons,etc
When I run my application and resize the window (either by dragging a corner of the window or by hitting the maximize button on top right corner) the Windows Forms form and the tabPage expand but the split container doesn't. It stays where it was. Also I want to anchor the split container so that if I shrink my window, the split cointainer still remain on top left. I am sorry I cannot put screenshots here.
Just set the Anchor property of the SplitContainer to Top, Left, Right, Bottom. Or experiment setting the Dock property to Fill.
Have you tried using a TableLayoutPanel? Windows Forms doesn't have great layout support (compared with, say, Java and WPF) but TLP works reasonably well - until you find a situation where it doesn't do what you want, and then it's a pain :)
I am hosting windowsforms control in WPF popup. Problems below:
If i make StaysOpen=False i can't interact with winform control. StaysOpen to false is required because when clicked outsidet the Popup region, it should close.
if i make StaysOpen=True i can interact with winform control but when i click outside the area of popup, it is not getting closed.
I tried setting StaysOpen=true in MouseEnter of popup and StaysOpen=False in MouseLeave, but MouseLeave fires as and when mouse is over winform control resulting in unexpected behaviour.
I even tried IsMouseCaptureWithin property of popup and found it does not work with winforms (i guess its a bug in framework).
Another problem, i was trying to close popup when root main form (which is windows form) is deactivated (pressed Alt+Tab), but this event (deactivate) is fired even when i enter into one of the controls in windowshostControl in popup.
Desired Behaviour:
should be able to host and interact with winform control in wpf popup.
on clicking on outside the area of popup, popup should close.
Appreciate any inputs.
Thanks.
I've had many problems with the defacto-standard popups in WPF, because they are in fact a new window with their own handle. This means if you drag your application around the screen, the popup stays put (it doesn't move with your window). It also means your popup has some strange behaviors and doesn't interact with your application in ways other controls normally do.
I've created 2 decorator classes to address this problem:
PopupDecorator.cs and
TimeoutPopupDecorator.cs
It's pretty simple to use:
Add a namespace declaration for the new popup classes. i.e.
xmlns:dday_wpf="clr-namespace:DDay.WPF"
Surround the area you want the popup to be able to be displayed with the decorator. i.e.
<dday_wpf:PopupDecorator x:Name="popup">
<dday_wpf:PopupDecorator.Popup>
... contents of popup go here ...
</dday_wpf:PopupDecorator.Popup>
... contents of panel go here ...
</dday_wpf:PopupDecorator>
It works pretty much identically to a normal Popup from that moment on.
This may not solve all your problems, but hopefully it helps.
This sounds a bit like my problem launching a modeless winform control from a WPF form.
Check out my question Why is my WPF textbox "kinda" readonly?.
The just being, based on what Doug said about popups being a window with its own handle, makes this applicable.
How can I add custom buttons to the existing MessageBox in WPF? Apart from the usual Ok and Cancel buttons, I need to add 3 more buttons and also handle their events.
Short answer: No it is not possible, you need to write a new window.
Long answer: the MessageBox class uses the Win32 MessageBox (or maybe MessageBoxEx) function, this function does not support extending the message box.
It is possible to modify the message box after it is opened, but:
It is a lot of work
It isn't supported
you have to do it using Win32 directly, the message box window is not WPF or even WinForms.
All in all, it's less work to write a window with one TextBlock, one Image and 5 buttons than to mess around with internal implementation details of the MessageBox code.