00001 #include <ShapeUpAPI.h> 00002 #include "./resource.h" 00003 00004 SURESULT __cdecl HookFunc(SUHANDLE hWorkspace, int hookType, SUHookData *args); 00005 SURESULT __cdecl OnWorkspaceReady(SUHANDLE hWorkspace); 00006 00007 // Every plug-in needs an instance of SUExport called suapi 00008 SUExport suapi; 00009 00010 size_t __cdecl fnVersion() 00011 { 00012 return SHAPEUP_API_VERSION; 00013 } 00014 00015 const GUID* __cdecl fnGUID() 00016 { 00017 // CREATE YOUR OWN GUID !! 00018 // {97F4EA41-7D7E-42c1-B555-2D4C86C912A7} 00019 static const GUID guid = 00020 { 0x97f4ea41, 0x7d7e, 0x42c1, { 0xb5, 0x55, 0x2d, 0x4c, 0x86, 0xc9, 0x12, 0xa7 } }; 00021 return &guid; 00022 } 00023 00024 SURESULT __cdecl fnInit(SUExport *pExport) 00025 { 00026 AFX_MANAGE_STATE(AfxGetStaticModuleState()); 00027 00028 pExport->import.pszName = "Test of GPI and ShapeUp API"; 00029 pExport->import.pszDescription = "Test of GPI and ShapeUp API\nGPI Test"; 00030 pExport->import.pszInfo = "Copyright (c) 2007"; 00031 pExport->import.pszPluginVersion = "1.00"; 00032 00033 // Now keep the entire struct which is the actual ShapeUp API 00034 // (we need the function pointers later) 00035 ::memcpy(&suapi, pExport, sizeof(SUExport)); 00036 00037 // Set-up our hook callback 00038 pExport->import.pfnHook = HookFunc; 00039 00040 // We want to get notified when a workspace has been initialized 00041 // We cannot add a data page before this event has occurred! 00042 ShapeUp_AddWorkspaceReadyHook(0); 00043 00044 return SURESULT_OK; 00045 } 00046 00047 // ShapeUp will call this function when an event occurs 00048 SURESULT __cdecl HookFunc(SUHANDLE hWorkspace, int hookType, SUHookData *args) 00049 { 00050 AFX_MANAGE_STATE(AfxGetStaticModuleState()); 00051 00052 switch (hookType) 00053 { 00054 case HOOKTYPE_WORKSPACEREADY: 00055 // At this point, it's ok to add a data page! 00056 return OnWorkspaceReady(hWorkspace); 00057 default: 00058 break; 00059 } 00060 00061 return SURESULT_OK; 00062 } 00063 00064 SURESULT __cdecl OnWorkspaceReady(SUHANDLE hWorkspace) 00065 { 00066 try 00067 { 00068 SUWorkspace workspace(hWorkspace); 00069 SUDataPage page = workspace.AddDataPage("Tree data"); 00070 00071 // Create a tree view control 00072 VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTL_TREEVIEW_REG)); 00073 00074 // The style to be. WS_CHILD is important. 00075 DWORD dwStyle = WS_VISIBLE | WS_TABSTOP | WS_CHILD 00076 | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_HASLINES 00077 | TVS_DISABLEDRAGDROP; 00078 00079 // Ask the data page for its windows handle to use as the new 00080 // controls parent 00081 HWND hwndParent = page.GetHWND(); 00082 00083 // Ctrl id. Any id is good. 00084 UINT nID = 42001; 00085 00086 // Create the control 00087 HWND hWnd = ::CreateWindowEx(0, WC_TREEVIEW, 00088 NULL, dwStyle, 0, 0, 100, 100, 00089 hwndParent, (HMENU)(UINT_PTR)nID, AfxGetInstanceHandle(), NULL); 00090 00091 if (hWnd != NULL) 00092 { 00093 // Populate the control 00094 TV_INSERTSTRUCT is; 00095 is.hInsertAfter = NULL; 00096 is.hParent = NULL; 00097 is.item.mask = TVIF_TEXT; 00098 is.item.pszText = "First line"; 00099 00100 HTREEITEM hRoot = TreeView_InsertItem(hWnd, &is); 00101 is.hParent = hRoot; 00102 is.item.pszText = "Another line"; 00103 for (int i = 0; i < 400; ++i) 00104 TreeView_InsertItem(hWnd, &is); 00105 } 00106 else 00107 page.Remove(); 00108 } 00109 catch (SUException &ex) 00110 { 00111 AfxMessageBox(ex.GetErrorDesc().c_str(), 0, 0); 00112 } 00113 00114 return SURESULT_OK; 00115 }