April 15, 2004
@ 11:15 PM

You can keep your window on top by using the code listed below.

Declare

Declare Sub SetWindowPos Lib "User" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, 
ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer,
ByVal wFlags As Integer)
Const SWP_NOMOVE = 2
Const SWP_NOSIZE = 1
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2

Code

Sub KeepOnTop (frmIn As Form, bOnTop As Integer)
     Dim iTopFlag As Integer
     Const wFlags = SWP_NOMOVE Or SWP_NOSIZE
 
     If bOnTop = True Then
           iTopFlag = HWND_TOPMOST
     Else
           iTopFlag = HWND_NOTOPMOST
     End If
     SetWindowPos frmIn.hWnd, iTopFlag, 0, 0, 0, 0, wFlags
     DoEvents
End Sub

Usage

To put a Form on top of all windows, then call:

KeepOnTop Me, True

To remove the Form from being on top, call:

KeepOnTop Me, False

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: Henk Hakvoort
Compatible With  Visual Basic 3.0, Visual Basic 4.0 16-bit


 
Categories: VB

Instead of SetWindowPos, it uses SetWindowWord. This lets you create a floating toolbar that stays above its app's window without staying on top of ALL windows. Very handy for that professional look.

Declare Sub SetWindowWord Lib "USER" (ByVal hWnd, ByVal nCmd, ByVal nVal) 
Const SWW_hParent = (-8)

Form_Load of the form that you want to keep on top. Set it about form1.

Sub Form_Load () 
     SetWindowWord hWnd, SWW_hParent, form1.hWnd
End Sub

Form_Unload of the from you want to keep on top this is for cleaning up.

Sub Form_Unload (Cancel As Integer) 
     SetWindowWord hWnd, SWW_hParent, 0
End Sub

 

Tip Submitted By: Jonathon Twigg


 
Categories: VB

Background

I was almost finished with an app I was writing. Twice in this app I did some time consuming formatting and I thought it would be nice to have a status bar in these loops. My program had Modal windows so the problem begun. I could not show a non modal window on to of a modal window and if I loaded a Modal window I could not execute the code in the current module. I did not want to put the code in the status window because there were 2 big loops that had to be in the modules they were. So this is what I found. You can show a window non-modal with the SetWindowPos call from windows. By showing the window with this call I had two windows that could get the focus so I had to disable the first form and I just did that with Me.Enabled = False. When the loop was finished I just Enabled my for again and unloaded the status form.

Code

Global Declare:

Declare Function SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer,
ByVal X As Integer, ByVal Y As Integer, ByVal cX As Integer, ByVal cY As Integer,
ByVal wFlags As Integer) As Integer
 
Global Const SWP_NOMOVE = &H2
Global Const SWP_NOSIZE = &H1
Global Const SWP_SHOWWINDOW = &H40
Global Const HWND_TOP = 0

The loop:

Sub DoAnyThing ()
     ' Show the status window
     i = SetWindowPos(frm_Status.hWnd, HWND_TOP, 0, 0, 0, 0, 
SWP_NOSIZE Or SWP_NOMOVE Or SWP_SHOWWINDOW)
     ' Disable Me
     Me.Enabled = False
     DoEvents
 
     ' Do the loop
     For I = 1 To 200
           ' do stuff
           ' set the status
           frm_Status.pic_Status.Line (0, 0)-(I, 100), QBColor(1), BF
           frm_Status.pic_Status.Refresh
           DoEvents
     Next I
 
     'Unload the status window
     Unload frm_Status
     ' Enable Me ...
     Me.Enabled = True
     ' and give me the focus
     Me.SetFocus
End Sub

 

Tip Submitted By: Olafur Orn Jonsson


 
Categories: VB

April 15, 2004
@ 11:05 PM

You could move the cursor off the screen, but there is an easy way to make the cursor invisible with an API call:

Declare

Declare Function ShowCursor Lib "User" (ByVal bShow As Integer) As Integer

Usage

To use the API, simply call:

R = ShowCursor(True)

or

R = ShowCursor(False)

There is one thing you should know about this API call. Whenever a program calls ShowCursor, Windows keeps an internal count of how many times ShowCursor was called. The problem is that there is no way to retrieve this counter. So just calling ShowCursor(False) might not work because it just decreases the counter by one. Unless the counter is zero, the cursor will not disappear. Use this routine instead.

