Solved

picture control(ie., rectangle)

Posted on 2004-08-02
6
1,310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: 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!

 

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

Industry Leaders: 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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.

738 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