#include #include #include #include #include #include "wintest.h" HINSTANCE hInst; LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { static HWND hwndStatus, hwndEdit, hwndInput; static HWND oldFocus; WORD id; RECT rect, statusRect; CHARFORMAT cf; PARAFORMAT pf; HFONT hfnt = GetStockObject(ANSI_FIXED_FONT); CHARRANGE cr; char tmp[80], *p; int val; static int count = 1; switch (msg) { case WM_CREATE: hwndStatus = CreateStatusWnd(hInst, hwnd, 2); hwndEdit = CreateWindowEx( WS_EX_CLIENTEDGE, "RichEdit20A", NULL, WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL, 0, 0, 0, 0, hwnd, NULL, hInst, NULL); memset(&cf, 0, sizeof(CHARFORMAT)); cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_FACE | CFM_SIZE | CFM_BOLD; cf.dwEffects = 0; cf.yHeight = 8 * 20; strcpy(cf.szFaceName, "Andale Mono"); memset(&pf, 0, sizeof(PARAFORMAT)); pf.cbSize = sizeof(PARAFORMAT); pf.dwMask = PFM_STARTINDENT; pf.dxStartIndent = 25; SendMessage(hwndEdit, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); SendMessage(hwndEdit, EM_SETPARAFORMAT, (WPARAM)0, (LPARAM)&pf); hwndInput = CreateWindowEx( WS_EX_CLIENTEDGE, "RichEdit20A", NULL, WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, 0, 0, 0, 0, hwnd, NULL, hInst, NULL); SendMessage(hwndInput, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf); SendMessage(hwndInput, EM_SETPARAFORMAT, (WPARAM)0, (LPARAM)&pf); SetFocus(hwndInput); break; case WM_SIZE: SendMessage(hwndStatus, WM_SIZE, wParam, lParam); SetStatusParts(hwndStatus, 2); GetClientRect(hwnd, &rect); GetWindowRect(hwndStatus, &statusRect); MoveWindow(hwndEdit, 0, 0, rect.right, rect.bottom - (statusRect.bottom - statusRect.top) - 24, TRUE); MoveWindow(hwndInput, 0, rect.bottom - (statusRect.bottom - statusRect.top) - 24, rect.right, 24, TRUE); break; case WM_COMMAND: id = LOWORD(wParam); switch (id) { case IDM_EXIT: PostQuitMessage(0); break; case IDM_CLEAR: SetWindowText(hwndEdit, (LPCTSTR)NULL); break; case IDM_INPUT: p = GetInput(hwnd, "Input", "", 300); if (p) { val = atoi(p); EditPrintf(hwndEdit, 10000, "%d\n", val * 1000); } break; case IDM_COMMAND: GetWindowText(hwndInput, tmp, 80); val = atoi(tmp); EditPrintf(hwndEdit, 1000, "%d\n", val * 1000); break; default: return FALSE; } break; case WM_ACTIVATE: if (LOWORD(wParam) == WA_INACTIVE) oldFocus = GetFocus(); else if (oldFocus) SetFocus(oldFocus); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd,msg,wParam,lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow) { WNDCLASS wc; HWND hwnd; MSG msg; HACCEL hAccel; hInst = hInstance; if (! LoadLibrary("riched20.dll")) { MessageBox(NULL, "Couldn't load riched20.dll", "SQLBase", MB_OK | MB_ICONERROR); return 0; } wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)MainWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInst; wc.hIcon = LoadIcon(hInst, IDI_WINLOGO); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszMenuName = "MainMenu"; wc.lpszClassName = "MainWndClass"; if (! RegisterClass(&wc)) return 0; hwnd = CreateWindow( "MainWndClass", "wintest", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL); ShowWindow(hwnd, nCmdShow); if (! (hAccel = LoadAccelerators(hInst, "Accel"))) return 0; while (GetMessage (&msg, NULL, 0, 0)) { if (! TranslateAccelerator(hwnd, hAccel, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } .