Hello, I try to code gdi plus, and this no draw anything! And no errors..why?
#include <windows.h>
#include <fgdiplusflat.h>
#pragma comment (lib,"Gdiplus.lib")
VOID OnPaint(HDC hdc)
{
GpStatus g_ok;
Graphics graphics;
Pen pen;
TextOut(hdc, 0, 0, "Hello, Windows!", 15);
g_ok = GdipCreateFromHDC(hdc,&graphics);
if(g_ok != Ok)
{
WCHAR errCode[4];
wsprintfW(errCode,L"%d",g_ok);
MessageBoxW(0,errCode,L"GdipCreateFromHDC",MB_OK);
return;
}
g_ok = GdipCreatePen1(MakeARGB(255, 0, 0, 255),1.0,UnitInch,&pen);
if(g_ok != Ok)
{
WCHAR errCode[4];
wsprintfW(errCode,L"%d",g_ok);
MessageBoxW(0,errCode,L"GdipCreatePen1",MB_OK);
return;
}
g_ok = GdipDrawLine(graphics,pen, 20, 20, 200, 100);
if(g_ok != Ok)
{
WCHAR errCode[4];
wsprintfW(errCode,L"%d",g_ok);
MessageBoxW(0,errCode,L"GdipDrawLine",MB_OK);
return;
}
GdipDrawRectangle(graphics, pen, 20, 20, 120, 120);
GdipDeletePen(pen);
GdipDeleteGraphics(graphics);
}
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE h, PSTR ss, INT iCmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASS wndClass;
GdiplusStartupInput gdiplusStartupInput = { 1, NULL, 0, 0 };
ULONG_PTR gdiplusToken;
// Initialize GDI+.
if(GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL))
MessageBoxW(0,L"Err GdiplusStartup",0,0);
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = TEXT("GettingStarted");
RegisterClass(&wndClass);
hWnd = CreateWindow(
TEXT("GettingStarted"), // window class name
TEXT("Getting Started"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL); // creation parameters
ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GdiplusShutdown(gdiplusToken);
return msg.wParam;
} // WinMain
LRESULT CALLBACK WndProc(HWND hWnd, UINT message,WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
if(!hdc)
MessageBoxW(0,L"Err",NULL,0);
OnPaint(hdc);
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
} // WndProc