Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Win32.h"
- Form::Form(){}
- void Form::ApplyFont(int iHeight,HWND hWnd,wstring FontName,bool Italic,bool Underline)
- {
- if (hWnd != NULL)
- {
- HFONT hFont = CreateFontW(iHeight,0, 0,0, FW_DONTCARE,Italic,Underline,FALSE, DEFAULT_CHARSET,
- OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH,FontName.c_str());
- if (hFont != NULL)
- SendMessage(hWnd, WM_SETFONT, reinterpret_cast<WPARAM>(hFont), TRUE);
- }
- }
- void Form::InitForm(HINSTANCE hThisInstance,wstring FrmText,wstring ClassText,
- DWORD dwStyle,HWND hParent,WNDPROC WndProc,int Width,int Height)
- {
- hInstance = hThisInstance;
- WNDCLASSEX wndEX;
- SecureZeroMemory(&wndEX, sizeof(WNDCLASSEX));
- wndEX.cbSize = sizeof(WNDCLASSEX);
- wndEX.lpfnWndProc = WndProc;
- wndEX.lpszClassName = ClassText.c_str();
- wndEX.hInstance = hThisInstance;
- wndEX.hbrBackground = WHITE_BRUSH;
- wndEX.hCursor = LoadCursor(hThisInstance,MAKEINTRESOURCE(IDC_ARROW));
- RegisterClassEx(&wndEX);
- hForm = CreateWindowEx(NULL,ClassText.c_str(),FrmText.c_str(),
- dwStyle,0,0,Width,Height,hParent,NULL,hInstance,NULL);
- SetLayeredWindowAttributes(hForm, RGB(0,0,0),(255 * 95)/100,
- LWA_ALPHA);
- ShowWindow(hForm,SW_SHOW);
- UpdateLayeredWindow(hForm,NULL,NULL,NULL,NULL,NULL,
- RGB(0,0,0),NULL,0);
- }
- void Form::SetHandle(HWND hWnd)
- {
- hForm = hWnd;
- }
- HWND Form::AddLabel(wstring LabelText,bool bBorder,UINT uID,int X,int Y,int Width,
- int Height)
- {
- HWND hBuffer = CreateWindowEx(WS_EX_LEFT,WC_STATIC,LabelText.c_str(),
- WS_VISIBLE | WS_CHILD | (bBorder ? WS_BORDER : N),X,Y,Width,Height,
- hForm,reinterpret_cast<HMENU>(uID),hInstance,NULL);
- if(hBuffer != NULL)
- ApplyFont(12,hBuffer,L"Calibri",false,false);
- return hBuffer;
- }
- HBITMAP Form::LoadFileImage(wstring Path)
- {
- return (HBITMAP)LoadImage(hInstance,Path.c_str(),
- LR_LOADFROMFILE || IMAGE_BITMAP,0,0,0);
- }
- HBITMAP Form::LoadResImage(UINT Resource)
- {
- return (HBITMAP)LoadImage(hInstance,MAKEINTRESOURCE(Resource),
- IMAGE_BITMAP,0,0,0);
- }
- HWND Form::AddPictureBox(HBITMAP hImage,UINT uID,int X,int Y,int Width,
- int Height)
- {
- HWND hBuffer = CreateWindowEx(WS_EX_LEFT,WC_STATIC,L" ",
- WS_VISIBLE | WS_CHILD | SS_BITMAP | SS_NOTIFY,X,Y,Width,Height,
- hForm,reinterpret_cast<HMENU>(uID),hInstance,NULL);
- if(hBuffer != NULL)
- SendMessage(hBuffer,STM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)hImage);
- return hBuffer;
- }
- HICON Form::LoadResIcon(UINT Resource,int x,int y)
- {
- return (HICON)LoadImage(hInstance,MAKEINTRESOURCE(Resource),IMAGE_ICON,
- x,y,LR_DEFAULTCOLOR);
- }
- HICON Form::LoadFileIcon(wstring Path,int x,int y)
- {
- return (HICON)LoadImage(hInstance,Path.c_str(),IMAGE_ICON,
- x,y,LR_DEFAULTCOLOR | LR_LOADFROMFILE);
- }
- HWND Form::AddButton(wstring BtnText,UINT uID,int X,int Y,int Width,
- int Height)
- {
- HWND hBuffer = CreateWindowEx(WS_EX_LEFT,WC_BUTTON,BtnText.c_str(),
- WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,X,Y,Width,Height,
- hForm,reinterpret_cast<HMENU>(uID),hInstance,NULL);
- if(hBuffer != NULL)
- ApplyFont(12,hBuffer,L"Calibri",false,false);
- return hBuffer;
- }
- HWND Form::AddButton(wstring BtnText,HICON Icon,UINT uID,int X,int Y,int Width,
- int Height)
- {
- HWND hBuffer = CreateWindowEx(WS_EX_LEFT,WC_BUTTON,BtnText.c_str(),
- WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_ICON,X,Y,Width,Height,
- hForm,reinterpret_cast<HMENU>(uID),hInstance,NULL);
- if(Icon != NULL)
- {
- SendMessage(hBuffer, BM_SETIMAGE, IMAGE_ICON, (LPARAM)Icon);
- ApplyFont(12,hBuffer,L"Calibri",false,false);
- }
- return hBuffer;
- }
- HWND Form::AddCheckBox(wstring BtnText,bool bChecked,UINT uID,int X,int Y,
- int Width,int Height)
- {
- HWND hBuffer = CreateWindowEx(WS_EX_LEFT,WC_BUTTON,BtnText.c_str(),
- WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,X,Y,Width,Height,
- hForm,reinterpret_cast<HMENU>(uID),hInstance,NULL);
- if(hBuffer != NULL)
- {
- SendMessage(hBuffer,BM_SETCHECK,(bChecked ? BST_CHECKED : BST_UNCHECKED),NULL);
- ApplyFont(12,hBuffer,L"Calibri",false,false);
- }
- return hBuffer;
- }
- HWND Form::AddTabControl(wstring TabCtrlText,UINT uID,int X,int Y,
- int Width,int Height)
- {
- HWND hBuffer = CreateWindowEx(WS_EX_LEFT,WC_TABCONTROL,TabCtrlText.c_str(),
- WS_VISIBLE | WS_CHILD,X,Y,Width,Height,
- hForm,reinterpret_cast<HMENU>(uID),hInstance,NULL);
- return hBuffer;
- }
- #ifndef WIN32_H
- #define WIN32_H
- #include "Defines.h"
- #include <Commctrl.h>
- #pragma comment(lib, "comctl32")
- #pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' \
- version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
- using namespace std;
- class Form
- {
- private:
- HINSTANCE hInstance;
- HWND hForm;
- void ApplyFont(int iHeight,HWND hWnd,wstring FontName,bool Italic,bool Underline);
- public:
- Form();
- void InitForm(HINSTANCE hThisInstance,wstring FrmText,
- wstring ClassText,DWORD dwStyle,HWND hParent,WNDPROC WndProc,
- int Width,int Height);
- HWND AddLabel(wstring LabelText,bool bBorder,UINT uID,int X,int Y,
- int Width,int Height);
- HBITMAP LoadResImage(UINT Resource);
- HBITMAP LoadFileImage(wstring Path);
- HWND AddPictureBox(HBITMAP hImage,UINT uID,int X,int Y,int Height,
- int Width);
- HICON LoadResIcon(UINT Resource,int x,int y);
- HICON Form::LoadFileIcon(wstring Path,int x,int y);
- HWND AddButton(wstring BtnText,UINT uID,int X,int Y,
- int Width,int Height);
- HWND AddButton(wstring BtnText,HICON Icon,UINT uID,int X,int Y,
- int Width,int Height);
- HWND AddCheckBox(wstring BtnText,bool bChecked,UINT uID,int X,int Y,
- int Width,int Height);
- HWND Form::AddTabControl(wstring TabCtrlText,UINT uID,int X,int Y,
- int Width,int Height);
- void SetHandle(HWND hWnd);
- };
- #endif
Add Comment
Please, Sign In to add comment