how to find disabled-parent window from dialog - winapi

I have a page (render in IE) that creates a model dialog with style: WS_POPUP - showModalDialog. I can find HWND of the dialog but how I can find the HWND of parent?
Because the model dialog and its parent run on different processes, API function getParent does not work. In addition! sometimes another window can stand between the dialog and parent page :(, This prevents me from using 'next window' :(.

There is no code, and "API function getParent does not work" isn't helpful. You should check with Spy++ parent value in Properties->Windows.
Please check also Remarks section in GetParent documentation
To obtain a window's owner window, instead of using GetParent, use GetWindow with the GW_OWNER flag. To obtain the parent window and not the owner, instead of using GetParent, use GetAncestor with the GA_PARENT flag.
You have written:
In addition! sometimes another window can stand between the dialog and parent page
This may suggest that you don't have true owner-owned relationship. Maybe it is only simulated by disabling your owner window and making your dialog topmost. You can verify this by using Spy++ looking for WS_EX_TOPMOST in Properties->Styles. With HideThatWindow application you can manipulate window styles on runtime and further confirm this.
For getting HWND I would post custom message from one window to other.
UINT MyWmMessage = RegisterWindowMessage( TEXT( "HereIsMyHWND.mydomainname.pl" ) );
...
PostMessage( DialogHWND, MyWmMessage, 0, (LPARAM) ParentHWND );
And in dialog window:
// If this is in another process, reregister custom message.
UINT MyWmMessage = RegisterWindowMessage( TEXT( "HereIsMyHWND.mydomainname.pl" ) );
...
LRESULT CALLBACK DialogWindowProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
...
if ( msg == MyWmMessage )
{
WeGotParentHWND = (HWND) lparam;
}
...
}

Related

how to inject custom window into windows explorer

RT.as the picture below.
I try several ways as below, but not work :
Explorer Bars, Tool Bands, and Desk Bands, see here
Namespace extensions,see here
Implementing a Folder View, see here
I have resolve this problem, just resize the folder view window and create a new custom window and move it to the right postion, show below, this code will show custom window in top of folder view window:
HWND phwnd = (HWND)explorer SHELLDLL_DefView handle;
HWND chwnd = (HWND)explorer DirectUIHWND handle;
RECT *rcClient = new RECT();
GetClientRect(phwnd, rcClient);
MoveWindow(chwnd, rcClient->left, rcClient->top+39, rcClient->right, rcClient->bottom-39, TRUE);
HWND haddwnd = ::CreateDialogParam(hInst,
MAKEINTRESOURCE(IDD_DIALOG1),
phwnd,
(DLGPROC)About,
(LPARAM)rcClient);
ShowWindow(haddwnd, SW_SHOWNOACTIVATE);
MoveWindow(haddwnd, 0, 0, rcClient->right, 39, TRUE);
<pre>

How can I create a button with default behavior in win32

I have been trying to create a button with the default behavior i.e when the user press ENTER, the button is fired.
I created the button with the WS_TABSTOP style and sent it the BM_SETSTYLE message with BS_DEFPUSHBUTTON has WPARAM parameter
but it's still not working.
HWND hwnd_Ok = CreateWindow("button", "Ok", WS_VISIBLE | WS_CHILD | WS_TABSTOP, 285, 195, 70, 25, hwnd, (HMENU)OK_BUTTON, NULL, NULL);
SendMessage(hwnd_Ok, BM_SETSTYLE, (WPARAM)BS_DEFPUSHBUTTON, TRUE);
I am trying to handle WM_GETDLGCODE for getting WM_KEYDOWN with VK_RETURN message in your control's WndProc. Sample code:
case WM_GETDLGCODE: {
if(wParam==VK_RETURN) {
return DLGC_WANTALLKEYS;
}
}
break;
The BS_DEFPUSHBUTTON is just a flag added to the button. The behavior you describe (along with lots of other field navigation behavior) is actually implemented by IsDialogMessage, which you get for free is a modal dialog box.
If you're trying to handle this in your own window class (or a modeless dialog), you can add IsDialogMessage to your message loop to get the dialog-style handling.

Let my MFC dialog receive keystroke events before its controls (MFC/Win32 equivalent of WinForms "KeyPreview")

I have an MFC dialog containing a dozen or so buttons, radio buttons and readonly edit controls.
I'd like to know when the user hits Ctrl+V in that dialog, regardless of which control has the focus.
If this were C#, I could set the KeyPreview proprety and my form would receive all the keystrokes before the individual controls - but how do I do that in my MFC dialog?
JTeagle is right. You should override PreTranslateMessage().
// Example
BOOL CDlgFoo::PreTranslateMessage( MSG* pMsg )
{
// Add your specialized code here and/or call the base class
if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )
{
int idCtrl= this->GetFocus()->GetDlgCtrlID();
if ( idCtrl == IDC_MY_EDIT ) {
// do something <--------------------
return TRUE; // eat the message
}
}
return CDialog::PreTranslateMessage( pMsg );
}
Add a handler to override PreTranslateMessage() in the dialog class, and check the details of the MSG struct received there. Be sure to call the base class to get the right return value, unless you want to eat the keystroke to prevent it going further.

