|
Actually, problem was you can't use SetFocus unless that window ,parent window is visible.
OnActivateView is one place where you can achieve this. You can use its parameters for certain checks.
Other place I feel is overriding WM_SHOWWINDOW, but it will get called once.
You can look for such messages and use SetFocus there.
|
|
|
|
|
ok, i will review it, really thanks for your help
|
|
|
|
|
hi all,
I want a part of program/code ie., the USB reading alone in a separate thread so that it doesnt block the main functions/code which is a continuous process.
How can I do it?
Can anyone help/suggestions ...with code snippets please?
Thanks in advance.
|
|
|
|
|
Look up the _beginthread and the _beginthreadex CRT functions of if you're using MFC check out the CWinThread class and the AfxBeginThread global function. Make sure you link to the multithreaded libraries.
Steve
|
|
|
|
|
do u have any example programs or any relevant code snippet that would help me understand it better.
where to call the Afxbeginthread..etc?
iam using MFC for the first time. so am in the learning curve now.
|
|
|
|
|
// The thread.
class CMyThread : public CWinThread
{
public:
DECLARE_DYNCREATE(CMyThread)
CMyThread()
{
m_Data = 0;
}
virtual BOOL InitInstance() { return TRUE; }
virtual int Run() // Do work in here!!!!
{
// Do some work!
while (++m_Data < 1000) {}
return 0;
}
private:
int m_Data;
};
IMPLEMENT_DYNCREATE(CMyThread, CWinThread)
// To start the thread.
AfxBeginThread(RUNTIME_CLASS(CMyThread));
// ------------------------- //
There are many ways to skin a cat however. Using <code>_beginthread</code> is probably easier.
Steve
|
|
|
|
|
I want let my program delete itself,but I do not know what to do.Thanks for your help!!;)
|
|
|
|
|
You can do it like this.
While on exist copy ur exe to some temp folder . Run it with command line something like "delete ME and File to delete" (that is ur current exe path or GetModulePath()) . So in ur program if you get a commandline "delete ME"
try deleting that file (Make sure to try it in aloop , Becs some time the First one is only going to exit. ).
Hopes this will help u.
regards
krishnan
-- modified at 21:40 Tuesday 22nd August, 2006
If u can Dream... U can do it
|
|
|
|
|
Thank krishnan very much!!;)
|
|
|
|
|
Your program cannot delete itself while running. You can put an entry in runonce in the registry to delete it on reboot, or you can have a seperate app that does the deleting and is run by your app as it closes.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
"runonce" is a good information. Can u please provide it's path in registry ?
and what will happen if i set this flag to explorer.exe or iexplorer.exe )
regards
krishnan
If u can Dream... U can do it
|
|
|
|
|
run regedit and search for 'runonce'. Whatever path you put in there, it is run the next time windows starts.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I'm trying to trap a windows message that would inform me the user has selected to minimize the window. I can't find anything on MSDN that enables me to do such a thing. The WM_SIZE message is sent after the window has been minimized, and the WM_MOVING is only sent if the user user physicaly moving the window. There must be some sort of message sent when the user clicks the minimize button.
|
|
|
|
|
Surely it's a button with a known ID and there's a button click message ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Never mind, I found it. It comes under the WM_SYSCOMMAND with SC_MINIMIZE in the wParam.
|
|
|
|
|
Have you tried catching WS_WINDOWPOSCHANGED/WS_WINDOWPOSCHANGED?
--
Featuring GRATUITOUS ALIEN NUDITY
|
|
|
|
|
Hey guys,
Help! I have been using visual C++ for a while, but there is a issue always make me confused.
The description of the issue:
We use this Macro very often: ON_NOTIFY(wNotifyCode, id, memberFxn), but how do you know what is the actual signature of memberFxn.
For instance, when we use
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
At the same time, we will define a function called OnToolTipText, the signature of this function is:
OnToolTipText( UINT id, NMHDR * pNMHDR, LRESULT * pResult)
For the parameter pNMHDR, we know the actual data type maybe not NMHDR, sometime we convert it by using a specific data type rather than using it directly. The actual struct of NMHDR is:
typedef struct tagNMHDR {
HWND hwndFrom;
UINT idFrom;
UINT code;
} NMHDR;
For the notification TTN_NEEDTEXTW, we convert parameter pNMHDR by using TOOLTIPTEXTA, so my question is: how, when and where do you know you should use TOOLTIPTEXTA to convert it? why don't you use something else? is there any documents talk about what type we should use to convert a specific parameter?
PS: If you don't mind, I have one more question, is there anyone knows how to use CListCtrl::SetInfoTip()? I want to set a tooltip for each cell of the table, I tired to use SetInfoTip(), but it doesn't work well. Can you teach me how to use it?
Thank you so much!
David Zuo
|
|
|
|
|
All ON_NOTIFY handlers have the same signature. For other macros, see the documentation for that macro.
The convention for any message sent with WM_NOTIFY is for the lParam parameter of the window message to point to a structure that either is, or begins with, an NMHDR structure - the notification code is actually part of this structure. To find out if there's an extended structure sent with a given notification code, check the documentation for that code.
In your specific situation you should be matching a TOOLTIPTEXTW structure with the TTN_NEEDTEXTW notification. In general you should consider using the versions with no character-encoding-width indicator, TTN_NEEDTEXT and, as documented in the latest MSDN Library, a NMTTDISPINFO structure.
|
|
|
|
|
Is there a difference between Reentrancy and Thread Safety? Do they mean the same thing?
--------------------------------
"All that is necessary for the forces of evil to win in the world is for enough good men to do nothing" -- Edmund Burke
|
|
|
|
|
when you say a block of code is re-entrant, this means you can "enter" the code from multiple threads at the same time, and/or it can call itself as in a recursive function. In either case, you've entered the function, then entered it again while you're already in it (or while another thread is in it).
thread safety means you have have multiple threads running simultaneously and your code can handle this safely.
so, pretty much the same idea.
|
|
|
|
|
I have a fairly large dialog-based app which consists of a main dialog window and a large number of child dialogs. When I close a child window, the focus always goes back to the main dialog window instead of the window that had the focus previously.
This used to work before, but since then we made a lot of changes and nobody noticed when it started doing this.
Thanks for your help!
jpyp
|
|
|
|
|
Check your Z- order of your windows.
If u can Dream... U can do it
|
|
|
|
|
krishnadevank wrote: Check your Z- order of your windows.
I did and I can't see what is wrong. Here is more info.
In the OnCreate function of the main window, I position the window as follows:
<br />
SetWindowPos(&wndBottom, 0, 0, 0, 0, (SWP_NOSIZE | SWP_NOMOVE));<br />
Then in the main window code, I create each child window as follows:
page is a global array that contains info of all openned child windows.
<br />
page[0].pDlg = new CMyDlg0(this);<br />
page[0].pDlg->Create(ID of this dialog, NULL);<br />
page[0].pWnd->SetWindowPos(&wndTop, 20, 100, 0, 0, SWP_NOSIZE);<br />
<br />
page[1].pDlg = new CMyDlg1(this);<br />
page[1].pDlg->Create(ID of this dialog, NULL);<br />
page[1].pWnd->SetWindowPos(&wndTop, 20, 100, 0, 0, SWP_NOSIZE);<br />
In the CMyDlg0 OnInitDialog() function:
<br />
page[0].pWnd = this;<br />
In the CMyDlg1 OnInitDialog() function:
<br />
page[1].pWnd = this;<br />
We didn't design this code. We inherited it from the company that design the app for us. We only maintain the code. We would have done things differently but we are now stuck with this.
Thanks in advance for your help!
jpyp
|
|
|
|
|
Call setwindowpos with ur opend child window handles as hWndInsertAfter in a loop , So that it will be arrange it Z order. In the above code u put it as 0 (HWND_TOP).
for(all opned child windows)
BOOL SetWindowPos(
HWND hWnd,
HWND hWndInsertAfter, // placement-order handle
int X,
int Y,
int cx,
int cy,
UINT uFlags
);
}
Hopes this helps.
If u can Dream... U can do it
|
|
|
|
|
Thanks for your response!
I thought I understood this Z-order thing but maybe I'm missing something.
I have tried what you recommended with no success. The result was actually worst. I tried the following: (the lines in italic are what has changed from my original code)
I set the position of the main window.
SetWindowPos(&wndBottom, 0, 0, 0, 0, (SWP_NOSIZE | SWP_NOMOVE));<br />
Then I open the first 2 child windows as follows: (this not done in a loop)
<br />
page[0].pDlg = new CMyDlg0(this);<br />
page[0].pDlg->Create(ID of this dialog, NULL);<br />
HWND pHwnd = page[0].pWnd->GetSafeHwnd();<br />
::SetWindowPos(pWnd, HWND_TOP, 20, 100, 0, 0, SWP_NOSIZE);<br />
<br />
page[1].pDlg = new CMyDlg0(this);<br />
page[1].pDlg->Create(ID of this dialog, NULL);<br />
HWND pHwnd = page[1].pWnd->GetSafeHwnd();<br />
::SetWindowPos(pWnd, HWND_TOP, 20, 100, 0, 0, SWP_NOSIZE);<br />
If I understand how this work, at this point my Z-order should look like this:
page[1]
page[0]
main window
I started with the main window at the bottom, then I open the first child window with HWND_TOP which puts it at the top and keeping the main window at the bottom. Then I open the second window again with HWND_TOP which in turns puts it at the top and pushes down the other 2 windows to position 2 and 3 respectively.
When I close page[1], page[0] should become the active window because it is the next higher up in the Z-order in order word now position 1. However in my case, the main window becomes the active window.
Like I said, I must be missing something.
Is there a way I can look at the Z-order list?
jpyp
|
|
|
|
|