BOOL MainDialog::OnNotify(WPARAM wParam, LPARAM lParam)
{
NMHDR NotifyHeader;
TEXTRANGE Range;
ENLINK Link;
char *Url = NULL;
memcpy(&NotifyHeader, (const void*)lParam, sizeof(NotifyHeader));
if((NotifyHeader.hwndFrom == RichEditWindow) && (NotifyHeader.code == EN_LINK)) {
memcpy(&Link, (const void*)lParam, sizeof(Link));
if(Link.msg == WM_LBUTTONUP) {
Url = new char[Link.chrg.cpMax - Link.chrg.cpMin + 1];
Range.chrg = Link.chrg;
Range.lpstrText = Url;
if(SendMessage(RichEditWindow, EM_GETTEXTRANGE, 0, (LPARAM)&Range) != ERROR_SUCCESS) {
Timestamp(RichEditWindow);
InsertFormattedText(RichEditWindow, RED, "Error %u occured while reading Url!\n", GetLastError());
}
if(ShellExecute(RichEditWindow, NULL, Url, NULL, NULL, SW_SHOWNORMAL) != ERROR_SUCCESS) {
Timestamp(RichEditWindow);
InsertFormattedText(RichEditWindow, RED, "Error %u occured while opening Url!\n", GetLastError());
}
delete [] Url;
}
}
return FALSE;
}
Both SendMessage and ShellExecute return ERROR_INVALID_HANDLE. I do not understand why.
Solution posted below
Are you executing this on the correct thread? You're only supposed to modify windows controls on the thread on which the handle was created.
Quote from: MyndFyre[vL] on October 11, 2006, 03:56 PM
Are you executing this on the correct thread? You're only supposed to modify windows controls on the thread on which the handle was created.
Yes..I am not creating any threads at all so I would assume so. This works correctly, meaning your Internet browser does open with the correct page, I just want to know why those return 6.
Wow, nevermind. I didn't read the return value part correctly on MSDN. For EM_GETTEXTRANGE it returns number of characters, and ShellExecute returns an HINSTANCE > 32 upon success...durr.
Doing Error = SendMessage(...) I see this...there is no errors, thanks anyways