vc++ forms window - c++

i have created a form using visual c++. all im trying to do is this when a button is clicked the form is gone and new window will be showen. i don't know if i should repaint the window or there is another solution? please help
Rami

What I would do is display your game in the client area of the MainWindow of your app. In (possibly) Init_Instance() also call your form for the login. When the user has filled it in, just close that window and your game will already be behind it. You may need to refresh the screen afterwards so you don't get any artifacts.
Also, just noticed the "how to paint the whole thing" question.
myWindow.Invalidate();
http://msdn.microsoft.com/en-us/library/2dtwaxz7(VS.71).aspx
myWindow.InvalidateRect(LPCRECT lpRect, BOOL bErase = TRUE);
http://msdn.microsoft.com/en-us/library/62w186xw(VS.71).aspx
Do not put it in the actual paint event, OnPaint().
I'm just answering the question.
Trap the button-click event, IOW, create a function for it and close the current window. Then call / create the new window in the same event / function. You'll most likely need a class level pointer to "hold" the current window.
No offense, but this would be a fairly bad design, unless you are making a "Wizard" type of construct. That is one window closing actually should bring up the next window.

Related

C++ WinApi - Send a click from parent window to all child window, at the same position

I'm currently using the Windows API to create a Sub-Window (with CreateWindowEx) and overlay it like a popup. I'm making it so the windows are always set to the exact same size and position (you change one, it changes the other), so they should always match. I want it so when one window is clicked, it passes it to the other window.
So if you click on an element on window A, it will do what ever it bound it it, then pass it to Window B afterwards. Sorry if this question is poorly worded, it's hard to describe.

Keyboard focus: looking for a general strategy

My application has a big graphics area with some controls (sliders, buttons, text edit controls) in a side panel. The graphics area understands some keyboard commands.
My problem is that when a control in the side panel is in focus, the main graphics area won't receive any keyboard commands, so this confuses the users. However, for some controls, this is intended, e.g. text edit controls.
What I want is the focus to automatically return to the graphics area at the earliest possible occasion (which I call "greedy" focus) -- e.g. when text editing is finished (Enter key), or when the user has selected an item from a combo box.
I am looking for a clean and robust strategy for dealing with the problem, either using Windows API or Borland Vcl.
I'd appreciate if you want to share your ideas.
I haven't fully solved the problem yet, but a very useful message to intercept on form level is CM_DIALOGKEY (Borland Vcl only). It gets sent for every key that is normally used for navigating within the UI. That is, cursor keys, tab and shift-tab, Enter and possibly others.
I've added an event handler for CM_DIALOGKEY that returns the focus to the graphics area and also forwards the key press to that component. This way the user can still control the UI elements via keyboard (important for text entry), but cursor keys are handled by the graphics area.
I know what you mean I had similar problem with some BIG apps lice CAD/CAM ...
My solution is simple, robust and I use it for years.
1.all keystrokes handling for that gfx area
must be done in events of the Form where the area is located
not in panels,paint box whatever...
2.create unfocus function (preferably member of form but it is not required)
this function will loose focus of any VCL item
so the focus goes to form itself which is what you want
I am using this:
//---------------------------------------------------------------------------
void main_unfocus()
{
Main->bt_unfocus->Visible=true;
Main->bt_unfocus->SetFocus();
Main->bt_unfocus->Visible=false;
}
//---------------------------------------------------------------------------
Main is the Form pointer
bt_unfocus is button (can be any focusable VCL component)
I place this button usually on the left upper corner of App and set its size to 2x2 pixels
it is invisible at start
the idea is to set focus to it (but first unhide it so no exception is thrown)
and then hide it so it loses focus
work well in BCB5 and BDS2006 (did not used it with any other IDE)
as you can see most of the time is this component invisible
4.now when to call main_unfocus ?
when you go with mouse from outside to inside of your gfx area (OnMouseMove event)
or when you click on it
also you can combine this with remembering if the focus is or not in gfx area
that can be done with events like OnExit ...
or when you hit Esc while focus is inside edit box ...\
I am sure you grasp the idea and adjust this to your needs
Hope it helps

MFC: How does a FrameWnd know when a docked pane is resized?

I have a CFrameWndEx with several docked CDockablePanes but I can't seem to get notified when the size of the docked pane is changed (so I can resize my other windows accordingly). Tried Spy++ to check for messages, but custom draw seems to be the only one (which doesn't seem appropriate) and also tried overriding RecalcLayout, but that is not called under this circumstance. OnSize doesn't work because the size of the frame itself is not changed. Any ideas?
(Ps: I'm pretty sure it's possible because I used to have a splitter window as the 'client' area, and it would resize itself magically when the panes were resized)
OK this is a bit weird, but I had the exact same question, searched on Google, then saw that I had answered this question over a year ago but completely misunderstood what the question was about :)
Anyway for reference of future Google using people, the answer to this question is to override virtual void CFrameWndEx::EAdjustDockingLayout(HDWP hdwp) and do any resizing of client controls there. To get the client area after the hiding/closing/whatever of panes, use m_dockManager.GetClientAreaBounds(). My AdjustDockingLayout looks like this (m_View is the child window that is supposed to fill the whole client area regardless of the state of any docking panes, adjust as needed):
void CMainFrame::AdjustDockingLayout(HDWP hdwp)
{
CFrameWndEx::AdjustDockingLayout(hdwp);
if (m_View.GetSafeHwnd()) {
CRect rectUsable = m_dockManager.GetClientAreaBounds();
m_View.MoveWindow(rectUsable);
}
}
I think the issue is that the 'content' of the CFrameWndEx is itself a window, and in that window live the 'main content' windows. Check with Spy++ for the window hierarchy and if any of the child windows of the CFrameWndEx (other than the dockable panes) do get message when they are resized. Basically when docking panes are docked, the CFrameWndEx resizes its children, so you'd have to detect it there and (if required) reflect the message back to the CFrameWndEx if that's really where you need it.
Alternatively, maybe I'm misunderstanding and is what I described exactly what you're trying to do. In that case, I think there is something wrong with the way you add your window to the CFrameWndEx since that should handle the resizing itself. Is the parent of the child window set correctly to the CFrameWndEx when you create it?

effective Overlapping of dialog windows in Visual C++ 6

Hello there I have issue with overlapping of child windows,I have created a software with menu driven interface( IDR_MAINFRAME - CFormView
etc) and upon clicking one of the menu items another child-window appears( Dialog based ) where I do the calculations as a normal
calculator.Now if I open any other entry say conversion of metrics which is also in menu entry then on overlapping with any other such
window the background windows gets horribly disfigured and if i move about the calculator or the metrics conversion calculator randomly
they get disfigured and its a mess.Also I have put up a bitmap image on the background.Upon moving the calculator the background image also
gets erased.
Please let me know about how to handle this issue.I have googled and found that handling of paint messages or WM_ERASEBKGND helps ..but I
have tried this piece of code which just doesn't help in OnEraseBkGnd();
BOOL COfficesoftDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CRect Rect;
GetClientRect(Rect);
//ClientToScreen(&Rect);
//this->ScreenToClient(&Rect);
this->InvalidateRect(Rect);
return CDialog::OnEraseBkgnd(pDC);
}
how can i achieve the smooth overlapping of different windows like a notepad overlapping a word document or even a calculator or even a VC6
IDE in my project.
Please explain it with an example .I am just a newbie and I need to understand in detail...thanks and regards
Override OnEraseBkgnd and return true so it stops erasing the background you're painting. Returning TRUE says that you've done the work. If you simply call the base class implementation, it's going to do this for you, and you'll lose the background until it gets a chance to paint.
You're not getting paint messages to the parent window for some reason. Make sure you're calling the modal in the correct manner. DoModal() works fine. Make sure you're not just creating the modal and showing it.
If your windows are children on the same dialog/window and they overlap or you have children on either dialog/window, make sure that you use clipchildren and clipsiblings (if children on a window overlap). Otherwise they'll get to paint in any order they choose artifacting all over the place.
Ensure that you're painting to memory and bitblting back to your dialog, otherwise you'll get a flashing effect.

How to add statusbar correctly?

Currently it is floating on top of my rendered window, i dont think thats good for few reasons:
1) i waste rendering time for rendering stuff that isnt visible.
2) it must be rendered every frame again when i wouldnt be updating the whole statusbar every frame anyways.
So how i could create a window where it leaves space for my statusbar and none of my OpenGL stuff could be rendered in that area?
At this moment i just adjust my viewports in a way that creates empty space for statusbar, but it causes some problems in my current way of doing things. i would have to make my code look much more messier to make it work.
http://www.gamedev.net/community/forums/topic.asp?topic_id=291682
Edit: Its not a simple question to answer. If you don't know what a child window is under Win32 then you may be in a much better position. However asking someone to give you a full explanation of the windows windowing system is no mean feat.
Here is an overview:
Basically you need to create a child window which can be done using CreateWindow to create a window with the WS_CHILD style and with its hWndParent parameter set to the window handle you want the new window to be a child of.
When you created the window you will have, necessarily, create a window procedure When you call DispatchMessage from your message pump (The Loop that does a Get/PeekMessage and then dispatches the messages is the message pump). Inside the window procedure you can then switch on the message type and handle each message sent to your window.
From here you can handle things like setup. Your initial window will have either a WM_CREATE or a WM_INITDIALOG (Depending on what type of window you create). It is from there that you need to create the child windows (Don't forget to call ShowWindow to make them visible!!). From this point you can then set up the DirectX device to be attached to the child window handle (HWND).
Furthermore if you want to be able to re-size the window then you ALSO need to take into account the WM_SIZE mesage. However I'd strongly recommend trying to get the rest working before even beginning to look into this as it gets very complicated as you will need to destroy and re-create your DirectX device so that it is the right size.
Anyway thats just a simple overview. I hope it helps!
One way may be to make your "rendered window" and "statusbar" both children of a containing window, and to add some code for the WM_SIZE message for that containing window to position the children so they don't overlap.