Wirehead Studios

General Discussion => Off-Topic => Topic started by: LooF on 2004-09-08, 20:33



Title: code posting like phoenix (I hate windows)
Post by: LooF on 2004-09-08, 20:33
whenever I want to make a window I just use this template I wrote and now I never have to do it again.... have fun with it....!

I couldn't use the carrots so... put them yourself

#include windows.h
#include time.h
#include stdio.h

#define class_name "I hate windows"
#define HEIGHT 300
#define WIDTH 300
#define FPS 10

LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR cmdLine, int iShow)
{
   HWND hwnd;
   MSG msg;
   WNDCLASSEX wndclassex = {0};

   wndclassex.cbSize = sizeof(WNDCLASSEX);
   wndclassex.style = CS_HREDRAW | CS_VREDRAW;
   wndclassex.lpfnWndProc = WinProc;
   wndclassex.hInstance = hInstance;
   wndclassex.lpszClassName = class_name;
   wndclassex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
   RegisterClassEx(&wndclassex);
   hwnd = CreateWindowEx(NULL,
                    class_name,
                    class_name,
                    WS_SYSMENU | WS_CAPTION,
                    CW_USEDEFAULT,
                    CW_USEDEFAULT,
                    WIDTH,
                    HEIGHT,
                    NULL,
                    NULL,
                    hInstance,
                    NULL);
   if(!hwnd)
      return EXIT_FAILURE;
   HDC   hdc = GetDC(hwnd);
   ShowWindow(hwnd, iShow);
   UpdateWindow(hwnd);
   
   while(1)
   {
      if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
      {
         if(msg.message == WM_QUIT)
            break;
            
         TranslateMessage(&msg);
         DispatchMessage(&msg);
      }
      if(frame(FPS))
         /*********************
         all the magic goes here
         **********************/
   }
   ReleaseDC(hwnd, hdc);
   UnregisterClass(class_name, hInstance);
   return msg.wParam;
}

LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   switch(message)
   {
   case WM_CLOSE:
   case WM_DESTROY:
      PostQuitMessage(0);
   }
   return(DefWindowProc(hwnd, message, wParam, lParam));
}


Title: Re: code posting like phoenix
Post by: Phoenix on 2004-09-08, 21:14
If you use the [code] tags to encapsulate your posting, as I did with mine, you can use any characters you wish and they will not be converted to html tags.[/color]