Solved

picture control(ie., rectangle)

Posted on 2004-08-02
6
1,306 Views
Last Modified: 2013-11-20
In MFC, I have a picture control(ie., rectangle). The video will be displayed there. Now, I want to change the resolution. I used the following code,

CWnd* pWnd = GetDlgItem( IDC_STATIC_PRE );
stat.SubclassDlgItem(IDC_STATIC_PRE, this);
stat.SetWindowPos(&CWnd::wndTop,1,1,40,40,SWP_DRAWFRAME|SWP_SHOWWINDOW);
CStatic stat;

But when I run the application, the static window(rectangle) disappears. Why?. What code I have to add to set the new window position?.
0
Comment
Question by:renetaprincy
6 Comments
 
LVL 13

Expert Comment

by:SteH
ID: 11693485
The code as posted above should not work. Do you meant:

CWnd* pWnd = GetDlgItem( IDC_STATIC_PRE ); // attention the return value can be temporary.
// stat.SubclassDlgItem(IDC_STATIC_PRE, this); // what is this needed for?
pWnd->SetWindowPos(&CWnd::wndTop,1,1,40,40,SWP_DRAWFRAME|SWP_SHOWWINDOW); // has no effect if pWnd is temporary.

But a more robust approach would be to use a control variable for that static frame. Open the class wizard and select the member variable tab. Here select the class and ID (IDC_STATIC_PRE) and create a variable. Here select as type control (not value). Now you cna use that member variable inside your functions to change the size and position.

m_csPre.SetWindowPos (...); // no need to find a window.
0
 
LVL 7

Accepted Solution

by:
vijay_visana earned 100 total points
ID: 11693510
Though it's not clear from your question what exacly your problem.

first line should be
CStatic* pWnd = (CStatic*)GetDlgItem( IDC_STATIC_PRE );

your declaring CStatic stat after you used it.

Please be specific about your problem and give code where you have doubt


vijay



0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11693528
CWnd* pWnd = GetDlgItem( IDC_STATIC_PRE );
stat.SubclassDlgItem(IDC_STATIC_PRE, this);
stat.SetWindowPos(&CWnd::wndTop,1,1,40,40,SWP_DRAWFRAME|SWP_SHOWWINDOW);
CStatic stat;

There are many strange things in your code:
- stat is defined (last line) AFTER using it. How this compiles?
- pWnd apparently points to your static control (first line), then, why do you apply SetWindowPos to stat intead of pWnd?
- Why do you subclass stat?
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:renetaprincy
ID: 11700787
CStatic m_csPre;
m_csPre.SetWindowPos (&CWnd::wndTop,1,1,40,40,SWP_DRAWFRAME|SWP_SHOWWINDOW);

I have selected the class and ID (IDC_STATIC_PRE) and created a variable. There I have selected as type control. Then I have used in the function. But, when I run, there is an error. Why?.


0
 
LVL 13

Expert Comment

by:SteH
ID: 11701267
What is the error? And where do you use it first? The control variable can only be used in or after OnInitDialog (assuming a dialog based app).
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11704734
CStatic m_csPre;
// Where is the m_csPre.Create(.......) ?
m_csPre.SetWindowPos (&CWnd::wndTop,1,1,40,40,SWP_DRAWFRAME|SWP_SHOWWINDOW);

CStatic m_csPre must be a member of your dialog or view object, because If you instantiate (declare) it inside a function, it will be destroyed at returning from function.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question