Код:
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <locale.h>
#include <string.h>
#include <windows.h>
#pragma comment(lib,"user32.lib")
#pragma comment(lib, "kernel32.lib")
#pragma comment(lib,"gdi32.lib")
HRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
struct c_program
{
WNDCLASSEX wc;
MSG msg;
HWND hwnd;
HDC hdc;
void draw_gdi(){ hdc = GetDC(hwnd);
MoveToEx(hdc, 40, 40, RGB(255, 0, 0)); LineTo(hdc, 140, 40);
MoveToEx(hdc, 140, 40, RGB(255, 0, 0)); LineTo(hdc, 140, 80);
MoveToEx(hdc, 40, 40, RGB(255, 0, 0)); LineTo(hdc, 40, 80);
MoveToEx(hdc, 40, 80,RGB(255, 0, 0)); LineTo(hdc, 140, 80);
MoveToEx(hdc, 40, 80, RGB(255, 0,0)); LineTo(hdc, 140, 40);
c_program(){ set_locale(LC_ALL,"Russian"); };
~c_program(){}
int main(){ HINSTANCE hInstance=GetModuleHandle(0); LPSTR CommandLine = GetCommandLine(); return WinMain(hInstance, NULL, CommandLine, SW_SHOWDEFAULT);};
void create_wndclass(HINSTANCE hInst){ wc.cbSize=sizeof(WNDCLASSEX); wc.style=CS_HREDRAW|CS_VREDRAW; wc.lpfnWndProc=(WNDPROC)WndProc; wc.cbClsExtra=NULL; wc.cbWndExtra=NULL;wc.hInstance=hInst;wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName="MainMenu"; wc.lpszClassName="SimpleWinClass"; wc.hIcon=LoadIcon(NULL, IDI_APPLICATION); wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION); wc.hCursor=LoadCursor(NULL, IDC_ARROW);RegisterClassEx(&wc);}
void create_windows(HINSTANCE hInst){ hwnd=CreateWindowEx(NULL, "SimpleWinClass","host",WS_OVERLAPPEDWINDOW, 100,100,1000,1000,NULL,(HMENU) NULL,hInst, NULL); ShowWindow(hwnd, SW_SHOWNORMAL)! UpdateWindow(hwnd);}
int message_cycle(){while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg); DispatchMessage(&msg);} return msg.wParam;}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR CmdLine, int CmdShow){create_wndclass(hInst); create_windows(hInst); return message_cycle();}
};
c_program z;
int main(int argc, char* argv[]){ return z.main();}
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_DESTROY: PostQuitMessage(NULL); return 0;
case WM_PAINT: z.draw_gdi(); return 0;
default: return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return DefWindowProc(hwnd,uMsg, wParam,lParam);
}
на GDI
|