|
Hello,
I am using dialog boxes and I need to capture window message when the window/dialog was displayed
I tried WM_SHOWWINDOW but the help says:
WM_SHOWWINDOW message is sent to a window when the window is about to be hidden or shown.
I can not fint the proper message.Can you give me a hind?
Thank you very much.
|
|
|
|
|
daavena wrote: displayed
What do you mean by 'displayed' - created, shown, redrawn?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
when I click on the button I need:
show window/dialog with message "Loading profile it can take several minutes" inside
and than when the window is shown(is visible) I need to run the function - but only once.
|
|
|
|
|
There's no window message that you only get when the window is shown the first time.
Instead, catch WM_SHOWWINDOW. Maintain a flag that tells you if your message has been shown. You can use this flag to tell you whether you should show your message or not - something like:
void CMyWindow::OnShowWindow(BOOL bShow, UINT nStatus)
{
if (bShow && !m_bShownMyMessage)
{
m_bShownMyMessage = TRUE;
}
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thaks for reply,
WM_SHOWWINDOW
WPARAM wParam
LPARAM lParam;
Parameters
wParam
Specifies whether a window is being shown. If wParam is TRUE, the window is being shown. If wParam is FALSE, the window is being hidden.
lParam is still 0
when I capture WM_SHOWWINDOW so wParam is always 1 -the window is being shown.
My function always runs first. Then I see the window.
This function takes a time - 10sec, that is reason why I need to see the window first.
WM_SHOWWINDOW message is called only once. I think it is not possible to do that.
|
|
|
|
|
WM_WINDOWPOSCHANGING?
Or you could even could WM_PAINT - that was when the window was actually shown to people!
So it depends on what you mean...
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Thanks for reply.
I need message when window/dialog has been shown - I need to see the window first and then run my function(only once).
|
|
|
|
|
Please consider the following code fragment written using C++ and MFC.
void<br />
GraphWindow::OnPaint()<br />
{<br />
CPaintDC dc(this);<br />
dc.TextOut( 50, 50, TEXT("A Parabola"), 11 );<br />
<br />
dc.SetWindowOrg( -cx/2, -cy/2 );<br />
<br />
CPen pen(PS_SOLID, 2, RGB(255, 0, 0) );<br />
CPen *pOldPen = dc.SelectObject( &pen );<br />
<br />
dc.MoveTo( -10, 100 );<br />
for( int i = -10; i<=10; i++ )<br />
dc.LineTo( i, (i*i) );<br />
<br />
dc.SelectObject( pOldPen );<br />
}<br />
This routine is suppose to graph the curve y = x^2. However, it graphs the function y = -x^2 because the windows orientation is that an increasing y value, moves down in the window. If I change the call to LineTo to the following, it works:
dc.LineTo( i, -(i*i) );
I believe that there is a call that will change the window orientation such that an increasing y value moves up rather than down. However, I have been unable to find the call. I am hoping that somebody can tell me what it is.
Thanks
Bob
|
|
|
|
|
|
Iain,
Thanks for the response. Based the article you sited, I tried the following piece of code:
<br />
void<br />
GraphWindow::OnPaint()<br />
{<br />
CPaintDC dc(this);<br />
<br />
dc.TextOut( 50, 50, TEXT("A Parabola"), 10 );<br />
<br />
dc.SetMapMode( MM_HIENGLISH );<br />
<br />
CPen pen(PS_SOLID, 2, RGB(0, 255, 0) );<br />
CPen *pOldPen = dc.SelectObject( &pen );<br />
<br />
dc.MoveTo( 100, 100 );<br />
dc.LineTo( 800, 800 );<br />
<br />
dc.SelectObject( pOldPen );<br />
I called the method SetMapMode to orient the window such that positive x values are to the right and positive y values are up. With the call to SetMapMode in there, the line does not appear. Without the call to SetMapMode, the line does appear. I do understand and I am hoping that somebody can explain it to me.
Thanks
Bob
|
|
|
|
|
You need to play with the article more...
But at a first guess - you've changed the map mode, and I think to a "Y is up" mode. But you've not changed the origin. So you're not drawing 50,50 above and to the right of the top left of the window - so nothing to see.
But the article has all sorts of things to vary, so you can experiment with this there.
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
hi,
I want to trap a events whenever user selects cell in excel sheet 2007. Can I do it by subclassing it. If yes how to do it.
Thanks
SNI
|
|
|
|
|
You need a different mechanism than to subclass to catch Windows messages.
Instead, you need to tell the relevant worksheet that you want to connect to its SelectionChange[^] event.
This CodeProject article[^] has information on COM connection points (that's what you need to use to catch the event).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi,
Thanks for your reply. But will it be same for Exccel 2007.
Thanks
SNI
|
|
|
|
|
Yes[^]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for your reply. I was able to capture events like WorkbookOpen,WorkbookActivate,SheetSelectionChange but my requirement is something different. Let assume that one excel file is open (Test.xlsx) and I have selected a cell and press F2 so that my cursor is inside a cell. Now I have opened this xlsx file so I know the name of it. but if I change the focus from this xlsx file to test.doc and again come back to Test.xlsx, I am not able to get the name of this file since the cursor is blinking inside the cell.
Here I want to capture this event either Active cell, which is not working nor all of the above mentioned events. How to capture this curosr blinking event inside the cell (EditDirectlyInCell).
Does Subclassing of Excel will help?
Thanks
SNI
|
|
|
|
|
SNI wrote: Does Subclassing of Excel will help?
I don't know. It's difficult to tell, because I don't know what you're trying to accomplish - why you feel you need such a fine granularity view of what Excel's doing.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Actually it is a requirement where I need to find out the file name and when I am selecting xlsx file again and cursor is in cell then we are not able to get any event. I trying to find out what event it fires when xlsx file gets a focus again with cursor is in cell.
SNI
|
|
|
|
|
I see now. I tried this little program to interrogate the running instance of Excel (2007 in my case as well):
#include <iostream>
#import "libid:00020813-0000-0000-C000-000000000046" version("1.6") auto_search no_dual_interfaces raw_dispinterfaces rename("DialogBox", "excelDialogBox") rename("RGB", "excelRGB") rename("DocumentProperties", "excelDocumentProperties") rename("SearchPath", "excelSearchPath") rename("CopyFile", "excelCopyFile") rename("ReplaceText", "excelReplaceText")
int _tmain(int argc, _TCHAR* argv[])
{
CoInitializeEx(0, COINIT_MULTITHREADED);
try
{
Excel::_ApplicationPtr xl;
if (SUCCEEDED(xl.GetActiveObject(__uuidof(Excel::Application))))
{
if (Excel::_WorkbookPtr wb = xl->ActiveWorkbook)
{
std::cout << "Getting name\n";
_bstr_t xlName = wb->FullName;
std::cout << xlName << std::endl;
if (Excel::SheetsPtr sheets = wb->Worksheets)
{
std::cout << sheets->Count << std::endl;
}
}
}
}
catch(_com_error& e)
{
std::cout << "EXCEPTION!!!\n";
std::cerr << CT2CA(e.ErrorMessage()) << std::endl;
}
CoUninitialize();
return 0;
}
When you're NOT editing a cell, this program works fine, printing the active workbook's file name and number of worksheets.
When you ARE editing a cell, it throws an exception (indicating an error status) when you interrogate the workbook object. That exception's text is "The message filter indicated that the application is busy". Now, I think that indicates that Excel is in a modal message loop and will not respond to any COM calls. Which means that Excel's window procedure isn't being called, so sub-classing Excel's window class won't help you at all anyway.
What you can do is (if Excel is busy) catch the Excel application's events. I think you'll find that Excel's SheetChange and AfterCalculate events are raised when you finish editing a cell. At that point, Excel won't be busy, so you can get the workbook's filename.
The resultant code could look something like this:
#include <iostream>
#include <atlcom.h>
#import "libid:00020813-0000-0000-C000-000000000046" version("1.6") auto_search no_dual_interfaces raw_dispinterfaces rename("DialogBox", "excelDialogBox") rename("RGB", "excelRGB") rename("DocumentProperties", "excelDocumentProperties") rename("SearchPath", "excelSearchPath") rename("CopyFile", "excelCopyFile") rename("ReplaceText", "excelReplaceText")
_ATL_FUNC_INFO SheetChangeInfo = { CC_CDECL, VT_EMPTY, 2, { VT_DISPATCH, VT_DISPATCH } };
class ExcelAppEventHandler : public IDispEventSimpleImpl<1, ExcelAppEventHandler, &__uuidof(Excel::AppEvents)>
{
public:
ExcelAppEventHandler(bool& doneFlag) : done_(doneFlag) { done_ = false; }
BEGIN_SINK_MAP(ExcelAppEventHandler)
SINK_ENTRY_INFO(1, __uuidof(Excel::AppEvents), 0x0000061c, &ExcelAppEventHandler::SheetChange, &SheetChangeInfo)
END_SINK_MAP()
void _stdcall SheetChange(IDispatch * Sh, struct Excel::Range * Target)
{
done_ = true;
}
private:
bool& done_;
};
_bstr_t GetActiveWorkbookName(Excel::_ApplicationPtr xl)
{
if (Excel::_WorkbookPtr wb = xl->ActiveWorkbook)
{
try
{
return wb->FullName;
}
catch(_com_error& e)
{
std::cout << "EXCEPTION!!!\n";
std::cerr << CT2CA(e.ErrorMessage()) << std::endl;
bool done;
ExcelAppEventHandler app(done);
if (SUCCEEDED(app.DispEventAdvise(xl)))
{
MSG msg;
while (!done && GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
app.DispEventUnadvise(xl);
return GetActiveWorkbookName(xl);
}
}
}
return _bstr_t();
}
int _tmain(int argc, _TCHAR* argv[])
{
CoInitializeEx(0, COINIT_APARTMENTTHREADED);
{
Excel::_ApplicationPtr xl;
if (SUCCEEDED(xl.GetActiveObject(__uuidof(Excel::Application))))
{
std::cout << "Getting name\n";
std::cout << GetActiveWorkbookName(xl) << std::endl;
}
}
CoUninitialize();
return 0;
}
The GetActiveWorkbookName function attempts to get the workbook name. If it fails, it tells Excel that it wants events, then when it gets SheetChange it returns, as Excel is no longer busy.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for your reply. I have tried above code but it is giving me following error
"fatal error C1083: Cannot open type library file: 'libid :00020813-0000-0000-C000-000000000046': No such file or directory" on VC++ 6.0. what needs to be done in order to compile this.
Thanks
SNI
|
|
|
|
|
VC 6.0...that doesn't support using a libid for #import. You'll have to find the Excel type library file yourself and import it.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
HI
i have given a path of cmd.exe while debugging a console application in "Executable debug session " dialog box.
Please tell me how to remove it .
Thanks
|
|
|
|
|
In the project properties, the path for cmd.exe will be available in Debugging -> Command.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Hello,
I have a window derived from CMDIChildWnd which when maximized doesnt merge with the main window.
class TableFrame : CMDIChildWnd
{
afx_msg void OnSize(UINT nType, int cx, int cy);
}
void TableFrame::OnSize(int nType, int cx, int cy)
{
switch(nType)
{
case SIZE_MAXIMIZED :
{
CRect ParentRect;
GetParent()->GetClientRect(ParentRect);
MoveWindow(ParentRect,true);
break;
}
}
Prithaa
|
|
|
|
|
prithaa wrote: I have a window derived from CMDIChildWnd which when maximized doesnt merge with the main window.
That's nice.
Is that a problem or not? Difficult to say as you're not asking a question...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|