MFC window graphic is gone after minimizing/maximizingHow do I remove minimize and maximize from a resizable window in WPF?MFC maximize window featureAPI-level Unicode GUI Native apps in C++ for Windows/Linux/MacMFC window maximized, but to wrong top coordinateDrawing will be cleared after minimizing window vc++ mfcHow to maximize a window after minimizing itMFC: how to minimize window on button click?MFC draw new at maximized windowMinimize and restore window using Send Messages in MFCWindows freezes after trying to render triangle in directx11

What defenses are there against being summoned by the Gate spell?

String Manipulation Interpreter

tikz: show 0 at the axis origin

How to write a macro that is braces sensitive?

Why Is Death Allowed In the Matrix?

Is it legal for company to use my work email to pretend I still work there?

What do three bars across the stem of a note mean?

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?

How to find program name(s) of an installed package?

Approximately how much travel time was saved by the opening of the Suez Canal in 1869?

Mage Armor with Defense fighting style (for Adventurers League bladeslinger)

Test whether all array elements are factors of a number

How can bays and straits be determined in a procedurally generated map?

How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?

What is the word for reserving something for yourself before others do?

Today is the Center

What do "features" mean/refer to in this sentence?

How do I create uniquely male characters?

Is it important to consider tone, melody, and musical form while writing a song?

Email Account under attack (really) - anything I can do?

What are the differences between the usage of 'it' and 'they'?

Fencing style for blades that can attack from a distance

Modeling an IP Address



MFC window graphic is gone after minimizing/maximizing


How do I remove minimize and maximize from a resizable window in WPF?MFC maximize window featureAPI-level Unicode GUI Native apps in C++ for Windows/Linux/MacMFC window maximized, but to wrong top coordinateDrawing will be cleared after minimizing window vc++ mfcHow to maximize a window after minimizing itMFC: how to minimize window on button click?MFC draw new at maximized windowMinimize and restore window using Send Messages in MFCWindows freezes after trying to render triangle in directx11






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am trying to create a Windows window and a graphic inside it using MFC, but after minimizing or maximizing the window the graphic is gone. Is there a way so that the graphic will still be up after minimizing or maximizing?



This is the code i wrote.



#include"Header.h"
#include <iostream>
using namespace std;
int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE,
LPSTR lpstr, int ncmdshow)
CS_VREDRAW;
RegisterClassEx(&wnd);

HWND hwnd = CreateWindow(TEXT("mywn"),
TEXT("mywn2"),
WS_OVERLAPPEDWINDOW,
50, 50, 300, 500,
NULL,
NULL,
hinstance,
0);

ShowWindow(hwnd, SW_SHOWNORMAL);

UpdateWindow(hwnd);

MSG msg;
while (GetMessage(&msg, NULL, 0, 0))

TranslateMessage(&msg);
DispatchMessage(&msg);



return 0;



LRESULT CALLBACK Mywndproc(HWND hwnd, UINT imessage, WPARAM
wparam, LPARAM lparam)



HDC hdc;
int x = LOWORD(lparam);
int y = HIWORD(lparam);
int cmd = LOWORD(wparam);


HBRUSH hbrush = CreateSolidBrush(RGB(125, 60, 250));
HBRUSH hbrush1 = CreateSolidBrush(RGB(255, 0, 0));
HPEN hpen = CreatePen(PS_DASH, 30, RGB(0, 50, 256));
PAINTSTRUCT ps;
switch (imessage)

case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:
hdc = GetDC(hwnd);
TextOut(hdc, x, y, TEXT("Name"), strlen("Name"));


DeleteDC(hdc);
break;
case WM_MOUSEMOVE:
hdc = GetDC(hwnd);
if (cmd == MK_LBUTTON)
SelectObject(hdc, hbrush1);

Ellipse(hdc, x, y, x + 100, y + 120);


else if (cmd == MK_RBUTTON)
TextOut(hdc, x, y, TEXT("Erevan"), strlen("Erevan"));




DeleteDC(hdc);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);

TextOut(hdc, 100, 100, TEXT("Text"), strlen("Text"));


EndPaint(hwnd, &ps);


break;


case WM_RBUTTONDOWN:

hdc = GetDC(hwnd);
SelectObject(hdc, hbrush1);

Ellipse(hdc, x, y, x + 100, y + 120);

EndPaint(hwnd, &ps);


DeleteDC(hdc);
break;
default:
return DefWindowProc(hwnd, imessage, wparam, lparam);


return 0;











