Monday, September 17, 2007

Introduction to Windows - Programming for Windows

History - DOS
Disk Operating System aka DOS was one of the earlier operating systems, it was a single task system, where the whole system and the OS was devoted to executing a single program and was basically a text based OS.

With the advent of the Windows Operating System, multiple process or applications could be run and it became a graphical OS (interface). So in order to support new features the basic structure of C/C++ programs changed from the main(){...} procedure to
something of a program as shown below and the a new compiler is required for compiling and generating Windows Executables, Visual C++ is such an example.

/*Program to
Display a Window on Windows
Test Compiled using Visual C++

#include <windows.h>


char szWinName[] = "MyWin";

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgs,
int nWinMode)
HWND hwnd;
MSG msg;

wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hInstance;
wcl.lpszClassName = szWinName;
wcl.lpfnWndProc = WindowFunc; = 0;
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcl.hIconSm = NULL;
wcl.hCursor = LoadCursor(NULL, IDC_ARROW);

wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;

wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);

if(!RegisterClassEx(&wcl)) return 0;



return msg.wParam;

UINT message,
WPARAM wparam,
LPARAM lparam)
return DefWindowProc(hwnd,message,wparam,lparam);
return 0;

Windows OS Skeleton
Windows is called so because all things you see on your desktop is broken into small Windows. A Window can have many child windows, parent window, and many other windows on the same level.

Getting Started to Windows Programming in C(++)?
A minimal Windows program must have atleast 2 functions
  • WinMain()
  • WindowFunc()

the WinMain() Function
The WinMain() function is the entry point to your program, i.e, the execution of your program starts with WinMain().
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszArgs,int WinMode)

The WinMain function must
  1. Define a window class

  2. Register the class (RegisterClassEx)

  3. Create Window (CreateWindowEx)

  4. Display Window (ShowWindow)

  5. Get the message loop running(while(GetMessage(...)))

The contents in italics is the functions used for doing the specified actions. Check them out in the code.

the Window Procedure
The window Procedure is the link between your program and windows. It is the window procedure that windows calls to send messages to your application.

That's all for now
stay tuned.

Saturday, September 8, 2007

Perl - cPanel V3 and the @INC

Modifying @INC in a SCRIPT

use Module;

is executed during compile time so if you modify the @INC array at run time it will not be reflected back in the compile time. So if you have to include any more include locations in the @INC inside a script, give it inside the BEGIN { }block.

push @INC,"location";

The BEGIN blocks are executed during compile time. So @INC is updated at compile time and the use module are correctly searched for in the updated directories.

cPanel-v3 Script

my $homedir = (getpwuid($>))[7];
my $n_inc = scalar @INC;
for (my $i = 0; $i < $n_inc; $i++ ) {
if (-d $homedir . '/perl' . $INC[$i]) {
unshift(@INC,$homedir . '/perl' . $INC[$i]);

This script dint work for me much, so I manually included the include locations into the BEGIN segment.

#! /usr/bin/perl -w
unshift @INC,"/home/directory/perl/usr/lib/perl5/site_perl/5.8.7/";

Monday, September 3, 2007

Multiple Instances of yahoo messenger

Yahoo Messenger
is a popular instant messaging software around. Yahoo messenger, by default, runs only a single copy on a single machine so for people with multiple yahoo id's this is a problem. Here is a short snippet that makes yahoo messenger to run multiple versions.

Open the registry editor.
Start > Run > regedit

Navigate to

+- Software
+- yahoo
+- pager

Create a new key inside pager named Test
Now inside the Test folder create REG_DWORD named pluralwith value 1.

Now you should be able to run multiple instances of yahoo messenger.

Alternate Method

Copy paste the text below exactly to a file with extension ".reg"



Double click the reg file and press "yes".

Thats all folks

Long time since made a post.
Howz life guys ?