|
Прошу помощи. Небольшая оболочка оболочка. WinAPi/
#38336301
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
|
|
|
Я не могу просто понять как сделать.
Создал базовый класс
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165.
class CWnd
{
protected:
virtual void OnClickButton()
{
MessageBox(NULL,L"virtualOnClickButton()",L"FDFD",MB_OK);
}
virtual LRESULT __stdcall WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static LRESULT __stdcall WndStat(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
HINSTANCE m_hInstance;
HWND m_hWnd;
public:
CWnd(){};
virtual ~CWnd(){};
virtual void Run();
virtual void Registration();
virtual void CreateEx(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, int x, int y, int nWidhth, int nHeight, HWND hWndParent,HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
};
Вот его реализация. Функции Registration();, Run(); там все по обычному.
LRESULT __stdcall CWnd::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HDC hDc;
PAINTSTRUCT paint;
switch( uMsg )
{
case WM_PAINT:
hDc = BeginPaint(hWnd, &paint);
EndPaint(hWnd, &paint);
break;
case WM_DESTROY:PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:OnClickButton();
break;
default:
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
return 0;
}
LRESULT __stdcall CWnd::WndStat(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if(uMsg == WM_CREATE)
{
LPCREATESTRUCT pCS = (LPCREATESTRUCT)lParam;
SetWindowLongPtr(hWnd,GWL_USERDATA,(LONG)pCS->lpCreateParams);
}
CWnd *pWnd = reinterpret_cast<CWnd*>(GetWindowLongPtr(hWnd,GWL_USERDATA));
if(pWnd)
{
return pWnd->WndProc(hWnd, uMsg, wParam, lParam);
}else{
return DefWindowProc( hWnd, uMsg, wParam, lParam);
}
}
Класс наследник
class CWindow: public CWnd
{
protected:
void OnClickButton()
{
MessageBox(NULL,L"OnClickButton()",L"FDFD",MB_OK);
}
LRESULT __stdcall WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
};
LRESULT __stdcall CWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HDC hDc;
PAINTSTRUCT paint;
switch( uMsg )
{
case WM_PAINT:
hDc = BeginPaint(hWnd, &paint);
EndPaint(hWnd, &paint);
break;
case WM_CREATE:;
break;
case WM_DESTROY:PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:OnClickButton();
break;
default:
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
}
Вот класс Edit, как сделать что бы при создания объекта рисовалась фигура на форме и создать для нее собственные обработчики событий ?
Как устроенна библиотека в C++ Builder ? ведь там все контролы на базе одного класса постороены.
Как мне сделать этот контрол?
class CEdit: public CWnd
{
LRESULT __stdcall WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
public:
CEdit(){};
~CEdit(){};
};
LRESULT __stdcall CEdit::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HDC hDc;
PAINTSTRUCT paint;
switch( uMsg )
{
case WM_PAINT:
hDc = BeginPaint(hWnd, &paint);
Rectangle(hDc,10,10,300,300);
// MessageBox(NULL,L"FD",L"FDFD",MB_OK);
EndPaint(hWnd, &paint);
break;
case WM_CREATE:;
break;
case WM_DESTROY:PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:OnClickButton();
break;
default:
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdShow, int nCmdShow)
{
CWindow Wnd;
Wnd.CreateEx(L"FDFD",L"FDFD",WS_OVERLAPPEDWINDOW | WS_VISIBLE ,10,10,500,500,HWND_DESKTOP,NULL,hInstance,NULL);
Wnd.Run();
return 0;
}
|
|
|