Zdravím, zde je pokus o vytvoření počítadla zobrazených ikon v okně ale pořád nějak zlobí TextOut...
Můžete kod zkontrolovat
#include <windows.h>
#include "resource1.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND hWnd;
int count[10];
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
TCHAR szAppName[] = TEXT("Default window"); // Header
MSG msg;
WNDCLASSEX wc;
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON)); // Ico
wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON)); // Ico_sm
wc.hCursor = (HCURSOR)LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CURSOR));
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+0); // Background
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;
RegisterClassEx(&wc);
hWnd = CreateWindowEx(0,szAppName,
szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, // Margin from left
CW_USEDEFAULT, // Margin from top
CW_USEDEFAULT, // Widht
CW_USEDEFAULT, // Height
NULL,
NULL,
hInstance,NULL);
ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
void Draw(WPARAM wParam, LPARAM lParam, int count[10])
{
POINTS ptCursor;
ptCursor = MAKEPOINTS(lParam);
HDC hDC;
hDC = GetDC(hWnd);
if(wParam & WM_LBUTTONDOWN)
DrawIcon(hDC, ptCursor.x, ptCursor.y,
(HICON)(WORD)GetClassLong(hWnd, GCL_HICON));
ReleaseDC(hWnd, hDC);
count++;
}
void Count()
{
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hWnd, &ps);
TextOut(hDC, 10, 10, count, 4);
EndPaint(hWnd, &ps);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
Count();
break;
case WM_MOUSEMOVE:
Draw(wParam, lParam, count);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
Děkuji za ochotu