Guest User

Untitled

a guest
Jan 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.68 KB | None | 0 0
  1. #include "Win32.h"
  2.  
  3. Form::Form(){}
  4.  
  5. void Form::ApplyFont(int iHeight,HWND hWnd,wstring FontName,bool Italic,bool Underline)
  6. {
  7. if (hWnd != NULL)
  8. {
  9. HFONT hFont = CreateFontW(iHeight,0, 0,0, FW_DONTCARE,Italic,Underline,FALSE, DEFAULT_CHARSET,
  10. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH,FontName.c_str());
  11.  
  12. if (hFont != NULL)
  13. SendMessage(hWnd, WM_SETFONT, reinterpret_cast<WPARAM>(hFont), TRUE);
  14. }
  15. }
  16.  
  17. void Form::InitForm(HINSTANCE hThisInstance,wstring FrmText,wstring ClassText,
  18. DWORD dwStyle,HWND hParent,WNDPROC WndProc,int Width,int Height)
  19. {
  20. hInstance = hThisInstance;
  21.  
  22. WNDCLASSEX wndEX;
  23.  
  24. SecureZeroMemory(&wndEX, sizeof(WNDCLASSEX));
  25.  
  26. wndEX.cbSize = sizeof(WNDCLASSEX);
  27. wndEX.lpfnWndProc = WndProc;
  28. wndEX.lpszClassName = ClassText.c_str();
  29. wndEX.hInstance = hThisInstance;
  30. wndEX.hbrBackground = WHITE_BRUSH;
  31. wndEX.hCursor = LoadCursor(hThisInstance,MAKEINTRESOURCE(IDC_ARROW));
  32.  
  33. RegisterClassEx(&wndEX);
  34.  
  35. hForm = CreateWindowEx(NULL,ClassText.c_str(),FrmText.c_str(),
  36. dwStyle,0,0,Width,Height,hParent,NULL,hInstance,NULL);
  37.  
  38. SetLayeredWindowAttributes(hForm, RGB(0,0,0),(255 * 95)/100,
  39. LWA_ALPHA);
  40.  
  41. ShowWindow(hForm,SW_SHOW);
  42.  
  43. UpdateLayeredWindow(hForm,NULL,NULL,NULL,NULL,NULL,
  44. RGB(0,0,0),NULL,0);
  45. }
  46.  
  47.  
  48. void Form::SetHandle(HWND hWnd)
  49. {
  50. hForm = hWnd;
  51. }
  52.  
  53. HWND Form::AddLabel(wstring LabelText,bool bBorder,UINT uID,int X,int Y,int Width,
  54. int Height)
  55. {
  56. HWND hBuffer = CreateWindowEx(WS_EX_LEFT,WC_STATIC,LabelText.c_str(),
  57. WS_VISIBLE | WS_CHILD | (bBorder ? WS_BORDER : N),X,Y,Width,Height,
  58. hForm,reinterpret_cast<HMENU>(uID),hInstance,NULL);
  59.  
  60. if(hBuffer != NULL)
  61. ApplyFont(12,hBuffer,L"Calibri",false,false);
  62.  
  63. return hBuffer;
  64. }
  65.  
  66. HBITMAP Form::LoadFileImage(wstring Path)
  67. {
  68. return (HBITMAP)LoadImage(hInstance,Path.c_str(),
  69. LR_LOADFROMFILE || IMAGE_BITMAP,0,0,0);
  70. }
  71. HBITMAP Form::LoadResImage(UINT Resource)
  72. {
  73. return (HBITMAP)LoadImage(hInstance,MAKEINTRESOURCE(Resource),
  74. IMAGE_BITMAP,0,0,0);
  75. }
  76. HWND Form::AddPictureBox(HBITMAP hImage,UINT uID,int X,int Y,int Width,
  77. int Height)
  78. {
  79. HWND hBuffer = CreateWindowEx(WS_EX_LEFT,WC_STATIC,L" ",
  80. WS_VISIBLE | WS_CHILD | SS_BITMAP | SS_NOTIFY,X,Y,Width,Height,
  81. hForm,reinterpret_cast<HMENU>(uID),hInstance,NULL);
  82.  
  83. if(hBuffer != NULL)
  84. SendMessage(hBuffer,STM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)hImage);
  85.  
  86. return hBuffer;
  87. }
  88.  
  89. HICON Form::LoadResIcon(UINT Resource,int x,int y)
  90. {
  91. return (HICON)LoadImage(hInstance,MAKEINTRESOURCE(Resource),IMAGE_ICON,
  92. x,y,LR_DEFAULTCOLOR);
  93. }
  94. HICON Form::LoadFileIcon(wstring Path,int x,int y)
  95. {
  96. return (HICON)LoadImage(hInstance,Path.c_str(),IMAGE_ICON,
  97. x,y,LR_DEFAULTCOLOR | LR_LOADFROMFILE);
  98. }
  99. HWND Form::AddButton(wstring BtnText,UINT uID,int X,int Y,int Width,
  100. int Height)
  101. {
  102. HWND hBuffer = CreateWindowEx(WS_EX_LEFT,WC_BUTTON,BtnText.c_str(),
  103. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,X,Y,Width,Height,
  104. hForm,reinterpret_cast<HMENU>(uID),hInstance,NULL);
  105.  
  106. if(hBuffer != NULL)
  107. ApplyFont(12,hBuffer,L"Calibri",false,false);
  108.  
  109. return hBuffer;
  110. }
  111. HWND Form::AddButton(wstring BtnText,HICON Icon,UINT uID,int X,int Y,int Width,
  112. int Height)
  113. {
  114. HWND hBuffer = CreateWindowEx(WS_EX_LEFT,WC_BUTTON,BtnText.c_str(),
  115. WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_ICON,X,Y,Width,Height,
  116. hForm,reinterpret_cast<HMENU>(uID),hInstance,NULL);
  117.  
  118. if(Icon != NULL)
  119. {
  120. SendMessage(hBuffer, BM_SETIMAGE, IMAGE_ICON, (LPARAM)Icon);
  121. ApplyFont(12,hBuffer,L"Calibri",false,false);
  122. }
  123.  
  124. return hBuffer;
  125. }
  126.  
  127. HWND Form::AddCheckBox(wstring BtnText,bool bChecked,UINT uID,int X,int Y,
  128. int Width,int Height)
  129. {
  130. HWND hBuffer = CreateWindowEx(WS_EX_LEFT,WC_BUTTON,BtnText.c_str(),
  131. WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,X,Y,Width,Height,
  132. hForm,reinterpret_cast<HMENU>(uID),hInstance,NULL);
  133.  
  134. if(hBuffer != NULL)
  135. {
  136. SendMessage(hBuffer,BM_SETCHECK,(bChecked ? BST_CHECKED : BST_UNCHECKED),NULL);
  137. ApplyFont(12,hBuffer,L"Calibri",false,false);
  138. }
  139.  
  140. return hBuffer;
  141. }
  142.  
  143. HWND Form::AddTabControl(wstring TabCtrlText,UINT uID,int X,int Y,
  144. int Width,int Height)
  145. {
  146. HWND hBuffer = CreateWindowEx(WS_EX_LEFT,WC_TABCONTROL,TabCtrlText.c_str(),
  147. WS_VISIBLE | WS_CHILD,X,Y,Width,Height,
  148. hForm,reinterpret_cast<HMENU>(uID),hInstance,NULL);
  149.  
  150. return hBuffer;
  151. }
  152.  
  153. #ifndef WIN32_H
  154. #define WIN32_H
  155.  
  156. #include "Defines.h"
  157.  
  158. #include <Commctrl.h>
  159.  
  160. #pragma comment(lib, "comctl32")
  161. #pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' \
  162. version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
  163. using namespace std;
  164.  
  165. class Form
  166. {
  167. private:
  168. HINSTANCE hInstance;
  169. HWND hForm;
  170. void ApplyFont(int iHeight,HWND hWnd,wstring FontName,bool Italic,bool Underline);
  171.  
  172. public:
  173. Form();
  174. void InitForm(HINSTANCE hThisInstance,wstring FrmText,
  175. wstring ClassText,DWORD dwStyle,HWND hParent,WNDPROC WndProc,
  176. int Width,int Height);
  177.  
  178. HWND AddLabel(wstring LabelText,bool bBorder,UINT uID,int X,int Y,
  179. int Width,int Height);
  180.  
  181. HBITMAP LoadResImage(UINT Resource);
  182. HBITMAP LoadFileImage(wstring Path);
  183. HWND AddPictureBox(HBITMAP hImage,UINT uID,int X,int Y,int Height,
  184. int Width);
  185.  
  186. HICON LoadResIcon(UINT Resource,int x,int y);
  187. HICON Form::LoadFileIcon(wstring Path,int x,int y);
  188. HWND AddButton(wstring BtnText,UINT uID,int X,int Y,
  189. int Width,int Height);
  190. HWND AddButton(wstring BtnText,HICON Icon,UINT uID,int X,int Y,
  191. int Width,int Height);
  192.  
  193. HWND AddCheckBox(wstring BtnText,bool bChecked,UINT uID,int X,int Y,
  194. int Width,int Height);
  195.  
  196. HWND Form::AddTabControl(wstring TabCtrlText,UINT uID,int X,int Y,
  197. int Width,int Height);
  198.  
  199. void SetHandle(HWND hWnd);
  200. };
  201.  
  202. #endif
Add Comment
Please, Sign In to add comment