⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 employee.cpp

📁 这个源代码是本程序演示了vc连接sql和access的方法好东东。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************
Copyright (c) 2000, Microsoft Corporation
All Rights Reserved.
***********************************************************************/

#define UNICODE
#define _UNICODE

// This hard coded path for "msado15.dll" need to be changed to the right path.
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
        no_namespace rename("EOF", "EndOfFile")

// Stardard headers
#include <windows.h>  
#include <commctrl.h>
#include <stdio.h>
#include "resource.h"

#define IDC_TAB 1000

// OLE headers
#include <ole2.h>
#include <conio.h>

// Global variables
TCHAR g_szAppName[100] = TEXT("Employee (ADO Sample)");

HWND g_hWnd = NULL;
HWND g_hDlg1Wnd = NULL;
HWND g_hDlg2Wnd = NULL;
HWND g_hTabWnd = NULL;
HINSTANCE g_hInst = NULL;

// Record set pointer.
_RecordsetPtr g_pRS = NULL;
 
// Predefined functions.
VOID EmptyDataFields ();
VOID DisplayData ();
VOID DisplayNotes ();
VOID DisplayPhoto ();
BOOL InitSQLServer ();
HWND DoCreateTabControl (HWND hwndParent);
BOOL CALLBACK Dlg1Proc (HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK Dlg2Proc (HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK MainDlgProc (HWND, UINT, WPARAM, LPARAM);

BOOL g_bTmp = FALSE;
/***********************************************************************

FUNCTION: 
  WinMain

PURPOSE: 
  Called by the system as the initial entry point for this application.

***********************************************************************/
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, 
                    LPSTR lpszCmdLine, int nCmdShow) 
{ 
  // Check if the application is running. If it's running then focus on 
  // the window.
  HWND hWnd = FindWindow (NULL, g_szAppName);  
  if (hWnd) 
  {
    SetForegroundWindow (hWnd);    
    return 0; 
  }

  g_hInst = hInstance;

  // Take care SQL stuff.
  if (!InitSQLServer ())
    return 0;
      
  // Bring up the main dialog box.
  DialogBox (hInstance, MAKEINTRESOURCE(IDD_MAINDLG), NULL, MainDlgProc);

  return 0;
} 

/***********************************************************************

FUNCTION: 
  MainDlgProc

PURPOSE: 
  Processes messages sent to the main dialog window. 

***********************************************************************/
BOOL CALLBACK MainDlgProc (HWND hWnd, UINT uMsg, WPARAM wParam, 
                           LPARAM lParam)
{
  switch (uMsg)
  {
    case WM_INITDIALOG:
    {
      g_hWnd = hWnd;
      g_hTabWnd = DoCreateTabControl (hWnd);
      TabCtrl_SetCurSel(g_hTabWnd, 0);
      g_hDlg1Wnd = CreateDialog (g_hInst, MAKEINTRESOURCE(IDD_DLG1), g_hTabWnd, Dlg1Proc);
      SetWindowPos (g_hDlg1Wnd, HWND_TOP, 5,25,0,0, SWP_NOSIZE | SWP_SHOWWINDOW);
      g_hDlg2Wnd = CreateDialog (g_hInst, MAKEINTRESOURCE(IDD_DLG2), g_hTabWnd, Dlg2Proc);
      SetWindowPos (g_hDlg2Wnd, HWND_TOP, 5,25,0,0, SWP_NOSIZE | SWP_SHOWWINDOW);
      ShowWindow (g_hDlg1Wnd, TRUE);
      ShowWindow (g_hDlg2Wnd, FALSE);
      DisplayData ();
      break;
    }
    
    case WM_COMMAND:
      switch (LOWORD (wParam))
      {
        case IDC_FIRST:
          if (g_pRS->AbsolutePosition > 1)   
          {
            g_pRS->MoveFirst ();
            DisplayData ();
          }
          break;

        case IDC_LAST:
          if (g_pRS->AbsolutePosition < g_pRS->RecordCount)   
          {
            g_pRS->MoveLast ();
            DisplayData ();
          }
          break;

        case IDC_PREVIOUS:
          if (g_pRS->AbsolutePosition > 1)   
          {
            g_pRS->MovePrevious ();
            DisplayData ();
          }
          break;

        case IDC_NEXT:
          if (g_pRS->AbsolutePosition < g_pRS->RecordCount)   
          {
            g_pRS->MoveNext ();
            DisplayData ();
          }
          break;

        case IDOK:
        case IDCANCEL:
        {
          g_pRS->Close();
          CoUninitialize();

          // Close the dialog box.
          EndDialog (hWnd, 0);
          break;
        }
      }
      break;

    case WM_NOTIFY: 
    {
      NMHDR *notifyHeader;

		  if (wParam != IDC_TAB)
			  break;
		  notifyHeader = (NMHDR *)lParam;
		  if (notifyHeader->code == TCN_SELCHANGE) 
      {
        int iPage = TabCtrl_GetCurSel(g_hTabWnd); 
        if (iPage == 0)
        {
          ShowWindow (g_hDlg1Wnd, TRUE);
          ShowWindow (g_hDlg2Wnd, FALSE);
          DisplayPhoto ();
        }
        if (iPage == 1)
        {
          ShowWindow (g_hDlg1Wnd, FALSE);
          ShowWindow (g_hDlg2Wnd, TRUE);
        }
      }
      break; 
    }

    default:
      break;
  }
  return FALSE;
}

/***********************************************************************

FUNCTION: 
  Dlg1Proc

PURPOSE: 
  Processes messages sent to the main dialog window. 

***********************************************************************/
BOOL CALLBACK Dlg1Proc (HWND hWnd, UINT uMsg, WPARAM wParam, 
                        LPARAM lParam)
{
  switch (uMsg)
  {
    case WM_INITDIALOG:
      break;
    case WM_COMMAND:
      switch (LOWORD (wParam))
      {     
        case IDOK:
        case IDCANCEL:
        {
          // Close the dialog box.
          EndDialog (hWnd, 0);
          break;
        }
      }
      break;
    default:
      break;
  }
  return FALSE;
}

/***********************************************************************

FUNCTION: 
  Dlg2Proc

PURPOSE: 
  Processes messages sent to the main dialog window. 

***********************************************************************/
BOOL CALLBACK Dlg2Proc (HWND hWnd, UINT uMsg, WPARAM wParam, 
                        LPARAM lParam)
{
  switch (uMsg)
  {
    case WM_INITDIALOG:
      break;
    case WM_COMMAND:
      switch (LOWORD (wParam))
      {     
        case IDOK:
        case IDCANCEL:
        {
          // Close the dialog box.
          EndDialog (hWnd, 0);
          break;
        }
      }
      break;
    default:
      break;
  }
  return FALSE;
}

/***********************************************************************

FUNCTION: 
  DoCreateTabControl

PURPOSE: 
  DoCreateTabControl - creates a tab control, sized to fit the 
  specified parent window's client area, and adds some tabs. 
  Returns the handle to the tab control. 
  hwndParent - parent window (the application's main window). 

***********************************************************************/
HWND DoCreateTabControl (HWND hwndParent) 
{ 
  HWND hwndTab; 
  TCITEM tie; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -