Reputation: 18251
I need to show input dialog form of program that main form dialog is minimised in tray. Currently I have input dialog form shown on the desktop, but when this form shown for the first time it is inactive. To make this dialog active I do :
BOOL CDialogExInput::OnInitDialog()
{
CDialogEx::OnInitDialog();
this->SetWindowPos(&this->wndTop,1000,1000,1000,1000,SWP_NOSIZE|SWP_NOMOVE);
return true;
}
But looks this has no influence since even dialog form size is not changed. Maybe this is not right place to make SetWindowPos
?
UPT:
Trying to focus my question. Let's auume I have simple dialog based application. Let's run it and deactivate (click mouse on any other window). I need on timer event make my dialog application form active (in keyboard input focus).
SetWindowPos
and SetFocus
doesn't help.
// focusDlg.cpp : implementation file
//
#include "stdafx.h"
#include "focus.h"
#include "focusDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#define ID_TIMER_1 100
// CfocusDlg dialog
CfocusDlg::CfocusDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CfocusDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CfocusDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CfocusDlg, CDialogEx)
ON_WM_TIMER()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDOK, &CfocusDlg::OnBnClickedOk)
END_MESSAGE_MAP()
// CfocusDlg message handlers
BOOL CfocusDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
SetTimer(ID_TIMER_1,3000,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CfocusDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CfocusDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CfocusDlg::OnTimer(UINT)
{
//MessageBox(L"Time");
this->SetWindowPos(&this->wndTop,1000,1000,1000,1000,SWP_NOSIZE|SWP_NOMOVE);// | SWP_SHOWWINDOW );
this->SetFocus();
}
void CfocusDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
CDialogEx::OnOK();
}
Upvotes: 0
Views: 302
Reputation: 50921
OnInitDialog()
is exactly the right place where you can modify the dialog window; when the framework calls this function, the dialog box window already exists but is not yet visible.
If you want the window to be moved and resized you mustn't specify the SWP_NOSIZE
nor the SWP_NOMOVE
flags during the call of SetWindowPos
.
Upvotes: 0