Once you've created a Window that is transparent like my funky full-screen one, MainWindow m = new MainWindow(this) This was an interesting edge class where WPF's definition of Transparent didn't quite line up with Window's definition. If you want transparency and hit testing, define a color with minimal alpha just as you have done. If something is 100% transparent then hit testing is bypassed. "Your almost-transparent brush fails the Windows transparency test, so windows delivers events to it. I get the look of transparency, except the Window is still there and I can click on it. Now if I set my Window's background to this Brush: new SolidColorBrush(Color.FromArgb(1,0,0,0)) You've got not just RGB, you've got an Alpha Channel PLUS RGB. I can make a Brush that is not just #000000 (Black) but also #01000000 (really really transparent black. Ok, but I have complete control over my Brushes and their colors. This is where WPF meets the rest of Windows. It cannot differentiate between null and Transparent."Īh, makes sense. "This is because a layered window is represented to the OS as a bitmap, so all it can do is look at the pixel values. This was interesting because everywhere else in WPF if you have a Brush that is null, that's "hollow" and Transparent is solid. "Windows treats fully transparent layered-windows windows as hollow." Well, here's why, and if I'd read 4 chapters into Chris Sell's book, I'd have figured this out. I could "click through" the application to the desktop below. It was totally invisble, except for my little bit of text at the top. This made the Window Transparent, but " hollow" in that I couldn't click on it. I went into my MainWindow.xaml and added these attributes: Background="Transparent" AllowsTransparency="True" WindowStyle="None"īam! Right? Well, kind of. I figured, hey, WPF must be good at that, transparency at all. Someone wanted the BabySmash Window to have the option to be transparent. Pick a single line, a section, or subsystem or the whole app! Post your solutions on your blog, in the comments, or in the Feedback and we'll all learn WPF together. I'm calling on community (that's you, Dear Reader) to blog about your solutions to different (horrible) selections of my code. It's not a good example of a WPF application even though it uses the technology. I wrote an application for my 2 year old using WPF, but as I'm a Win32-minded programmer, my working app is full of Win32-isms. Also check out for more developer info on WPF.īACKGROUND: This is one of a series of posts on learning WPF. TODO: Optionally, set a nicer font than the default.NOTE: If you haven't read the first post in this series, I would encourage you do to that first, or check out the BabySmash category. Draw the text into the center of each of the rectangles. Rectangle(hDC, rc4.left, rc4.top, rc4.right, rc4.bottom) Rectangle(hDC, rc3.left, rc3.top, rc3.right, rc3.bottom) Rectangle(hDC, rc2.left, rc2.top, rc2.right, rc2.bottom) Rectangle(hDC, rc1.left, rc1.top, rc1.right, rc1.bottom) Draw (differently-colored) borders around these rectangles. they don't butt up right next to each other and we can distinguish them. Optionally, deflate each of the rectangles by an arbitrary amount so that Rc1.bottom -= (rcWindow.bottom - rcWindow.top) / 2 Rc1.right -= (rcWindow.right - rcWindow.left) / 2 Calculate the dimensions of the 4 equal rectangles. HBRUSH hbrushOld = static_cast(SelectObject(hDC, GetStockObject(NULL_BRUSH))) HPEN hpenOld = static_cast(SelectObject(hDC, GetStockObject(DC_PEN))) Set up the device context for drawing. Put a pencil and paper to it if you can't visualize it in your head. So all you really have to do is write code to divide your window's client area up into 4 equal parts, and then pass those rectangles to the DrawText function. The GDI text output functions can do that for you if you pass the appropriate flags.įor example, if you call DrawText and pass the DT_CENTER flag, it will automatically draw the text in the middle of the specified rectangle (horizontally centered).Īssuming you have only a single line of text (which it sounds like you do), you can get it to automatically vertically center the text by passing the DT_SINGLELINE and DT_VCENTER flags. You don't actually have to center the text yourself.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |