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"?
Related
When cursor honver over the title zone (HTCAPTION),press left mouse button, then you can drag a window and move it. When you release the left mouse button , you can stop this dragging action. When you move a window , it triggered the message WM_MOVE. When release the mouse button , I don't know which message should be handled for catching this action.
What I'm doing is when you drag a window(let's say window A) into another window's area(window B), make window A a child window of window B, when drag window A out of window B's area , make window A a WS_POPUP window, without WS_CHILD style.
I handled message WM_MOVE and WM_CAPTURECHANGED( I don't think it's the right one).
In WM_CAPTURECHANGED , I found something wired. The API SetWindowPos seemed not work well. To be percise, the 3rd and the 4th parmater , specified the window's position not work.
case WM_CAPTURECHANGED: {
RECT rcc;
GetClientRect(main,&rcc);
// here main is the handler of window B , hwnd is for window A,as referrence above.
if(docker_mode==DOCKER_LEFT) {
// docker_mode is assigned by WM_MOVE message handler. recording which area window A was moved into.
if((WS_CHILD&GetWindowLongPtr(hwnd,GWL_STYLE))!=WS_CHILD) {
SetWindowLongPtr(hwnd,GWL_STYLE,(~WS_POPUP)&(WS_CHILD|GetWindowLongPtr(hwnd,GWL_STYLE)));
SetParent(hwnd,main);
}
//The following code not work. It should be moved into the left-top corner of window B,
//but NOT in fact.
SetWindowPos(hwnd,NULL,0,0,300,rcc.bottom-rcc.top,SWP_NOZORDER);
}
else {
if((WS_CHILD&GetWindowLongPtr(hwnd,GWL_STYLE))==WS_CHILD) {
SetWindowLongPtr(hwnd,GWL_STYLE,((~WS_CHILD)&GetWindowLongPtr(hwnd,GWL_STYLE))|WS_POPUP);
SetParent(hwnd,NULL);
SetWindowPos(hwnd,NULL,300,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);
}
}
} break;
SetWindowLongPtr(...,GWL_STYLE,...) was called to set the window style . A top level has no WS_CHILD style, and the handle of parent window should be NULL , I use SetParent(hwnd,NULL) to do this. A child window should have WS_CHILD style, and the parent window should be assigned.
I put a button into the window , and copy those code into the handle of button click event. When click the button it works well , change a popup window into a sub window , put the sub window into right position. SetWindowPos has no problem at all. I don't know why.
SetWindowPos is a very interesting API when working on WM_CAPTURECHANGED handler. What's wrong ?
If I recall correctly, when the user drags a window, that window receives a sequence of messages like this:
WM_ENTERSIZEMOVE
WM_WINDOWPOSCHANGING
WM_MOVING
WM_WINDOWPOSCHANGED
WM_MOVE
WM_EXITSIZEMOVE
(There are other messages, too, but I don't think you need to worry about those. There may be some final messages after WM_EXITSIZEMOVE with the final resting place for the window.)
The steps in the middle will happen repeatedly as the user drags the window. (In the Old Days, only some of those middle steps would happen, and there may still be an option to cut down on the messages during the drag operation.)
You can try using Spy++ (included with Visual Studio) to confirm the above.
So you shouldn't need to deal with the mouse capture messages. Have window A watch for WM_EXITSIZEMOVE. At that point, window A can check its position to see if it overlaps the target window (B). If it does overlap, then it should send a message to window B to initiate the docking operation.
I have the AutoHotKey EnterPad Keyboard/Pad with 120 Programmable Keys
It works by sending a Hotkey press for each key to an AutoHotKey script which has a Label function for each key named 001 through 120
Below is my AHK Label function called when key 115 is pressed.
My code allows me to select rows in any Windows Listview component and it will show a popup GUI window with a textbox filled in with the data from the selected rows with each column separated with a TAB space. I can then copy or save it or view it whatever I like.
;---------------------------------------------------------------------115-----
; Copy Selected Windows Listview Items to Tab Spaced Text - Show popup Window Gui
; https://superuser.com/questions/814831/copy-to-clipboard-from-table-list-in-a-program-on-windows
115:
Gui, SelectedListRowsTextGui:Destroy
MouseGetPos, , , , ListView_hwnd, 2 ;2 means return HWND
ControlGet, selected_row_text, List, Selected, , ahk_id %ListView_hwnd%
Gui, SelectedListRowsTextGui: +ToolWindow +AlwaysOnTop -Caption
Gui, SelectedListRowsTextGui:Add, Edit, vUnused_variable x11 y15 w950 h66, %selected_row_text%
Gui, SelectedListRowsTextGui:Add, Button, x62 y84 w140 h30 +Center, Close
Gui, SelectedListRowsTextGui:Show, ,
return
ButtonClose:
Gui, SelectedListRowsTextGui:Destroy
return
Return
Problem
My issue is that once the popup window is opened from my AHK GUI, my CloseButton label dose not get called when I click the close button.
I realize it likely has something to do with it being nested under the key 115s label function. How can I best achieve the desired result?
I tried moving the CloseButton label outside of the 115 label however it still is not called from the GUI's Close button click.
You can see I have named the GUI SelectedListRowsTextGui this is to allow this Enterpad.ahk script to contain many GUI windows for different actions it will perform.
Preview of the GUI window this script creates when listview items are selected and this Label function is called:
I got it now....
Since my GUI is named SelectedListRowsTextGui I had to add that name in front of my CloseButton label name so it is now SelectedListRowsTextGuiButtonClose and works great
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 ?
I did a SetFocus to a button in a dialog. The button gets the dashed outline. When the user presses the return key, the dialog get a IDOK message rather than a message from the button were I set the focus. The same thing happens under other circumstances.
Why is this happening? And how can I cause the return to act as a button press?
Plain c++ windows app, no MFC, no NET.
Feature, not a bug. The [Enter] key operates the button that's marked as the default button for a dialog. Either with the DEFPUSHBUTTON in the .rc file or the BS_DEFPUSHBUTTON style flag. Which is typically the "OK" button so getting IDOK back is expected. The [Escape] key is special that way too, typically the [Cancel] button. This is bound to ring a bell if you think back on how you used dialogs before.
You click a button that has the focus by pressing the space bar instead.
In another SO question I found KB article that might help you:
If a dialog box or one of its controls currently has the input focus,
then pressing the ENTER key causes Windows to send a WM_COMMAND
message with the idItem (wParam) parameter set to the ID of the
default command button. If the dialog box does not have a default
command button, then the idItem parameter is set to IDOK by default.
When an application receives the WM_COMMAND message with idItem set to
the ID of the default command button, the focus remains with the
control that had the focus before the ENTER key was pressed. Calling
GetFocus() at this point returns the handle of the control that had
the focus before the ENTER key was pressed. The application can check
this control handle and determine whether it belongs to any of the
edit controls in the dialog box. If it does, then the user was
entering data into one of the edit controls and after doing so,
pressed ENTER. At this point, the application can send the
WM_NEXTDLGCTL message to the dialog box to move the focus to the next
control.
According to MSDN,
Dialog Box Keyboard Interface
The system provides a special keyboard interface for dialog boxes that carries out special processing for several keys. The interface generates messages that correspond to certain buttons in the dialog box or changes the input focus from one control to another. Following are the keys used in this interface and their respective actions.
...
ENTER: Sends a WM_COMMAND message to the dialog box procedure. The wParam parameter is set to IDOK or control identifier of the default push button.
Since the system intercepts and processes ENTER key pressed directly through the dialog, you'll need to handle it in your dialog box procedure by calling GetFocus() to first see which control has the focus, and perform the appropriate action for that particular control.
I have a win32 app which uses DialogBox() to display its main window.
I now want to start this app up with the dialog box invisible, and later set it visible with
SetWindowPos(hDlg, HWND_TOPMOST, ...
Unfortunately
http://msdn.microsoft.com/en-us/library/ms645452(VS.85).aspx
The function displays the dialog box (regardless of whether the template specifies the WS_VISIBLE style)
... it seems that there's no way of doing this using DialogBox().
I could add a call to
SetWindowPos(hDlg, HWND_NOTOPMOST...
in my dialog procedure in the WM_INITDIALOG handler.
... but I'm concerned that under heavy system loading the dialog box will briefly appear then disappear, giving an ugly flicker effect.
Is there a way of creating my dialog box via DialogBox() without showing it?
ShowWindow(Hwnd, SW_HIDE);
i think it will work.
http://www.winprog.org/tutorial/modeless_dialogs.html
I had some success with this technique
void CMyDlg::OnWindowPosChanging(WINDOWPOS* lpWndPos)
{
// hide dialog
lpWndPos->flags &= ~SWP_SHOWWINDOW;
CDialog::OnWindowPosChanging(lpWndPos);
}
from here