GDI+, as with the PB graphic commands allows me to draw outside a drawing area, IE a Graphic control.
How do I scroll to uncover the portion that is not displayed?
The attached code demonstrates what I mean. (Mostly derived from José Roca's most excellent Forum)
Here I draw vertical lines that start off inside the drawing area, but quickly exceed it's area
and most are drawn outside of the viewing area.
I had though that GdipTranslateWorldTransform would allow me to reposition the view origin and
a simple graphic refresh would give me what I want (as in clicking the 'Scroll button' in the top right), but of course it's not that simple. Nothing is with Windows.
Am I aproaching this in the wrong way? Do I have to handle it the same way as if using the
ordinary drawing API - IE something like ScrollwindowEX and then draw the uncovered portion?
I was hoping that GDI+ handled all this stuff.
How do I scroll to uncover the portion that is not displayed?
The attached code demonstrates what I mean. (Mostly derived from José Roca's most excellent Forum)
Here I draw vertical lines that start off inside the drawing area, but quickly exceed it's area
and most are drawn outside of the viewing area.
I had though that GdipTranslateWorldTransform would allow me to reposition the view origin and
a simple graphic refresh would give me what I want (as in clicking the 'Scroll button' in the top right), but of course it's not that simple. Nothing is with Windows.
Am I aproaching this in the wrong way? Do I have to handle it the same way as if using the
ordinary drawing API - IE something like ScrollwindowEX and then draw the uncovered portion?
I was hoping that GDI+ handled all this stuff.
Code:
#PBForms Created V1.51 '------------------------------------------------------------------------------ ' The first line in this file is a PB/Forms metastatement. ' It should ALWAYS be the first line of the file. Other ' PB/Forms metastatements are placed at the beginning and ' end of "Named Blocks" of code that should be edited ' with PBForms only. Do not manually edit or delete these ' metastatements or PB/Forms will not be able to reread ' the file correctly. See the PB/Forms documentation for ' more information. ' Named blocks begin like this: #PBFORMS BEGIN ... ' Named blocks end like this: #PBFORMS END ... ' Other PB/Forms metastatements such as: ' #PBFORMS DECLARATIONS ' are used by PB/Forms to insert additional code. ' Feel free to make changes anywhere else in the file. '------------------------------------------------------------------------------ #Compile Exe '------------------------------------------------------------------------------ ' ** Includes ** '------------------------------------------------------------------------------ #PBForms Begin Includes %USEMACROS = 1 #If Not %Def(%WINAPI) #Include "WIN32API.INC" #EndIf #If Not %Def(%COMMCTRL_INC) #Include "COMMCTRL.INC" #EndIf #Include "PBForms.INC" #PBForms End Includes #Include "GDIPLUS.INC" '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Constants ** '------------------------------------------------------------------------------ #PBForms Begin Constants %IDD_DIALOG1 = 101 %IDC_GRAPHIC1 = 1001 %IDC_Scroll = 1002 #PBForms End Constants '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Declarations ** '------------------------------------------------------------------------------ Declare CallBack Function ShowDIALOG1Proc() Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long #PBForms Declarations '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Main Application Entry Point ** '------------------------------------------------------------------------------ Function PBMain() PBFormsInitComCtls (%ICC_WIN95_CLASSES Or %ICC_DATE_CLASSES Or _ %ICC_INTERNET_CLASSES) Local hr As Long Local hDlg As Dword Local token As Dword Local StartupInput As GdiplusStartupInput ' Initialize GDI+ StartupInput.GdiplusVersion = 1 hr = GdiplusStartup(token, StartupInput, ByVal %Null) If hr =-1 Then MsgBox "Error initializing GDI+" Exit Function End If ShowDIALOG1 %HWND_DESKTOP End Function '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** CallBacks ** '------------------------------------------------------------------------------ CallBack Function ShowDIALOG1Proc() Local hDC As Dword Local n As Single Local hStatus As Long Static pGraphics As Dword Local pPen As Dword Select Case As Long CbMsg Case %WM_INITDIALOG Graphic Get DC To hDC hStatus = GdipCreateFromHDC(hdc, pGraphics) hStatus = GdipSetPageUnit(pGraphics, %Unitinch) ' // Set the page units to inches hStatus = GdipCreatePen1(GdiPlusMakeARGBColor(255, 0, 0, 0), 2, %UnitPixel, pPen) ' // Create a Pen For n=1 To 150 GdipDrawLine pGraphics, pPen, n/10 , 0, n/10 , n/10 ' // Draw the line Next n ' Graphic ReDraw ' // Cleanup If pPen Then GdipDeletePen(pPen) ' If pGraphics Then GdipDeleteGraphics(pGraphics) 'This should be done on exit Case %WM_NCACTIVATE Static hWndSaveFocus As Dword If IsFalse CbWParam Then ' Save control focus hWndSaveFocus = GetFocus() ElseIf hWndSaveFocus Then ' Restore control focus SetFocus(hWndSaveFocus) hWndSaveFocus = 0 End If Case %WM_COMMAND ' Process control notifications Select Case As Long CbCtl 'I expected **something** like this to work. 'Here's the question - how do I scoll to the part that is not displayed???? Case %IDC_Scroll If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then 'Graphic Get DC To hDC 'hStatus = GdipCreateFromHDC(hdc, pGraphics) 'hStatus = GdipSetPageUnit(pGraphics, %Unitinch) hStatus = GdipTranslateWorldTransform(pGraphics, 1, 0, %MatrixOrderPrepend) Graphic ReDraw End If End Select End Select End Function '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Dialogs ** '------------------------------------------------------------------------------ Function ShowDIALOG1(ByVal hParent As Dword) As Long Local lRslt As Long #PBForms Begin Dialog %IDD_DIALOG1->-> Local hDlg As Dword Dialog New hParent, "GDI+ Scrolling - It's a Mystery to me!", 70, 70, _ 356, 248, %WS_POPUP Or %WS_BORDER Or %WS_DLGFRAME Or %WS_SYSMENU Or _ %WS_CLIPSIBLINGS Or %WS_VISIBLE Or %DS_MODALFRAME Or %DS_3DLOOK Or _ %DS_NOFAILCREATE Or %DS_SETFONT, %WS_EX_CONTROLPARENT Or %WS_EX_LEFT _ Or %WS_EX_LTRREADING Or %WS_EX_RIGHTSCROLLBAR, To hDlg Control Add Graphic, hDlg, %IDC_GRAPHIC1, "", 50, 25, 295, 195, %WS_CHILD _ Or %WS_VISIBLE Or %WS_BORDER Graphic Attach hDlg, %IDC_GRAPHIC1 Graphic Color %Black, %White Graphic Clear Control Add Button, hDlg, %IDC_Scroll, "Scroll", 5, 25, 40, 30 #PBForms End Dialog Dialog Show Modal hDlg, Call ShowDIALOG1Proc To lRslt #PBForms Begin CleanUp %IDD_DIALOG1 #PBForms End CleanUp Function = lRslt End Function '------------------------------------------------------------------------------
Comment