Sub EnableCursor (iSetting As Integer)
     Select Case iSetting
           Case True
                 Do While ShowCursor(True) <= 0
                 Loop
           Case False
                 Do While ShowCursor(False) >= 0
                 Loop
     End Select
End Sub

To use this Sub, call it with the iSetting parameter set to either True or False. The cool thing about this API call is that it makes the cursor invisible but MouseMove, etc., events still work. This technique also works in Windows 95.

 

This tip is reprinted from the VB Tips & Tricks Volume 1 book.
Parts of this tip was submitted by: David McCarter

Compatible with: Visual Basic 3.0, Visual Basic 4.0 16-bit


 
Categories: VB

April 15, 2004
@ 11:02 PM

To do effective error handling, you must write them into each and every routine. What a pain! There are many ways to do error handling, from coding it yourself to purchasing add-on tools that will do most of the code writing for you.

This tip is for those who prefer to do it themselves. This is a good idea, because you have much more control over it. Also, another important part of error handling is writing the error to a file. This will save you tons of time in development and also help with technical support problems. Instead of trying to get information on the error message from the user, they can simply send the error log. This tip incorporates that philosophy.

Declare

Global Const errExit = 0
Global Const errResume = 1
Global Const errNext = 2
Global Const errSelect = 3

Code

Public Function ErrorHandler(iErrorNumber As Integer, sErrText As String, 
iErrOption As Integer) As Integer
Dim sMessage As String
Dim iReturn As Integer
     'Create message string
     sMessage = "Error #:" & Str(iErrorNumber) & " - "
     sMessage = sMessage & sErrText
     'Save to error log file
     ErrWriteLogFile sMessage
 
     Select Case iErrOption
           Case errExit
                 MsgBox sMessage, vbCritical, _
                       "Exiting program..."
                 GoTo errHandlerEnd
           Case errResume
                 MsgBox sMessage, vbCritical, "Error"
                 ErrorHandler = errResume
           Case errNext
                 MsgBox sMessage, vbCritical, "Error"
                 ErrorHandler = errNext
           Case errSelect
                 iReturn = MsgBox(sMessage, vbCritical + _
                       vbAbortRetryIgnore, "Error")
                 Select Case iReturn
                       Case Is = vbAbort
                             GoTo errHandlerEnd
                       Case Is = vbRetry
                             ErrorHandler = errResume
                       Case Is = vbIgnore
                             ErrorHandler = errNext
                 End Select
     End Select
     Exit Function
errHandlerEnd:
     MsgBox "Click OK to Exit Program"
     End
End Function
 
Public Sub ErrWriteLogFile(sLogMsg As String)
     Dim sFile As String
     Dim lFile As Long
     Dim sErrDir As String
 
     On Error GoTo errWriteLogFileErr
     sErrDir = App.Path
     lFile = FreeFile
     sFile = sErrDir & "\" & App.EXEName & ".err"
     Open sFile For Append As lFile
     Print #lFile, Format$(Now, "General Date") & ": " _
           & sLogMsg
     Close #lFile
     GoTo errWriteLogFileExit
errWriteLogFileErr:
     MsgBox Str(Err) + "-" + Error$, vbCritical, _
           "Unable to Write Error Log"
     Exit Sub
errWriteLogFileExit:
End Sub

Example

This is a sample of how you could use this tip:

Dim R As Long
Dim I As Integer
On Error GoTo ErrorHandler1
     For I = 3000 To 100000
           DoEvents
     Next I
ErrorHandler1:
     R = ErrorHandler(iErrorNumber:=Err.Number, sErrText:=Err.Description, iErrOption:=errNext)

Even though this tip was written in Visual Basic 4.0, it can be easily modified for any other version of Visual Basic. It’s also easy to modify for your particular needs.

 

This tips is reprinted from the VB Tips & Tricks Volume 1 book.
Some parts of this tips was submitted by: George Graff


 
Categories: VB

April 15, 2004
@ 10:57 PM

Declare

Private Declare Function MakeSureDirectoryPathExists Lib "IMAGEHLP.DLL" 
(ByVal DirPath As String) As Long

Code

