|
lctrncs wrote: how might I change my program so that it is harder for the user to delete existing text which has unwanted selection upon gaining focus to the edit control using the tab key?
When the control receives focus, call its SetSel(0, 0) method.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
lctrncs wrote: when the user tabs to either edit control, existing text in the control is selected
This is the default behaviour of the dialog manager. If this is undesirable you should tell the dialog manager, by subclassing the edit control and handling WM_GETDLGCODE[^] to not return the DLGC_HASSETSEL flag (call the base class procedure and mask it out ie. & ~DLGC_HASSETSEL).
lctrncs wrote: using EN_SETFOCUS (after changing the on_notify to on_en_setfocus in the message map),
How did you go about doing this? Using the IDE or manual edits to the message map? EN_SETFOCUS is sent through a WM_COMMAND message, and not a WM_NOTIFY message. The member function signature for both are different. Not sure if this is the problem though as I think the compiler should complain if you made a mistake.
Edit: Link regarding WM_GETDLGCODE http://blogs.msdn.com/oldnewthing/archive/2003/11/14/55678.aspx[^]
-- modified at 15:19 Thursday 24th August, 2006
|
|
|
|
|
hfry - thanx.
your proposed solution looks feasible, and I will give it a try soon
I will have to understand all this subclassing stuff first...
it looks interesting.
You asked about how I changed on_notify and on_en_setfocus
hfry wrote: How did you go about doing this? Using the IDE or manual edits to the message map?
I based my changes on this url
http://support.microsoft.com/default.aspx?scid=kb;en-us;181664[^]
after making the ON_NOTIFY TO EN_SETFOCUS change to the messagemap associated withthe Visual C++ 5.0 and 6.0 bug discussed in the link
I added my pointer/SetSel(0,0) code to the OnSetFocusTheEditControl function
there were no compiler errors
everything worked fine in debug configuration
however, changing to release configuration caused an access violation - with or without my pointer/SetSel(0,0) code whenever the modified function was present
the Microsoft page about the bug also said that you had to have AfxInitRichedit() in your dialog initinstance and modify the message handlers, but I cannot find any difference in the handlers other than the arguments
variations on these themes were not successful either - still the Access Violation in release config when oninit the dialog
A different link suggested that my pointer might be trying to hit the control before it existed - maybe that is the missing "this"? However, the problem occurs even without my pointer
I tried to use the en_killfocus a while back for something else using the same type of messagemap modifications, and had a similar release configuration exception - which forced me to use a different aproach
I wish I understood what the problem is with the modified on_en_setfocus, or better, how to eliminate it in release config and understand it.
I hope this answers your question.
Thanks again.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
The handler should look like
void OnSetfocusRichedit1();
instead of
void OnSetfocusRichedit1(NMHDR* pNMHDR, LRESULT* pResult);
Is the first handler what you have?
|
|
|
|
|
I tried both - but I got compiler errors unless I included the LRESULT*pResult argument for the first one.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
lctrncs wrote: I got compiler errors unless I included the LRESULT*pResult argument for the first one.
That can't be right. What are the compile errors? Having a return value when there isn't supposed to be one would put your stack out of whack. I don't have VC6 (I use VS2003) so the classwizard is fine.
I created a simple MFC dialog app, added a Edit and RichEdit control and have focus handlers for both and I can't duplicate this behaviour.
|
|
|
|
|
Wow.
Thanks for your feedback!
I very much appreciate it.
You seem interested in this from an almost didactic standpoint.
I can appreciate that.
I need to clear the selection on my control so my users do not erase their data.
Perhaps we can collaborate.
What can't be right? Including the LRESULT*pResult?
Let me first say that I used to test ATM network protocol analyzers for HP - and can test many options quickly.
Let me know more about your area of interest - and I will try to assist.
Lets review the possibilities.
I am using Visual C++ 6.0 Standard (copyright 1994-1998) MSCorp.
I used the classwizard to add an EN_SETFOCUS function for either/both a rich edit control or an edit control, then changed the message map as directed by the microsoft bug admission url (see previous message) - and added AfxInitRichEdit(); to my InitInsatnce as directed by the MS URL.
Perhaps this is/can be a baseline?
I will test the options now - good thing I am sleep apnea/narcoletpic/insomniac!
1. does afxinitrichedit end exception if present in initinstance if altered on_en_setfocus code present(not include SetSel) in release?
stand by ...
release config - no onsetfocus -> no access violotion - open dilog box interface to DB on top of document view - no problem
remove comments from altered on_notify->on_en_setfocus map/handler/function - but no pointer/SetSel(0,0) code int onsetfocus function...
PS: dialog box modeless....
->Unhandled exceptoin - access violation = true.
onsetfocus arguments (Lresult *pResult) -> onsetfocus arguments (Lresult *pResult) ->access violation = true
onsetfocus arguments () -> access violation = true
onsetfocus arguments (NMHDR, pNMHDR, Lresult *pResult) -> access violation = true
ADD SetSel(0,0) -> access violation = true
previous post appears incorrect that onsetfocus arguments (Lresult *pResult) ->access violation = false <- false
if setfocus code present - even though compiles in debug p (after) changing on_notify to ON-En-Setfocus - access violation in release config
no possibility appears to function when unaltered, or altered onsetfocus code present in release config (although fixed in debug when onsetfocus arguments (NMHDR, pNMHDR, Lresult *pResult).
A local high end embedded programmer suggested that I might not have allthe libraries I need.
perhaps I should be trying to learn about subclassing
All I want to do is clear a selection when I hit the control...
WHY is this so hard?
I hope this delivers useful info.
Thanks again for your feedback.
sleep awaits...
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
After 10 winks or so, I thought I would run through the cases again to make sure I didn't miss anything.
This time, it appears to work in release config with the following changes to the original code ...
AfxInitRichEdit in the initinstance
alterations to the classwizard's incorrect messagemap from on_notify to on_en_setfocus
alterations to the handler to reflect change in messagemap
including removing all arguments in the handler - and then the function
maybe the key ingredient here was sleep!
I think I go get more.
Thanks for your help!
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
Hello everyone,
my Prob is not really MFC related I think, but I didnt find a better spot.
So, I have a SDI app, in which I have the normal IDR_MAINFRAME thing and a corresponding icon.
But I also use xp style menus, where I use icons, which are NOT published in the "Resource.h". If do so, the icons dont show up anymore in my contextmenus. But if I dont publish them in the resource.h then my application icon is somehow overwritten. That means the icon shown for my app is the last icon I added for my menus.
Resource.h
<br />
#define IDR_MAINFRAME 24<br />
#define IDI_BROWSER 123<br />
App.rc
<br />
IDR_MAINFRAME ICON res\\app.ico<br />
IDI_BROWSER res\\browser.ico<br />
if I put it like that, then the desktop icon is correct, but my icons dont show in the contextmenus
if I remove the line #define IDI_BROWSER 123, then my menus show the icons, but my app icon is all of a sudden the browser icon, or the last icon I added to the menu icons in the app.rc. I also tried rearanging the order, because it says the lowest number is the programms icons...didnt help. Or did I change orders in the wrong place ?
The mainapp window icon never changes, that is allways the correct app.ico
So my actual question is :
What can I do about that?
How can I manually influence, which icon is shown on the desktop? Where is that set?
Thanks a lot for any small hint!
Best regards $motty
|
|
|
|
|
easy actually. open the resource header and assign a new number to the icons. The icon you want on the desktop should have the lowest number.
|
|
|
|
|
yes, thats what I understand from reading to comments in the app.rc, but thats my prob, I cant assign numbers to the menu icons, so I cant make sure they are lower
internaly they seem to get lower assignments if I DONT give them numbers.
I have been working on a different app for a while, where the desktop icon didnt have a number at all, at least from I saw......
But from review that I think I found the trick......DONT assign a number to any icon and let the NAME (stupid but it works) just be the very first in alphabetic order....
thanks for ur help, it made me figure it out!
|
|
|
|
|
You don't need to open the .rc file. Alongside the resource file there is a header file, usualy called resources.h this has all the #define statements for the items in the resource file. Just find your icon and change the number to 1. i.e.
#define IDI_ICON1 1
or whatever name you decided to give it
|
|
|
|
|
thank you again for thinking about this !
But as soon as I define IDI_ICON1, I cannot use this icon anymore for my officeXP Style contextmenus.
So the solution for my problem was hand opening the app.rc, putting in my icons with
IDI_Icon1 ICON res\\someIcon1.ico
IDI_Icon2 ICON res\\someIcon2.ico
IDI_Icon3 ICON res\\someIcon3.ico
and then using
__IDI_APPICON ICON res\\myApp.ico <---- the "____" is the trick to get it to position #1 (lexicographic order)
for the desktop and then using
ShowIcon(myAppIco,TRUE)
to show that icon in the dialog window.
thx
$motty
|
|
|
|
|
What are you talking about? within the .rc file there is no ordering, lexicographical, numerical, alphabetical, none! All those words that you see there: IDI_Icon1 , IDI_Icon3 , __IDI_APPICON will be turned into a number when you compile the resources. Those numbers are defined in the .rc's header file. Look at the top few lines you will see something like #include "resources.h" then open that file. There you will find all the resource definitions. All you need do is find the name you assigned for your icon, and change it's number.
|
|
|
|
|
Hm.....I do understand, what YOU are talking about
But I DONT give them numbers (names, defines) in the .rc´s header file (the resources.h).
If I do what you suggest, I cannont use the icons for the xp style context menus anymore (dont ask why, thats just how it works)
During compiling they certainly all get number to be identified, but then again it looks like this compiletime number assignment was lexicographical if you DONT assign a number in the first place (which I cant).
Does this make it clearer to you ?
As I said, now it finally all works the way I want it to. But it does so without filling the resources.h.
When I use the VS resource editor, the icons (the way I use them now) have IDs like "IDI_ICON1" instead of what they have when they have a predefined number like IDI_ICON1, without the " " around them and you CANNOT reassign a number in the editor.
$motty
-- modified at 10:54 Friday 25th August, 2006
|
|
|
|
|
Hi every body,
Now, i want to write a program, it can send message to Yahoo users, but I don't know how to do it. Every body have experience about it, please tell me.
Thanks & Best Regards
xyz
|
|
|
|
|
Silly Boy wrote: Now, i want to...send message to Yahoo users,
Isn't that what Yahoo's IM is for?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Yahoo has an Activex Control for that. Try inserting activex control in dialog or anywhere u like.
regards
krishnan
If u can Dream... U can do it
|
|
|
|
|
Silly Boy wrote: Now, i want to write a program, it can send message to Yahoo users, but I don't know how to do it. Every body have experience about it, please tell me.
if you want to send EMAIL to yahoo users you have to use POP classes!... and if you want to send im to yahoo user .. this link might help
http://gaim.sourceforge.net/[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hi people, im using Update Resource to change a Bitmap in a DLL.
The bitmap is beign changed, but the new added bitmap hasn't a valid format.
I found this at expert exchange
char* buf = (char*)HeapAlloc (GetProcessHeap(), 0, dwFileSize + 2);
memcpy (buf, &dwFileSize, sizeof (dwFileSize));
memcpy (buf + 4, lpBuffer + 2, dwFileSize - 2);
This guy said that the resource BMP dont start with BM, instead the first 4 bytes are the lenght of the resource.
But a working BMP in the DLL begins with BM.
I tried without that code and the newly added BMP has an invalid format anyway.
Any suggestion??
Thanks a lot people
HANDLE hFile;<br />
DWORD dwFileSize, dwBytesRead;<br />
LPBYTE lpBuffer;<br />
<br />
hFile = CreateFile("test.bmp", GENERIC_READ, <br />
0,<br />
NULL,<br />
OPEN_EXISTING,<br />
FILE_ATTRIBUTE_NORMAL,<br />
NULL);<br />
<br />
if (INVALID_HANDLE_VALUE != hFile)<br />
{<br />
dwFileSize = GetFileSize(hFile, NULL);<br />
<br />
lpBuffer = new BYTE[dwFileSize];<br />
<br />
if (ReadFile(hFile, lpBuffer, dwFileSize, &dwBytesRead, NULL) != FALSE)<br />
{<br />
<br />
<br />
char* buf = (char*)HeapAlloc (GetProcessHeap(), 0, dwFileSize + 2);<br />
memcpy (buf, &dwFileSize, sizeof (dwFileSize));<br />
memcpy (buf + 4, lpBuffer + 2, dwFileSize - 2);<br />
<br />
<br />
<br />
if( UpdateResource( targetModule,<br />
RT_BITMAP,<br />
MAKEINTRESOURCE(1002),<br />
MAKELANGID(LANG_SPANISH,SUBLANG_SPANISH_ARGENTINA),<br />
(LPVOID)buf,<br />
sizeof(buf))) {<br />
<br />
MessageBox("Update OK", NULL, MB_OK);<br />
<br />
}<br />
else {<br />
MessageBox("Error in update", NULL, MB_OK);<br />
}<br />
<br />
if(EndUpdateResource(targetModule, FALSE)) <br />
MessageBox("Res changed", "ERROR", MB_OK);<br />
else<br />
MessageBox("Error updating res", "ERROR", MB_OK);<br />
<br />
<br />
}<br />
<br />
delete [] lpBuffer; <br />
<br />
CloseHandle(hFile);<br />
}
|
|
|
|
|
Kharfax wrote: im using Update Resource to change a Bitmap in a DLL. The bitmap is beign changed, but the new added bitmap hasn't a valid format.
Get the bitmap's format fixed first before moving on to UpdateResource() . It doesn't make sense to update a resource via UpdateResource() when the resource is not even vaid.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Maybe I didn't explain myself well :S
If I add the new bitmap in the project via Visual Studio, it works great.
The problem is when I load the same bitmap, a .bmp file, into memory and then add it to the DLL using UpdateResorce.
The new bitmap replaces the old, but Visual studio tell me that the resource had an invalid format and dont show me the image, Loadbitmap also fails the load and shows me an empty static control in my test app.
|
|
|
|
|
I´m not sure, but try to check the EXACT format of ur bitmap.....I had the same prob with a GIF file and after checking the exact properties of the working image and after moving my properties to match them exa ctly it worked.....if it looks the same it isnt necessarily the same for VS
|
|
|
|
|
mmm, I don't understand, maybe I missing something...
I have a static control, and I set a Bitmap resource in it using SetBitmap(), that way, I can see the image.
If I add the resorces bmps using visual studio, it work fantastic.
But when I use UpdateResource to change the Bitmap, for another working bitmap made with VS also, it fails, and I don't see anything.
So I open the DLL to check if the resourse was added and I find it's there, but when I try to see it, VS tell me it has an invalid format.
So... The question would be, the bitmap stored as resourse is changed in some way?
Should I write the lenght of the resource at the beginning?
Actually I'm doing an exact copy of the file to the resource, and I also tried writing the lenght and removing the BM at the beginning, but nothing works.
I dont understand what you mean with "check the EXACT format of the bitmap"
|
|
|
|
|
hi
try this. First put a bitmap to your resource file using VS . then change that resource. next put the same bitmap using updateresource api. save that resource also. try comparing it. and try to catch out which bytes are missing ? This might lead you to a solution , i hopes
regards
krishnan
If u can Dream... U can do it
|
|
|
|
|