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
|
//Includes
#include <windows.h>
//Defines
#define ErrorMessageBox(a,b) MessageBox(a,b,"Error:",MB_ICONWARNING)
//Function declarations
void PrintText (int, int, char*, HWND);
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
//Entry point
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpsCommandLine, int iCmdShow)
{
//Create and register a WindowClass
WNDCLASSEX WindowClass;
WindowClass.hInstance = hInstance;
WindowClass.lpszClassName = "1";
WindowClass.lpfnWndProc = WindowProcedure;
WindowClass.style = 0;
WindowClass.cbSize = sizeof (WNDCLASSEX);
WindowClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
WindowClass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
WindowClass.hCursor = LoadCursor (NULL, IDC_ARROW);
WindowClass.lpszMenuName = NULL;
WindowClass.cbClsExtra = 0;
WindowClass.cbWndExtra = 0;
WindowClass.hbrBackground = CreateSolidBrush (RGB (255, 255, 255));
if (!RegisterClassEx (&WindowClass))
{
ErrorMessageBox (NULL, "Window class registration for class \"1\" has failed.");
return 0;
}
//Create the window
HWND hWnd = CreateWindow ("1", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 544, 375, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
ErrorMessageBox (NULL, "Window handle \"hWnd\" is NULL.");
return 0;
}
//Show the window
ShowWindow (hWnd, SW_SHOW);
//Message loop
MSG uMsg = {0};
while (GetMessage (&uMsg, NULL, 0, 0) > 0)
{
TranslateMessage (&uMsg);
DispatchMessage (&uMsg);
}
return 0;
}
//Function to print text
void PrintText (int iX, int iY, char *cpText, HWND hWnd)
{
InvalidateRect (hWnd, NULL, FALSE); //Re-Paint the window
PAINTSTRUCT ps;
HDC hDC = BeginPaint (hWnd, &ps);
TextOut (hDC, iX, iY, cpText, 1); //Print the "*"
EndPaint (hWnd, &ps);
}
//Window procedure
LRESULT CALLBACK WindowProcedure (HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
switch (uiMsg)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
//If we press the Left mouse button
case WM_LBUTTONDOWN:
{
POINT cursorPos;
GetCursorPos (&cursorPos);
PrintText (cursorPos.x, cursorPos.y, "*", hWnd); //Call the print text function
}
break;
}
return DefWindowProc (hWnd, uiMsg, wParam, lParam);
}
|