Solved

picture control(ie., rectangle)

Posted on 2004-08-02
6
1,303 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now