How to get a unique WindowRef in a dockable Qt application on Mac

How do I get a unique WindowRef from a Qt application that includes docked windows on the Mac?
My code boils down to:
int main(int argc, char* argv[])
{
QApplication* qtApp = new QApplication(argc, argv);
MyQMainWindow mainwin;
mainwin.show();
}
class MyQMainWindow : public QMainWindow
{
//...
QDockWidget* mDock;
MyQWidget* mDrawArea;
QStackedWidget* mCentralStack;
};
MyQMainWindow::MyQMainWindow()
{
mDock = new QDockWidget(tr("Docked Widget"), this);
mDock->setMaximumWidth(180);
//...
addDockWidget(Qt::RightDockWidgetArea, mDock);
mDrawArea = new MyQWidget(this);
mCentralStack = new QStackedWidget();
mCentralStack->addWidget(mDrawArea);
// Other widgets added to stack in production code.
setCentralWidget(mCentralStack);
//...
}
(Apologies if the above isn't syntactically correct, it's just easier to illustrate than to describe.)
I added the following temporary code at the end of the above constructor:
HIViewRef view1 = (HIViewRef) mDrawArea->winId();
HIViewRef view2 = (HIViewRef) mDock->winId();
WindowRef win1 = HIViewGetWindow(view1);
WindowRef win2 = HIViewGetWindow(view2);
My problem is that view1 and view2 are different, but win1 and win2 are the same!
I tried the following equivalent on Windows:
HWND win1 = (HWND)(mCentralDrawArea->winId());
HWND win2 = (HWND)(mDock1->winId());
This time win1 and win2 are different.
I need the window handle to pass on to a 3rd party SDK so that it can draw into the central area only.
BTW, I appreciate that the winId() method comes with lots of portability warnings, but a substantial refactor is out of the question for me. The same goes for using Carbon instead of Cocoa.
Thanks.
To wrap this up, I contacted Qt who said that this is expected behaviour and that it's unusual for a 3rd party application to require a windowref like this. They suggested looking into the widget attributes Qt::WA_PaintOnScreen and Qt::WA_NoSystemBackground on the widget.
Beyond this, I guess the fix will be to request that the 3rd party SDK is edited to take carbon / cocoa window handles.

How do I set WindowText on the Taskbar?

const char* title = "old title";
HWND hwnd = FindWindow(title, title);
SetWindowText(hwnd, "new title");
This sets the title bar to "new title", but the caption in the task bar is still "old title". How do I set both?
If relevant, this is being done in a DLL loaded in the process which owns the window.
This should set both, window title and task bar item. Your call
HWND hwnd = FindWindow(title, title);
does not look good, first parameter has to be class name (look at FindWindow). It looks to me that problem is somewhere else but I may be wrong.

Resources