Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

picture control(ie., rectangle)

Posted on 2004-08-02
6
Medium Priority
?
1,324 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 300 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

877 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