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
|
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#include <windows.h>
#define IDC_USER_LABEL 2000
#define IDC_LOGIN_EDIT 2005
#define IDC_PASSWORD_LABEL 2010
#define IDC_PASSWORD_EDIT 2015
#define IDC_LOGIN_BUTTON 2020
#define IDC_EXIT_BUTTON 2025
LRESULT CALLBACK fnWndProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
HINSTANCE hIns;
hIns=((LPCREATESTRUCT)lParam)->hInstance;
CreateWindowEx(NULL, L"Static", L"Username: ", WS_CHILD | WS_VISIBLE, 10, 20, 75, 20, hWnd, (HMENU)IDC_USER_LABEL, hIns, NULL);
CreateWindowEx(NULL, L"Edit", NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 100, 20, 150, 20, hWnd, (HMENU)IDC_LOGIN_EDIT, hIns, NULL);
CreateWindowEx(NULL, L"Static", L"Password: ", WS_CHILD | WS_VISIBLE, 10, 50, 75, 20, hWnd, (HMENU)IDC_PASSWORD_LABEL, hIns, NULL);
CreateWindowEx(NULL, L"Edit", NULL, WS_CHILD | ES_PASSWORD | WS_VISIBLE | WS_TABSTOP, 100, 50, 150, 20, hWnd, (HMENU)IDC_PASSWORD_EDIT, hIns, NULL);
CreateWindowEx(NULL, L"Button", L"Connect", WS_CHILD | WS_VISIBLE, 100, 80, 90, 25, hWnd, (HMENU)IDC_LOGIN_BUTTON, hIns, NULL);
CreateWindowEx(NULL, L"Button", L"Exit", WS_CHILD | WS_VISIBLE, 200, 80, 50, 25, hWnd, (HMENU)IDC_EXIT_BUTTON, hIns, NULL);
SetFocus(GetDlgItem(hWnd,IDC_LOGIN_EDIT));
return 0;
}
case WM_CTLCOLORSTATIC:
{
SetTextColor((HDC)wParam,RGB(109,194,222));
SetBkMode((HDC)wParam,TRANSPARENT);
return GetClassLongPtr(hWnd, GCLP_HBRBACKGROUND);
}
case WM_CTLCOLOREDIT:
{
SetTextColor((HDC)wParam, RGB(255, 255, 255));
SetBkMode((HDC)wParam,TRANSPARENT);
return GetClassLongPtr(hWnd,GCLP_HBRBACKGROUND);
}
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_LOGIN_BUTTON:
MessageBox(hWnd,L"You Clicked The Login Button!",L"Button Click Report!",MB_OK);
break;
case IDC_EXIT_BUTTON:
MessageBox(hWnd,L"You Clicked The Exit Button!",L"Button Click Report!",MB_OK);
DestroyWindow(hWnd);
break;
}
return 0;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
POINT Pt;
HDC hDC=BeginPaint(hWnd,&ps);
HPEN hPen=(HPEN)GetStockObject(WHITE_PEN);
HPEN hOriginalPen=(HPEN)SelectObject(hDC,hPen);
MoveToEx(hDC,98,18,&Pt);
LineTo(hDC,250,18);
LineTo(hDC,250,40);
LineTo(hDC,98,40);
LineTo(hDC,98,18);
SelectObject(hDC,hOriginalPen);
EndPaint(hWnd,&ps);
return 0;
}
case WM_DESTROY:
{
DeleteObject((HBRUSH)GetClassLongPtr(hWnd,GCLP_HBRBACKGROUND));
PostQuitMessage(0);
return 0;
}
}
return (DefWindowProc(hWnd, msg, wParam, lParam));
}
int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
MSG messages;
WNDCLASS wc;
HWND hWnd;
memset(&wc,0,sizeof(WNDCLASS));
wc.lpszClassName = L"Form1";
wc.lpfnWndProc = fnWndProc;
wc.hInstance = hIns;
wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
RegisterClass(&wc);
hWnd=CreateWindowEx(0,wc.lpszClassName,wc.lpszClassName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,400, 200,HWND_DESKTOP,0,hIns,0);
ShowWindow(hWnd,iShow);
while(GetMessage(&messages,NULL,0,0))
{
if(!IsDialogMessage(hWnd,&messages))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
}
return messages.wParam;
}
| |