|
Thanks, I definitely will.
|
|
|
|
|
Good. Please register here at CP instead of posting Anonymously. I tend to ignore anonymous posts as do others.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
Hi,
I have a CDialog which contains several CEdit fields. I would like to be able to set one of those CEdit fields to have initial input focus.
I'm trying to use the following code but it does nothing. I've made sure editField1 is valid at that point.
<br />
BOOL MyDialog::OnInitDialog() <br />
{<br />
CDialog::OnInitDialog();<br />
editField1.SetFocus();<br />
<br />
return true;<br />
}<br />
Thoughts/hints?
Thanks
Hua-Ying
|
|
|
|
|
Calling SetFocus() in a dialog (or anywhere else) can be problematic. You could try editField1.PostMessage( WM_SETFOCUS ... ) which will have a far better chance of working. You need to test stuff like this on all patforms your app will run on.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
When I tried what you suggested, the CEdit field stops accepting user input(just beeps when you type)? It does put the caret in the edit box when the dialog starts up though.
editField1.PostMessage(WM_SETFOCUS);
Hua-Ying
|
|
|
|
|
hyling wrote:
When I tried what you suggested, the CEdit field to stop accepting input at all? It does put the caret in the edit box when the dialog starts up though.
Have you specified the correct vaues for the PostMessage() wParam and lParam params. Look at WM_SETFOCUS in the Help for details.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
Would you explain why you said this: Calling SetFocus() in a dialog (or anywhere else) can be problematic. I couldn't find anything discussions about this with google.
Also, I could never get PostMessage to work right.
I tried this:
<br />
mIDField.PostMessage(WM_SETFOCUS, (WPARAM)m_hWnd, 0);<br />
According to the docs:
Parameters
-wParam
Handle to the window that has lost the keyboard focus. This parameter can be NULL.
-lParam
This parameter is not used.
Thanks
Hua-Ying
|
|
|
|
|
hyling wrote:
Would you explain why you said this: Calling SetFocus() in a dialog (or anywhere else) can be problematic. I couldn't find anything discussions about this with google.
You can and do get into race conditions where your code is trying to SetFocus and Windows is also trying to SetFocus(). A common mistake people make where this is evident is validating a control in its OnKillFocus() handler and calling SetFocus() when it is invalid to set the focus back to the control loosing focus. This won't work because upon return from OnKillFocus() windows will set the focus to the next control etc. PostMessage() is a way to handle this scenario.
David has pointed out the correct answer however.
Neville Franks, Author of ED for Windows www.getsoft.com and Surfulater www.surfulater.com "Save what you Surf"
|
|
|
|
|
When posting code snippets, it's beneficial to post them verbatim rather than typing them in manually. This is evident in the fact that you are returning a bool from a BOOL method.
Since OnInitDialog() is created by AppWizard or ClassWizard, you've no doubt noticed the comment that gets placed near the bottom of the OnInitDialog() method:
return TRUE;
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
AppWizard didn't create a OnInitDialog function for this class, I had to add it in by hand and didn't see the comment before.
You're right, I should have been returning false for this function.
The following code works for me:
<br />
BOOL MyDialog::OnInitDialog() <br />
{<br />
CDialog::OnInitDialog();<br />
editField1.SetFocus();<br />
<br />
return FALSE;<br />
}<br />
Thanks!
Hua-Ying
|
|
|
|
|
|
Hi,
I Want to disable move menuitem in a window's system menu, please help.
Thanks
Bose
|
|
|
|
|
Congratulations!!! Good question. I wasted two hours of my life today doing this s..t for you.
Below is a solution of the problem:
BOOL CYourDlg::PreTranslateMessage(MSG* pMsg)
{
if((pMsg->message==WM_NCLBUTTONDOWN && SendMessage(WM_NCHITTEST,0,pMsg->lParam)==HTSYSMENU) ||
(pMsg->message==WM_NCRBUTTONDOWN && SendMessage(WM_NCHITTEST,0,pMsg->lParam)==HTCAPTION))
{
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
if(GetStyle()&WS_THICKFRAME)
pSysMenu->EnableMenuItem(SC_SIZE,MF_BYCOMMAND|MF_ENABLED);
else
pSysMenu->EnableMenuItem(SC_SIZE,MF_BYCOMMAND|MF_GRAYED);
if(GetStyle()&WS_MINIMIZEBOX||GetStyle()&WS_MAXIMIZEBOX)
{
if(GetStyle()&WS_MINIMIZEBOX)
{
if(IsIconic())
{
pSysMenu->EnableMenuItem(SC_MINIMIZE,MF_BYCOMMAND|MF_GRAYED);
pSysMenu->EnableMenuItem(SC_RESTORE,MF_BYCOMMAND|MF_ENABLED);
}
else
{
pSysMenu->EnableMenuItem(SC_MINIMIZE,MF_BYCOMMAND|MF_ENABLED);
pSysMenu->EnableMenuItem(SC_RESTORE,MF_BYCOMMAND|MF_GRAYED);
}
}
else
pSysMenu->EnableMenuItem(SC_MINIMIZE,MF_BYCOMMAND|MF_GRAYED);
if(GetStyle()&WS_MAXIMIZEBOX)
{
if(IsZoomed())
{
pSysMenu->EnableMenuItem(SC_MAXIMIZE,MF_BYCOMMAND|MF_GRAYED);
pSysMenu->EnableMenuItem(SC_RESTORE,MF_BYCOMMAND|MF_ENABLED);
}
else
{
pSysMenu->EnableMenuItem(SC_MAXIMIZE,MF_BYCOMMAND|MF_ENABLED);
pSysMenu->EnableMenuItem(SC_RESTORE,MF_BYCOMMAND|MF_GRAYED);
}
}
else
pSysMenu->EnableMenuItem(SC_MAXIMIZE,MF_BYCOMMAND|MF_GRAYED);
}
<BR>pSysMenu->EnableMenuItem(SC_MOVE,MF_BYCOMMAND|MF_GRAYED);
int nRet = pSysMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON|TPM_RETURNCMD, LOWORD(pMsg->lParam), HIWORD(pMsg->lParam), this);
PostMessage(WM_SYSCOMMAND,nRet,pMsg->lParam);
return 1;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
Regards,
Andrzej Markowski
|
|
|
|
|
I have an application that is compiled for Unicode (MSVC 7.0). I need to call functions in a DLL that is MBCS only. I need suggestions on how to convert the function args that are passed between the Unicode and non-unicode layers.
Jim S
|
|
|
|
|
I have an angry baby sitting on my lap so I'm going to be quick about it:
MultiByteToWideChar
WideCharToMultiByte
look'em up
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
|
I knew about converting strings to/from Unicode and the ATL macros. I didn't know if anything special had to be done to make function calls work correctly between a Unicode and a non-Unicode DLL. I think that the answer is that you only have to worry about keeping the strings straight.
|
|
|
|
|
I have 5 CString and i want to write it to a txt file on 5 different lines at the end of the file help please.
|
|
|
|
|
insert "\r\n" between each CString then call CFile::Write()
[insert witty comment here]
bdiamond
|
|
|
|
|
that what i did it printed 2 ascii
|
|
|
|
|
I want to write an APP for window media player to play a video.
What should i do?
|
|
|
|
|
RockRock wrote:
I want to write an APP for window media player to play a video.
What should i do?
Have you actually tried yet? If so, what have you done so far, and what didn't work? You're a lot more likely to get answers if you post a question we could actually answer, such as:
"I'm trying to use Windows Media Player to play a video from inside my application, but calling CoCreateInstance() to create an IWMPCore object always fails. I've got Media Player 9 installed and I'm successfully calling CoInitialize(). What else could cause CoCreateInstance() to fail?"
Notice the difference between that and your question?
If you haven't tried yourself, then I don't think many people would be willing to help.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
i am sorry.
since i don't know how to get started on it.
|
|
|
|
|
Well, you can have a look at the Windows Media Player ActiveX control, or you can use the IWMPCore interface that I mentioned before. I haven't done it myself so I can't really help much more than that.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I was working on something when the computer crushed and msdev.exe closed. After that i opened msdev.exe but there was no menu items, toolbar no nothing but only the editing window displayed i suspected that the toolbar and menu setting file (probably the .ini) file become corrupted.
i have heard some where that when i execute the program from the start->run and run the program by writing "msdev.exe -something" and runningthe program i can fix all this but i searched the windows help and msdn for such things but couldn't find any
i have a friend who has the same problem with microsoft word but he gets around using the keyboard shortcuts.
if you know this by any way pls help me i am stuck and got a work to do.
|
|
|
|