Tuesday, December 22, 2009

How to Install Windows XP without Deleting Linux Partition

[Click to enlarge the image]

You try to start installation of Windows XP from a bootable CD/DVDROM. It displays a message saying “Setup is inspecting your computer's hardware configuration” and after a while screen goes black. It seems like as if the installation procedure hanged up.

It happens when you have a Linux partition (mostly ext3) in your disk (HDD). Easiest way is to avoid Windows XP. For example, Windows Vista and Seven doesn’t have this requirement that hard-disk should not contain a Linux partition. You can install them flawlessly.

If it is strictly required that you should install Windows XP, if you don’t need Linux anymore you can delete those Linux partitions from disk management (Right click My Computer -> click Manage -> click Disk Management and you go there).

[Click to enlarge the image]

But if you require to install Windows XP and to keep the Linux unaffected at the same time this is what this page is mainly about.

If you can access Windows in your computer then try first solution. But if you cannot access Windows or want to fix it up using Linux even if you cannot boot into Linux for bootloader problem try second solution.

You need a gnu utility called testdisk to do this. Thanks GNU for their nicest work. Download testdisk from here.

First Solution
  • For Windows you should click Windows on the download page and then complete the download.

    Unzip the downloaded file.

    Go the testdisk directory. Enter into win directory.

    Double click testdisk_win.exe.

    [Click to enlarge the image]
  • If you have more than one hard-disk select the hard-disk containing Operating Systems first.

    [Click to enlarge the image]
  • Now select “proceed” and then pres enter. [pressing left or right arrow key selects an option].

    [Click to enlarge the image]
  • Select Intel (if you are using other system you know it) and then press enter.

    [Click to enlarge the image]
  • Select analyse and hit enter.

    [Click to enlarge the image]
  • Let’s first keep a back of the existing partition table.
    Select Backup and then press enter.

    [Click to enlarge the image]
  • Press ‘n’ if you were not using Windows Vista/Seven to create partitions and hit enter.

    Select quick search and then press enter. Testdisk will now be searching for lost partitions. Don’t worry about that.

    [Click to enlarge the image]
    And finally it you will be complete and a list of partitions will be displayed.

    [Click to enlarge the image]
  • We are temporarily going to delete Linux entries from partition table. Select every Linux partition and press left/right arrow key to change their status. Make them D as shown in image above. Please be careful in this step.

    And then press enter. Updated list of partitions will be displayed.

    [Click to enlarge the image]
  • Now select write as shown in image and then press enter.
  • It will ask for confirmation. Press ‘y’ and then enter.

    After restart you will be able to install Windows XP.
  • After installation run testdisk again. Follow the steps same like first solution but select quick search this time and hit enter key.
  • Press l to load back up in partition list window. Following screen will be displayed.

    [Click to enlarge the image]
  • Select load and hit enter.
  • Partition list will be displayed again. Hit enter. Now select write. And then y and then enter again. Now your linux partitions are back. To fix linux bootloader now follow this link.

Second Solution
If you have Linux in your disk but cannot boot into then check this link out to recover your linux bootloader.

After booting into your Linux system. Download the linux version of testdisk (rpm for Fedora Core, Suse, RHEL, CentOS and .tar.bz2 for other versions) you will have to type testdisk in a terminal after loggin in as root or doing an su.

Now follow the steps described in first solution starting from running testdisk.

N.B: Be careful about losing data giving wrong commands or committing mistakes. We suggest you to keep backup of your essential data.

If you face a problem still write in comments.

[Copy-right material. Contents of this post shouldn’t be copied to any other website for any kind of profit without permission. Contact unix9n at gmail dot com]

Monday, December 21, 2009

How to Configure Dial Up Internet Connection on Solaris 10

Googling for the solution with many types of workarounds in different references brings confusion. It's why I"m describing actually how I configured it.