Public Sub CreatePath(ByVal DestPath As String)
    If Right(DestPath, 1) <> "\" Then
        DestPath = DestPath & "\"
    End If
    If MakeSureDirectoryPathExists(DestPath) = 0 Then
        MsgBox "Error creating path: " & DestPath
    End If
End Sub

 

Tip Submitted By: Kevin Buchan


 
Categories: VB

The User Interface Process Application Block provides a simple yet extensible framework for developing user interface processes. It is designed to abstract the control flow and state management out of the user interface layer into a user interface process layer. This helps you write generic code for the control flow and state management for different applications types (for example, Web and Windows) and helps manage user's tasks in complex scenarios (for example, suspending and resuming tasks).

 

http://www.microsoft.com/downloads/details.aspx?FamilyID=98c6cc9d-88e1-4490-8bd6-78092a0f084e&DisplayLang=en


 
Categories: WinForms

Microsoft will now support the MSJVM until Dec. 31, 2007.
 
Categories: Development

The service was initially built with Java, but CafePress.com came to realize that developing on that platform was slow, problematic, and was otherwise preventing them from moving their business forward. CafePress.com is now using the Microsoft .NET Framework and has seen a vast improvement in their ability to develop new features and solutions. The ability to quickly bring new ideas to market is resulting in increased sales.

Company Overview

CafePress.com offers an outsourced e-commerce solution that allows individuals, groups, and companies to sell a wide variety of merchandise without the typical hassles and overhead of doing business online. The company manages every aspect of doing business online, including e-commerce services, product manufacturing and sourcing, fulfillment, and customer service. In just minutes, anyone can set up a store selling imprinted merchandise, such as T-shirts, mugs, and more, with no setup fees and no inventory investment.

The service was originally built using Java. In time, the company came to realize that they were spending too much time patching components together and maintaining their development framework, and not enough time developing new features and solutions.

"We were running into serious compatibility problems with the previous solution," says Fred Durham, Chief Executive Officer, CafePress.com. "After an upgrade from the vendor, the issues still existed so we decided we could not wait any longer for the vendor to fix things and needed to find a new framework to develop around. Previously we had been using a combination of Java tools, runtimes, beans, and libraries. It became clear to us that a single framework would be far more productive. We wanted to get out of the cycle of maintenance and constant patching, and into new application development again."

Solution

"Along with the .NET Framework, we examined BEA WebLogic and Orion. The .NET Framework proved to have everything we wanted—the richest library, and the best price point," says Durham. "We were able to do a 100 percent conversion of all our systems in less than four months from initial testing to complete rollout. For a time during the transition, we had Java and the .NET Framework running side by side without problems on our live Web servers."

The company is now using the application server features of the Microsoft .NET Framework, including Microsoft ASP.NET to build their solutions. "A user simply uploads images and CafePress.com's servers superimpose those images onto product shots of items like T-shirts and mugs," explains Durham. "The user's store is then filled with products for sale without having to produce any actual merchandise in advance. Customers purchase items though the user's Web site and on the back end CafePress.com processes the payments." CafePress.com also has a manufacturing facility that accesses a private Web site where work orders, images, and product specifications are automatically accessed as needed to manufacture and deliver the products.

CafePress.com now uses the .NET Framework exclusively for every part of this service—utilizing ASP.NET pages, custom ASP.NET controls, and .NET-based console applications for various administrative tasks.

Benefits

Making the switch to the .NET Framework was easy and quick, and has resulted in significant advantages for CafePress.com. The most significant benefit involves development time. For CafePress.com, turning new ideas into features and services in a timely fashion is critical. Developing with the .NET Framework is allowing CafePress.com to quickly produce and add new features to their service, and to produce customized solutions to meet the needs of larger customers.

The advantages go beyond the improved developing capabilities of the .NET Framework: The CafePress.com Web site has realized impressive performance increases.

Faster Development

"We are a start-up in the classic Silicon Valley model—moving fast and bringing things to market at the bleeding edge," says Durham. "We evaluate products based on their ability to advance our business." For CafePress.com, the ability to quickly add features to their service and to develop new service for larger customers is critical to their success. The .NET Framework allows the company to move quickly in the increasingly competitive Internet industry.

