|
Hi,
this is my problem.
I have an MFC diaog based application with multiple edit boxes.
What I need to do is to automatically select all the text inside a box when clicking on it.
That's just what happens on Explorer address bar...
I've tried writing inside each OnSetfocusEdit function
m_edit.SetSel(0,-1);
m_edit.SetFocus();
I also tried to write only the line
m_edit.SetSel(0,-1);
but it didn't work.
If I put the same 2 lines in a button click the operation succeeds.
Why is this?
Can anyone help me?
Thank you in advance,
Marco.
|
|
|
|
|
the SetFocus call is not necessary anymore in the OnSetFocus.. functions, since it allready is getting the focus.
That`s probably the source of all evil...
Regards,
Davy
|
|
|
|
|
Already done, but it doesn't work...
Any other suggestion?
Thanks,
Marco.
|
|
|
|
|
Hi Marco,
Try the PreTranslateMessage override, e.g. for an IE address bar type behaviour...
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
BOOL bEatMe = FALSE;
if (pMsg && pMsg->message == WM_LBUTTONDOWN)
{
CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT1);
if (pEdit && pEdit->GetSafeHwnd() && pMsg->hwnd == pEdit->GetSafeHwnd())
{
CWnd* pPrevFocus = pEdit->SetFocus();
if (pPrevFocus == pEdit)
{
}
else
{
bEatMe = TRUE;
pEdit->SetSel(0,-1, TRUE);
}
}
}
return (bEatMe) ? TRUE:CDialog::PreTranslateMessage(pMsg);
}
Hope this helps,
Andy
|
|
|
|
|
;););););););););););););););)
Thanks a lot !!!!!! Now it WORKS !!!!!!
Marco.
;););););););););););););););)
|
|
|
|
|
If the clicking of an edit control selects all of the text contained within it, how is a person able to make a correction? Normally, a double-click of an edit control selects all of the text contained within it, and a single-click merely places the edit cursor at some point within the control. Doesn't this sound counterintuitive?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I think you'd want this behavior only if the user is likely to almost always replace the existing text. The user can still modify the text by pressing "End", "Home" or the arrow keys to first clear the selection, although this involves an extra keystroke.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I hv Integer Value which i need to convert as POSITION to assign starting POSITION for the collection class.
CTypedPtrMap m_Contacts;
POSITION pos;
CString strKey;
CContact* pContact; // Collection class which reads information from local file
int iIndex = m_screenName.GetCurSel(); // gets cursor position from combo
Now i need to assign the cursor position as POSITION for CTypedPtrMap.
m_Contacts.GetNextAssoc(pos, strKey, pContact);
Please inform me how to solve this?
|
|
|
|
|
Is the screen name the key into the contacts map? If it is, you can get that using m_screenName.GetLBText . If not, you could associate the key with the item in the combo using m_screenName.SetItemData .
I assume you have a good reason for using a Map, otherwise I would suggest using a List or an Array. MFC's map classes are based on a hash-table, which means that you won't get elements out of them in the order you inserted them, or in any predictable order, so you can't just call GetStartPosition then call GetNextAssoc repeatedly.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
A POSITION is like an iterator for a collection - its not synomous with an integer.
The CTypedPtrMap will be keyed by what ever you templateized it on - looking at this a string.
So you can find your CContact based on a CSring easily, which is the key into the map.
How did you insert into the map?
Did you insert all the keys into m_screenName, then insert each CContact into the map based on the key?
If so, you can do a GetText on the combo to get the text for item iIndex, then use that look up in the map.
CString str;
str = m_screenName.GetText(iIndex);
CContact* p = NULL;
BOOL b = m_Contacts.Lookup(str, p);
etc
If not, the only thing u can do is to advance around the map until u hit the position at iIndex:
POSTION pos = m_Contacts.GetStartPosition();
int nElement = 0;
while(pos != NULL && nElement++ <= iIndex)
{
pos = m_Contacts.GetNextAssoc(pos, strKey, pContact);
}
You get the idea - iterate around the map until you get to element iIndex.
|
|
|
|
|
Hi,
In my application i created 2 Threads.From the T1(first thread) i create the T2(second thread).While the T2 is executed,i need the T1 to pause and block all
IO operations completely like getting and writing data from named pipes and sockets.
Pls do help how to achieve this.I'm strugling.I used flags to block IO but that doesn't seems to block completely.
Pls help.Thanks in advance
ram
|
|
|
|
|
Create an event and use WaitForSingleObject
then signal the event from thread 2 whenever you want thread 1 to go on
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Thanks for the reply.
Problem here is,in second thread ,only on a particular condition i need to block th e user input.the second thread should run as background process without interrupting the
first thread.
I need to block all IO operations.I'm using named pipes and overlapped IO.
in this case how to block IO.even though i set flags,after finishing the second thread,
all pending IO gets excuted.How to avoid this.Pls help
Can i use CancelIO?
Thnks
ram
|
|
|
|
|
Use the HANDLE of the second thread as the Kernel object in WaitForSingleObject() in the first thread.
HANDLE hThread2 = CreateThread(...);<br />
WaitForSingleObject( hThread2, INFINITE);
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Thanks for the reply.
Problem here is,in second thread ,only on a particular condition i need to block th e user input.the second thread should run as background process without interrupting the
first thread.
I need to block all IO operations.I'm using named pipes and overlapped IO.
in this case how to block IO.even though i set flags,after finishing the second thread,
all pending IO gets excuted.How to avoid this.Pls help
Can i use CancelIO?
Thnks
ram
|
|
|
|
|
i wana create the window but there is some problem can any one slove it
#include<afxwin.h>
#include"resource.h"
class Dialog:public CDialog
{
public:
Dialog(int n = IDD_FORMVIEW):CDialog(n)
{
}
};
class MyDialog:public CDialog
{
public:
MyDialog(int n = IDD_DIALOG1):CDialog(n)
{
}
void OnOK()
{
CWnd *p;
p = new CWnd;
MyDialog gh;
int i;
CString str;
GetDlgItemText(IDC_EDIT_PASSWORD,str);
if(str == "arif")
{
MessageBox("Welcome","Conregulation");
p->Create(0, "Hi", WS_CHILD | WS_VISIBLE,
CRect(0, 0, 20, 20), NULL, NULL,NULL);
p->ShowWindow(1);
}
else
PostQuitMessage(0);
}
void OnCancel()
{
//Create(NULL,"Hello",WS_OVERLAPPEDWINDOW,CRect(20,20,200,200),NULL);
}
};
class CPassword:public CFrameWnd
{
private:CEdit *ed;
CString str;
public:
CPassword()
{
MyDialog dlg;
LoadAccelTable(MAKEINTRESOURCE(IDR_ACCELERATOR1));
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CPassword,CFrameWnd)
END_MESSAGE_MAP()
class CPasswordApp:public CWinApp
{
public:
int InitInstance()
{ MyDialog dlg;
CString str;
MyDialog *p;
p = new MyDialog;
p->Create(IDD_DIALOG1,NULL);
p->GetDlgItemText(IDC_EDIT_PASSWORD,str);
p->ShowWindow(1);
m_pMainWnd = p;
return 1;
}
};
CPasswordApp a;
|
|
|
|
|
Yes....
Get youself a good MFC book and go from there...
|
|
|
|
|
Anonymous wrote:
i wana create the window but there is some problem...
And that problem would be? Please be more specific with your request. You'll get way more help that way. Unless there is money involved, no one likes having code dumped in front of them with a note saying "There is some problem. Can any one solve it?"
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi all,
I have 7 edit boxes, with the tab order 1-2-3-4-5-6-7
I wrote my own tab control jumping using the PreTranslateMsg as follows:
if i am at edit box 7, i jump to an other control(checkbox)
if i am at other control (spin button) i jump to edit box 1
the problem is , when i am at edit box 6 and press Tab, i see the jumping to edit box 7 and immediately i jump into the checkbox (meaning i didn't stop at editbox 7)
same as for the spin button, if i am at edit box 2 and press SHIFT+Tab(jumping backwards) i see it is jumped to edit box1 and automatically jumps to the spin control
here is the code i am using:
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
short nShiftKeyDown = GetKeyState(VK_SHIFT);
BOOL bShiftKeyDown = ((nShiftKeyDown & 0x8000) == 0x8000);
if (pMsg->hwnd == m_editAns1.m_hWnd)
{
if ( (pMsg->wParam == VK_TAB) )
{
if (bShiftKeyDown)
{
m_pParentWnd->SendMessage(UM_SET_QTXT_FOCUS);
return TRUE;
}
}
}
if (pMsg->hwnd == m_editAns5.m_hWnd)
{
if ( (pMsg->wParam == VK_TAB) )
{
if (!bShiftKeyDown)
{
m_pParentWnd->SendMessage(UM_SET_CB_FOCUS);
return TRUE;
}
}
}
return CBaseDlg::PreTranslateMessage(pMsg);
}
what am i doing wrong here?
thanks in advanced
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
I found out the problem!
it was getting there due to WM_KEYDOWN and WM_KEYUP
if i added the conditio pMsg->message == WM_KEYDOWN
it works
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Hi,
I have a problem regarding embedded dlls (managed and unmanaged).. Could you help me please ?
My problem is the following..
- my target is a Pocket PC
- I want to export an unmanaged dll that I've done using Embedded Visual C++ 4.0 and wrap it with a managed dll written in C++. My unmanaged class is :
header :
--------
#ifdef UNM
#define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif
class DLL_API DLLUnmanaged
{
public:
DLLUnmanaged();
DLLUnmanaged(const char * const);
~DLLUnmanaged();
const char * getstring() const {return str;}
char * suffix(int n);
private:
char * str;
unsigned short len;
};
cpp:
#include
#include "stdafx.h"
#pragma warning( disable : 4091 )
#include "UnmanagedDLL.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
DLLUnmanaged::DLLUnmanaged()
{
str = (char *)LocalAlloc(0, sizeof(char));
str[0] = '\0';
len = 0;
}
DLLUnmanaged::DLLUnmanaged(const char * const str0)
{
len = (unsigned short)strlen(str0);
str = (char *) LocalAlloc(0, sizeof(char)*(len+1));
for(unsigned short i = 0; i < len; i++)
str[i] = str0[i];
str[i] = '\0';
}
char * DLLUnmanaged::suffix(int pos)
{
unsigned short suffix_length;
pos--;
if (pos < 0) pos = 0;
suffix_length = len - pos + 1;
if (suffix_length > 0)
{
char * suff = new char[suffix_length];
for(unsigned short i = pos; i < len+1; i++)
suff[i - pos] = str[i];
return suff;
} else
return 0;
}
DLLUnmanaged::~DLLUnmanaged()
{
LocalFree(str);
len = 0;
}
- I want to use the managed extensions of Visual Studio .Net like this :
#using
using namespace System;
#include
using std::cout; using std::endl;
#include "path.../UnmanagedDLL.h"
public __gc class DLLManaged // to avoid using "DLLImport"s..
{
public:
String * find_suffix(String * s, int pos)
{
int length = s->Length;
char * in_string = new char[length+1];
for(unsigned short i = 0; i
{
in_string[i] = (char)s->Chars[i];
}
in_string[length] = '\0';
DLLUnmanaged * s0 = new DLLUnmanaged(in_string);
delete [ ] in_string;
return s0->suffix(pos);
}
};
... so here is what I've done when doing it only with Visual Studio .Net. I've added to the solution (that has got the unmanaged (I took "DLL MFC") and managed (I took ".Net DLL") ) a C# windows application that simply references the managed dll. All that works fine..
but if I want to make a project like this (actually the unmanaged dll that I use is a bit more complicated that the one I gave you) for a Pocket PC I encounter a lot of problems (please don't blame me, I'm a beginner!)
I tried to do it this way. The thing is that I don't know how to make an EMBEDDED MANAGED C++ DLL...
if I do the unmanaged project with Embedded Visual C++ 4, and if I make a .Net DLL similar to the one I've given to you upper, I get errors like:
ManagedDLL error LNK2020: jeton non résolu (0A000009) _CxxThrowException
ManagedDLL error LNK2020: jeton non résolu (0A00000B) delete
ManagedDLL fatal error LNK1120: 2 externes non résolus
(sorry, I've the French version of VS .Net)
obviously the linkage goes wrong..
So..what is the thing I've to do ? could you help me please, since I'm trying to fix the problem for many days now!
thanks to pay attention to it,
Julien (IT student)
|
|
|
|
|
Hi all,
Does anybody can tell me how to change the back ground color of the printable area of the print preview view. If I override the erase background method and set the background color then the area other than the printable area background is changed. I want to just change the printable area background.
thanx in advance
thanvir
|
|
|
|
|
This is done in the void CPreviewView::OnDraw(CDC* pDC) function which can be found in viewprev.cpp line 631.
You would have to replace the existing version of this function (probably by using your own class inheriting from CPreviewView). Take a look at my enhanced print preview articles which should get you going.
Roger Allen - Sonork 100.10016
Strong Sad: I am sad I am flying
Who is your favorite Strong?
|
|
|
|
|
Hi,
I encountered a problem in a project ,the realease version can not work properly while the debug version working well .
A cricheditctrl was created dynamically , I call the RequestResize() function in the onkeydown() for sending the EN_REQUESTRESIZE nofification message.
then I capture the EN_REQUESTRESIZE in onnotify() ,which is in the parent-window.
All above is for control the richedit control size freely.
the problem is this function can run smoothly in debug version , but not in release version!!!
who can help you , Thks ahead
Best Regards
Jun Mu
|
|
|
|
|
mujun wrote:
the problem is this function can run smoothly in debug version , but not in release version!!!
"Run smoothly", or lack thereof, is not a very specific description. What sort of problem are you seeing? Have you put in any sort of "debugging" code (e.g., message box, writing to a file) that tells you the state of things as the program is running?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|