Win32 program to create dialog box with tabcontrol - Kalyan

CoderSource.net
Win32 program to create dialog box with tabcontrol - Kalyan
Rating:

Date: 5/1/2004 12:00:00 AM

   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.

 

You Can Rate this Article, if you are Logged In      
 

More Links from CoderSource.net:

 
Refer to a Friend:

Your Details:

Name:     e-mail:

Friend Details:

Name:    e-mail:    


MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Add to Google
Add to My Yahoo!
Welcome to Codersource.Net Login | Register | Faq  

SEARCH
Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us