|
Use:
HWND GetActiveWindow(VOID);
and then use BringWindowToTop() function
Cheers
"Peace of mind through Technology"
|
|
|
|
|
Nish has a good work around for this problem. this one i have taken from voidnish.com
He says:
How to steal focus on 2K/XP
I bet that sometimes you long for the old days when a simple SetForegroundWindow brought your dialog into focus. Sigh! Now with 2K/XP things have sorta changed so that if you try a simple SetForegroundWindow you end up flashing the taskbar icon a few times (I never counted but something tells me it flashes thrice). Not exactly what you wanted to do, eh? Luckily there are ways to bring your dialog into the foreground.
The trick is to use AttachThreadInput to attach the thread that owns the current foreground window to our thread, then call SetForegroundWindow and then detach the attached thread, again using AttachThreadInput. Cool, huh?
AttachThreadInput(
GetWindowThreadProcessId(
::GetForegroundWindow(),NULL),
GetCurrentThreadId(),TRUE);
SetForegroundWindow();
SetFocus();
AttachThreadInput(
GetWindowThreadProcessId(
::GetForegroundWindow(),NULL),
GetCurrentThreadId(),FALSE);
SaRath.
"Don't Do Different things... Do Things Differently..."
Understanding State Pattern in C++
|
|
|
|
|
Hi,
I have used Splitter window and did a (1 row,2 cols ) split and Created Views for the Corresponding two panes. The View in the left pane has tree control in it and in the right pane has form view.
If I Click on the Items in the left pane I don't have any problem but if I
click the view in right pane and again click the left pane I am getting an exception.
CCreateContext context;
context.m_pCurrentFrame = NULL;
context.m_pCurrentDoc = GetActiveDocument();
//Getting an Exception in the above Line
context.m_pNewViewClass = NULL;
context.m_pNewDocTemplate = NULL ;
Any suggestions Please
Thanx in advance
|
|
|
|
|
In the good old days I believe people were using the arcane technology which came to be known as COM+ to embed other application's document in their own document.
Like a Word with document a Windows Media Player or Excel or Visio document inside, double click on it and *bang* you coud start edit it using Excel/WMP/Visio toolbar.
Apparently even OpenOffice could do that.
Now here is my question:
I'm a new generation programmer. Blissfully ignorant of such thing.
But I would like to know and embed Word, Excel or other kind of document in my application's own document!
How could I do that?
And is there an up-to-date technology (i.e.: .NET API) to do that?
|
|
|
|
|
i ahve one bitmap loaded in picture control with scrollbars .know what i want is when we click the bitmap and dragged it should move to corresponding co-ordinates.
for example.
in irfan view when the image is bigger then a window then mouse cursor will change his shape to hand. we drag to see the full picture
thank u in advance.
sreee
|
|
|
|
|
sree_as wrote: i ahve one bitmap loaded in picture control with scrollbars .know what i want is when we click the bitmap and dragged it should move to corresponding co-ordinates.
for example.
in irfan view when the image is bigger then a window then mouse cursor will change his shape to hand. we drag to see the full picture
thank u in advance.
You have to override OnMousemove method..track the mouse cooridates when LBUTTON is DOWN and bitblt the bitmap with the proportion of the mouse coordinates so that your bitmap will display fully.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
thank u laxman.
i intension is hwen click the lButton and drag to some point then Lbutton up then bitmap should move to corridinates how many we dragged.
thank u
sree
|
|
|
|
|
When you click down and the image is scrollable, set a flag to indicate that the mouse is down and set the capture to the window and change the cursor to the hand cursor.
When the mouse moves store the previous x y position the mouse is at. If the mouse is down you take the current position and previous position, find the offset and scroll your window appropriately.
When the mouse button goes up clear the flag to indicate the mouse is down and release the capture and set the cursor back to the arrow cursor.
|
|
|
|
|
thank u .
any sample code or any link please.
sree.
|
|
|
|
|
Exactly what problem are you facing? Depending on how you are actually doing the scrolling (setting x and y start point and invalidating the window in the OnVScroll/OnHScroll handler etc) this can't be more than a couple of lines of code.
Show what you currently have in your OnLButtonDown/OnMouseMove/OnLButtonUp handlers and then someone might help you.
-- modified at 2:55 Tuesday 13th June, 2006
|
|
|
|
|
<br />
void CImageDlg::OnLButtonDown(UINT nFlags, CPoint point) <br />
{<br />
as=true;<br />
<br />
SetScrollPos(SB_VERT,point.y,true);<br />
SetScrollPos(SB_HORZ,point.x,true);<br />
SetCapture();<br />
<br />
<br />
<br />
CDialog::OnLButtonDown(nFlags, point);<br />
}<br />
<br />
void CImageDlg::OnLButtonUp(UINT nFlags, CPoint point) <br />
{<br />
ReleaseCapture(); <br />
<br />
as=false;<br />
<br />
CDialog::OnLButtonUp(nFlags, point);<br />
}<br />
<br />
void CImageDlg::OnMouseMove(UINT nFlags, CPoint point) <br />
{<br />
<br />
<br />
if((point.x>=89&&point.x<=363)&&(point.y>=67&&point.y<=271))<br />
SetClassLong(m_hWnd,GCL_HCURSOR,(LONG)LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_CURSOR1)));<br />
else<br />
SetClassLong(m_hWnd,GCL_HCURSOR,(LONG)LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_CURSOR2)));<br />
<br />
<br />
<br />
<br />
if (as==true)<br />
{<br />
SetScrollPos(SB_HORZ,point.x,TRUE);<br />
m_bitmap.SetWindowPos(NULL,<br />
-point.x,<br />
view.top,<br />
0, 0,<br />
SWP_NOSIZE | SWP_NOZORDER);<br />
SetScrollPos(SB_VERT,point.y,TRUE);<br />
m_bitmap.SetWindowPos(NULL,<br />
view.left,<br />
-point.y,<br />
0, 0,<br />
SWP_NOSIZE | SWP_NOZORDER);<br />
}<br />
CDialog::OnMouseMove(nFlags, point);<br />
}
|
|
|
|
|
What's with all the magic numbers? What is m_bitmap and why are you using SetWindowPos? You should be writing a control that displays the bitmap and manages the scrolling by itself and this should not be part of the logic of a dialog that is containing it.
Note that point is in client coordinates and would never exceed the size of your window, so it's not particularly helpful to just set the scroll pos based on that.
void CMyBitmapView::OnMouseMove(UINT nFlags, CPoint point)
{
:
if(m_bLButtonDown==true)
{
SetScrollPos(SB_HORZ, GetScrollPos(SB_HORZ) + m_ptPrevious.x - point.x, TRUE);
SetScrollPos(SB_VERT, GetScrollPos(SB_VERT) + m_ptPrevious.y - point.y, TRUE);
}
m_ptPrevious = point;
:
}
Another note regarding cursors, if what you want is the arrow and hand cursors, use IDC_ARROW and IDC_HAND (IDC_HAND is available for Win2k/XP etc just set WINVER >= 0x0500 if you target Win9x as well then by all means add a hand cursor for that OS). I happen to use custom arrow and hand cursors in WinXP and I don't understand why devs feel the need to have their own special arrow and hand cursors for their applications.
-- modified at 4:07 Tuesday 13th June, 2006
|
|
|
|
|
thank u.sorry for disturbing u again and again.
same problem .
scrollers are moving,bitmap is not moving.
thank u in advance,
sree
|
|
|
|
|
You didn't answer any of my questions. What is m_bitmap? I can only assume that that is the window that is actually drawing the bitmap, in which case your approach is incorrect and you should be subclassing the window that is drawing the bitmap to add additional functionality. If it really is your dialog that is drawing the bitmap (which would be a rather strange design) you would have to show me your OnHScroll/OnVScroll and OnPaint handlers.
|
|
|
|
|
m_bitmap is a member varialble for our picture control where we load the picture.
void CImageDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) <br />
{<br />
int newpos = GetScrollPos(SB_HORZ);<br />
SCROLLINFO info;<br />
::ZeroMemory(&info, sizeof(info));<br />
info.cbSize = sizeof(info);<br />
info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS;<br />
GetScrollInfo(SB_HORZ, &info);<br />
<br />
int low = info.nMin;<br />
int high = info.nMax - info.nPage;<br />
<br />
<br />
CRect view;<br />
GetClientRect(&view);<br />
<br />
<br />
<br />
CRect image;<br />
m_bitmap.GetWindowRect(&image);<br />
ScreenToClient(&image);<br />
<br />
<br />
switch(nSBCode)<br />
{ <br />
case SB_LINEUP:<br />
newpos -= ::GetSystemMetrics(SM_CXVSCROLL);<br />
if(newpos < low)<br />
newpos = low;<br />
break;<br />
case SB_LINEDOWN:<br />
newpos += ::GetSystemMetrics(SM_CXVSCROLL);<br />
if(newpos > high)<br />
newpos = high;<br />
break;<br />
case SB_PAGEUP:<br />
newpos -= view.Height();<br />
if(newpos < low)<br />
newpos = low;<br />
break;<br />
case SB_PAGEDOWN:<br />
newpos += view.Height();<br />
if(newpos > high)<br />
newpos = high;<br />
break;<br />
case SB_THUMBTRACK:<br />
newpos = info.nTrackPos;<br />
break;<br />
case SB_THUMBPOSITION:<br />
newpos = info.nTrackPos;<br />
break;<br />
} <br />
SetScrollPos(SB_HORZ, newpos);<br />
m_bitmap.SetWindowPos(NULL,<br />
-newpos,<br />
image.top,<br />
0, 0,<br />
SWP_NOSIZE | SWP_NOZORDER);<br />
<br />
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);<br />
}<br />
<br />
void CImageDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) <br />
{<br />
SCROLLINFO info;<br />
::ZeroMemory(&info, sizeof(info));<br />
info.cbSize = sizeof(info);<br />
info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS;<br />
GetScrollInfo(SB_VERT, &info);<br />
<br />
int low = info.nMin;<br />
int high = info.nMax - info.nPage;<br />
int newpos = info.nPos;<br />
<br />
CRect view;<br />
GetClientRect(&view);<br />
<br />
<br />
CRect image;<br />
m_bitmap.GetWindowRect(&image);<br />
ScreenToClient(&image);*/<br />
switch(nSBCode)<br />
{ <br />
case SB_LINEUP:<br />
newpos -= ::GetSystemMetrics(SM_CYHSCROLL);<br />
if(newpos < low)<br />
newpos = low;<br />
break;<br />
case SB_LINEDOWN:<br />
newpos += ::GetSystemMetrics(SM_CYHSCROLL);<br />
if(newpos > high)<br />
newpos = high;<br />
break;<br />
case SB_PAGEUP:<br />
newpos -= view.Height();<br />
if(newpos < low)<br />
newpos = low;<br />
break;<br />
case SB_PAGEDOWN:<br />
newpos += view.Height();<br />
if(newpos > high)<br />
newpos = high;<br />
break;<br />
case SB_THUMBTRACK:<br />
newpos = info.nTrackPos;<br />
break;<br />
case SB_THUMBPOSITION:<br />
newpos = info.nTrackPos;<br />
break;<br />
} <br />
SetScrollPos(SB_VERT, newpos);<br />
m_bitmap.SetWindowPos(NULL,<br />
image.left,<br />
-newpos,<br />
0, 0,<br />
SWP_NOSIZE | SWP_NOZORDER);<br />
<br />
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);<br />
}<br />
void CImageDlg::OnPaint() <br />
{<br />
if (IsIconic())<br />
{<br />
CPaintDC dc(this);
<br />
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);<br />
<br />
int cxIcon = GetSystemMetrics(SM_CXICON);<br />
int cyIcon = GetSystemMetrics(SM_CYICON);<br />
CRect rect;<br />
GetClientRect(&rect);<br />
int x = (rect.Width() - cxIcon + 1) / 2;<br />
int y = (rect.Height() - cyIcon + 1) / 2;<br />
<br />
dc.DrawIcon(x, y, m_hIcon);<br />
}<br />
else<br />
{<br />
CDialog::OnPaint();<br />
}<br />
}
|
|
|
|
|
I hope you realise that you have a very strange approach to your problem. The whole move the static control around thing to scroll isn't a good way of doing it and it's not particularly hard to write your own picture control that can encapsulate scrolling. Is this school work?
If you need any more functionality than this like zoom in/out etc, or you find yourself needing to reuse this scrollable picture in a different dialog, you'll see what's wrong with your current approach.
Anyway if this works for normal scrolling using your mouse (make sure you've removed those SetWindowPos() things from your OnMouseMove handler - SetScrollPos should trigger the notifications to get OnVScroll and OnHScroll called). Set breakpoints in OnVScroll and OnHScroll and start dragging and see what's different.
|
|
|
|
|
thank u iam new to vc++.actually my domain is java.
i searched the code for scrollbar and i completed this.
yes,iam reuse this scrollable picture in a different dialog.
do u ahve any example regarding this,or any code
-- modified at 5:46 Tuesday 13th June, 2006
|
|
|
|
|
The proper approach would be to write a custom control, the static picture control is not meant for anything fancy. You can think of writing a custom control as deriving from a JComponent. Wouldn't you agree that moving a JComponent around in a JDialog to achieve scrolling sounds like a bad idea (Yeah it would be nice to have something like JScrollPane in MFC)
I searched codeproject and came up with an article on writing custom controls in MFC. As a bonus the custom control is a simple control that draws a bitmap. (I tried looking for a bitmap control when you first posted but couldn't find one in the Bitmap section - probably because it's considered too simple). It also shows how you can subclass a window on a dialog using DDX.
http://www.codeproject.com/miscctrl/customcontrol.asp[^]
Of course it's a little too simple, but this can be fixed with some cut and pasting from the bitmap scrolling article. The classes he wrote for the article isn't very well designed (Unless his goal was to minimise the number of windows he creates) but it demonstrates how to draw and scroll a bitmap quite clearly. In particular take note of the OnPaint/OnVScroll/OnHScroll handlers and modify the custom control accordingly (Needs some modifications). Note that there's usually no need to create scrollbar windows. A window with the WS_HSCROLL/WS_VSCROLL style will draw a scrollbar on the sides of the window. These are so-called fake scrollbars as they don't have a window but are drawn in response to WM_NCPAINT.
http://www.codeproject.com/bitmap/bmpscroll.asp[^]
You can just tack on the OnLButtonDown/OnMouseMove/OnLButtonUp code that you've already written in the custom control and it should work as expected. As the custom control is entirely encapsulated as a window you can reuse it on dialogs and can even have it as a view on a frame.
|
|
|
|
|
thank u very much.
u directing we very well.
i will try and i will give message after completion of that.
really thank u so much.
sree.
|
|
|
|
|
actually this code is given by my Project leader.he tell do the modification to get the desire result,what we discuss until know.u sended me that customs control,this is useful
when i start the project at 1st step.
so plese tell me how to modify this existing code,
i know iam really troubleing u, but i have no other way,
plese be kind heartly help me
|
|
|
|
|
I have modified the custom control demo with the relevant changes. The source and release binary is included below. It probably has bugs and it has nowhere near the functionality that I usually stuff in my controls (I usually write using WTL, so I also did this as a way to brush up on MFC)
http://www.yousendit.com/transfer.php?action=download&ufid=F1596C4701B5A33B[^]
It sounds like your project leader also doesn't know what is going on. Perhaps you should invest in a good book (I don't have any recommendations as it's ages since I leafed thru an MFC book)
|
|
|
|
|
Oh... Please use
< Pre>
.....code.....
</ Pre> Tags.
Then you can get code with indentation.
Nice talking to you.
If you judge people, you have no time to love them. -- Mother Teresa
|
|
|
|
|
|
You could create a CScrollView derived class's object in the window or dialog, and use its WM_MOUSEMOVE , WM_LBUTTONDOWN , WM_LBUTTONUP etc to move the picture. You can display the picture in your CScrollView-derived class's OnDraw() etc.
There may be easier ways of doing it.
this is this.
|
|
|
|
|
thank u .
any sample code or any link please.
sree.
|
|
|
|
|