Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


Sign in to follow this  
BenoitRen

I want to make a Notepad alternative in C

Recommended Posts

Right, that did it. Odd, usually the reference shows to cast it, which is why I didn't do it.

GetClassName() requires you to allocate a buffer, which is always a pain. And I have no idea what the class names of those dialog boxes would be, since they're created from resources.

There should be a better way to know which window I'm dealing with. If not, I'll just use an extra variable, I guess.

Still open for suggestions on how to get the RichEdit control to update its scrollbars properly and how to have the search dialog focussed while still showing selected text.

Share this post


Link to post
Share on other sites

GetClassName() requires you to allocate a buffer, which is always a pain. And I have no idea what the class names of those dialog boxes would be, since they're created from resources.
Then I didn't understand your problem. The classname of a dialog is always "DIALOG", so you can't use it to seperate different dialogs. You could useGetWindowText(), which gives you the titlebar of the dialog (if any), or an extra variabele. You can also store some extra data with the handle with Set/GetWindowLong( GWL_USERDATA ). Or use different windowprocs.
Still open for suggestions on how to get the RichEdit control to update its scrollbars properly and how to have the search dialog focussed while still showing selected text.
In which case does the control not update properly, and is it really nessessairy to focus the editcontrol to show the selected text?

Share this post


Link to post
Share on other sites
In which case does the control not update properly

When I load a file's contents into it. I can only scroll part of the document horizontally. The vertical scroll bar doesn't have this problem. It's solved as soon as I make a change in the text.

is it really nessessairy to focus the editcontrol to show the selected text

If I don't do it, the text is selected, but you can't see it is until you focus the RichEdit control. So I focus it.

Share this post


Link to post
Share on other sites

On scrollbar: Obviously the scrollbar range is not calculated correctly on loading the file. Maybe it helps to turn it off and on?

ShowScrollBar( hEdit, SB_HORZ, FALSE );

ShowScrollBar( hEdit, SB_HORZ, TRUE );

On focus: I think you should use EM_HIDESELECTION.

EDIT: I quickly figured to look in the DLLs that Wordpad uses, and it looks like the two dialogs I'm after are part of COMDLG32.DLL.
AFAIK ComDlg32 is not intended for this. Probably it exports some API functions which do the whole dialog part of the resources you need, like Find and Replace Dialog Boxes

Share this post


Link to post
Share on other sites
AFAIK ComDlg32 is not intended for this. Probably it exports some API functions which do the whole dialog part of the resources you need, like Find and Replace Dialog Boxes

Thanks. I've rewritten my program to make use of this instead. It's done now, save for the same quirks.

On scrollbar: Obviously the scrollbar range is not calculated correctly on loading the file. Maybe it helps to turn it off and on?

Tried it. Didn't help.

On focus: I think you should use EM_HIDESELECTION.

Now that I've rewritten the findreplace code, the RichEdit is automatically focussed when I receive feedback from the dialog. Not sure if I should focus the dialog back.

I have one more minor problem now. The message box I show after having done the Replace All action doesn't show all the text.

int replacements = 0;
char strReplacements[17];
itoa(replacements, strReplacements, 10);
MessageBox(hwnd, strcat(strcat("Kladblok is klaar met het doorzoeken van het document en heeft\r\n", strReplacements), " wijzigingen gemaakt."), "Kladblok", MB_ICONINFORMATION | MB_OK);

After the number I get nothing. It must be some silly mistake with strings, but I don't know what it is.

Thanks for your assistance so far. :)

Edited by BenoitRen

Share this post


Link to post
Share on other sites

While looking at the documentation for EM_HIDESELECTION, I've noticed that it also has the ability to change styles. I looked further, and found the ES_NOHIDESEL style. I found it easier to just apply that directly when the control gets created.

That and focussing the dialog after I'm done takes care of that problem.

I've implemented the "Search next" menu item that I forgot about, and it works fine, but for some reason pressing F3 doesn't activate it, even though I've altered and recompiled the resource file. It shows on the menu, too.

MENUITEM "&Volgende zoeken\tF3", ID_SEARCH_NEXT

There doesn't seem to be anything wrong with this...

Share this post


Link to post
Share on other sites
I have one more minor problem now. The message box I show after having done the Replace All action doesn't show all the text.

