DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Most Elementary Win-API "Hello, 'ere I Am' Code
This does nothing but opening a window for 5 seconds. No MFC, no C#, no resources, no whatsoever...
#include<windows.h>
#include<tchar.h>
HWND NewWindow(
LPCTSTR str_Title,
int int_XPos,
int int_YPos,
int int_Width,
int int_Height);
LRESULT CALLBACK OurWindowProcedure(
HWND han_Wind,
UINT uint_Message,
WPARAM parameter1,
LPARAM parameter2);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPreviousInstance,
LPSTR lpcmdline,
int nCmdShow
)
{
HWND han_Window = NewWindow(_T("DirectX C++ Tutorial"),100,100,500,500);
Sleep(5000);
DestroyWindow(han_Window);
return 0;
}
HWND NewWindow(
LPCTSTR str_Title,
int int_XPos,
int int_YPos,
int int_Width,
int int_Height)
{
WNDCLASSEX wnd_Structure;
wnd_Structure.cbSize = sizeof(WNDCLASSEX);
wnd_Structure.style = CS_HREDRAW | CS_VREDRAW;
wnd_Structure.lpfnWndProc = OurWindowProcedure;
wnd_Structure.cbClsExtra = 0;
wnd_Structure.cbWndExtra = 0;
wnd_Structure.hInstance = GetModuleHandle(NULL);
wnd_Structure.hIcon = NULL;
wnd_Structure.hCursor = NULL;
wnd_Structure.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
wnd_Structure.lpszMenuName = NULL;
wnd_Structure.lpszClassName = _T("WindowClassName");
wnd_Structure.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
RegisterClassEx(&wnd_Structure);
return CreateWindowEx(
WS_EX_CONTROLPARENT,
_T("WindowClassName"),
str_Title, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE,
int_XPos,
int_YPos,
int_Width,
int_Height,
NULL,
NULL,
GetModuleHandle(NULL),
NULL);
}
LRESULT CALLBACK OurWindowProcedure(HWND han_Wind,UINT uint_Message,WPARAM parameter1,LPARAM parameter2)
{
return DefWindowProc(han_Wind,uint_Message,parameter1,parameter2);
}





