Hey all, Back with another Win32 question. When I paint to my window (create a background image), what happens is that everything is fine until I draw the window off the screen causing it to invalidate everything.. When dragged back onscreen, my background is redrawn but my controls are all gone until I hover over the spot where they were before.. THEN they reappear.. I need help fixing it please!! I've been trying for so long and cannot figure it out.

   hwnd = CreateWindowEx(WS_EX_TOOLWINDOW, szClassName, L"Reflector", WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, 291, 157, HWND_DESKTOP, NULL, hThisInstance, NULL);

    CreateRegion(hwnd);                  //Create a Region and Blt a bitmap to it.. AKA create Background Image.
    ShowWindow (hwnd, nCmdShow);
    UpdateWindow(hwnd);

    while (GetMessage (&messages, NULL, 0, 0))
    {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }

    return messages.wParam;
}

RECT WindowRect;
POINT Offset, CursorPos;

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT PS;

    switch (message)
    {
        case WM_CREATE:
            License = CreateWindow(L"Button", L"License", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, 26, 77, 75, 23, hwnd, (HMENU)ID_LICENSE, hInst, 0);
            WinXP = CreateWindow(L"Button", L"Win-XP", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, 195, 77, 75, 23, hwnd, (HMENU)ID_WINXP, hInst, 0);
            Injection = CreateWindow(L"Button", L"Trial", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, 26, 120, 75, 23, hwnd, (HMENU)ID_Trial, hInst, 0);
            Help = CreateWindow(L"Button", L"Help", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, 195, 120, 75, 23, hwnd, (HMENU)ID_HELP, hInst, 0);
            break;

        case WM_COMMAND:
            switch(wParam)
            {
                case ID_CLOSE:
                break;
            }
            break;

        case WM_LBUTTONDOWN:
            SetCapture(hwnd);
            GetWindowRect(hwnd, &WindowRect);
            GetCursorPos(&Offset);
            ScreenToClient(hwnd, &Offset);
            break;

        case WM_LBUTTONUP:
            ReleaseCapture();
            break;

        case WM_MOUSEMOVE:
            GetCursorPos(&CursorPos);
            if (wParam & MK_LBUTTON)    //wParam == MK_LBUTTON
            {
                MoveWindow(hwnd, CursorPos.x - Offset.x, CursorPos.y - Offset.y, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, true);
            }
            break;

        case WM_PAINT:
            BeginPaint(hwnd, &PS);
            PaintRegion();                  //Paint the Region Created.. After painting, Controls aren't redrawn :S
            EndPaint(hwnd, &PS);
            break;

        case WM_DESTROY:
            DeleteObject(hRgn);
            DeleteDC(hdcMem);
            DeleteDC(hdcDest);
            PostQuitMessage (0);
            break;

        default:
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

void PaintRegion()
{
    BitBlt(hdcDest, 0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, hdcMem, 0, 0, SRCCOPY);
}

I'm just translating my .Net code to win32API:

            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->BackColor = System::Drawing::SystemColors::ControlText;
            this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"$this.BackgroundImage")));
            this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
            this->ClientSize = System::Drawing::Size(294, 160);
            this->Controls->Add(this->Help);
            this->Controls->Add(this->Trial);
            this->Controls->Add(this->WinXP);
            this->Controls->Add(this->License);
            this->Controls->Add(this->WelcomeLabel);
            this->Controls->Add(this->Close);
            this->DoubleBuffered = true;
            this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
            this->Name = L"Form1";
            this->Opacity = 0.95;
            this->Text = L"Reflector";
            this->TransparencyKey = System::Drawing::Color::Black;


            System::Void Close_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e)
            {
                System::Drawing::Drawing2D::GraphicsPath^ GraphicsPath = gcnew System::Drawing::Drawing2D::GraphicsPath;
                System::String^ stringText = "X";
                FontFamily^ family = gcnew FontFamily("Courier New");
                int fontStyle = (int)FontStyle::Bold;
                float emSize = 15;
                Point origin(5, 5);
                StringFormat^ format = gcnew StringFormat(StringFormat::GenericDefault);
                GraphicsPath->AddString(stringText, family, fontStyle, emSize, origin, format);

                Close->Region = gcnew System::Drawing::Region(GraphicsPath);
                this->Invalidate();

                delete Region;
                delete format;
                delete family;
            }

A bit of a sledgehammer approach but try calling InvalidateRect on you controls as you paint your window e.g. InvalidateRect(License, NULL, FALSE);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.