Win32 program to create dialog box with tabcontrol - Kalyan

   As any body know how to create a dialog box in Win32, but lot of them are struggling how to place controls on that dialog. We don't have specific idea how to do that when we are new to Win32. Here I am showing sample code to place a tab control on dialog.

   Some of the steps that may be used for creating this application.

  • Create a new Empty Win32 application in VC++. The sample name can be SampleTab.

  • Click on Menu --> Add To Project --> New --> C++ source file and name the file as SampleTab.cpp

  • Copy and paste the code below.


#include <windows.h>
 #include "resource.h"
 #include "commctrl.h"

 BOOL CALLBACK LoginDlgProc(HWND, UINT, WPARAM, LPARAM); 

 int PASCAL WinMain (HINSTANCE hInst, HINSTANCE, LPSTR, int) 
 { 
     int nRet = DialogBoxParam(hInst, MAKEINTRESOURCE (IDD_DIALOG1), NULL, LoginDlgProc, 1);
     return 0;
 }

 BOOL CALLBACK LoginDlgProc(HWND hWnd, UINT uMsg, WPARAM wp, LPARAM lp)
{

//Initialize the common controls library.
//This will enable the program to use Tab control
 INITCOMMONCONTROLSEX InitCtrlEx;
 InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
 InitCtrlEx.dwICC = ICC_TAB_CLASSES;
 InitCommonControlsEx(&InitCtrlEx);
 switch(uMsg)
 {

 case WM_INITDIALOG:
 {
    TCITEM tci1,tci2;
    tci1.mask = TCIF_TEXT;
    tci1.pszText = "Pane!";
    tci1.cchTextMax = strlen("Pane1") + 1;
    tci1.iImage = -1;
    tci1.lParam = 0;
    tci2.mask = TCIF_TEXT;
    tci2.pszText = "Pane2";
    tci2.cchTextMax = strlen("Pane2") + 1;
    tci2.iImage = -1;
    tci2.lParam = 0;
    TabCtrl_InsertItem(GetDlgItem(hWnd , IDC_TAB1), 0, & tci1);
    TabCtrl_InsertItem(GetDlgItem(hWnd , IDC_TAB1), 1, & tci2);
    return TRUE;
    break;
 } 
default:
   return FALSE;

 }

 }


  • Add a new dialog by clicking Menu --> Insert --> Resource --> Dialog. This is the dialog editor provided by VC++.
  • Keep the Dialog resource id as IDD_DIALOG1.
  • Place a tab control with the Resource ID as IDC_TAB1.
  • Save the resource file and resource.h file in the project folders.
  • Add the resource files to the project by using Menu --> Project --> Add to Project --> Files
  • This program will need the comctl32.lib for initializing the common controls like tab control. So add comctl32.lib to Project Settings --> Link Tab --> Object/Library modules.
  • Build and run the project.

 

Close    To Top
  • Prev Article-Programming:
  • Next Article-Programming:
  • Now: Tutorial for Web and Software Design > Programming > win32 > Programming Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction