Stoic Joker Posted August 30, 2007 Share Posted August 30, 2007 However, it seems to be not nessesary here. That's according to the documentation which says you'll only need InitCommonControls() when you want to use XP theme's in your rich edit. But on the other hand, it stated you'll only need to call LoadLibrary() to find out which version of rich edit you have, which seems to be untrue.I did some Googling on this part and ran across a comment that if using MFC LoadLibrary is not required, if using pure Win32 API then LoadLibrary(...) is required.Does that sound about right? Link to comment Share on other sites More sharing options...
BenoitRen Posted March 26, 2008 Author Share Posted March 26, 2008 I haven't given up on this yet. In fact, I finally started on it. I've already got a basic notepad that can open and save files using the RichEdit control. That's the easy part, I guess. Link to comment Share on other sites More sharing options...
galahs Posted March 29, 2008 Share Posted March 29, 2008 your challenge is to make one better than TheGunn http://www.movsd.com/thegun.htm Link to comment Share on other sites More sharing options...
BenoitRen Posted March 29, 2008 Author Share Posted March 29, 2008 I can't do better than that. TheGun is coded in Microsoft Assembler, while I'm coding in C. No way I'll be able to make an alternative that small.If anyone else is reading, I'm struggling to implement features. I have a Windows API reference, but it leaves some things to be desired. For most functions I need to allocate an array of chars that is big enough to contain the result. But I don't know how I would poll for the size needed. Link to comment Share on other sites More sharing options...
Mijzelf Posted March 30, 2008 Share Posted March 30, 2008 You'll have to be a bit more specific. There are serveral different ways to get the needed buffer size. Sometimes there's you can provide a null-pointer in which case the function returns the needed buffersize. Sometimes there's a seperate function to ask for the needed buffersize. Sometimes the only way is polling. (Provide a buffer, and while the system tells it's not enough, enlarge it.) Link to comment Share on other sites More sharing options...
BenoitRen Posted March 30, 2008 Author Share Posted March 30, 2008 For instance, the EM_GETSELTEXT message needs a buffer that is big enough to store the selected text in. Do I use the EM_EXGETSEL message, and calculate the size of the selection from that, or something? Link to comment Share on other sites More sharing options...
Mijzelf Posted March 31, 2008 Share Posted March 31, 2008 Yes, AFAIK that is the most appropriate way. To ensure the buffer is big enough you could also use GetWindowTextLength(), since the selected text cannot be bigger than the total text. Of course this can be inefficient when you only want to copy a few bytes.As you may have noticed, EM_GETSELTEXT is a dangerous function, since you can't provide the size of the buffer you're using. So I would avoid using it, and use a combination of EM_EXGETSEL and EM_GETTEXTRANGE Link to comment Share on other sites More sharing options...
BenoitRen Posted April 20, 2008 Author Share Posted April 20, 2008 (edited) Great... My own application created a looping BSOD. I had to press Ctrl+Alt+Del to get out of it, which rebooted my system.I'm trying to implement the Edit menu. But the way I did it is probably wrong. On MSDN it's totally different. Here's the code: case ID_EDIT_COPY: { HWND hRichEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT); CHARRANGE crSel; SendMessage(hRichEdit, EM_EXGETSEL, 0, (LPARAM) &crSel); if(crSel.cpMin != crSel.cpMax) { TEXTRANGE trSel; LPSTR pszText; DWORD dwBufferSize = crSel.cpMax - crSel.cpMin + 1; pszText = GlobalAlloc(GPTR, dwBufferSize); trSel.chrg.cpMin = crSel.cpMin; trSel.chrg.cpMax = crSel.cpMax; trSel.lpstrText = pszText; SendMessage(hRichEdit, EM_GETTEXTRANGE, 0, (LPARAM) &trSel); if(OpenClipboard(hwnd)) { EmptyClipboard(); SetClipboardData(CF_TEXT, pszText); CloseClipboard(); GlobalFree(pszText); } } break; }What I copy to the clipboard is random garbage. And sometimes it creates the aforementioned BSOD. Edited April 20, 2008 by BenoitRen Link to comment Share on other sites More sharing options...
Tihiy Posted April 20, 2008 Share Posted April 20, 2008 You can replace your code with just one WM_COPY. Although, if you're planning to support multiple clipboard formats (the right thing to do), i can't see a problem in your code. Except maybe RichEdit is not in ANSI mode? Link to comment Share on other sites More sharing options...
BenoitRen Posted April 20, 2008 Author Share Posted April 20, 2008 (edited) Thanks, that worked! And it made it easy to also implement Cut, Paste, Clear and Undo. I also could implement Select All thanks to the experience I got earlier. That'll do for now.I still would like to know where my previous code went wrong, though. Edited April 20, 2008 by BenoitRen Link to comment Share on other sites More sharing options...
Mijzelf Posted April 21, 2008 Share Posted April 21, 2008 if(crSel.cpMin != crSel.cpMax) { DWORD dwBufferSize = crSel.cpMax - crSel.cpMin + 1; pszText = GlobalAlloc(GPTR, dwBufferSize);If the cpMin and cpMax members are equal, the range is empty. The range includes everything if cpMin is 0 and cpMax is –1.Maybe cpMax is -1? In that case you alloc 0 bytes to contain all text. Link to comment Share on other sites More sharing options...
BenoitRen Posted April 21, 2008 Author Share Posted April 21, 2008 When I tested my function, I never selected the entire range.Next challenge is the Search dialog. I'll probably make it a resource. Link to comment Share on other sites More sharing options...
BenoitRen Posted April 21, 2008 Author Share Posted April 21, 2008 I made a window with Resource Workshop. Problem is that even though the Windows platform target is Win32, it still looks like a Win 3.1 window. Eww. I'm guessing it's because of the compiler, Borland C++ 4.51, because the resource seems fine:#include <resource.h>DLG_SEARCH DIALOG 8, 21, 207, 95STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENUCAPTION "Zoeken"FONT 8, "MS Sans Serif"{ DEFPUSHBUTTON "&Volgende zoeken", ID_SEARCHNEXT, 135, 22, 63, 14 PUSHBUTTON "Annuleren", ID_CANCEL, 135, 40, 63, 14 LTEXT "&Zoeken naar:", -1, 4, 7, 45, 12 EDITTEXT IDC_SEARCHTEXT, 52, 6, 146, 13, WS_BORDER | WS_TABSTOP CONTROL "Heel &woord", IDC_FULLWORD, "BorCheck", BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 5, 27, 51, 13 CONTROL "&Identieke hoofdletters/kleine letters", IDC_CASESENSITIVE, "BorCheck", BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 5, 43, 128, 11 GROUPBOX "Richting", IDC_DIRECTION, 5, 60, 92, 30, BS_GROUPBOX CONTROL "&Omhoog", IDC_SEARCHUP, "BorRadio", BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 11, 73, 58, 10 CONTROL "Om&laag", IDC_SEARCHDOWN, "BorRadio", BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 54, 73, 39, 10} Link to comment Share on other sites More sharing options...
Mijzelf Posted April 22, 2008 Share Posted April 22, 2008 According to Wikipedia, version 4.52 is the first to support W95. That *could* mean that you are creating 16 bit software. When you are creating 32 bit software, look if you can target for Windows 4.0. (That should be a linker option). If you can't, try to add the DS_3DLOOK flag after STYLE. Link to comment Share on other sites More sharing options...
BenoitRen Posted April 23, 2008 Author Share Posted April 23, 2008 I'm pretty sure I'm targeting Win32. Anyway, when I add the flag, it complains about an incomplete expression. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now