Follow the steps given below correctly.
  • If you have selected non-networked during installation of Solaris 10 then you have to activate your network interface using the following command:

    # ifconfig interfaceName plumb up ipAddress netmask subnetMask

    In my PC the default network interface is rtls0. You can get your interfacename using following command and then looking up a while.
    # ifconfig -a

    ipAddress means ip Address of your Machine in LAN (you can get it
    from Windows if you have or contact your ISP).

    Subnet Mask is the subnet mask of your PC something like this
  • Create a file /etc/ppp/peer/isp with following contents:

    plugin pppoe.so 
    connect "/usr/lib/inet/pppoec interfaceName" 
    user atiq...@smile.com.bd           # my account name at my ISP 
    remotename smile.com.bd # name of the ISP; for pap-secrets 
    noauth                  # do not authenticate the ISP's identity (client) 
    noipdefault             # assume no IP address; get it from ISP 
    defaultroute            # install default route; ISP is Internet gateway 
    updetach                # log errors and CONNECT string to invoker 
    noccp                   # ISP doesn't support free compression 
  • Append to /etc/ppp/pap-sectrects and /etc/ppp/chap-sectrects

    ispProvidedUserName     ispName password

    Be careful no space as separator should be used. You must place tab instead. For example,
    abcd...@smile.com.bd        smile.com.bd    abcdef
  • Create /etc/ppp/pppoe.if with content
    You have to set your interface name. interfaceName in my case is rtls0.
  • Create /etc/resolv.conf with content
    nameserver primaryDNSServer 
    nameserver secondoryDNSServer
    You can get them from Windows(peeping into your dialup connection
    detais) or asking your ISP. For example, mine is:
  • Apply following commands
    # sppptun plumb pppoed interfaceName
    # sppptun plumb pppoe interfaceName # pppd call isp

    Or you can use debug to check for errors.
    # pppd debug call isp

How to Install Network Simulator (NS) and nsnam on Solaris 10

Follow the steps given below.
  • Download the ns-allinone package from here:
  • Extract it or apply following command and cd to the directory where you downloaded the file. Now apply following commands.
    # gtar xzvf \
    # cd ns-allinone-2.33
  • Now download all the files attached with this post (look at the bottom) in the same directory. After download is complete enter following commands.

    # chmod a+x ns_fix.sh
    # ./ns_fix.sh
Say yes if it asks to over-write any file.


What fixes have been done to make the installation successful is described here.

I chose ns-allinone-2.33 package which contains
* Tcl release 8.4.18 (required component)
* Tk release 8.4.18 (required component)
* Otcl release 1.13 (required component)
* TclCL release 1.19 (required component)
* Ns release 2.33 (required component)
* Nam release 1.13 (optional component)
* Xgraph version 12 (optional component)
* CWeb version 3.4g (optional component)
* SGB version 1.0 (?) (optional component, builds sgblib for all UNIX
type platforms)
* Gt-itm gt-itm and sgb2ns 1.1 (optional component)
* Zlib version 1.2.3 (optional, but required should Nam be used)

First, Make your system gnu compatible (fix cc, make).

I have seen cases where setting enveronmental variables does not help. Still
you can try.
$ CC=gcc 
$ MAKE=gmake 

Better try this,
# ln -s /usr/sfw/bin/gcc /usr/sfw/bin/cc 
# ln -s /usr/sfw/bin/gmake /usr/sfw/bin/make

Put /usr/sfw/bin in PATH variable.
# export PATH=/usr/sfw/bin/:$PATH
To make it permanent add it to .bashrc in your home directory if you are using bourne again shell. Else add to .profile. To know which shell: give this command "echo $SHELL" without quotations exactly.

After doing this gcc will be used instead of Sun's default compiler. And gnu make will be default make. If there were no problems if you just extracted the package installed them using ./install command inside the dir it was enough. But it is actually not enough.

