Created
October 29, 2016 09:18
-
-
Save Soulstorm50/ea19d8015d957942a678d7dc363d8094 to your computer and use it in GitHub Desktop.
Ticker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <tchar.h> | |
#include <time.h> | |
LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM); | |
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime); | |
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszCmdLine, int nCmdShow) | |
{ | |
TCHAR szClassWindow[] = L"Win32Application"; | |
TCHAR szWindowCaption[45] = L"Exsample of the ticker in WinAPI "; | |
int screenWidth = GetSystemMetrics(SM_CXSCREEN); | |
int screenHeight = GetSystemMetrics(SM_CYSCREEN); | |
HWND hWnd; | |
MSG lpMsg; | |
WNDCLASSEX wcl; | |
wcl.cbSize = sizeof(wcl); | |
wcl.style = CS_HREDRAW | CS_VREDRAW; | |
wcl.lpfnWndProc = WindowProc; | |
wcl.cbClsExtra = 0; | |
wcl.cbWndExtra = 0; | |
wcl.hInstance = hInst; | |
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION); | |
wcl.hCursor = LoadCursor(NULL, IDC_ARROW); | |
wcl.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); | |
wcl.lpszMenuName = NULL; | |
wcl.lpszClassName = szClassWindow; | |
wcl.hIconSm = NULL; | |
if (!RegisterClassEx(&wcl)) | |
return 0; | |
hWnd = CreateWindowEx(0, szClassWindow, szWindowCaption, WS_POPUPWINDOW | WS_CAPTION, | |
screenWidth / 2 - 100, screenHeight / 2 - 100, 320, 100, NULL, NULL, hInst, NULL); | |
ShowWindow(hWnd, nCmdShow); | |
UpdateWindow(hWnd); | |
SetTimer(hWnd, 1, 200, TimerProc); | |
while (GetMessage(&lpMsg, NULL, 0, 0)) | |
{ | |
TranslateMessage(&lpMsg); | |
DispatchMessage(&lpMsg); | |
} | |
return lpMsg.wParam; | |
} | |
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) | |
{ | |
TCHAR szWindowCaption[45]; | |
TCHAR szBuffer[45]; | |
GetWindowText(hwnd, szWindowCaption, 45); | |
szBuffer[0] = szWindowCaption[38]; | |
for (int i = 0; i < 43; i++) | |
szBuffer[i + 1] = szWindowCaption[i]; | |
szBuffer[44] = NULL; | |
SetWindowText(hwnd, szBuffer); | |
} | |
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) | |
{ | |
switch (message) | |
{ | |
case WM_DESTROY: | |
PostQuitMessage(0); | |
break; | |
default: | |
return DefWindowProc(hWnd, message, wParam, lParam); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment