Advertisement
konalisp

WinAPI Hello World

Jan 21st, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2. #include <stdio.h>
  3.  
  4. const char g_szClassName[] = "myWindowClass";
  5.  
  6. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
  7.     switch(msg) {
  8.         case WM_CLOSE:
  9.             DestroyWindow(hwnd);
  10.             break;
  11.         case WM_DESTROY:
  12.             PostQuitMessage(0);
  13.             break;
  14.         default:
  15.             return DefWindowProc(hwnd, msg, wParam, lParam);
  16.     }
  17.     return 0;
  18. }
  19.  
  20. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  21.     WNDCLASSEX wc;
  22.     HWND hwnd;
  23.     MSG Msg;
  24.     //Step 1: Registering the Window Class
  25.     wc.cbSize = sizeof(WNDCLASSEX);
  26.     wc.style = 0;
  27.     wc.lpfnWndProc = WndProc;
  28.     wc.cbClsExtra = 0;
  29.     wc.cbWndExtra = 0;
  30.     wc.hInstance = hInstance;
  31.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  32.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  33.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  34.     wc.lpszMenuName = NULL;
  35.     wc.lpszClassName = g_szClassName;
  36.     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  37.  
  38.     if(!RegisterClassEx(&wc)) {
  39.         MessageBox(NULL, "Window Registration Failed!", "Error!",
  40.         MB_ICONEXCLAMATION | MB_OK);
  41.         return 0;
  42.     }
  43.  
  44.     // Creating the Window
  45.     hwnd = CreateWindowEx(
  46.         WS_EX_CLIENTEDGE,
  47.         g_szClassName,
  48.         "OH SHIT NIGGER WHAT THE FUCK ARE YOU DOING",
  49.         WS_OVERLAPPEDWINDOW,
  50.         CW_USEDEFAULT, CW_USEDEFAULT, 440, 140,
  51.         NULL, NULL, hInstance, NULL);
  52.  
  53.     if(hwnd == NULL){
  54.         MessageBox(NULL, "Window Creation Failed!", "Error!",
  55.         MB_ICONEXCLAMATION | MB_OK);
  56.         return 0;
  57.     }
  58.     ShowWindow(hwnd, nCmdShow);
  59.     UpdateWindow(hwnd);
  60.  
  61.     // The Message Loop
  62.     while(GetMessage(&Msg, NULL, 0, 0) > 0) {
  63.         TranslateMessage(&Msg);
  64.         DispatchMessage(&Msg);
  65.     }
  66.     return Msg.wParam;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement