Button not refreshing on going different window form - winapi

I had created buttons on a dialog using resource editor(using Visual C++,X64) . On the button click event i have to show another window which is exactly of the same size and at same place (For further details i want to tell you that i have two buttons "next" and "previous" . on clicking them i have preview of "Image" and a "File" respectively). My dialog uses the handle of parent which comes from GetWindow function. See this please -
SomeClassOrFounctionNoMatterWhat::GetWindow(HWND *phwnd)
{
HRESULT hr = E_INVALIDARG;
if (phwnd)
{
*phwnd = m_hwndParent; //m_hwndParent is the parent handle now
hr = S_OK;
}
return hr;
}
So i mean the parent handle is m_hwndParent and using this handle i have created Dialog using this-
m_hwndPreview = CreateDialogParam(g_hInst
MAKEINTRESOURCE(IDD_MAINDIALOG),
m_hwndParent,
(DLGPROC)DialogProc,
(LPARAM)this);
and m_hwndPreview contains the button which i have created on the dialog IDD_MAINDIALOG.
and on button click event i am displaying the a file contents like this-
m_hwndPreview3 = CreateWindowExW(0,
MSFTEDIT_CLASS,
NULL, //This window is to display the html file.
WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_MULTILINE|ES_READONLY|WS_EX_TOPMOST,
m_rcParent.left, m_rcParent.top,
RECTWIDTH(m_rcParent),RECTHEIGHT(m_rcParent),
m_hwndPreview,
NULL,
NULL,
NULL); // similarly m_hwndPreview2 for image preview
See I am using m_hwndPreview as its parent which contains the buttons. I am doing so because i want to have buttons on my every window in order to display different contents by clicking on them.
So my problem is the buttons are created succesfully and are working properly but when i click any button it takes me on different window for the display of the file or Image. But when it takes me on different window the button disappears on the first sight and they appears only when i move mouse over them.
What should i do in order to have the button appearing on every window without moving mouse over them ?

Related

MFC: Freezing on dialog SetParent()

Note: Using SetParent freeze the parent window exists, but does NOT seem to be related to this problem as its in an entirely different framework, in a different language, and seems to be an issue with the message pump (though the message pump here could be the problem, I dont think any solution directly helps the problem I am facing here)
I am trying to create a dialog in MFC and attaching it to a parent window as a modeless dialog. My first attempt at this looks like the following:
// Add window to the segment dialog vector
m_segmentDialogs.emplace_back(std::make_unique<DlgSegmentDatum>(this));
const int tab_number = m_segmentDialogs.size() - 1;
std::string tab_text = "Segment " + std::to_string(tab_number);
m_tabSegments.InsertItem(tab_number, tab_text.c_str());
// Initialize the new dialog
auto& dlg = m_segmentDialogs.back();
dlg->Create(IDD_DIALOG_SEGMENT_DATUM, this);
CRect rc_client, rc_window;
m_tabSegments.GetClientRect(&rc_client);
m_tabSegments.AdjustRect(FALSE, &rc_client);
m_tabSegments.GetWindowRect(&rc_window);
ScreenToClient(rc_window);
rc_client.OffsetRect(rc_window.left, rc_window.top);
dlg->MoveWindow(&rc_client);
displaySegmentTab(tab_number);
This results in the child dialog spawning in the top left corner of the my screen. I assumed that this was because the child dialog didn't associate itself with the parent for some reason. To fix this, I updated the following code segment.
// Initialize the new dialog
auto& dlg = m_segmentDialogs.back();
dlg->Create(IDD_DIALOG_SEGMENT_DATUM, this);
dlg->SetParent(this);
This positions the dialog correctly, but immediately freezes the program.
When you create Dialog resource, it has WS_POPUP style by default. To make it a child of another window, it has to be WS_CHILD.
You can either fix it in your resource file (easy), or, if you use that template elsewhere as a modal dialog, modify its style at run time using ModifyStyle

MFC: How do you get CMFCToolBarComboBoxButton to show on a CMFCToolBar?

Something I thought would be easy I can't get to work. How do I get a ComboBox to show on the CMFCToolBar? Here's what I have done that doesn't work (meaning it just shows the original placeholder button with the circle (grayed out)).
1 - I added a button to the toolbar in resource editor giving it the id ID_EDIT_FIND_COMBO (I also put a circle in it just to know it's in use).
2- in CMainFrame I added ON_REGISTERED_MESSAGE(AFX_WM_RESETTOOLBAR, OnToolbarReset) to message map and the OnToolbarReset() function below:
afx_msg LRESULT CMainFrame::OnToolbarReset(WPARAM wparm, LPARAM )
{
UINT uitoolbarid = (UINT) wparm;
if (uitoolbarid == IDR_MAINFRAME) {
CMFCToolBarComboBoxButton btncombo(ID_EDIT_FIND_COMBO, GetCmdMgr()->GetCmdImage(ID_EDIT_FIND));
m_wndToolBar.ReplaceButton(ID_EDIT_FIND_COMBO, btncombo);
}
return 0;
}
The ReplaceButton() returns 1 saying it replaced it.
What am I missing?
To be clear, here's what MS says to do which is what is done above:
1 - Reserve a dummy resource ID for the button in the parent toolbar resource. For more information about how to create buttons by using the Toolbar Editor in Visual Studio, see the Toolbar Editor article.
2 - Reserve a toolbar image (button icon) for the button in all bitmaps of the parent toolbar.
3 - In the message handler that processes the AFX_WM_RESETTOOLBAR message, do the following steps:
a. Construct the button control by using a CMFCToolbarButton-derived class.
b. Replace the dummy button with the new control by using CMFCToolBar::ReplaceButton. You can construct the button object on the stack, because ReplaceButton copies the button object and maintains the copy.
TIA!!
Here's a sample project where it doesn't work. Just the button on the toolbar, not a combobox. Even took code sample from MS sample.
Sample Project
The answer is that MFC caches the toolbar so if you ever run it without the combo, once you replace the button to use the combo it still doesn't use it. You can make it pick up the change by either going to customize for the toolbars (if you have that option enabled) and choose Reset All, otherwise, you'll find under Computer\HKEY_CURRENT_USER\Software\{NameAsUsedInSetRegistryCall}\{appname}\Workspace all the cache items, of which the various MFCToolBar entries. Delete the key and run app again, then it works. Why they wouldn't make it smart and have a timestamp to know if to automactially update, not sure?

How can I get data from dialog of window?

I am a newbie in Xlib world. In my project,I want to share my window to another via Remote desktop protocol, but they only saw content of window and didn't see anything if click on menu item of window. I used XGetImage to get data of specifies window. But If that window contain dialog ( see image here) I couldn't get data of dialog .
I use freeRDP source code, I modify in X11_shadow.c
function:
int x11_shadow_screen_grab(x11ShadowSubsystem* subsystem){
...
image = XGetImage(subsystem->display, 58720435, 0, 0, surface->width,
surface->height, AllPlanes,ZPixmap); //with 58720435 is window id of chrome
... }
In my opinion, the most important here is how can I get data of dialog in Window. I have a solution :
1. get window id of that dialog ( I am not sure the dialog has owner Window ID)
2. Use XGetImage get data of that dialog.
But It's not working.
I works on Linux environment.
Are there any solutions for my problems?
Thank you very much

Creating a second child window causes the first to disappear?

I'm attempting to create both "Button" style and "Edit" style windows, so that the user can enter a string and then press the button to proceed through the application.
The button is created first:
hButton = CreateWindow(L"button",L"Label",WS_CHILD|WS_VISIBLE,100,100,
100,100,hWnd,(HMENU)BUTTON_ID,NULL,NULL);
ShowWindow(hButton,SW_SHOW);
Then, later in the application, I repaint the window, so I redisplay the button ...
ShowWindow(hButton,SW_SHOW);
... and then create the text box:
HWND hTextBox = CreateWindowEx(WS_EX_CLIENTEDGE,TEXT("Edit"),TEXT(""),
WS_CHILD|WS_VISIBLE, 500,500,500,500,hWnd,NULL,NULL,NULL);
HFONT font =CreateFont((int)24.0f,0,0,0,FW_THIN,false,false,false,
ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,L"Helvetica");
SendMessage(hTextBox,WM_SETFONT,(WPARAM)font,false);
ShowWindow(hTextBox,SW_SHOW);
Unfortunately the button never re-appears, and the text box doesn't look right (no CLIENTEDGE style, no Helvetica font, etc.) Interestingly, if I remove the text box code, the button shows up just fine after the second ShowWindow(hButton,SW_SHOW) call.
Any ideas on what my problem could be? Since both the button and the text box are child windows of hWnd, could they somehow be "interfering"?

how to create toolbars in an MFC dialog-based application

I wonder how this guy has created this toolbar on the program:
this is a modeless dialog created by the guy, I think:
but my dialog is a modal one. I don't think it makes a lot of change!
and this the code written by him to use the toolbar supplied in the res folder:
MainFrm.h
protected: // control bar embedded members
CMFCMenuBar m_wndMenuBar;
CMFCToolBar m_wndToolBar;
CMFCStatusBar m_wndStatusBar;
CMFCToolBarImages m_UserImages;
MainFrm.cpp
the code added in function:CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) to initialize the toolbar supplied in the resource:
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 : IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
CString strToolBarName;
bNameValid = strToolBarName.LoadString(IDS_TOOLBAR_STANDARD);
ASSERT(bNameValid);
m_wndToolBar.SetWindowText(strToolBarName);
CString strCustomize;
bNameValid = strCustomize.LoadString(IDS_TOOLBAR_CUSTOMIZE);
ASSERT(bNameValid);
m_wndToolBar.EnableCustomizeButton(TRUE, ID_VIEW_CUSTOMIZE, strCustomize);
// Allow user-defined toolbars operations:
InitUserToolbars(NULL, uiFirstUserToolBarId, uiLastUserToolBarId);
if (!m_wndStatusBar.Create(this))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));
// TODO: Delete these five lines if you don't want the toolbar and menubar to be dockable
m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_wndMenuBar);
DockPane(&m_wndToolBar);
// enable Visual Studio 2005 style docking window behavior
CDockingManager::SetDockingMode(DT_SMART);
// enable Visual Studio 2005 style docking window auto-hide behavior
EnableAutoHidePanes(CBRS_ALIGN_ANY);
// Enable toolbar and docking window menu replacement
EnablePaneMenu(TRUE, ID_VIEW_CUSTOMIZE, strCustomize, ID_VIEW_TOOLBAR);
// enable quick (Alt+drag) toolbar customization
CMFCToolBar::EnableQuickCustomization();
if (CMFCToolBar::GetUserImages() == NULL)
{
// load user-defined toolbar images
if (m_UserImages.Load(_T(".\\UserImages.bmp")))
{
CMFCToolBar::SetUserImages(&m_UserImages);
}
}
// enable menu personalization (most-recently used commands)
// TODO: define your own basic commands, ensuring that each pulldown menu has at least one basic command.
CList<UINT, UINT> lstBasicCommands;
lstBasicCommands.AddTail(ID_FILE_NEW);
lstBasicCommands.AddTail(ID_FILE_OPEN);
lstBasicCommands.AddTail(ID_FILE_SAVE);
lstBasicCommands.AddTail(ID_FILE_PRINT);
lstBasicCommands.AddTail(ID_APP_EXIT);
lstBasicCommands.AddTail(ID_EDIT_CUT);
lstBasicCommands.AddTail(ID_EDIT_PASTE);
lstBasicCommands.AddTail(ID_EDIT_UNDO);
lstBasicCommands.AddTail(ID_APP_ABOUT);
lstBasicCommands.AddTail(ID_VIEW_STATUS_BAR);
lstBasicCommands.AddTail(ID_VIEW_TOOLBAR);
CMFCToolBar::SetBasicCommands(lstBasicCommands);
**In fact something that I don't understand and has wasted my time two days and made me to post four questions in this site is that after making a new toolbar supply here:
and leading to the toolbar editor
1-how can I create a new toolbar button here on the toolbar that has been supplied?
2-how can I change the shape of this button to the standard 24bit depth images or to a desired icon?
at last I want to have an image like this for my toolbar in my res folder and surely I want the buttons to be seperately clickable in my program's window.
If there's a need to the source of the project, I have uploaded the guy's project here
The program with mainframe.cpp is not a modeless dialog, it is an MFC doc/view program that is designed to support a menu bar and toolbar.
A dialog-based program does not have the toolbar support designed in. The MFC sample program DLGCBR32 (in MSDN) shows how to put a toolbar on a dialog.
I think it's just a question of reading the proper documentation, create new toolbar button: see MSDN Creating a New Toolbar Button and Toolbar Editor.
Changing the image depth of the buttons in a toolbar: load the bmp file associated with the toolbar (in the Res folder) in a bitmap editor (like Paint), save as a bmp with a different image depth, load the sln in VS and rebuild the project.

Resources