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...
Printable View
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...
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;
}