Click here to Skip to main content
15,881,875 members
Articles / Desktop Programming / MFC
Article

A Library for Quick and Easy Development of Win32 Applications

Rate me:
Please Sign up or sign in to vote.
3.50/5 (9 votes)
5 Nov 20044 min read 66.2K   1.3K   31   12
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"<A href="http://www.google.com/" target=_blank>http://www.google.com/</A>");

    //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


Written By
Team Leader University of Washington
United States United States
I was born in Moscow, USSR. In 1998, I earned Master’s degree in Chemistry from the Moscow State University. In 2000, I moved to Germany to pursue a PhD degree in Genetics. Currently I live with my family in the United States.
I have been always involved is a multidisciplinary research side-by-side with biologists. The research involves physical chemistry, bioinformatics and electrical engineering.

Comments and Discussions

 
GeneralCatching results of operations Pin
Karl N M6-May-05 15:38
Karl N M6-May-05 15:38 
GeneralRe: Catching results of operations Pin
Dr. APo7-May-05 5:19
professionalDr. APo7-May-05 5:19 
GeneralHire me! Pin
John R. Shaw14-Nov-04 11:23
John R. Shaw14-Nov-04 11:23 
GeneralRe: Hire me! Pin
Dr. APo14-Nov-04 14:42
professionalDr. APo14-Nov-04 14:42 
GeneralNeeds a tad bit of work... Pin
Anonymous13-Oct-04 10:19
Anonymous13-Oct-04 10:19 
GeneralRe: Needs a tad bit of work... Pin
Dr. APo13-Oct-04 10:37
professionalDr. APo13-Oct-04 10:37 
QuestionWhy not just make a console app? Pin
Don Clugston11-Oct-04 18:02
Don Clugston11-Oct-04 18:02 
AnswerRe: Why not just make a console app? Pin
Dr. APo12-Oct-04 4:12
professionalDr. APo12-Oct-04 4:12 
GeneralRe: Why not just make a console app? Pin
Jim Crafton12-Oct-04 4:41
Jim Crafton12-Oct-04 4:41 
GeneralRe: Why not just make a console app? Pin
Jim Crafton12-Oct-04 4:52
Jim Crafton12-Oct-04 4:52 
GeneralRe: Why not just make a console app? Pin
Dr. APo12-Oct-04 7:41
professionalDr. APo12-Oct-04 7:41 
GeneralRe: Why not just make a console app? Pin
Jim Crafton12-Oct-04 11:05
Jim Crafton12-Oct-04 11:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.