Window without title bar

This is a discussion on Window without title bar within the Windows Programming forums, part of the Platform Specific Boards category; I would like to make a window without title bar, so I can design the whole window and make my ...

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    Window without title bar

    I would like to make a window without title bar, so I can design the whole window and make my own title bar and/or maximise, minimise and exit buttons...

  2. #2
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    One way is to create the window with the WS_POPUPWINDOW style.
    The following piece of code creates a fake title bar that you can use to drag and move the window about. You can see what it looks like here:

    Poorly Taken Screenshot

    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WndProc( HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam )
    {
      static RECT clientRect = { 0, 0, 300, 200 };
      static RECT titleRect  = { 0, 0, 300, 30  };  
      
      switch(msg)  
      {
        case WM_PAINT:
          {
            PAINTSTRUCT ps ;
            HDC hdc = BeginPaint(hwnd,&ps) ;
              MoveToEx(hdc, 0, 30, 0) ;
              LineTo(hdc, 300, 30) ;
              SetBkMode(hdc,TRANSPARENT) ;
              TextOut(hdc, 8, 8, "My Title Bar", strlen("My Title Bar") );
            EndPaint(hwnd,&ps) ;
            return 0 ;
          }
        
        case WM_LBUTTONDOWN: {
            POINT pt = { LOWORD(lParam), HIWORD(lParam) };
            if ( PtInRect(&titleRect, pt) )
              SendMessage(hwnd,WM_NCLBUTTONDOWN,HTCAPTION,lParam) ;
            return 0 ;
        }  
        
        case WM_DESTROY:
          {
            PostQuitMessage(0);
            return 0;
          }
          
        default: return DefWindowProc(hwnd,msg,wParam,lParam);
      }
    }
    
    int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrev, LPSTR args, int nShow )
    {
      WNDCLASS wc = {0};
      wc.lpszClassName = TEXT( "FakeTitleBar" );
      wc.hInstance     = hInst ;
      wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
      wc.lpfnWndProc   = WndProc ;
      wc.hCursor       = LoadCursor(0,IDC_ARROW);
      
      RegisterClass(&wc);
      CreateWindow( wc.lpszClassName,TEXT(""), WS_POPUPWINDOW|WS_VISIBLE,
                    0,0,300,200,0,0,hInst,0);
      
      MSG  msg ;  
      while( GetMessage(&msg,0,0,0) > 0 ) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
      return (int)msg.wParam;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21