"Since moving to the .NET Framework, our development speed has increased dramatically," says Durham. "Project cycle times have been reduced to approximately one-quarter of the previous development cycle times. That means more features and services for our users. With the .NET Framework, we can much more easily develop custom code for larger clients. It also means we offer more services and features at large. Again, this is because development times are compressed and the lines of code needed have dropped significantly."

An Efficient Platform

The reason that CafePress.com is realizing improved development times is because the .NET Framework provides a single development platform and eliminates the integration and maintenance issues that plagued the company when they were working with Java.

"Our development environment was messy," says Durham. "We had been using Borland Jbuilder for Java Code and HomeSite for HTML. We could never find a useful Java-based imaging library, so we were forced to use an OCX control. To use that we also had to use a COM-to-Java component from yet another vendor, with routine compatibility problems. The JDBC driver was ineffective and crashed periodically. Java is supposed to have everything, but it doesn't. We had to cobble together a lot of stuff from different vendors. We found developing in this environment to be highly inefficient. We were spending far too much time patching and maintaining our development process, when we should have been spending that time bringing new features and services to market."

The Microsoft .NET Framework Software Development Kit (SDK) contains a wealth of resources—including DLLs, tools, compilers, and samples—that enable developers to build efficient, powerful, and scalable Web-based applications and services. It provides companies like CafePress.com with a single framework for developing new applications.

"In the end, what really solidified our decision to adopt the .NET Framework was the incredibly rich class library that handled all the application plumbing you could ever think of," says Durham. The .NET Framework class library is a comprehensive, object-oriented collection of reusable classes that can be used to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET and XML Web services. "The class library saves us time. Our applications don't have to be built from the ground up anymore. It reduces the amount of code we have to produce and test."

One project that CafePress.com was able to undertake because of the improved development environment of the .NET Framework is called "Strip of the Day." One of CafePress.com's partners is Dilbert.com—the online home of the popular Dilbert comic strip. What CafePress.com had envisioned was a feature that would allow people to order any comic strip printed on a variety of merchandise. Previously, only select strips from the past were available. Every Dilbert comic strip is now available on CafePress.com's array of merchandise, including today's strip.

"We had wanted to do this with Dilbert.com for a long time," says Durham. "When we were on the Java platform, we always knew that developing this feature would be troublesome and would take too long. Simply put, we never got around to it because we knew what we were in for. With the .NET Framework, we developed this feature in just one week. Since implementing this feature, sales have increased dramatically—perhaps a four or five times increase in sales. More projects like this are in the works. Previously, these projects would not have even made it to our development list."

Improving Web Site Performance

Moving to the .NET Framework has not only benefited the company because of the improved development environment, it has also resulted in improved Web site performance. Web traffic is significant for CafePress.com, a Webby Award recipient. Monthly traffic for CafePress.com runs at about 50 million hits. "The performance increase after moving to the .NET Framework was unbelievable," says Durham. "The machines used to run at about 50- to 70-percent utilization and now run at about 2- to 3-percent. I have never heard of such an increase in performance."

"We're supporting about 5,000 concurrent sessions, and 10-20 pages per second with imaging, plus lots of dynamic database page views," says Durham. "We had five dual processor machines that have now been converted to one machine. There's no way we could have done that with Java."

"We handle about 1 million unique visitors a month on a single server that refuses to go above 200-megabytes of ram usage even though it has 1 gig installed, and never goes above 3 percent CPU utilization. We sustain a 5 megabit per second average throughput. Where's the top end? I have no idea."

VSDN Tips & Tricks CafePress.com store 

Posted: November 11, 2001

Original Article: http://www.microsoft.com/resources/casestudies/CaseStudy.asp?CaseStudyID=11721


 
Categories: ASP.NET | News

The Microsoft Office Project 2003 SDK is designed for solution providers, value-added resellers, and other developers to help customize Project 2003, and to extend and integrate Project Server 2003 with other applications for Enterprise Project Management. It features articles, programming references, tools, and sample code, including extensive articles called Solution Starters.

 

http://www.microsoft.com/downloads/details.aspx?familyid=4d2abc8c-8bca-4db9-8753-178c0d3099c5&displaylang=en


 
Categories: Development

