Click here to Skip to main content
15,887,464 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Device Context Pin
002comp19-Dec-10 21:48
002comp19-Dec-10 21:48 
GeneralRe: Device Context Pin
Richard MacCutchan19-Dec-10 22:45
mveRichard MacCutchan19-Dec-10 22:45 
AnswerRe: Device Context Pin
bleedingfingers20-Dec-10 0:05
bleedingfingers20-Dec-10 0:05 
GeneralRe: Device Context Pin
002comp20-Dec-10 0:49
002comp20-Dec-10 0:49 
GeneralRe: Device Context Pin
Richard MacCutchan20-Dec-10 1:02
mveRichard MacCutchan20-Dec-10 1:02 
QuestionRe: Device Context Pin
bleedingfingers20-Dec-10 1:05
bleedingfingers20-Dec-10 1:05 
AnswerRe: Device Context Pin
002comp20-Dec-10 1:13
002comp20-Dec-10 1:13 
AnswerRe: Device Context Pin
pasztorpisti21-Dec-10 23:36
pasztorpisti21-Dec-10 23:36 
In win32 you can retrieve the active MDI child of a window with this:
HWND active_mdi_child = (HWND)SendMessage(hMainWnd, WM_MDIGETACTIVE, 0, 0);

In MFC you can also retrieve the active MDI child using this code:
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;

// Get the active MDI child window.
CMDIChildWnd *pChild = (CMDIChildWnd*)pFrame->GetActiveFrame();
// or CMDIChildWnd *pChild = pFrame->MDIGetActive();
// Get the active view attached to the active MDI child
// window.
CMyView *pView = (CMyView*)pChild->GetActiveView();

I just copy-pasted this from here[^].

In MFC depending on your window structure you have to draw on either pChild or pView. You can get the HWND by writing either pChild->m_hWnd or pView->m_hWnd. From now on you can use the GetDC() or GetWindowDC() to obtain a HDC to the drawable surface and you have to release it using ReleaseDC() when you are done, but this is the general win32 approach. In MFC you can use the corresponding methods of the pChild or pView objects so you don't have to mess with win32 functions and the m_hWnd member (pChild->GetDC(), pChild->ReleaseDC(...) and so on).

BUT, if you want to draw your image somewhere, then you need a control (maybe a custom control) that draws the image on its own surface every time its WndProc() is called with WM_PAINT event, otherwise your image stays there only till the next time windows asks the window to redraw a part of its surface. It would be better to put a ON_WM_PAINT() to the message map of your view and then implement the OnPaint() method in your view, this guarantees that your image is always drawn there when it is needed. In pure win32 you have to make a control that is subclassed somehow (there are many solutions to this) if order to handle its WM_PAINT event, this is a bit more difficult then just adding an entry in a message map in MFC. If you have to do this then search for "window subclassing" with google.
QuestionCToolBar Flickers Pin
janaswamy uday19-Dec-10 18:33
janaswamy uday19-Dec-10 18:33 
AnswerRe: CToolBar Flickers Pin
Roger Allen10-Jan-11 1:53
Roger Allen10-Jan-11 1:53 
GeneralRe: CToolBar Flickers Pin
janaswamy uday10-Jan-11 23:36
janaswamy uday10-Jan-11 23:36 
Questionvariable 'bool' / header stdbool.h Pin
Randy12719-Dec-10 16:30
Randy12719-Dec-10 16:30 
AnswerRe: variable 'bool' / header stdbool.h [modified] Pin
Luc Pattyn19-Dec-10 16:59
sitebuilderLuc Pattyn19-Dec-10 16:59 
GeneralRe: variable 'bool' / header stdbool.h Pin
Randy12719-Dec-10 19:38
Randy12719-Dec-10 19:38 
AnswerRe: variable 'bool' / header stdbool.h Pin
Luc Pattyn20-Dec-10 3:14
sitebuilderLuc Pattyn20-Dec-10 3:14 
AnswerRe: variable 'bool' / header stdbool.h Pin
T210219-Dec-10 19:38
T210219-Dec-10 19:38 
AnswerRe: variable 'bool' / header stdbool.h Pin
Aescleal20-Dec-10 3:55
Aescleal20-Dec-10 3:55 
QuestionWhy VC project won't run on Windows 7 Pin
ed welch19-Dec-10 10:45
ed welch19-Dec-10 10:45 
AnswerRe: Why VC project won't run on Windows 7 Pin
T210219-Dec-10 19:36
T210219-Dec-10 19:36 
GeneralRe: Why VC project won't run on Windows 7 Pin
ed welch20-Dec-10 1:31
ed welch20-Dec-10 1:31 
GeneralRe: Why VC project won't run on Windows 7 Pin
T210220-Dec-10 2:12
T210220-Dec-10 2:12 
QuestionOwner Button Width Pin
john563218-Dec-10 18:19
john563218-Dec-10 18:19 
AnswerRe: Owner Button Width Pin
Maximilien19-Dec-10 1:40
Maximilien19-Dec-10 1:40 
Question890927 - Invalid Input Format exception in sscanf_s Pin
ilostmyid218-Dec-10 1:48
professionalilostmyid218-Dec-10 1:48 
AnswerRe: 890927 - Invalid Input Format exception in sscanf_s Pin
ALLERSLIT18-Dec-10 2:59
ALLERSLIT18-Dec-10 2:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.