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
|
#include <windows.h>
#define IDC_CUSTOM_BUTTON 101
#define IDC_CUSTOM_EDITBOX 102
#define File_Exit 104
#define Help_About 105
#define Help_Info 106
HWND hEdit;
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
INT WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR lpCmdLine, INT nShowCmd)
{
WNDCLASSEX wClass;
ZeroMemory(&wClass,sizeof(WNDCLASSEX));
wClass.cbClsExtra=NULL;
wClass.cbSize=sizeof(WNDCLASSEX);
wClass.cbWndExtra=NULL;
wClass.hbrBackground=(HBRUSH)COLOR_WINDOW;
wClass.hCursor=LoadCursor(NULL,IDC_ARROW);
wClass.hIcon=NULL;
wClass.hIconSm=NULL;
wClass.hInstance=hInst;
wClass.lpfnWndProc=(WNDPROC)WinProc;
wClass.lpszClassName="Window Class";
wClass.lpszMenuName=NULL;
wClass.style=0;
if(!RegisterClassEx(&wClass))
{
int nResult = GetLastError();
MessageBox(NULL, "Window Class Creation Failed!", "Window Class Failed", MB_ICONERROR | MB_OK);
}
HWND hWnd = CreateWindowEx(NULL, "Window Class", "Chat Client", WS_OVERLAPPEDWINDOW, 200, 200, 640, 480, NULL, NULL, hInst, NULL);
if(!hWnd)
{
int nResult = GetLastError();
MessageBox(NULL, "Window Creation Failed!", "Window Creation Failed", MB_ICONERROR | MB_OK);
}
ShowWindow(hWnd, nShowCmd);
MSG msg;
ZeroMemory(&msg,sizeof(MSG));
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
break;
case WM_CREATE:
{
HWND hWndButton = CreateWindowEx(NULL, "BUTTON", "OK", WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON, 517, 386, 100, 24, hWnd, (HMENU)IDC_CUSTOM_BUTTON, GetModuleHandle(NULL), NULL);
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD|WS_VISIBLE, 10, 387, 500, 24, hWnd, (HMENU)IDC_CUSTOM_EDITBOX, GetModuleHandle(NULL), NULL);
HGDIOBJ hfDefault = GetStockObject(DEFAULT_GUI_FONT);
SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE,0));
SendMessage(hWndButton, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE,0));
// menu
HMENU hMenu, hSubMenu;
hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "File");
AppendMenu(hSubMenu, MF_STRING, File_Exit, "Exit");
hSubMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "Help");
AppendMenu(hSubMenu, MF_STRING, Help_About, "About");
AppendMenu(hSubMenu, MF_STRING, Help_Info, "Info");
SetMenu(hWnd, hMenu);
//icon
HICON hIcon = (HICON)LoadImage(NULL, "chat.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
if(hIcon)
SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
else
MessageBox(hWnd, "Could not load large icon!", "Error", MB_OK | MB_ICONERROR);
HICON hIconSm = (HICON)LoadImage(NULL, "chat.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
if(hIconSm)
SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);
else
MessageBox(hWnd, "Could not load small icon!", "Error", MB_OK | MB_ICONERROR);
}
break;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_CUSTOM_BUTTON:
{
char buffer[256];
SendMessage(hEdit, WM_GETTEXT, sizeof(buffer)/sizeof(buffer[0]), reinterpret_cast<LPARAM>(buffer));
MessageBox(hEdit, buffer, "Information", MB_ICONINFORMATION);
}
break;
case File_Exit:
{
PostQuitMessage(0);
return 0;
}
break;
case Help_About:
{
MessageBox(hWnd, "SEnergy, Version 1.00\n2010", "About", MB_OK | MB_ICONINFORMATION);
}
break;
case Help_Info:
{
MessageBox(hWnd, "Chat Client", "Information", MB_OK | MB_ICONINFORMATION);
}
}
break;
}
case WM_KEYDOWN:
{
switch(wParam)
{
case VK_RETURN:
{
char buffer[256];
SendMessage(hEdit, WM_GETTEXT, sizeof(buffer)/sizeof(buffer[0]), reinterpret_cast<LPARAM>(buffer));
MessageBox(hEdit, buffer, "Information", MB_ICONINFORMATION);
}
break;
}
break;
}
case WM_RBUTTONDOWN:
{
int iPosX = LOWORD(lParam);
int iPosY = HIWORD(lParam);
char waCoord[20];
wsprintf(waCoord, ("%i, %i"), iPosX, iPosY);
MessageBox(hWnd, waCoord, NULL, MB_OK);
}
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
|