Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

A Library for Quick and Easy Development of Win32 Applications

0.00/5 (No votes)
5 Nov 2004 3  
win32easy is a static library that makes win32 programing as easy as old good C-like programming with a "main" routine.

Introduction

Windows programming can be a very tedious task even for experienced programmers. Numerous API functions and windows messages, Component Object Model and other things on one hand make applications very powerful, on the other hand it can be very discouraging since even for a simple application one has to invest a lot of time and effort to build it. The latter is especially true for people in computer related sciences like bioinformatics when the scientist is primary concentrated on its scientific stuff and doesn�t really want to understand all bells and whistles of win32 API. As the result, in the scientific world we have a lot of software with extremely poor and unobvious interface.

Very often what we need from the Windows application is a decent looking input and handy output. It is very annoying to convert data for example from Excel into a text file, process them through an application and then reformat back to Excel. Unfortunately this is the case for most of the programs in the scientific world.

Win32Easy is a static library that facilitates and speeds up the process of development of Win32 applications. Win32Easy provides several classes that handle windowing and interaction with other applications (like IE and Excel) via COM. These classes hide complexity from the programmer, but the code of the library is very much transparent and easy to understand unlike Microsoft Foundation Classes (MFC). In addition, the library does not overwhelm with the number of classes, instead it provides the most important ones. The library is not intended to avoid completely win32 native code; instead it helps to use it in a seamless manner.

Using Win32Easy

A typical application code looks like this:

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
             LPSTR lpCmdLine, int nCmdShow)
{
    /*no panic, just initializing OLE - we are communicating with Office */
    HRESULT hr;
    if(FAILED(hr = OleInitialize(0)) )
       throw ole_exception(hr); 


    HtmlWin htmlWindow(hInstance);
    htmlWindow.OpenURL(L"http://www.google.com/" target=_blank>http://www.google.com/");


    //do some work

   TextOutWindow tow(hInstance);
   tow.PrintText(TEXT("Some text"));


   Chart ch(hInstance);
   double dx[] = {10,20,30,40,50,60,70};
   double dy[] = {100,400,900,1600,2500,3600,4900};
   ch.Setx(0, dx, 7);
   ch.Sety(0, dy, 7);


   tow.WaitForEnd();
   return 0;
}

That is it. You will not find in the main routine anything like a message loop or a hassle with hundreds of parameters for window creation. This hassle indeed exists in the implementation of the HtmlWin or TextOutWindow classes, but this does not disturb the clarity of the code and its primary focus � the calculations that the program has to perform. It looks like an old good C++ program with a main routine. In fact, old command-line code with the main routine can be easily ported to a GUI application.

How does it work?

The mechanism how this works is straightforward: the objects representing windows create their own thread and do all GUI job there. The program flow is concentrated in the main thread in the WinMain procedure, while message handling and other windows related operations are hidden in the implementation of the objects. Naturally, win32easy library assists development of the master-like applications, which guide the user through the entire calculation process, rather than just waiting for the user actions. Such a behavior is often very welcome especially when the developer wants to save potential users of his application from reading voluminous manuals.

Example of Some Classes

The purpose of this section is to provide examples of some useful classes and show some of their member functions in order to demonstrate how it is easy to perform tasks with the library being described that are quite complicated to accomplish otherwise using just native win32 code.

MSExcel

Should you read or save results of your computation in an Excel file, this class is very convenient. It provides functionality for creating new, opening and saving existing files. Doing this through straightforward OLE one has to create numerous interfaces for many intermediate objects making code very difficult to manage. Just some member functions:

int OpenFile(LPOLESTR fname);
int SaveAs(LPOLESTR Fname);
int SetCellsArray(LPOLESTR lpSheet, LPRECT lpr, int *pdx);
int GetCellsArray(LPOLESTR lpSheet, LPRECT lpr, double *parr) const;
int CellValue(LPOLESTR lpSheet, int iRow, int iColumn, double *d);

TerminalWindow

Many times it is necessary to inform the user about the process that is going on at the moment or provide some textual information. Using just TextOut(HDC...) function is not a very convenient way since one has to take care of text lines on the screen, scrolling, possible conversion of numbers to text. It would be great to have something like old printf(...) function that takes care about all of this but in a window and it would be also great to be able to copy that text to clipboard. TerminalWindow does all of it:

bool PrintText(int iResID, va_list args) const;
bool PrintText(LPCTSTR format, va_list args) const;
bool PrintText(int iResID) const; 
bool PrintText(LPCTSTR lszText) const;

Library Homepage

Detailed information about the library and description of each object and its member functions is available here. Also, you'll find a molecular dynamic application which is powered by win32easy that uses all modern technologies like GUI, COM and DirectX.

Enjoy easy win32 development.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here