String Manipulation Example

#include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; MSG msg; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszClassName = TEXT("myWindowClass"); RegisterClassEx(&wc); CreateWindowEx( WS_EX_CLIENTEDGE, TEXT("myWindowClass"), TEXT("String Manipulation"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 340, 320, NULL, NULL, hInstance, NULL); while(GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT Ps; HDC hdc; switch(msg) { case WM_PAINT: { hdc = BeginPaint(hwnd, &Ps); // Original string TCHAR OutputText[128] = TEXT("STRING MANIPULATION"); int stringlength = lstrlen(OutputText); TextOut(hdc, 0, 0, OutputText, stringlength); // Convert to lower case CharLower(OutputText); TextOut(hdc, 0, 15, OutputText, stringlength); // Move pointer to second character LPCTSTR newstring = CharNext(OutputText); TextOut(hdc, 0, 30, newstring, stringlength - 1); // Skip characters one at a time int i; for(i = 2; i <= 7; i++) { newstring = CharNext(newstring); TextOut(hdc, 0, 15 + (15 * i), newstring, stringlength - i); } // Copy remaining string lstrcpy(OutputText, newstring); stringlength = lstrlen(OutputText); // Convert back to upper case CharUpper(OutputText); TextOut(hdc, 0, 135, OutputText, stringlength); EndPaint(hwnd, &Ps); } break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }