PowerBASIC Peer Support Forums
 

Go Back   PowerBASIC Peer Support Forums > Jose's Corner > Source Code

Source Code Source code related to Jose's work. Posts and uploads may be made by any forum member.

Reply
 
Thread Tools Display Modes
  #16  
Old Apr 6th, 2012, 02:02 PM
Josť Roca Josť Roca is online now
Moderator
 
Join Date: Mar 2004
Location: Valencia, Spain
Posts: 6,644
Outlook View Control

Demonstrates how to embed an instance of the Microsoft Office Outlook View Control.

Code:
' ########################################################################################
' Demonstrates how to embed an instance of the Microsoft Office Outlook View Control
' ########################################################################################

#COMPILE EXE
#DIM ALL
%UNICODE = 1
%USEOLECON = 1

#INCLUDE "CWindow.inc"            ' // CWindow class
#INCLUDE "olecon.inc"             ' // OLE Container
#INCLUDE "commctrl.inc"           ' // Common controls constants and declares
#INCLUDE "outlctl.inc"            ' // Microsoft View Control include file
#INCLUDE "ToolbarCtrl.inc"        ' // Toolbar wrapper functions
#INCLUDE "CAfxImageList.inc"      ' // Image List class
#RESOURCE RES, "EX_OVC_01.RES"    ' // Resource file

' Control identifiers
%IDC_TOOLBAR         = 1001
%IDC_OVC             = 1002

%IDM_CALENDAR        = 28000
%IDM_CONTACTS        = 28001
%IDM_DELETED         = 28002
%IDM_DRAFTS          = 28003
%IDM_INBOX           = 28004
%IDM_NOTES           = 28005
%IDM_OUTBOX          = 28006
%IDM_SENT            = 28007
%IDM_TASKS           = 28009

' Icon identifiers
%IDI_CALENDAR        = 100
%IDI_CONTACTS        = 101
%IDI_DELETED         = 102
%IDI_DRAFTS          = 103
%IDI_INBOX           = 104
%IDI_JOURNAL         = 105
%IDI_NOTES           = 106
%IDI_OUTBOX          = 107
%IDI_OUTLOOK         = 108
%IDI_PERSONALFOLDERS = 109
%IDI_SENT            = 110
%IDI_TASKS           = 111

' ========================================================================================
' Creates the toolbar
' ========================================================================================
FUNCTION OvcCreateToolbar (BYVAL pWindow AS IWindow) AS DWORD

   LOCAL hToolBar AS DWORD
   LOCAL cx, cy AS LONG

   ' // Create the ToolBar Window.
   hToolBar = pWindow.AddToolBar(pWindow.hwnd, %IDC_TOOLBAR, "", 0, 0, 0, 0, _
              %WS_CHILD OR %WS_VISIBLE OR %TBSTYLE_TOOLTIPS OR %TBSTYLE_FLAT)
   ' // Set the extended style
   ToolBar_SetExtendedStyle hToolbar, %TBSTYLE_EX_DRAWDDARROWS

   ' // Set the size of the bitmapped images
   ToolBar_SetBitmapSize(hToolbar, 24, 24)

   ' // Add buttons to the toolbar
   Toolbar_AddButton hToolBar, 0, %IDM_CALENDAR
   Toolbar_AddButton hToolBar, 1, %IDM_CONTACTS
   Toolbar_AddButton hToolBar, 2, %IDM_DELETED
   Toolbar_AddButton hToolBar, 3, %IDM_DRAFTS
   Toolbar_AddButton hToolBar, 4, %IDM_INBOX
   Toolbar_AddButton hToolBar, 5, %IDM_NOTES
   Toolbar_AddButton hToolBar, 6, %IDM_OUTBOX
   Toolbar_AddButton hToolBar, 7, %IDM_SENT
   Toolbar_AddButton hToolBar, 8, %IDM_TASKS

   ' // Update the size of the toolbar
   ToolBar_AutoSize(hToolbar)

   ' // Create the image list
   LOCAL pAfxImageList AS IAfxImageList
   pAfxImageList = CLASS "CAfxImageList"
   IF ISNOTHING(pAfxImageList) THEN EXIT FUNCTION

   ' // Desired icon size width and height
   cx = GetSystemMetrics(%SM_CXSMICON)
   cy = GetSystemMetrics(%SM_CYSMICON)
   ' // Create the image list
   pAfxImageList.CreateImageList(cx, cy, %ILC_COLOR32 OR %ILC_MASK, 9)

   ' // Give a name to the image list
   pAfxImageList.Name = "Toolbar image list"

   ' // Add the bitmaps from the resource file
   pAfxImageList.LoadResBitmapMasked(%IDI_CALENDAR, cx, cy)
   pAfxImageList.LoadResBitmapMasked(%IDI_CONTACTS, cx, cy)
   pAfxImageList.LoadResBitmapMasked(%IDI_DELETED, cx, cy)
   pAfxImageList.LoadResBitmapMasked(%IDI_DRAFTS, cx, cy)
   pAfxImageList.LoadResBitmapMasked(%IDI_INBOX, cx, cy)
   pAfxImageList.LoadResBitmapMasked(%IDI_NOTES, cx, cy)
   pAfxImageList.LoadResBitmapMasked(%IDI_OUTBOX, cx, cy)
   pAfxImageList.LoadResBitmapMasked(%IDI_SENT, cx, cy)
   pAfxImageList.LoadResBitmapMasked(%IDI_TASKS, cx, cy)

   ' // Set the image list
   ToolBar_SetImageList(hToolbar, pAfxImageList.hImageList)

   ' // Register the image list class in the collection
   pWindow.AddObject "Toolbar image list", pAfxImageList

   ' // Return the handle of the toolbar
   FUNCTION = hToolbar

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   ' // Set process DPI aware
   IF AfxGetWindowsVersion => 6.00 THEN SetProcessDPIAware

   ' // Create an instance of the class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Create the main window
   pWindow.CreateWindow(%NULL, "Microsoft Outlook View Control Demo", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
   ' // Disable background erasing
   pWindow.ClassStyle = %CS_DBLCLKS
   ' // Set the client siz
   pWindow.SetClientSize 600, 350
   ' // Center the window
   pWindow.CenterWindow

   ' // Create the View Control window container
   LOCAL hCtl AS DWORD
   hCtl = pWindow.AddOCX(pWindow.hwnd, %IDC_OVC, "OVCtl.OVCtl", "", 0, 0, 0, 0)
   ' // Get a reference to the control
   LOCAL pOvc AS OVCtl_IViewCtl
   pOvc = OC_GetDispatch(hCtl)
   IF ISOBJECT(pOvc) THEN
      ' // Choose the Calendar view
      pOvc.Folder = "Inbox"
      ' // Release the reference
      pOvc = NOTHING
   END IF

   ' // Add the toolbar
   OvcCreateToolBar pWindow

   ' // Default message pump (you can replace it with your own)
   pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   LOCAL  hCtl       AS DWORD
   LOCAL  rc         AS RECT
   LOCAL  pOvc       AS OVCtl_IViewCtl
   LOCAL  pTOOLTIP   AS TOOLTIPTEXT PTR
   LOCAL  lpNmh      AS NMHDR  PTR
   STATIC pWindow    AS IWindow        ' // Reference to the IWindow interface
   STATIC wszTipText AS WSTRINGZ * 64

   ' // Process window mesages
   SELECT CASE uMsg

      CASE %WM_CREATE
         ' // Get a reference to the IWindow interface from the CREATESTRUCT structure
         pWindow = CWindow_GetObjectFromCreateStruct(lParam)
         EXIT FUNCTION

      CASE %WM_SYSCOMMAND
        ' Capture this message and send a %WM_CLOSE message
        IF (wParam AND &HFFF0) = %SC_CLOSE THEN
           SendMessage hWnd, %WM_CLOSE, 0, 0
           EXIT FUNCTION
        END IF

      CASE %WM_COMMAND

         SELECT CASE LO(WORD, wParam)

            CASE %IDCANCEL
               ' // If the Escape key has been pressed...
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ' // ... close the application by sending a WM_CLOSE message
                  SendMessage hwnd, %WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF

            CASE %IDM_CALENDAR, %IDM_CONTACTS, %IDM_DRAFTS, %IDM_DELETED, %IDM_INBOX, _
                 %IDM_NOTES, %IDM_OUTBOX, %IDM_SENT, %IDM_TASKS
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  hCtl = GetDlgItem(hwnd, %IDC_OVC)
                  pOvc = OC_GetDispatch(hCtl)
                  IF ISOBJECT(pOvc) THEN
                     ' Choose the view
                     SELECT CASE LO(WORD, wParam)
                        CASE %IDM_CALENDAR : pOvc.Folder = "Calendar"
                        CASE %IDM_CONTACTS : pOvc.Folder = "Contacts"
                        CASE %IDM_DRAFTS   : pOvc.Folder = "Drafts"
                        CASE %IDM_DELETED  : pOvc.Folder = "Deleted Items"
                        CASE %IDM_INBOX    : pOvc.Folder = "Inbox"
                        CASE %IDM_NOTES    : pOvc.Folder = "Notes"
                        CASE %IDM_OUTBOX   : pOvc.Folder = "Outbox"
                        CASE %IDM_SENT     : pOvc.Folder = "Sent Items"
                        CASE %IDM_TASKS    : pOvc.Folder = "Tasks"
                     END SELECT
                     ' Release the reference
                     pOvc = NOTHING
                  END IF
                  EXIT FUNCTION
               END IF

         END SELECT

      CASE %WM_NOTIFY
         lpNmh = lParam
         SELECT CASE @lpNmh.Code
         CASE %TTN_NEEDTEXT ' ToolTips
            pTOOLTIP = lParam
            wszTipText = ""
            IF @pTOOLTIP.hdr.code = %TTN_NEEDTEXT THEN
               SELECT CASE @pTOOLTIP.hdr.idFrom
                  CASE %IDM_CALENDAR : wszTipText = " Calendar "
                  CASE %IDM_CONTACTS : wszTipText = " Contacts "
                  CASE %IDM_DELETED  : wszTipText = " Deleted Items "
                  CASE %IDM_DRAFTS   : wszTipText = " Drafts "
                  CASE %IDM_INBOX    : wszTipText = " Inbox "
                  CASE %IDM_NOTES    : wszTipText = " Notes "
                  CASE %IDM_OUTBOX   : wszTipText = " Outbox "
                  CASE %IDM_SENT     : wszTipText = " Sent Items "
                  CASE %IDM_TASKS    : wszTipText = " Tasks "
               END SELECT
               IF wszTipText <> "" THEN
                  @pTOOLTIP.lpszText = VARPTR(wszTipText)
                  EXIT FUNCTION
               END IF
            END IF
         END SELECT

      CASE %WM_SIZE
         ' // If the window isn't minimized, resize it
         IF wParam <> %SIZE_MINIMIZED THEN
            ' // Resize the toolbar
            LOCAL hToolBar AS DWORD
            hToolBar = GetDlgItem(hwnd, %IDC_TOOLBAR)
            SendMessage hToolBar, uMsg, wParam, lParam
            ' // Calculate the size of the toolbar
            LOCAL ToolBarHeight AS DWORD
            pWindow.GetControlWindowRect hToolbar, rc
            ToolBarHeight = rc.Bottom - rc.Top
            ' // Resize the outlook view control
            pWindow.MoveWindow GetDlgItem(hwnd, %IDC_OVC), 0, ToolBarHeight, pWindow.ClientWidth, pWindow.ClientHeight - ToolBarHeight, %TRUE
         END IF

      CASE %WM_DESTROY
         ' // End the application
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   ' // Pass unprocessed messages to Windows
   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================
Attached Images
File Type: jpg EX_CW_OC_OVC_01.jpg (62.7 KB, 34 views)
Attached Files
File Type: zip OutlookViewControl.zip (31.9 KB, 16 views)
__________________
Website: http://www.jose.it-berater.org/index.html
SED Editor, TypeLib Browser.
Forum: http://www.jose.it-berater.org/smfforum/index.php
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:14 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright © 1999-2011 PowerBASIC, Inc. All Rights Reserved.
Error in my_thread_global_end(): 1 threads didn't exit