int replacements = 0;
char strReplacements[17];
itoa(replacements, strReplacements, 10);
MessageBox(hwnd, strcat(strcat("Kladblok is klaar met het doorzoeken van het document en heeft\r\n", strReplacements), " wijzigingen gemaakt."), "Kladblok", MB_ICONINFORMATION | MB_OK);

After the number I get nothing. It must be some silly mistake with strings, but I don't know what it is.

You're lucky this doesn't crash your program. strcat concatenates 2 strings, and puts the result in the first argument buffer. In your case this is a static string, which has no room for the added data. You could write it this way:

char buffer[ 256 ] = "Kladblok is klaar met het doorzoeken van het document en heeft\r\n";
MessageBox(hwnd, strcat(strcat( buffer, strReplacements), " wijzigingen gemaakt."), "Kladblok", MB_ICONINFORMATION | MB_OK);

or

char buffer[ 256 ];
sprintf( buffer, "Kladblok is klaar met het doorzoeken van het document en heeft\r\n%u wijzigingen gemaakt.", replacements );
MessageBox(hwnd,buffer,...);

but for some reason pressing F3 doesn't activate it
I think you have to use LoadAcceletators(). This loads a table from recource, which links some hotkeys to menu items.

Share this post


Link to post
Share on other sites

Thanks. I really should read through my course of C again when it comes to pointers and strings. That, and read the documentation better. I didn't note that the end result is stocked in the first argument.

LoadAccelerators() requires an accelerator table, which I don't have. I tried with my menu resource anyway, and it didn't help. What's strange is that the accelerators for Cut, Copy and Paste worked when I defined them. They didn't work at first.

EDIT: I researched more about this on MSDN, and it turns out that I do need an accelerator table. Including the text in the menuitem doesn't magically activate it. It was too good to be true.

So now the only issue is the bad scrollbar calculation. I've just seen it a couple times with the vertical scrollbar as well. It's getting worse. :(

Edited by BenoitRen

Share this post


Link to post
Share on other sites

Yes, I used SetWindowText. Okay, rewrote the loadFile function to make use of EM_STREAMIN. But it doesn't seem to have changed anything. I even tried an extra UpdateWindow(). :(

Share this post


Link to post
Share on other sites

In that case I can only think of a workaround. You write that the problem is solved when you start typing. So you could send 2 fake keystrokes to the control after loading the file. Set the focus to the control, and use keybd_event to send space backspace to the control.

Share this post


Link to post
Share on other sites

That helps a bit, but not completely. How can I make sure that the entire text has been loaded before I do this? Also, shouldn't there be a message that I can use to force it to recalculate its scroll bars?

I wonder if I'm the only one who's ever had this problem. I've Googled it again, and no one seems to have had a similar problem.

Share this post


Link to post
Share on other sites
How can I make sure that the entire text has been loaded before I do this?
It should be loaded after SendMessage( , EM_STREAMIN, ) or SetWindowText() returns. You program is singlethreaded, I suppose, so the control has to do it's work inside these commands.
Also, shouldn't there be a message that I can use to force it to recalculate its scroll bars?
Should? It should not be necessary to do so.
I wonder if I'm the only one who's ever had this problem. I've Googled it again, and no one seems to have had a similar problem.
Maybe you should install IE? I suppose it will update RichEdit.

On the VS CD there's a program called spy++. Don't know if you can extract it without installing the whole blurb. When you can you can use it to watch the messages Wordpad sends to the RichEdit when a file loads, and compare it to your own program.

Share this post


Link to post
Share on other sites

I tried Winspector the other day, but boy was it slow. Now I finally tracked down Spy++.

Wordpad never displays a horizontal scroll bar, actually. :( So I looked at NotepadEx, and it uses a bunch of EM_GETLINE messages followed by EM_CANUNDO ones, and a lot of unknown ones.

I don't know what to make of this. Saving the output to logs seems to require some magic tricks, so I can't paste it here.

By the way, that file SPYHK50.DLL kept denying access when I wanted to move and then delete it. I removed it from pure DOS.

Edited by BenoitRen

Share this post


Link to post
Share on other sites

I still have no idea how NotepadEx fixes the bug, though it must be some hack, as the other day the horizontal scroll bar wasn't calculated properly. Probably because of tabs in the file.

However, I've tried the RICHED32.DLL file in the RICHED9X.EXE file that MDGx provides on his site, and it seems to not have the issue. :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...