CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2020

    Creating a windows with WS_POPUP style.

    I'm implementing a simple program displaying an image on the screen using `GDI+` `WinAPI`.

    Here is the code I have so far:

        #include <windows.h>
        #include <objidl.h>
        #include <gdiplus.h>
        using namespace Gdiplus;
        #pragma comment (lib, "Gdiplus.lib")
        void Example_DrawImage9(HDC hdc) {
          Graphics graphics(hdc);
          Image image(L"C:/test.bmp");
          graphics.DrawImage(&image, 0, 0);
        LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
        int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR pCmdLine, int nCmdShow) {
          ULONG_PTR token;
          GdiplusStartupInput input = { 0 };
          input.GdiplusVersion = 1;
          GdiplusStartup(&token, &input, NULL);
          const wchar_t CLASS_NAME[] = L"Sample Window Class";
          WNDCLASS wc = {};
          wc.lpfnWndProc = &WindowProc;
          wc.hInstance = hInstance; 
          wc.lpszClassName = CLASS_NAME;
          HWND hwnd = CreateWindowEx(0, CLASS_NAME, L"Learn to Program Windows", WS_POPUP, 0, 0, 190, 110, NULL, NULL, hInstance, NULL);
          if (hwnd != NULL) {
            ShowWindow(hwnd, nCmdShow);
            MSG msg;
            while (GetMessage(&msg, NULL, 0, 0) > 0)
          return 0;
        LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
          switch (uMsg)
          case WM_DESTROY:
            return 0;
          case WM_PAINT: {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hwnd, &ps);
            FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
            EndPaint(hwnd, &ps);
            return 0;
          return DefWindowProc(hwnd, uMsg, wParam, lParam);
    Because I'd like to show only the image itself (no Non-Client-Area) i'm using the `WS_POPUP` style for the created window.
    But there is apparently sth. wrong with the window - when i move the mouse over the app window i get "loading/busy" (animating blue circle). Moreover i cant' move the window. When i change the style to for example `WS_CAPTION` all is OK - the mouse cursor is "normal" (just arrow as usually) and i can move/drag the window. How can i use the `WS_POPUP` style without this bizarre side effects I've described?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    Re: Creating a windows with WS_POPUP style.

    [Moved from Visual C++ Programming forum]
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width