Creating visual class instances

PowerBuilder Native Interface

Creating visual class instances

PBXEXPORT PBXRESULT PBXCALL PBX_CreateVisualObject
(
   IPB_Session*         pbsession,
   pbobject            pbobj,
   LPCTSTR               className,      
   IPBX_VisualObject   **obj
)
{
   PBXRESULT result = PBX_OK;

   string cn(className);
   if (cn.compare("visualext") == 0)
   {
      *obj = new CVisualExt(pbsession, pbobj);
   }
   else
   {
      *obj = NULL;
      result = PBX_FAIL;
   }

   return PBX_OK;
};

Registering the window class

void CVisualExt::RegisterClass()
{
   WNDCLASS wndclass;

   wndclass.style = CS_GLOBALCLASS | CS_DBLCLKS;
   wndclass.lpfnWndProc = WindowProc;
   wndclass.cbClsExtra = 0;
   wndclass.cbWndExtra = 0;
   wndclass.hInstance = g_dll_hModule;
   wndclass.hIcon = NULL;
   wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
   wndclass.hbrBackground =(HBRUSH) (COLOR_WINDOW + 1);
   wndclass.lpszMenuName = NULL;
   wndclass.lpszClassName = s_className;

   ::RegisterClass (&wndclass);
}
void CVisualExt::UnregisterClass()
{
   ::UnregisterClass(s_className, g_dll_hModule);
}
BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD reasonForCall,
                       LPVOID lpReserved
                     )
{
   g_dll_hModule = (HMODULE)hModule;

   switch (reasonForCall)
   {
      case DLL_PROCESS_ATTACH:
         CVisualExt::RegisterClass();
          break;

      case DLL_THREAD_ATTACH:
      case DLL_THREAD_DETACH:
         break;

      case DLL_PROCESS_DETACH:
         CVisualExt::UnregisterClass();
         break;
   }
   return TRUE;
}

Implementing CreateControl

TCHAR CVisualExt::s_className[] = "PBVisualExt";

LPCTSTR CVisualExt::GetWindowClassName()
{
   return s_className;
}

HWND CVisualExt::CreateControl
(
   DWORD dwExStyle,      // extended window style
   LPCTSTR lpWindowName, // window name
   DWORD dwStyle,        // window style
   int x,             // horizontal position of window
   int y,                // vertical position of window
   int nWidth,           // window width
   int nHeight,          // window height
   HWND hWndParent,      // handle to parent or
                         // owner window
   HINSTANCE hInstance   // handle to application
                         // instance
)
{
   d_hwnd = CreateWindowEx(dwExStyle, s_className,
      lpWindowName, dwStyle, x, y, nWidth, nHeight,
      hWndParent, NULL, hInstance, NULL);

   ::SetWindowLong(d_hwnd, GWL_USERDATA, (LONG)this);
   return d_hwnd;
}