Re: display array in a frame wnd



See below...
On Wed, 5 Sep 2007 22:20:48 +0200, "J-F Portala" <jfportala@xxxxxxx> wrote:

Thank you Joseph for your help.

"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> a écrit dans le message de
news: 24otd3t718oaqcts5oi46fnd7fob0eii2i@xxxxxxxxxx
First, you have to create an app that is suitable for displaying an image.
There are
several options:

A CDialog-based app, with a CStatic control in which the image is
displayed

An SDI app, where the image is displayed in the view.
In general, I use single document without document view architecture.
****
This is almost certainly a mistake. This is a CLEAR application of doc/view architecture!
****

An MDI app, where the image is displayed in the view.

The details differ slightly in how you do this, but ultimately, there is
an OnPaint
handler for the subclassed CStatic in the dialog or an OnDraw handler for
the
CView-derived class in your SDI or MDI app. All your drawing logic
belongs in the
OnPaint/OnDraw handler.

There would never be a need to create a frame window; it is not at all
clear why such code
would be written. Such code is automatically generated by the AppWizard.
But I need several windows (2,3 or 10).
Some of them can be with special menu and status bar.
When I move with the mouse on a window, in the status bar,
I want to show location of the mouse in the image and value of pixel at this
point.
****
So use the AppWizard to create a standard SDI app! You get the status bar, free. Then
follow the instructions in the Scribble tutorial on how to add mouse tracking (add a new
control ID such as ID_MOUSE_COORDINATES, add it to the status bar, create a dummy status
bar string (0000,0000) which is the maximum length of the string you can format; this is
well-documented)
****

There is no reason to do a DestroyWindow, or create a new window, to do
the display; the
window is already there. An approach which does not make this assumption
is probably the
wrong approach.
When a window corresponding to a image result is no more usefull, I thik it
is better to desetroy it.

In an SDI app or MDI app there is already a status bar, menus, and
toolbars. There is an
MSDN article on how to add toolbars and status bars to a dialog-based app,
but for this
project, it strikes me that an SDI or MDI app would be the correct choice.
Since all the
"future enhancements" you think you want are already present, and cost you
zero effort,
there is no reason to take some macho I-have-to-write-everything-myself
approach.

I did not have enough time free to do that, that is the reason why I want to
be sure to make the
good choice.
I better prefered to reuse display provided with the librairy opencv, but I
can obtain handle of the window.
but when I attach it to a CWnd (with FromHandle), the window does not react
to ShowWindow(SW_SHOW) or CreateStatusBar.
****
The library clearly suffers from serious design issues. It should not be creating
windows. It should be handed the handle of the window it is supposed to use. If you
start with components that have defective designs, creating a robust application from them
is difficult.
****
cvNamedWindow("test",0) ; // window is created
cvShowImage("test",pImg) ; // window is displayed with the array pImg
// just two lines to create and display the image
cvSetMouseCallBack("test",on_mouse,this) ; // permits to define a static
function on_mouse where it is possible to catch mouse events

The creation of window does not use MFC, but I was thinking it was possible
to create a MFC window starting from HWND
****
I fail to see why any library, MFC or not, would be creating a window, when this is
probably a very poor approach to the problem.
****
// the following is what I have tried
hWnd = (HWND) cvGetWindowHandle("test") ; // handle of the window
pWnd = FromHandle(hWnd) ;// attach to a CWnd
pStatusBar->Create(pWnd) ;
****
Having attached the window, calling Create makes no sense, since that will try to create a
window where one is already created. This code is flat-out wrong. Either you have an
HWND (even though this is bad design) and therefore you don't need to do any creation, or
you don't have a window, in which case this code cannot possibly function. In either
case, it is wrong
****

but when I want to create a CStatusBar, it displays nothing in the window.
pWnd->ShowWindow(SW_HIDE) does not work too.
So I can't attach a menu too.
****
You would not put a status bar in the window. You would not put a menu in the window. The
window in which the image is drawn needs to be a child of some window, and if the library
does not allow you to specify the parent, and create a child, the library is even worse
than I could have imagined. There are many problems with using defective libraries, and
you clearly have one, so it is hard to figure out how to work around its fundamental
flaws.
****


Such an
attitude is counterproductive, and not even sensible. I think the
fundamental failure you
have made here is in not using the correct tools to create an app, instead
thinking you
have a chance of doing this from scratch. Such an approach is usually
doomed; very few
MFC programmers would adopt such an approach, and the ones who do are
usually very
sophisticated MFC programmers. This is *never* a viable approach for a
beginner, no
matter what bizarre book you are using that suggests it could possibly
make sense. It is
just an inappropriate approach, and should be instantly scrapped.

I think I have a big lack in how displaying a bitmap. I have never worked
with document view architecture,
because I think it is not adapted to my applications.
I always created projects in Single Document without document/view
architecture.
****
This application is CLEARLY a doc/view problem, so I think you are not understanding what
a document/view architecture does, or how to use it. By ignoring this powerful
architecture, you are making your life a good deal more miserable than it needs to be.
Those tools are there for a reason, and they are worth learning.

I suggest spending some time working with the Scribble tutorial. It will take a few days,
but the payoff willl be immense.

I cannot recall the last time I actually created an SDI app for any purpose (other than
teaching a course), since they are so useless. The few times I ever did one, the client
immediately decided they wanted MDI, so now my apps are either MDI or dialog-based.
joe
****

So start over. Create either an MDI or SDI app, copy code across, make
sure ALL drawing
is done in the OnDraw handler of the CView-derived class. There is no
need to create new
windows, so the approach that requires creating and destroying windows
should be
abandoned.
joe


Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: display array in a frame wnd
    ... you have to create an app that is suitable for displaying an image. ... There would never be a need to create a frame window; it is not at all clear why such code ... I have to display results. ... Why is this not in an OnPaint handler? ...
    (microsoft.public.vc.mfc)
  • Re: Layered Windows in VMWare and Terminal Services
    ... I know that the display change is causing a repaint (a couple or three, ... to function in the app for the lifetime of the app. ... I used Spy++ to get all the messages sent to the window during a mode change ... the VGA display driver and you change, ...
    (microsoft.public.win32.programmer.gdi)
  • Re: display array in a frame wnd
    ... An SDI app, where the image is displayed in the view. ... There would never be a need to create a frame window; ... I better prefered to reuse display provided with the librairy opencv, ...
    (microsoft.public.vc.mfc)
  • Re: Popup window blocking in XP Service Pack 2
    ... > I have a web app that has a legitimate use for pop up windows. ... > I also use it later to display a pdf application form. ... If I display it in the main window then I would have to ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Detecting system shutdown in a spawned Win98 MFC Console app?
    ... >> a hidden MFC Console app that does some network stuff inside a while ... >> is set by the main SDI app. ... Then this handle is set the console app ... The first thing I did was add a hidden window the ...
    (microsoft.public.vc.mfc)