I create a dialog window with some controls based on the resource file using CreateDialog function. Then I can get a control handle this way:
HWND ctrlHwnd = GetDlgItem(dlgHwnd, IDC_LIST);
and get a control dimensions using functions like GetClientRect etc. Let's assume that using SetWindowPos I change a control dimension. Is there any way to get initial dimensions from the resource file ? I know that I can save an initial RECT data in my program memory but I wonder if there is other way ?
Related
I wonder if there is any way to somehow interact with windows that are currently open on a Windows system. I am interested in getting some of their properties, namely:
Location
Dimension
is in background?
possibly window title
Preferably, I would like to do that in Java but any suggestions are welcome.
A comment by theB linked to good resources for Java. I'll run through the relevant Windows APIs, in case you want to go native with C++.
To enumerate all the top-level windows in the system, use EnumWindows. You give it a callback function with the signature of EnumWindowsProc, so it will receive each window handle as the first parameter.
You can get the window location (in screen coordinates) and dimensions with the GetWindowRect function. Pass in the window handle you received and get an LPRECT (pointer to RECT) out.
To determine whether a window is maximized, use GetWindowPlacement and check the showCmd field of the WINDOWPLACEMENT structure you receive.
Finally, to get a window's caption, use GetWindowText. (As an aside, if you want to get the text of a control in another process, you'll need to send the WM_GETTEXT message yourself.)
I have a VB6 application with a ListView (MSCOMCTL.OCX). I need to get the window handle (hwnd) for a listviewitem, or preferably (if something like that exists) - of a specific subitem.
I know I can get the handle for the column headers using FindWindowEx and looking for the class msvb_lib_header, but I don't know how to get the handle for the item. Spy++ shows a msvb_lib_header window as the child of the listview, but does not show any other windows.
List view items and subitems are not window handles. They are internal children of the list view, exposed using the LVM_GETITEM and LVM_SETITEM messages and the LVITEM structure. (Subitems use the same interface; the iSubItem member of LVITEM would be nonzero in this case.)
ListView.ListItem object has not hwnd.
You should search ListView by class name, next use SendMessage() to send the message LVM_GETITEM and using the LVITEM structure to get info about items:
LVM_GETITEM message (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/bb774953(v=vs.85).aspx
LVITEM structure (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/bb774760(v=vs.85).aspx
this reference page may help you:
List-View Control Reference (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/ff485973(v=vs.85).aspx
I'm learning Win32 assembly. Have some question I search but not suitable result.
Anyone can explain for me What difference between control's window handle and controlID.
They have nothing in common. Every window has a handle, returned by CreateWindowEx(). Such a window can have a few extra properties attached, like a menu handle. The hMenu argument in CreateWindowEx(). If the window doesn't have a menu, a child window won't have one, then you can use that argument to pass an arbitrary other bit of data. It will be assigned to the GWLP_ID property (see GetWindowLongPtr). Also note the GWLP_USERDATA, an extra property that's entirely yours to use as you see fit.
Dialogs take advantage of this, a dialog template that you create in the resource editor gives you a way to number the child controls. With a helper function like GetDlgItem() to get the handle back for a control with a specific number. Which is pretty necessary for dialogs since it is Windows that create the child controls from the dialog template so you don't know the window handles for them yourself.
WinAPI to return Window Resizing Object size (This is the boarder around a window that allows you to resize the window). I just need the number of pixels it takes. (Under Windows 7, it looks like it is about 10 pixels.)
Also, what is the official name for this object?
I am coding in a language call PL/B and placing objects on their window. I am using GetWindowRect to get the window size, now I just need to adjust the size by the Window Resizing Object.
Generally, you're better off looking at GetClientRect and ClientToScreen, rather than trying to use GetWindowRect and trimming off the nonclient portions, but if you're dead set on doing that, try GetSystemMetrics with SM_CXSIZEFRAME and SM_CYSIZEFRAME.
The GetClientRect function, according to MSDN, is actually only good for determining the client width & height, since left & top are always zero. Is there a way to get the complete client coordinates, including left & top (either in screen space, or in window space)?
Call ClientToScreen on the top left and bottom right of the returned RECT. If you're using MFC, CWnd has a helper overload of CWnd::ClientToScreen that will do this transparently for you.
Maybe you are needing GetWindowRect.
You're looking for the GetWindowPlacement function. This function returns a WINDOWPLACEMENT struct which has an rcNormalPosition property which specifies the window's position when it is in the normal (rather than maximized or minimized) display state.
EDIT: itowilson's answer is actually cleaner because the WINDOWPLACEMENT structure also contains a bunch of data you don't need.