Subclassing


Subclassing

When Microsoft Windows was created the only language was C. So in order to incorporate Inheritance to Microsoft Windows using only C, Microsoft created sub-classing. Sub-classing allows overriding method in a Microsoft Windows control. For instance, it is possible to override (replace) the Window_Paint (WM_PAINT event) function of a button to change the appearance of the button.
Cuando Microsoft Windows fuecreado el único lenguage era C. A fin de incorporar herencia en Microsoft Windows usando C, Microsoft creo sub-classing. Sub-classing permite sobre-cargar (reemplazar) los métodos en un control de Microsoft Windows. Por ejemplo, es posible sobre-cargar la función Window_Paint (el evento de WM_PAINT) de un botón para cambiar la apariencia del botón.

Problem 1
Create a Wintempla dialog application called MyBoxTab to test sub-classing in a textbox. By default, it is not possible to insert a tab in a textbox, however, the textbox receives an event WM_GETDLGCODE where the textbox can indicate that it would like to receive the tab keys. Insert three textboxes, you will be able to input tabs only in the first text box (tbx1).
Cree una aplicación de diálogo de Wintempla llamada MyBoxTab para pobrar el sub-classing en una caja de texto. Por defecto no es posible insertar tabuladores en una caja de texto, sin embargo, la caja de texto recibe un evento WM_GETDLGCODE dónde la caja de texto puede indicar que si le gustaría recibir la tecla de tab. Inserte tres cajas de texto, usted podrá insertar tabulaciones solamente en la primera caja de texto (tbx1).

MyBoxTabRun

MyBoxTab.h
#pragma once //______________________________________ MyBoxTab.h
#include "Resource.h"
class MyBoxTab: public Win::Dialog
{
public:
     MyBoxTab()
     {
     }
     ~MyBoxTab()
     {
     }
     static WNDPROC originalProc;
     static LRESULT CALLBACK TextBoxProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
protected:
     ...
};

MyBoxTab.cpp
#include "stdafx.h" //________________________________________ MyBoxTab.cpp
#include "MyBoxTab.h"

WNDPROC MyBoxTab::originalProc;

...

void MyBoxTab::Window_Open(Win::Event& e)
{
     originalProc = tbx1.SetProc(TextBoxProc);
}

LRESULT CALLBACK MyBoxTab::TextBoxProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     LRESULT result = CallWindowProc(originalProc, hWnd, message, wParam, lParam);

     if (message == WM_GETDLGCODE)
     {
          return result |= DLGC_WANTTAB;
     }
     else if (message == WM_KEYDOWN && wParam == VK_TAB)
     {
          POINT point;
          GetCaretPos(&point);
          int carPos = ::SendMessage(hWnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
          int nPos = LOWORD(carPos);
          ::SendMessage(hWnd, EM_SETSEL, nPos, nPos);
          ::SendMessage(hWnd, EM_REPLACESEL, true, (LPARAM)L"\t");
           return TRUE;
     }
     return result;
}


© Copyright 2000-2019 Wintempla selo. All Rights Reserved. Sep 05 2019. Home