27 Nisan 2020 Pazartesi

RegisterClassEx metodu

Giriş
WNDCLASSEX tipinde parametre alır
Örnek
WNDCLASSEX yapısını doldurduktan sonra şöyle yaparız
if (!RegisterClassEx(&win_class))
{
  OutputDebugString(L"Registering Class Failed");
  return false;
}
Bu çağrıdan sorna CreateWindow() ve ShowWindow() çağrılarını da yaparsak penceremiz gösterilir.
Şöyle yaparız
LPCWSTR m_wintitle =  L"DirectX";
DWORD m_winstyles = WS_OVERLAPPEDWINDOW;

RECT r = {0,0,m_winwidth,m_winheight};

AdjustWindowRect(&r, m_winstyles, FALSE);

uint_fast16_t f_width = r.right - r.left;
uint_fast16_t f_height = r.bottom - r.top;

uint_fast16_t f_width_final = GetSystemMetrics(SM_CXSCREEN) / 2 - f_width / 2);
uint_fast16_t f_height_final = (GetSystemMetrics(SM_CYSCREEN) / 2 - f_height / 2);

HWND hwnd = CreateWindow(L"dx_main_class", m_wintitle, m_winstyles, f_width_final,
f_height_final, f_width, f_height, NULL,   NULL, m_hinstance, NULL);

ShowWindow(m_hwnd, SW_SHOW);
WNDCLASSEX Alanları
Şöyle yaparız
WNDCLASSEX win_class;
win_class.cbSize = sizeof(WNDCLASSEX);
win_class.style = CS_HREDRAW | CS_VREDRAW;
win_class.lpfnWndProc = WINDOWPROC;
win_class.cbClsExtra = 0;
win_class.cbWndExtra = 0;
win_class.hInstance = m_hinstance;
win_class.hIcon = LoadIcon(NULL, IDI_APPLICATION);
win_class.hCursor = 0;
win_class.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
win_class.lpszMenuName = NULL;
win_class.lpszClassName = L"dx_main_class";
win_class.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
cbSize Alanı
Açıklaması şöyle
The WNDCLASSEX structure is similar to the WNDCLASS structure. There are two differences. WNDCLASSEX includes the cbSize member, which specifies the size of the structure [...]
Örnek
Şöyle yaparız.
// Register the windows class.
const wchar_t CLASS_NAME[] = L"Sample Window Class";


WNDCLASSEX wc = {};
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
wc.cbSize = sizeof wc;

RegisterClassEx(&wc);
hInstance Alanı
WinMain metoduna geçen parametre olmalıdır
Örnek
Şöyle yaparız
int WINAPI wWinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    PWSTR pCmdLine,
    int nCmdShow)
{

  WNDCLASSEX wc = {};
  wc.hInstance = hInstance;
  ...
  RegisterClassEx(&wc);
  ...
  return 0;
}
lpfnWndProc Alanı
Gelen mesajları işleyen koddur. WindowProc CallBack yazısına taşıdım

Hiç yorum yok:

Yorum Gönder