Gelen mesajları işleyen koddur. Bu kodda kendi swith/case kodumuzdan sonra en altta return DefWindowProc() çağrısı yapmak gerekir.
Örnek - WM_CREATE
Şöyle yaparız. Bir EditBox ve bir Button yaratır. Düğmeye tıklanınca MessageBox gösterir.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR heading[] = _T("CD ROM READER");
TCHAR CSCI_No_Inst[] = _T("Please enter the CSCI No below:");
TCHAR CSCI_NO[60];
switch (message)
{
case WM_CREATE:
{
TextBox = CreateWindow(TEXT("EDIT"), TEXT(""),
WS_VISIBLE | WS_CHILD | WS_BORDER,
150, 140, 250, 25,
hWnd, NULL, NULL, NULL);
HWND hwndButton_Enter = CreateWindow(
L"BUTTON", L"ENTER",
WS_VISIBLE | WS_CHILD | WS_BORDER, //Styles
405, 140, 70, 25,
hWnd, (HMENU)ENTER_BUTTON, NULL, NULL);
return 0;
}
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case ENTER_BUTTON:
int gwtstat = 0;
TCHAR title[] = _T("CSCI_NO");
gwtstat = GetWindowText(TextBox, &CSCI_NO[0], 60);
TCHAR buff[100] = L"";
TCHAR name[] = _T("CSCI_NO");
wsprintf(buff, L"The CSCI No you entered is: %s", CSCI_NO);
MessageBox(hWnd, buff, title, MB_OK);
break;
}
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
Örnek - WM_DESTROY
Şöyle yaparız
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW + 1));
EndPaint(hwnd, &ps);
}
return 0;
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
Hiç yorum yok:
Yorum Gönder