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>

LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);

char szWinName[] = "MyWin";

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

wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hInstance;
wcl.lpszClassName = szWinName;
wcl.lpfnWndProc = WindowFunc;
wcl.style = 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;

hwnd = CreateWindow(szWinName,"Windows XP",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);


ShowWindow(hwnd,nWinMode);
UpdateWindow(hwnd);

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

LRESULT CALLBACK WindowFunc(HWND hwnd,
UINT message,
WPARAM wparam,
LPARAM lparam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
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.


BEGIN
{
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]);
$n_inc++;
$i++;
}
}


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


#! /usr/bin/perl -w
BEGIN {
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.

REGEDIT
Open the registry editor.
Start > Run > regedit

Navigate to


+- HKEY_CURRENT_USER
+- 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"


REGEDIT4

[HKEY_CURRENT_USER\Software\yahoo\pager\Test]
"Plural"=dword:00000001



Double click the reg file and press "yes".

Thats all folks

Long time since made a post.
Howz life guys ?