Sign in to follow this  
Maxfpv

[C]Open Window with WinAPI

Recommended Posts

This Code opens  a Window with the use of the WinAPI

 

 

[hide]

 

#include

 

LRESULT CALLBACK WindowProc(HWND hWnd,

UINT message,

WPARAM wParam,

LPARAM lParam);

 

 

int WINAPI WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nCmdShow)

{

 

HWND hWnd;

WNDCLASSEX wc;

ZeroMemory(&wc, sizeof(WNDCLASSEX));

wc.cbSize = sizeof(WNDCLASSEX);

wc.style = CS_HREDRAW | CS_VREDRAW;

wc.lpfnWndProc = WindowProc;

wc.hInstance = hInstance;

wc.hCursor = LoadCursor(NULL, IDC_ARROW);

wc.hbrBackground = (HBRUSH)COLOR_WINDOW;

wc.lpszClassName = L"WindowClass1";

RegisterClassEx(&wc);

hWnd = CreateWindowEx(NULL,

L"WindowClass1",  

L"First Test-Window",

WS_OVERLAPPEDWINDOW,

300, 

300, 

500, 

400,   

NULL,  

NULL,  

hInstance,   

NULL);  

 

ShowWindow(hWnd, nCmdShow);

 

 

MSG msg;

 

while (GetMessage(&msg, NULL, 0, 0))

{

 

TranslateMessage(&msg);

 

 

DispatchMessage(&msg);

}

 

 

return msg.wParam;

}

 

 

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

{

 

switch (message)

{

 

case WM_DESTROY:

{

PostQuitMessage(0);

return 0;

} break;

}

 

 

return DefWindowProc(hWnd, message, wParam, lParam);

}

 

 

[/hide]

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this