Spadix Software has a free screen ruler utility that makes it easy to measure the sizes of things on your screen: http://www.spadixbd.com/freetools/index.htm. This solves the problem of deciding a form needs to be bigger, resizing it at runtime, and then trying to figure out what the new size is. I usually brought up the Debugger and typed something like “_screen.activeform.width” into the Watch window, but this is a lot easier.
Tuesday, September 29, 2009
Thursday, September 24, 2009
Sizing a ListView to Avoid Scrolling
I prefer to avoid horizontal scrollbars if possible. A horizontal scrollbar automatically appears in a ListView ActiveX control if the columns are sized too wide for the width of the ListView. I like to size the columns so they exactly fit within the width of the ListView. However, if the ListView’s Anchor property is set to resize the control when the user resizes the form, at some point a vertical scrollbar appears if the ListView is sized too short for the rows displayed. Since the scrollbar takes up some of the width of the ListView, a horizontal scrollbar also appears.
The trick is to detect when the vertical scrollbar appears and adjust the width of the columns so they fit within the remaining width. The following code, which goes in the Resize event of the form or container the ListView is in, handles that. This code assumes there’s only two columns and the second column should be resized. Adjust the code as necessary to use different columns
with This.oListView
* See if the ListView has a vertical scrollbar.
#define WS_HSCROLL 0x100000
#define WS_VSCROLL 0x200000
#define GWL_STYLE -16
declare integer GetWindowLong in Win32API integer hwnd, integer nIndex
llScroll = bitand(GetWindowLong(.hWnd, GWL_STYLE), WS_VSCROLL) <> 0
* Set the width of the second column.
lnWidth = .Width - .ColumnHeaders.Item(1).Width - sysmetric(4) - ;
iif(llScroll, sysmetric(7), 0) + 4
&& 4 is a fudge factor for width
.ColumnHeaders.Item(2).Width = max(lnWidth, 0)
endwith
Tuesday, September 22, 2009
.NET Tools Survey
Just fill in this quick 10 minute survey about .NET tools and you could win one of five $100 vouchers to spend with Amazon. Take the survey here: http://www.questionpro.com/akira/TakeSurvey?id=1325041
Thursday, September 10, 2009
Southwest Fox “Recession Buster” Deals
Due to the condition of the global economy, we're seeing a drop in registrations for Southwest Fox 2009 this year. So we have a couple of special "recession buster" deals we hope will encourage a few more people to sign up for the best Visual FoxPro conference in North America.
Deal #1: "Organizers: please share my deal!"
If you already registered and paid for the conference and you know someone who wants to register, you can give them the same deal you got when you registered. If you want to come to the conference and you know someone who got in at the Super Saver ($620) or the Early-bird ($695) registration, you can sign up for the same price they did. Sharing is caring!
Deal #2: Southwest Fox "Pair Programmer" deal
Have one or more FoxPro friends who are considering coming to Southwest Fox? Sign up together and take $50 off each of the registrations.
No matter what deal you take, we will give you your first pre-conference session for free!
There's only one catch. You have to take advantage of this deal by 11:59 PM September 30, 2009 Eastern time. We have to make some serious commitments on October 1 for various expenses we have for the conference. See the Registration page for more details.
Friday, September 04, 2009
Southwest Fox 2009 Keynote
For the first time, this year’s edition of Southwest Fox will have a real keynote speaker. Sara Ford, Program Manager for CodePlex at Microsoft, is doing a presentation called “Towards a Stronger Open Source Ecosystem on CodePlex.com.” As you likely know, VFPX, the premier VFP community site, is hosted on CodePlex. For more details, see the Southwest Fox Blog.
I’ve met Sara several times and let me tell you, she is a character. She’s also very interested in VFPX. She gave us several tips early on about how to better organize VFPX (VFPX is unusual for CodePlex in that it’s a collection of many projects rather than just a single one) and even made a tweak to CodePlex to help VFPX work better.
Between the line-up of speakers, top-notch sessions, great networking opportunities, a chance to talk face-to-face with exhibitors about their products, and now having Sara deliver the keynote, Southwest Fox 2009 is shaping up to be even better than last year. See you next month in Arizona!
Wednesday, August 26, 2009
More on TreeViews and GDIPlusX
In my blog post Disabling a TreeView Control, I showed some code that visually disables a TreeView. It doesn’t really do that; instead, it uses GDIPlusX to take a snapshot of the TreeView, converts the snapshot to have a “disabled” appearance, hides the TreeView, and displays the snapshot in its place.
I just found another use for this technique. Suppose you want a VFP control to temporarily appear on top of a TreeView control. As you’re likely aware, the TreeView is an ActiveX control, and although it doesn’t visually appear this way, ActiveX controls display in their own window. As a result, any VFP control occupying the same space of a TreeView appears behind the TreeView, regardless of ZOrder.
Here’s an example. I’m adding a new feature to Stonefield Query that allows the developer to display fields organized by screen/form rather than by table. The idea is to make it easier for the user to find the fields they’re interested in because the fields map directly to what the user sees in their application. In this case, the Accounts Receivable module has three sub-modules: A/R Customers, A/R Setup, and A/R Transactions. A/R Customers has four forms: Customer Groups, National Accounts, Customers, and Ship-To Locations. The user chooses the desired form from a drop-down control (the SFComboTree control discussed in my article in the September 2009 issue of FoxRockX) and a TreeView control displays a list of the pages in that form and the fields on each page in a hierarchical view.
Notice the problem in this screen shot? The border around the dropped down SFComboTree disappears where it overlaps the available fields TreeView control. The drop-down part is a Shape surrounding another TreeView. While the dropped-down TreeView overlaps the fields TreeView as expected (an ActiveX control can overlap another ActiveX control), the Shape disappears behind the fields TreeView.
Fortunately, there’s an easy solution for this: use the same lightbox technique I discussed earlier but this time don’t make the image appear disabled: just take a snapshot of the TreeView, hide the TreeView, and place the snapshot where the TreeView is. Here’s the result:
The border for the dropped-down control now appears because the TreeView is temporarily hidden and what you see underneath is a snapshot of the TreeView.
The code is even simpler than the lightbox code because it doesn’t have to change colors. This is the code used when the SFComboTree is dropped down:
with This.Parent
loTree = .oTree
lnWidth = loTree.Width
lnHeight = loTree.Height
with .imgLightBox
.Top = loTree.Top
.Left = loTree.Left
.Width = lnWidth
.Height = lnHeight
endwith
loBmp = _screen.System.Drawing.Bitmap.FromScreen(.imgLightBox)
with .imgLightBox
.PictureVal = loBmp.GetPictureValFromHBitmap()
.ZOrder(0)
.Visible = .T.
endwith
loTree.Visible = .F.
endwith
The more I use GDIPlusX, the more I love it! My GDIPlusX session at Southwest Fox 2009 will cover other interesting uses for GDIPlusX. I’m also doing that session and an introduction to GDIPlusX session at the 2009 German DevCon. Hope to see you there.
Tuesday, August 25, 2009
Southwest Fox 2009 Early-Bird Deadline Next Week
Southwest Fox is only seven weeks away. This year’s conference has an incredible line-up of speakers and sessions. Not to pick favorites, but I’m especially looking forward to Christof’s Excelporting session, Paul’s Lucene.NET presentation, Jim’s sessions on PEM Editor and FoxCharts, and both of Cathy’s sessions. I’d also really like to see Toni’s session on Subversion and Walt’s session on Vault (especially after seeing his video), but they’re both pre-conference sessions and Thursday is registration day. As an organizer, I’m pretty busy that day.
If you haven’t registered yet, be sure to do so before September 1 to save $50 on your registration fee. If you’ve been to Southwest Fox before, you know what a great training and networking opportunity it is. If you haven’t, read what attendees from past years have said. In addition to the usual perks, this year you’ll get a chance to meet and hang out with the Ceil Silver Ambassador from Brazil.
Thursday, August 20, 2009
Disabling a TreeView Control
In my post “Setting the Background Color of a TreeView Control”, I presented some code that sets the background color of a TreeView to make it appear disabled. However, a reader named Alberto pointed out that after running that code, indented nodes have an ugly white background in front of them. I played with this a bit but couldn’t come up with a way to fix it.
Fortunately, there’s another solution: using a “lightbox”. Bernard Bout blogged about using the VFPX GDIPluxX project to create an image with a darker representation of a form and overlaying the form with the image to make the entire form appear disabled. I adapted his code to do the same thing with a TreeView control. Pass this code up to four parameters:
- A reference to the form the TreeView is on.
- A reference to the TreeView itself.
- .T. to enable the TreeView or .F. to disable it
- Optionally, an RGB value to use as the disabled color. If this isn’t passed, grey—RGB(240, 240, 240)—is used. This parameter isn’t used if the third parameter is .T.
This code creates an image object, takes a snapshot of the TreeView contents, makes the snapshot darker so it appears disabled, and uses the snapshot as the picture for the image. Note that a VFP control can’t cover an ActiveX control, so the code hides the TreeView. Of course, to the user, it looks like the TreeView is still there but disabled because the image is placed exactly where the TreeView is and contains a picture that looks just like a disabled version of the TreeView.
This code requires System.APP, which comes with GDIPlusX.
lparameters toForm, ;
toTreeView, ;
tlEnable, ;
tnColor
local llImage, ;
lnWidth, ;
lnHeight, ;
lnColor, ;
lnFactor, ;
lnRed, ;
lnGreen, ;
lnBlue, ;
loClrMatrix, ;
loBmp, ;
loGfx, ;
lcFile
* See if the specified form has a LightBox image.
llImage = pemstatus(toForm, 'imgLightBox', 5)
do case
* It does and we're supposed to enable the TreeView, so hide the image and
* redisplay the TreeView.
case tlEnable and llImage
toForm.imgLightBox.Visible = .F.
toForm.imgLightBox.PictureVal = ''
toTreeView.Visible = .T.
* We're supposed to disable the TreeView, so ensure GDIPlusX libraries are
* open and create the image if necessary.
case not tlEnable
do System.app
if not llImage
toForm.AddObject('imgLightBox', 'Image')
endif not llImage
* Size the image as necessary.
lnWidth = toTreeView.Width
lnHeight = toTreeView.Height
with toForm.imgLightBox
.Top = toTreeView.Top
.Left = toTreeView.Left
.Width = lnWidth
.Height = lnHeight
endwith
* If we weren't passed a color to use, use grey.
if vartype(tnColor) = 'N'
lnColor = tnColor
else
lnColor = rgb(240, 240, 240)
endif vartype(tnColor) = 'N'
* Get the colors we'll need.
lnFactor = 0.90 && 0 = Dark 1 = Bright
lnRed = bitand(lnColor, 0x000000FF) / 255 * lnFactor
lnGreen = bitrshift(bitand(lnColor, 0x0000FF00), 8) / 255 * lnFactor
lnBlue = bitrshift(bitand(lnColor, 0x00FF0000), 16) / 255 * lnFactor
* Create a BMP of the desired color and use it as the picture for the image.
with _Screen.System.Drawing as xfcSystem of Source\System.PRG
loClrMatrix = .Imaging.ColorMatrix.New( ;
lnRed, 0, 0, 0, 0, ;
0, lnGreen, 0, 0, 0, ;
0, 0, lnBlue, 0, 0, ;
0, 0, 0, 1, 0, ;
0, 0, 0, 0, 1)
loBmp = .Bitmap.FromScreen(toForm.imgLightBox)
loBmp.ApplyColorMatrix(loClrMatrix)
loGfx = .Graphics.FromImage(loBmp)
loGfx.FillRectangle(.SolidBrush.New(.Color.FromARGB(10, 0, 0, 0)), ;
0, 0, lnWidth, lnHeight)
endwith
with toForm.imgLightBox
.PictureVal = loBmp.GetPictureValFromHBitmap()
.ZOrder(0)
.Visible = .T.
endwith
toTreeView.Visible = .F.
endcase
Friday, August 14, 2009
Tuesday, August 11, 2009
Outlook 2007 RSS Feeds Not Refreshing
I’ve had this happen several times over the past couple of years: suddenly, Outlook no longer refreshes RSS feeds. The only solution I’d found to make it start re-reading the feeds was to select each one and click Send/Receive (or press F9). When you have more than 100 feeds, that’s time-consuming and painful.
Fortunately, Alun Jones found a faster (but still lame) way: just select each feed and it’ll refresh next time send/receive occurs. Hopefully MS will fix this.