There is a problem with the Solaris MIN MAX macros. To fix it I have provided files: config.h and mobile/mip-reg.cc Finally provide tcp_cong.c where replaced strsep with getToken function because strsep is not in Solaris 10 (details here: http://does-not-exist.org/mail-archives/mutt-dev/msg10335.html)

It is included with later releases of Solaris. So you might find it easier to install ns in Solaris Express versions (OpenSolaris, SXCE). (Note: Architecture dependant fix: config.h and mip-reg.cc, OS dependant
fix: tcp_cong.c)

Files are attached with this post. Click to download files.

Sunday, December 20, 2009

How to Install Sun Nimbus Theme on Fedora Core Linux

Enter the following command providing root password after su.

# su

# yum install nimbus-theme-gnome
Loaded plugins: presto, refresh-packagekit
Setting up Local Package Process
Examining nimbus-theme-gnome-0.1.4-2.fc12.noarch.rpm:
Marking nimbus-theme-gnome-0.1.4-2.fc12.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package nimbus-theme-gnome.noarch 0:0.1.4-2.fc12 set to be updated
--> Processing Dependency: gtk-nimbus-engine for package:
--> Processing Dependency: nimbus-icon-theme for package:
--> Processing Dependency: nimbus-metacity-theme for package:
--> Running transaction check
---> Package gtk-nimbus-engine.i686 0:0.1.4-2.fc12 set to be updated
---> Package nimbus-icon-theme.noarch 0:0.1.4-2.fc12 set to be updated
---> Package nimbus-metacity-theme.noarch 0:0.1.4-2.fc12 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

 Package                    Arch        Version              Repository    Size
 nimbus-theme-gnome         noarch      0.1.4-2.fc12
Installing for dependencies:
 gtk-nimbus-engine          i686        0.1.4-2.fc12         updates       59 k
 nimbus-icon-theme          noarch      0.1.4-2.fc12         updates      8.7 M
 nimbus-metacity-theme      noarch      0.1.4-2.fc12         updates       45 k

Transaction Summary
Install       4 Package(s)
Upgrade       0 Package(s)

Total size: 8.8 M
Total download size: 8.8 M
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 8.8 M
(1/3): gtk-nimbus-engine-0.1.4-2.fc12.i686.rpm           |  59 kB     00:04     
(2/3): nimbus-icon-theme-0.1.4-2.fc12.noarch.rpm         | 8.7 MB     08:43     
(3/3): nimbus-metacity-theme-0.1.4-2.fc12.noarch.rpm     |  45 kB     00:02     
Total                                            17 kB/s | 8.8 MB     08:52     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : nimbus-icon-theme-0.1.4-2.fc12.noarch                    1/4 
  Installing     : nimbus-metacity-theme-0.1.4-2.fc12.noarch                2/4 
  Installing     : gtk-nimbus-engine-0.1.4-2.fc12.i686                      3/4 
  Installing     : nimbus-theme-gnome-0.1.4-2.fc12.noarch                   4/4 

  nimbus-theme-gnome.noarch 0:0.1.4-2.fc12                                      

Dependency Installed:
  gtk-nimbus-engine.i686 0:0.1.4-2.fc12                                         
  nimbus-icon-theme.noarch 0:0.1.4-2.fc12                                       
  nimbus-metacity-theme.noarch 0:0.1.4-2.fc12                                   


Click System Menu -> Preferences -> Appearance.

Under theme tab now you'll see the nimbus theme. Select it and then click close. Nimbus theme is set now and appearance will be in effect accordingly.

Screenshot 1

Screenshot 2

Instant Messenger for Linux, How to Install and Configure

Messenger for Linux, how to get to play with it!

It just doesn't work like Windows. No Yahoo Messenger(there is an archaic release available though), no google talk. So what! Still we have the best instant message client in Linux. You might have heard about it. It's pidgin.

To start pidgin click Main Menu -> Internet -> Pidgin Instant Messenger

If you don't find it there install it. For Fedora Core, type su, provide root password, hit enter and then type the command as shown below.

# su

# yum install pidgin

For Ubuntu try this,
# sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com \
# echo deb http://ppa.launchpad.net/pidgin-developers/ppa/ubuntu \
`lsb_release --short --codename` main | \
sudo tee /etc/apt/sources.list.d/pidgin-ppa.list

# sudo apt-get update
# sudo apt-get install pidgin

After it is installed you'll find it in the menu. Now after clicking the icon in the menu you'll see a dialog box appeared.

Click add. Select protocol, for example, if you want to use your yahoo id then you have to select yahoo id.

Enter correct username and password. If it is your own PC then might like to check the tickbox before "Remember Password"

Locat alias is the name you want be familiared with. You can provide any name. Just don't do mistake in the username and password. After clicking add pidgin will log you in if entered information was correct!

Installing Audio / Video Players in Fedora Core Linux

First of all install rpmfusion repository support.

# rpm -Uvh http://download1.rpmfusion.org/free/fedora/\
warning: rpmfusion-free-release-stable.noarch.rpm: Header V3 DSA signature: NOKEY,
key ID 49c8885a
Preparing...                ########################################### [100%]
   1:rpmfusion-free-release ########################################### [100%]

# rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/\
warning: rpmfusion-nonfree-release-stable.noarch.rpm: Header V3 DSA signature: NOKEY,
key ID b1981b68
Preparing...                ########################################### [100%]
   1:rpmfusion-nonfree-relea########################################### [100%]

Now you can install video players following the instructions as given next.

How to Install Xine DVD Player

Apply following commands to install xine.

# yum install xine xine-lib-extras libdvdread libdvdnav xine-lib-extras-freeworld
Loaded plugins: presto, refresh-packagekit
Setting up Install Process
Resolving Dependencies
-- Running transaction check
--- Package xine-ui.i686 0:0.99.5-16.fc12 set to be updated
-- Processing Dependency: xine-lib-extras for package: xine-ui-0.99.5-16.fc12.i686
-- Processing Dependency: libaa.so.1 for package: xine-ui-0.99.5-16.fc12.i686

If you know some of the keyboard shortcuts of xine it will make your life a lot easier.
* Pressing v decreases the audio volume.
* Pressing SHIFT + v increases the audio volume.
* Pressing F make the Video Window full screen
* Pressing h you can toggle hiding video panel
* Pressing Alt + 3 makes 200% zoom
* Pressing Alt + 2 makes 100% zoom

Enjoy the open spirit!

How to Install MPlayer

Apply following commands to install rpmfusion repository supports.

# yum install mplayer mplayer-gui gecko-mediaplayer
Loaded plugins: presto, refresh-packagekit
Setting up Install Process
Resolving Dependencies
-- Running transaction check
--- Package mplayer.i686 0:1.0-0.111.20091029svn.fc12 set to be updated
-- Processing Dependency: libliveMedia.so.0 for package: mplayer-1.0-0.111.20091029svn.fc12.i686

Pressing / decreases sound volume where pressing * increases it!

How to Install VLC Media Player

It's damn easy to install VideoLan Media Player! Try it out.

# yum install vlc

How to Install Other Audio / Media Players

There are many other players around. Simple "yum install playername" command should work for players like amarok, kaffeine, pulse-audio, totem-xine, kplayer etc. If you get an exception write in comments.

Screenshots of Xine DVD Player

Xine running in Fedora Core 12, theme Cinema Gold

Xine DVD Player Fullscreen

MPlayer Screeenshots

Mplayer Running in Window

Mplayer in Fullscreen

Totem Movie Player Screenshots

This player is by default available and installed with gnome. It's doing good these days too. When it asks for a codec you just need to click install. Linux really made a bit easier than before!

Totem Movie Player in Window

Totem Movie Player Fullscreen

[All images are in high resolution. You have to click them to enlarge or zoom in.]

How to Install Google Chrome on Linux

This post has been revised and moved to SAOSLab. Please visit the post here at http://tech.saoslab.com/post/2012/09/27/How-to-install-Google-Chrome-on-different-Linux-distributions.in for . Thank you.

yum Command Doesn't Work Because 'Another app is currently holding the yum lock'

Another behavior of foolish Linux (Fedora Core mostly) is it cannot automatically disable yum when it is busy for no reason!

Hence, you might face this messages after applying an yum command!

Existing lock /var/run/yum.pid: another copy is running as pid 6302.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  17 M RSS ( 32 MB VSZ)
    Started: Fri Dec 18 18:50:55 2009 - 02:39 ago
    State  : Sleeping, pid: 6302
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  17 M RSS ( 32 MB VSZ)
    Started: Fri Dec 18 18:50:55 2009 - 02:41 ago
    State  : Sleeping, pid: 6302

Now what? Well, as the OS is foolish we have to take the control! Kill the boring yum running in background and force it to do our work! That's it.

Note the pid from the message. Look in my case it is 6302. So I'll apply this command.
# kill -9 6302

This will kill the process blocking yum. Now reenter the previous yum command that you wanted to perform.

File Browser Opens Every Folder in New Windows in Linux! How to Fix

An annoying behaviour of gnome nautilus file browser is when you double click a folder icon it always opens in new windows and those windows are plain. I don't know why do they mess the system up before impressing the user for first time use! Is it only in Fedora Core or default gnome behavior?!!

Anyway, there is a way to change it. You need to do couple of mouse clicks!

Click Computer. Then Click Edit -> Preferences. A new window will appear

Click Behavior Tab. It will look like the one given displayed below:

[Click the image to enlarge.]
Under behavior Tick the box before Always open in browser windows.

And under Executalbe Text Files Select View executable text files. (It also makes life little easier.) It will look like this.

[Click the image to enlarge.]

From now the behavior and appearance of nautilus is changed.

How to Change MAC Address on Linux [system-config-network Way]

If you want to change MAC address using NetworkManager follow this post.

To succeed in system-config-network way we need to make sure NetworkManage tool does not exist! Because it won't let us change the MAC of eth0 device with ifconfig command!
# service NetworkManager stop
# yum -y remove NetworkManager

To change the MAC address of a Linux Machine you have to change the MAC address on system-config-network tool, then apply the ifconfig command and then start the interface.

# ifconfig eth0 down
# ifconfig eth0 hw ether 00:11:22:33:44:55
# ifconfig eth0 up

To change the MAC address in system-config-network you need to do the following.

1. Apply command system-config-network either on gnome-terminal or pressing alt+F2.

2. It will ask for root password. Provide the password.

3. Deactivate the current eth0 profile by clicking deactivate if it is shown active.

4. Now double click the eth0 device profile.

5. Click Hardware Device Tab.

[Click image to enlarge]

6. Tick "Bind to MAC address" option. And provide the new MAC address(as used ifconfig command) on the textbox following the format aa:bb:cc:dd:ee:ff (colon after every 2 literals). Then click ok.

Now let's change the eth0 hardware address using ifconfig command.

# ifconfig eth0 down
# ifconfig eth0 hw ether 00:11:22:33:44:55
# ifconfig eth0 up

Where 00:11:22:33:44:55 should be replaced by your PC's physical address.

Now activate eth0 from system-config-network.

To check if the change is in effect apply this command.

# ifconfig | grep HWaddr

If you still cannot access network restart the network service.

# service network restart
ping to check back your internet connection.

$ $ ping www.google.com
PING www.l.google.com ( 56(84) bytes of data.
64 bytes from bw-in-f105.1e100.net ( icmp_seq=1 ttl=53 time=220 ms
64 bytes from bw-in-f105.1e100.net ( icmp_seq=2 ttl=53 time=220 ms
64 bytes from bw-in-f105.1e100.net ( icmp_seq=3 ttl=53 time=219 ms
64 bytes from bw-in-f105.1e100.net ( icmp_seq=4 ttl=53 time=220 ms
64 bytes from bw-in-f105.1e100.net ( icmp_seq=5 ttl=53 time=220 ms
--- www.l.google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4298ms
rtt min/avg/max/mdev = 219.408/220.194/220.799/0.709 ms
Press Ctrl + C to exit ping. All these commands require root privilege. Either do an su or login as root.

This command works on all Linux Distros(Fedora Core, Ubuntu, Suse, Mandriva etc). But system-config-network & NetworkManager commands may be different on distros other than Fedora Core OSs.

How to Configure / Setup Broandband Internet Connection in Fedora Core Linux

First of all, you need some network informations which you can get from windows.

In windows click start menu. Click run.

Type cmd. Then type ipconfig /all

Write down those information(ip, subnet, default gateway and DNS). Or save them in a text file and mount from Fedora Core.

Click System>Administration>Network. The window is as below:

Double click the eth0 device. A window will open like this one

You have to uncheck the tickbox saying Controlled by Network Manager. Enter ip address right to the Address.

Subnet mask and default gateway.

Now click DNS tab, The window is shown as below:

Enter Primary DNS (DNS server 1 from windows) 
Enter Secondary DNS (DNS server 2 from windows
And then click activate to activate the network interface. After it is activated you are connected to the internet. (It's done in this step for providers such as bracnet, BD, smile, BBTS-onilne etc)

Configure the proxies if your provider connects you through proxy servers.
Click System>Preferences>Internet and Network>Network Proxy. This loooks like this:

Click manula proxy configuraton and then enter your settings.. and you are done... 

Install / Update Packages Using yum from Locad DVD / Repository / ISO

Install / Update Packages Using yum from Locad DVD / Repository / ISO

For example, you have downloaded a live fedora CD. Now you have a DVD or iso of the DVD or have a local repository. Therefore you can update your system using them. Install or remove packages too.

If you wish to update from DVD then enter the dvd. It should be auto-mounted. Know the mount point. If you don't know how check /media directory there should be a directory named DVD-ROM or the Volume Label of the DVD!

For iso you have to mount it and have to know the mount point. If you don't know how to mount isos follow here.

Let's assume the mount point is /mnt/tmp

Login as root or type su on the terminal. Edit /etc/yum.conf apply the following command.
# gedit /etc/yum.conf

But if you don't have a GUI Desktop Environment use vi editor instead.

Append the following lines in your yum.conf(at the last of the file)
name=Fedora Core 12 - i386 - Base

Base url="The mount point of your repository"

Now clean up yum files.

# yum clean all

Now try installing some software packages. For example,
# yum install wireshark-gnome

If you find a conflict with other repos. Try this command instead.
# yum --disablerepo=* --enablerepo=base localinstall somepackage

Use the name of package you want to install instead of somepackage.

How to mount iso files in Linux

ISO files are disk image. The standard is provided by International Standard Organization as it is named. Accessing an iso file may be important sometimes in Linux to upgrade/repair the system.

Open a terminal. To acquire root privilege type
# su

Provide password and hit enter.

Now create a mount point.
# mkdir /mnt/isotemp

Mount the iso file to mount point.
# mount -o loop /path to iso/filename.iso /mnt/isotemp

Display the file list.
# ls

Now you can access those files in read-only mode. To unmount use this command

# umount /mnt/isotemp

Saturday, December 19, 2009

Win32 Programming: How to add version and other information

[Click the image to enlarge]

Here we’re telling how you can add application information on its executable file. If you don’t understand this tutorial much I suggest you read the previous ones where I shown how to add resource files(resource.h and prog.rc)

Pretty easy task it is. Add following lines in your resource(.rc) file.

// Version

#ifdef _DEBUG
    BLOCK "StringFileInfo"
        BLOCK "040904e4"
            VALUE "Comments", "This program shows Bangla Clock in Unicode"
            VALUE "CompanyName", "Saint Group"
            VALUE "FileDescription", "SA OS Tut7 Executable"
            VALUE "FileVersion", "1.0"
            VALUE "InternalName", "Unicode Bangla Clock"
            VALUE "LegalCopyright", "Saint Atique (c) 2009"
            VALUE "LegalTrademarks", "Saint Group"
            VALUE "OriginalFilename", "SA-OS Tutorial 7.exe"
            VALUE "ProductName", "SA-OS Tutorial"
            VALUE "ProductVersion", "1.0"
    BLOCK "VarFileInfo"
        VALUE "Translation", 0x409, 1252

Change the information according to your need. Build and run the solution.

Details about versioninfo resource on msdn:

Friday, December 18, 2009

Win32 Programming: Using Menu and icons

How to create a Menu in your application

The images above demonstrate the use of menu in a win32 application. To create Menu you need two file.
  • resource.h
  • ProgramName.rc

In our case they are resource.h and tut6_CreatingMenuItem.rc (files are attached with this post)

tut6_CreatingMenuItem.rc has following contents

// Microsoft Visual C++ generated resource script.
#include "resource.h"
#include "afxres.h"

// Menu

    POPUP "&Menu"
        MENUITEM "&About",                       ID_ABOUT
        MENUITEM "&Exit",                        ID_EXIT

//IDI_PROGICON    ICON "prog.ico"

resource.h has following contents

// Microsoft Visual C++ generated include file.
// Used by tut6_CreatingMenuItem.rc
#define IDC_STATIC                      -1
#define SAW_MENU1                       40101
#define ID_ABOUT                        40102
#define ID_EXIT                         40103

In your main program tut6_CreatingMenuItem.cpp add the following line in top of your program.
#include "resource.h"
Now add the rc file in your program as shown in images below.

And change this line in your program
wcex.lpszMenuName   = NULL;
wcex.lpszMenuName   = MAKEINTRESOURCE(SAW_MENU1);

How to take action when a Menu item is clicked
When a menu item is clicked application receives a WM_COMMAND message. Hence we have to handle this message to perform necessary actions.

Add these lines in your callback function

      switch(LOWORD (wParam)) {
            case ID_ABOUT:
                  MessageBox(hWnd, "Tutorial 6: Working with menu and icons",
            case ID_EXIT:
                  PostMessage(hWnd, WM_CLOSE, 0, 0);
Posting WM_CLOSE message in message queue closes the application.

How to set an icon for your windows application
You have to use 16x16 or 32x32 icon file to make this work. In our case it is prog.ico
  • Add the following line in tut6_CreatingMenuItem.rc
    SAW_PROGICON    ICON "prog.ico"

  • Add the following in resource.h
    #define SAW_PROGICON                    40104

  • And change this line in your WinMain function
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(SAW_PROGICON));

Build the program and run again.

How to disable/gray a Menu Item

To disable or make a Menu item gray add following lines in your code where necessary

HMENU hmenu = GetMenu(hwnd);        // hwnd is the handle of the window containing the menu
EnableMenuItem(hmenu, ID_EXIT, MF_GRAYED);

Files are attached with this post. Click to download.