The Microsoft SharePoint™ Developers' Conference 2003 presented an opportunity to learn about the upcoming release of Microsoft SharePoint products and technologies, including Microsoft Windows® SharePoint Services, Microsoft Office SharePoint Portal Server 2003, Web Parts, Microsoft Office FrontPage® 2003, Microsoft Office InfoPath™ 2003, Microsoft SQL Server™, Microsoft Exchange Server 2003, and the Microsoft Office System—among others. The content focused on the developer extensibility of these technologies, providing a head start to extending this terrific collaboration platform, built on Microsoft Windows Server™ 2003 and ASP.NET.

 

http://www.microsoft.com/downloads/details.aspx?familyid=d5bd33cb-4a0c-45c6-9bd3-091470db7943&displaylang=en


 
Categories: Development

Windows Services for UNIX 3.5 provides a full range of supported and fully integrated cross-platform network services for enterprise customers to use in integrating Windows into their existing UNIX-based environments.

 

http://www.microsoft.com/downloads/details.aspx?familyid=896c9688-601b-44f1-81a4-02878ff11778&displaylang=en


 
Categories: Development

The BizTalk Server 2004 Rollup Package 1 provides a cumulative rollup of updates that have been offered since the release of BizTalk Server 2004, and is discussed in the BizTalk Server 2004 installation guide as well as Microsoft Knowledge Base Article 837168. Download now to update your BizTalk Server 2004.

 

http://www.microsoft.com/downloads/details.aspx?familyid=c7eb0146-5f20-4d94-9f52-3e7e575736df&displaylang=en


 
Categories: Development

The BizTalk Server 2004 SDK Refresh contains updates and additions to samples, utilities, headers, and other developer artifacts to aide in the development of BizTalk Server 2004 applications.

http://www.microsoft.com/downloads/details.aspx?familyid=8a1ca3af-790c-4261-838a-9f0661c72887&displaylang=en


 
Categories: Development

The .NET Framework version 1.1 redistributable package includes everything you need to run applications developed using the .NET Framework.

The .NET Framework version 1.1 provides improved scalability and performance, support for mobile device development with ASP.NET mobile controls (formerly the Microsoft Mobile Internet Toolkit), support for Internet Protocol version 6, and ADO.NET classes for native communication with Open Database Connectivity (ODBC) and Oracle databases. It also enables the use of code access security to further lock down and isolate ASP.NET applications. For more information, read the .NET Framework Version 1.1 Product Overview.

Important: You cannot install two different language versions of the .NET Framework on the same machine. Attempting to install a second language version of the .NET Framework will cause the following error to appear: "Setup cannot install Microsoft .NET Framework because another version of the product is already installed." If you are targeting a non-English platform or if you wish to view .NET Framework resources in a different language, you must download the appropriate language version of the .NET Framework language pack.

 

http://www.microsoft.com/downloads/details.aspx?FamilyID=262d25e3-f589-4842-8157-034d1e7cf3a3&DisplayLang=en


 
Categories: .NET

This is a multi-part download of Service Pack 6 for Visual Basic 6.0. Customers with broadband connections are encouraged to download the one-file version. See the Related Resources link.

Service Pack 6 for Visual Basic 6.0 provides the latest updates to Visual Basic 6.0. It is recommended for all users of Visual Basic 6.0.

 

http://www.microsoft.com/downloads/details.aspx?familyid=83bf08e6-012d-4db2-8109-20c8d7d5c1fc&displaylang=en


 
Categories: VB

vbrun60sp6.exe is a self-extracting executable file that installs versions of the Microsoft Visual Basic run-time files required by all applications created with Visual Basic 6.0. The files include the fixes shipped with Service Pack 6 for Visual Basic 6.0.

 

http://www.microsoft.com/downloads/details.aspx?familyid=7b9ba261-7a9c-43e7-9117-f673077ffb3c&displaylang=en


 
Categories: VB

The MDAC 2.8 SDK is for developers who are building applications using ADO, OLE DB, and ODBC. It contains updated documentation, headers, libs and typelibs for x86, IA64 and AMD64 platforms, as well as updated sample applications and developer tools.

The MDAC 2.8 SDK is designed for use with MDAC 2.8, which is also available for download from the Microsoft Download Center.

http://www.microsoft.com/downloads/details.aspx?familyid=5067faf8-0db4-429a-b502-de4329c8c850&displaylang=en


 
Categories: ADO.NET | News