Using an event name with return type and arguments
The following description uses the first syntax. The class has two
events, onclick and ondoubleclick:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
PBXEXPORT LPCTSTR PBXCALL PBX_GetDescription() { static const TCHAR desc[] = { "class visualext from userobject " "event int onclick() " "event int ondoubleclick() " "subroutine setcolor(int r, int g, int b) " "subroutine settext(string txt) " "end class " }; return desc; } |
Capturing messages and mouse
clicks
The code in the extension captures the Windows messages that cause
the window to be drawn, as well as mouse clicks and double
clicks:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
LRESULT CALLBACK CVisualExt::WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { CVisualExt* ext = (CVisualExt*)::GetWindowLong(hwnd, GWL_USERDATA); switch(uMsg) { case WM_CREATE: return 0; case WM_SIZE: return 0; case WM_COMMAND: return 0; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); RECT rc; GetClientRect(hwnd, &rc); LOGBRUSH lb; lb.lbStyle = BS_SOLID; // Get color using the visual class's GetColor method lb.lbColor = ext->GetColor(); HBRUSH hbrush = CreateBrushIndirect(&lb); HBRUSH hbrOld = (HBRUSH)SelectObject(hdc, hbrush); Rectangle(hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top); SelectObject(hdc, hbrOld); DeleteObject(hbrush); // Get text using the visual class's GetText method DrawText(hdc, ext->GetText(), ext->GetTextLength(), &rc, DT_CENTER|DT_VCENTER|DT_SINGLELINE); EndPaint(hwnd, &ps); } return 0; // Trigger event scripts in the PowerBuilder application case WM_LBUTTONUP: ext->TriggerEvent("onclick"); break; case WM_LBUTTONDBLCLK: ext->TriggerEvent("ondoubleclick"); break; } return DefWindowProc(hwnd, uMsg, wParam, lParam); } |
Triggering click events
The following is the TriggerEvent method that triggers the Onclick
and Ondoubleclick events:
|
1 2 3 4 5 6 7 8 9 10 11 |
void CVisualExt::TriggerEvent(LPCTSTR eventName) { pbclass clz = d_session->GetClass(d_pbobj); pbmethodID mid = d_session->GetMethodID(clz, eventName, PBRT_EVENT, "I"); PBCallInfo ci; d_session->InitCallInfo(clz, mid, &ci); d_session->TriggerEvent(d_pbobj, mid, &ci); d_session->FreeCallInfo(&ci); } |
Document get from Powerbuilder help
Thank you for watching.
Subscribe
Login
0 Comments
Oldest