share|improve this question




























    0















    I am trying to create a Windows window and a graphic inside it using MFC, but after minimizing or maximizing the window the graphic is gone. Is there a way so that the graphic will still be up after minimizing or maximizing?



    This is the code i wrote.



    #include"Header.h"
    #include <iostream>
    using namespace std;
    int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE,
    LPSTR lpstr, int ncmdshow)
    CS_VREDRAW;
    RegisterClassEx(&wnd);

    HWND hwnd = CreateWindow(TEXT("mywn"),
    TEXT("mywn2"),
    WS_OVERLAPPEDWINDOW,
    50, 50, 300, 500,
    NULL,
    NULL,
    hinstance,
    0);

    ShowWindow(hwnd, SW_SHOWNORMAL);

    UpdateWindow(hwnd);

    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))

    TranslateMessage(&msg);
    DispatchMessage(&msg);



    return 0;



    LRESULT CALLBACK Mywndproc(HWND hwnd, UINT imessage, WPARAM
    wparam, LPARAM lparam)



    HDC hdc;
    int x = LOWORD(lparam);
    int y = HIWORD(lparam);
    int cmd = LOWORD(wparam);


    HBRUSH hbrush = CreateSolidBrush(RGB(125, 60, 250));
    HBRUSH hbrush1 = CreateSolidBrush(RGB(255, 0, 0));
    HPEN hpen = CreatePen(PS_DASH, 30, RGB(0, 50, 256));
    PAINTSTRUCT ps;
    switch (imessage)

    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    case WM_LBUTTONDOWN:
    hdc = GetDC(hwnd);
    TextOut(hdc, x, y, TEXT("Name"), strlen("Name"));


    DeleteDC(hdc);
    break;
    case WM_MOUSEMOVE:
    hdc = GetDC(hwnd);
    if (cmd == MK_LBUTTON)
    SelectObject(hdc, hbrush1);

    Ellipse(hdc, x, y, x + 100, y + 120);


    else if (cmd == MK_RBUTTON)
    TextOut(hdc, x, y, TEXT("Erevan"), strlen("Erevan"));




    DeleteDC(hdc);
    break;
    case WM_PAINT:
    hdc = BeginPaint(hwnd, &ps);

    TextOut(hdc, 100, 100, TEXT("Text"), strlen("Text"));


    EndPaint(hwnd, &ps);


    break;


    case WM_RBUTTONDOWN:

    hdc = GetDC(hwnd);
    SelectObject(hdc, hbrush1);

    Ellipse(hdc, x, y, x + 100, y + 120);

    EndPaint(hwnd, &ps);


    DeleteDC(hdc);
    break;
    default:
    return DefWindowProc(hwnd, imessage, wparam, lparam);


    return 0;











    share|improve this question
























      0












      0








      0








      I am trying to create a Windows window and a graphic inside it using MFC, but after minimizing or maximizing the window the graphic is gone. Is there a way so that the graphic will still be up after minimizing or maximizing?



      This is the code i wrote.



      #include"Header.h"
      #include <iostream>
      using namespace std;
      int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE,
      LPSTR lpstr, int ncmdshow)
      CS_VREDRAW;
      RegisterClassEx(&wnd);

      HWND hwnd = CreateWindow(TEXT("mywn"),
      TEXT("mywn2"),
      WS_OVERLAPPEDWINDOW,
      50, 50, 300, 500,
      NULL,
      NULL,
      hinstance,
      0);

      ShowWindow(hwnd, SW_SHOWNORMAL);

      UpdateWindow(hwnd);

      MSG msg;
      while (GetMessage(&msg, NULL, 0, 0))

      TranslateMessage(&msg);
      DispatchMessage(&msg);



      return 0;



      LRESULT CALLBACK Mywndproc(HWND hwnd, UINT imessage, WPARAM
      wparam, LPARAM lparam)



      HDC hdc;
      int x = LOWORD(lparam);
      int y = HIWORD(lparam);
      int cmd = LOWORD(wparam);


      HBRUSH hbrush = CreateSolidBrush(RGB(125, 60, 250));
      HBRUSH hbrush1 = CreateSolidBrush(RGB(255, 0, 0));
      HPEN hpen = CreatePen(PS_DASH, 30, RGB(0, 50, 256));
      PAINTSTRUCT ps;
      switch (imessage)

      case WM_DESTROY:
      PostQuitMessage(0);
      break;
      case WM_LBUTTONDOWN:
      hdc = GetDC(hwnd);
      TextOut(hdc, x, y, TEXT("Name"), strlen("Name"));


      DeleteDC(hdc);
      break;
      case WM_MOUSEMOVE:
      hdc = GetDC(hwnd);
      if (cmd == MK_LBUTTON)
      SelectObject(hdc, hbrush1);

      Ellipse(hdc, x, y, x + 100, y + 120);


      else if (cmd == MK_RBUTTON)
      TextOut(hdc, x, y, TEXT("Erevan"), strlen("Erevan"));




      DeleteDC(hdc);
      break;
      case WM_PAINT:
      hdc = BeginPaint(hwnd, &ps);

      TextOut(hdc, 100, 100, TEXT("Text"), strlen("Text"));


      EndPaint(hwnd, &ps);


      break;


      case WM_RBUTTONDOWN:

      hdc = GetDC(hwnd);
      SelectObject(hdc, hbrush1);

      Ellipse(hdc, x, y, x + 100, y + 120);

      EndPaint(hwnd, &ps);


      DeleteDC(hdc);
      break;
      default:
      return DefWindowProc(hwnd, imessage, wparam, lparam);


      return 0;











      share|improve this question














      I am trying to create a Windows window and a graphic inside it using MFC, but after minimizing or maximizing the window the graphic is gone. Is there a way so that the graphic will still be up after minimizing or maximizing?



      This is the code i wrote.



      #include"Header.h"
      #include <iostream>
      using namespace std;
      int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE,
      LPSTR lpstr, int ncmdshow)
      CS_VREDRAW;
      RegisterClassEx(&wnd);

      HWND hwnd = CreateWindow(TEXT("mywn"),
      TEXT("mywn2"),
      WS_OVERLAPPEDWINDOW,
      50, 50, 300, 500,
      NULL,
      NULL,
      hinstance,
      0);

      ShowWindow(hwnd, SW_SHOWNORMAL);

      UpdateWindow(hwnd);

      MSG msg;
      while (GetMessage(&msg, NULL, 0, 0))

      TranslateMessage(&msg);
      DispatchMessage(&msg);



      return 0;



      LRESULT CALLBACK Mywndproc(HWND hwnd, UINT imessage, WPARAM
      wparam, LPARAM lparam)



      HDC hdc;
      int x = LOWORD(lparam);
      int y = HIWORD(lparam);
      int cmd = LOWORD(wparam);


      HBRUSH hbrush = CreateSolidBrush(RGB(125, 60, 250));
      HBRUSH hbrush1 = CreateSolidBrush(RGB(255, 0, 0));
      HPEN hpen = CreatePen(PS_DASH, 30, RGB(0, 50, 256));
      PAINTSTRUCT ps;
      switch (imessage)

      case WM_DESTROY:
      PostQuitMessage(0);
      break;
      case WM_LBUTTONDOWN:
      hdc = GetDC(hwnd);
      TextOut(hdc, x, y, TEXT("Name"), strlen("Name"));


      DeleteDC(hdc);
      break;
      case WM_MOUSEMOVE:
      hdc = GetDC(hwnd);
      if (cmd == MK_LBUTTON)
      SelectObject(hdc, hbrush1);

      Ellipse(hdc, x, y, x + 100, y + 120);


      else if (cmd == MK_RBUTTON)
      TextOut(hdc, x, y, TEXT("Erevan"), strlen("Erevan"));




      DeleteDC(hdc);
      break;
      case WM_PAINT:
      hdc = BeginPaint(hwnd, &ps);

      TextOut(hdc, 100, 100, TEXT("Text"), strlen("Text"));


      EndPaint(hwnd, &ps);


      break;


      case WM_RBUTTONDOWN:

      hdc = GetDC(hwnd);
      SelectObject(hdc, hbrush1);

      Ellipse(hdc, x, y, x + 100, y + 120);

      EndPaint(hwnd, &ps);


      DeleteDC(hdc);
      break;
      default:
      return DefWindowProc(hwnd, imessage, wparam, lparam);


      return 0;








      c++ user-interface mfc






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 21 at 18:41









      Sero MirzakhanyanSero Mirzakhanyan

      344




      344






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Drawing outside of processing of the WM_PAINT message is absolutely OK:



          Painting and Drawing



          You should call ReleaseDC() rather than DeleteDC() to return a HDC you got by calling GetDC().



          Also, resources you select into a HDC must be selected out before releasing or destroying it.



          However, a WM_PAINT message may indeed be received as a result of "invalidating" a part or all of the client area, due to moving, resizing, unhiding etc the window. So in response to a WM_PAINT message you should perform a full repaint, ie all the items you want to be displayed.






          share|improve this answer
































            0














            Do all your drawing in WM_PAINT, not WM_LBUTTONDOWN, WM_MOUSEMOVE, and WM_RBUTTONDOWN. Save what you want to draw in WM_LBUTTONDOWN, WM_MOUSEMOVE, and WM_RBUTTONDOWN and call Invalidate() to send a WM_PAINT message to draw them. Your drawing will be up all the time.






            share|improve this answer

























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55287210%2fmfc-window-graphic-is-gone-after-minimizing-maximizing%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              Drawing outside of processing of the WM_PAINT message is absolutely OK:



              Painting and Drawing



              You should call ReleaseDC() rather than DeleteDC() to return a HDC you got by calling GetDC().



              Also, resources you select into a HDC must be selected out before releasing or destroying it.



              However, a WM_PAINT message may indeed be received as a result of "invalidating" a part or all of the client area, due to moving, resizing, unhiding etc the window. So in response to a WM_PAINT message you should perform a full repaint, ie all the items you want to be displayed.






              share|improve this answer





























                1














                Drawing outside of processing of the WM_PAINT message is absolutely OK:



                Painting and Drawing



                You should call ReleaseDC() rather than DeleteDC() to return a HDC you got by calling GetDC().



                Also, resources you select into a HDC must be selected out before releasing or destroying it.



                However, a WM_PAINT message may indeed be received as a result of "invalidating" a part or all of the client area, due to moving, resizing, unhiding etc the window. So in response to a WM_PAINT message you should perform a full repaint, ie all the items you want to be displayed.






                share|improve this answer



























                  1












                  1








                  1







                  Drawing outside of processing of the WM_PAINT message is absolutely OK:



                  Painting and Drawing



                  You should call ReleaseDC() rather than DeleteDC() to return a HDC you got by calling GetDC().



                  Also, resources you select into a HDC must be selected out before releasing or destroying it.



                  However, a WM_PAINT message may indeed be received as a result of "invalidating" a part or all of the client area, due to moving, resizing, unhiding etc the window. So in response to a WM_PAINT message you should perform a full repaint, ie all the items you want to be displayed.






                  share|improve this answer















                  Drawing outside of processing of the WM_PAINT message is absolutely OK:



                  Painting and Drawing



                  You should call ReleaseDC() rather than DeleteDC() to return a HDC you got by calling GetDC().



                  Also, resources you select into a HDC must be selected out before releasing or destroying it.



                  However, a WM_PAINT message may indeed be received as a result of "invalidating" a part or all of the client area, due to moving, resizing, unhiding etc the window. So in response to a WM_PAINT message you should perform a full repaint, ie all the items you want to be displayed.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 21 at 23:20

























                  answered Mar 21 at 23:08









                  Constantine GeorgiouConstantine Georgiou

                  762410




                  762410























                      0














                      Do all your drawing in WM_PAINT, not WM_LBUTTONDOWN, WM_MOUSEMOVE, and WM_RBUTTONDOWN. Save what you want to draw in WM_LBUTTONDOWN, WM_MOUSEMOVE, and WM_RBUTTONDOWN and call Invalidate() to send a WM_PAINT message to draw them. Your drawing will be up all the time.






                      share|improve this answer





























                        0














                        Do all your drawing in WM_PAINT, not WM_LBUTTONDOWN, WM_MOUSEMOVE, and WM_RBUTTONDOWN. Save what you want to draw in WM_LBUTTONDOWN, WM_MOUSEMOVE, and WM_RBUTTONDOWN and call Invalidate() to send a WM_PAINT message to draw them. Your drawing will be up all the time.






                        share|improve this answer



























                          0












                          0








                          0







                          Do all your drawing in WM_PAINT, not WM_LBUTTONDOWN, WM_MOUSEMOVE, and WM_RBUTTONDOWN. Save what you want to draw in WM_LBUTTONDOWN, WM_MOUSEMOVE, and WM_RBUTTONDOWN and call Invalidate() to send a WM_PAINT message to draw them. Your drawing will be up all the time.






                          share|improve this answer















                          Do all your drawing in WM_PAINT, not WM_LBUTTONDOWN, WM_MOUSEMOVE, and WM_RBUTTONDOWN. Save what you want to draw in WM_LBUTTONDOWN, WM_MOUSEMOVE, and WM_RBUTTONDOWN and call Invalidate() to send a WM_PAINT message to draw them. Your drawing will be up all the time.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 22 at 14:23

























                          answered Mar 21 at 18:57









                          Staytuned123Staytuned123

                          195




                          195



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55287210%2fmfc-window-graphic-is-gone-after-minimizing-maximizing%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                              용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                              155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해