Help Center

CGraphCtx.Example 1method

CWindow Graphic Control Skeleton.

GraphicsmethodCGraphCtx.incdoc-orphan
No implementation located. This member is documented, but the source scan found no matching declaration. It is likely declared in a header this scan does not resolve, or provided by a macro.

Example

' ######################################################################################## ' Microsoft Windows ' File: CW_GraphCtxSkeleton.bas ' Contents: CWindow Graphic Control Skeleton ' Compiler: FreeBasic 32 & 64 bit ' Copyright (c) 2025 José Roca. Freeware. Use at your own risk. ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER ' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF ' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. ' ########################################################################################

#define UNICODE #INCLUDE ONCE "AfxNova/CWindow.inc" #INCLUDE ONCE "AfxNova/CGraphCtx.inc" USING AfxNova

CONST IDC_GRCTX = 1001

DECLARE FUNCTION wWinMain (BYVAL hInstance AS HINSTANCE, _

BYVAL hPrevInstance AS HINSTANCE, _
                       BYVAL pwsszCmdLine AS WSTRING PTR, _
                       BYVAL nCmdShow AS LONG) AS LONG

END wWinMain(GetModuleHandleW(NULL), NULL, WCOMMAND(), SW_NORMAL)

' // Forward declaration DECLARE FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

' ======================================================================================== ' Main ' ======================================================================================== FUNCTION wWinMain (BYVAL hInstance AS HINSTANCE, _

BYVAL hPrevInstance AS HINSTANCE, _
               BYVAL pwsszCmdLine AS WSTRING PTR, _
               BYVAL nCmdShow AS LONG) AS LONG

' // Set process DPI aware SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE) ' // Enable visual styles without including a manifest file AfxEnableVisualStyles

' // Create the main window DIM pWindow AS CWindow pWindow.Create(NULL, "CWindow Graphic Control Skeleton", @WndProc) pWindow.SetClientSize(600, 350) pWindow.Center

' // Add a graphic control DIM nWidth AS LONG = pWindow.ClientWidth DIM nHeight AS LONG = pWindow.ClientHeight DIM pGraphCtx AS CGraphCtx = CGraphCtx(@pWindow, IDC_GRCTX, "", 0, 0, nWidth, nHeight) pGraphCtx.Clear BGR(255, 255, 255) ' // Anchor the control pWindow.AnchorControl(IDC_GRCTX, AFX_ANCHOR_HEIGHT_WIDTH)

' // Capture the desktop window and display it in the control DIM hBitmap AS HBITMAP = AfxCaptureDisplay pGraphCtx.SetVirtualBufferSize(AfxGetBitmapWidth(hBitmap), AfxGetBitmapHeight(hBitmap)) AfxDrawBitmap(pGraphCtx.GetMemDC, 0, 0, hBitmap) DeleteObject hBitmap

' // Dispatch Windows events FUNCTION = pWindow.DoEvents(nCmdShow)

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

' ======================================================================================== ' Main window callback procedure ' ======================================================================================== FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

SELECT CASE uMsg

CASE WM_CREATE
     AfxEnableDarkModeForWindow(hwnd)
     RETURN 0

  ' // Theme has changed
  CASE WM_THEMECHANGED
     AfxEnableDarkModeForWindow(hwnd)
     RETURN 0

  CASE WM_COMMAND
     SELECT CASE GET_WM_COMMAND_ID(wParam, lParam)
        CASE IDCANCEL
           ' // If ESC key pressed, close the application by sending an WM_CLOSE message
           IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
              SendMessageW hwnd, WM_CLOSE, 0, 0
              EXIT FUNCTION
           END IF
     END SELECT

CASE WM_DESTROY

' // End the application
     PostQuitMessage(0)
     EXIT FUNCTION

END SELECT

' // Default processing of Windows messages FUNCTION = DefWindowProcW(hWnd, uMsg, wParam, lParam)

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

Reference

  • Include file CGraphCtx.inc
  • Documented in Graphics/CGraphCtx Class.md
  • Topic: CGraphCtx Class