Thread: Ws_popup

  1. #1
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80

    Ws_popup

    Guys, i have a problem which i couldn't figure out. I wanna create a window without borders or titlebox, basically i only wan the client area. I tried WS_POPUP but the created window just stayed in my taskbar minimized, i couldn't activate or show it at all. What should i do ? i tried combining it with | WS_MAXIMIZE but to no avail, please advice me on this. This is my code.
    Code:
    #include <windows.h>
    
    const char g_szClassName[] = "Skeleton";
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(msg)
    	{
         	case WM_PAINT:
    			HDC hdc;
    			PAINTSTRUCT ps;
    			hdc = BeginPaint(hwnd,&ps);
    			MoveToEx(hdc,10,10,NULL);
    			LineTo(hdc,60,20);
    			EndPaint(hwnd,&ps);
    
    		case WM_DESTROY:
    			PostQuitMessage(0);
    		break;
    		default:
    			return DefWindowProc(hwnd, msg, wParam, lParam);
    	}
    	return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    	LPSTR lpCmdLine, int nCmdShow)
    {
    	WNDCLASSEX wc;
    	HWND hwnd;
    	MSG Msg;
    
    	//Step 1: Registering the Window Class
    	wc.cbSize		 = sizeof(WNDCLASSEX);
    	wc.style		 = CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc	 = WndProc;
    	wc.cbClsExtra	 = 0;
    	wc.cbWndExtra	 = 0;
    	wc.hInstance	 = hInstance;
    	wc.hIcon		 = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hCursor		 = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    	wc.lpszMenuName  = NULL;
    	wc.lpszClassName = g_szClassName;
    	wc.hIconSm		 = LoadIcon(NULL, IDI_APPLICATION);
    
    	if(!RegisterClassEx(&wc))
    	{
    		MessageBox(NULL, "Window Registration Failed!", "Error!",
    			MB_ICONEXCLAMATION | MB_OK);
    		return 0;
    	}
    
    	hwnd = CreateWindowEx(
    		NULL,
    		g_szClassName,
    		"Skeleton",
    		WS_POPUPWINDOW | WS_MAXIMIZE,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		NULL,
    		NULL,
    		hInstance,
    		NULL);
    
    	if(hwnd == NULL)
    	{
    		MessageBox(NULL, "Window Creation Failed!", "Error!",
    			MB_ICONEXCLAMATION | MB_OK);
    		return 0;
    	}
    
    	ShowWindow(hwnd, nCmdShow);
    	UpdateWindow(hwnd);
    
    	while(GetMessage(&Msg, NULL, 0, 0) > 0)
    	{
    		TranslateMessage(&Msg);
    		DispatchMessage(&Msg);
    	}
    	return Msg.wParam;
    }
    /* Have a nice day */

  2. #2
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80
    Is it possible to even drop the titlebar ? I just wan to client area without the titlebar, is it possible ? kinda, like those we see in Splash Screen, just for the eyes.
    /* Have a nice day */

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You need to return 0; (or break; if you prefer) at the end of your WM_PAINT case statement, otherwise the program drops down into the WM_DESTROY handler.

    You might want to add a WM_KEYDOWN case statement just before the WM_DESTROY one (let that drop through ie. no 'return 0') so you can quit the program if any key is pressed.
    Code:
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
      switch(msg)
        {
        case WM_PAINT:
          HDC hdc;
          PAINTSTRUCT ps;
          hdc = BeginPaint(hwnd,&ps);
          MoveToEx(hdc,10,10,NULL);
          LineTo(hdc,60,20);
          EndPaint(hwnd,&ps);
          return 0;
        case WM_KEYDOWN:
        case WM_DESTROY:
          PostQuitMessage(0);
          break;
        default:
          return DefWindowProc(hwnd, msg, wParam, lParam);
      }
      return 0;
    }
    The WS_POPUP style is fine on it's own so you can safely remove other styles.

    edit: Actually, you also need to explicitly set the window dimensions (replace CW_USEDEFAULT) in your CreateWindowEx call.
    Last edited by Ken Fitlike; 04-27-2005 at 11:19 AM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80
    Ken, i spotted that error and did amendments and gave the window some fixed dimensions. The problem is still around though, the window just won't show on my desktop, it stubbornly stayed in the taskbar minimized, what should i do ??
    /* Have a nice day */

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The following is your code amended as I've suggested which creates and displays a window with the WS_POPUP style and dimensions 400x400.
    Code:
    #include <windows.h>
    
    const char g_szClassName[] = "Skeleton";
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
      switch(msg)
      {
        case WM_PAINT:
          HDC hdc;
          PAINTSTRUCT ps;
          hdc = BeginPaint(hwnd,&ps);
          MoveToEx(hdc,10,10,NULL);
          LineTo(hdc,60,20);
          EndPaint(hwnd,&ps);
          return 0;
        case WM_KEYDOWN:
        case WM_DESTROY:
          PostQuitMessage(0);
        break;
        default:
          return DefWindowProc(hwnd, msg, wParam, lParam);
      }
      return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
      LPSTR lpCmdLine, int nCmdShow)
    {
      WNDCLASSEX wc;
      HWND hwnd;
      MSG Msg;
    
      //Step 1: Registering the Window Class
      wc.cbSize     = sizeof(WNDCLASSEX);
      wc.style     = CS_HREDRAW | CS_VREDRAW;
      wc.lpfnWndProc   = WndProc;
      wc.cbClsExtra   = 0;
      wc.cbWndExtra   = 0;
      wc.hInstance   = hInstance;
      wc.hIcon     = LoadIcon(NULL, IDI_APPLICATION);
      wc.hCursor     = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
      wc.lpszMenuName  = NULL;
      wc.lpszClassName = g_szClassName;
      wc.hIconSm     = LoadIcon(NULL, IDI_APPLICATION);
    
      if(!RegisterClassEx(&wc))
      {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
          MB_ICONEXCLAMATION | MB_OK);
        return 0;
      }
    
      hwnd = CreateWindowEx(
        0,
        g_szClassName,
        "Skeleton",
        WS_POPUP,
        0,
        0,
        400,
        400,
        0,
        0,
        hInstance,
        0);
    
      if(hwnd == NULL)
      {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
          MB_ICONEXCLAMATION | MB_OK);
        return 0;
      }
    
      ShowWindow(hwnd, nCmdShow);
      UpdateWindow(hwnd);
    
      while(GetMessage(&Msg, NULL, 0, 0) > 0)
      {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
      }
      return Msg.wParam;
    }
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  6. #6
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80
    thanz a lot Ken, but how did u make it appear ?? is it there an additional style, i couldn't find the difference, please dun tell me its just becoz u added the dimensions ? Alrite, so i got the window out, if i wan it to be moveable, but nt resizeable is it possible ?
    /* Have a nice day */

  7. #7
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    For client movement (ie. to drag the window by the client area), handle the WM_NCHITTEST message and return HTCAPTION - search this board if you need clarification as there are plenty of examples of that.

    If you want to be able to resize the window then you'll need to work out where the mouse is in relation to your window edges during WM_NCHITTEST handling and return a constant appropriate to that position.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  8. #8
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80
    So to be able to move the window i created would involve the case WM_NCHITTEST, damn, i was hoping that there were current window styles that could take care of it like like WS_MOVEABLE ? just kidding. Great thanz for your help man !
    /* Have a nice day */

Popular pages Recent additions subscribe to a feed