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;
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
add a comment |
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
add a comment |
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
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
c++ user-interface mfc
asked Mar 21 at 18:41
Sero MirzakhanyanSero Mirzakhanyan
344
344
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
edited Mar 21 at 23:20
answered Mar 21 at 23:08
Constantine GeorgiouConstantine Georgiou
762410
762410
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Mar 22 at 14:23
answered Mar 21 at 18:57
Staytuned123Staytuned123
195
195
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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