Click to See Complete Forum and Search --> : Problem with GetWindowContextHelpId


CppMaster
October 2nd, 2005, 08:19 PM
Hello, in my program, a text editor, I'm using a menu and 2 edit box (keeping it simple for now). I had the following problem: When I maximized my window, the child windows would stay the same size. I create a small size-changing algorithm (there's probably an easier way, and if there is please answe my question AND tell me what another solution would be) with the following code:

//...
case WM_SIZE:
if(!counter){
counter = true;
return DefWindowProc(hWnd, message, wParam, lParam);
}
if(!GetWindowRect(hWnd, &wndRect))
{
MessageBox(NULL, "Error while getting window rect", "ERROR", MB_ICONERROR);
return FALSE;
}
EnumChildWindows(hWnd, Gui::setChildWindows, 0);
HWND* childWindows;
if(!Gui::getChildWindows(childWindows)){
MessageBox(NULL, "Error while getting child windows", "ERROR", MB_ICONERROR);
return FALSE;
}
length = Gui::childWindowsLength();
Gui::deleteChildWindows();
if(childWindows == NULL)
{
MessageBox(NULL, "childWindows is NULL after call do deleteChildWindows!",
"ERROR", MB_ICONERROR);
return false;
}
DWORD ID;
RECT rect;
int width;
int height;
for(int i = 0; i < length; i++){
std::cout << "WM_SIZE -> line " << __LINE__ << " Inside for loop" <<'\n';
ID = GetWindowContextHelpId(childWindows[i]);
std::cout << "WM_SIZE -> line " << __LINE__ << " Inside for loop" <<'\n';
if(ID == hEditId){
GetWindowRect(childWindows[i], &rect);
std::cout << "WM_SIZE -> line " << __LINE__ << " Inside if(ID == hEditId)" <<'\n';
width = rect.left - rect.right;
std::cout << "WM_SIZE -> line " << __LINE__ << " Inside if(ID == hEditId)" <<'\n';
height = rect.top - rect.bottom;
std::cout << "WM_SIZE -> line " << __LINE__ << " Inside if(ID == hEditId)" <<'\n';
SetWindowPos(childWindows[i],NULL, 0, 0,(int)(width*dHERWidth),
(int)(height*dHERHeight), (SWP_NOMOVE|SWP_NOZORDER|SWP_SHOWWINDOW));
}else
if(ID == hCommandId){
std::cout << "WM_SIZE -> line " << __LINE__ << " Inside if(ID == hCommandId)" <<'\n';
GetWindowRect(childWindows[i], &rect);
std::cout << "WM_SIZE -> line " << __LINE__ << " Inside if(ID == hCommandId)" <<'\n';
width = rect.left - rect.right;
std::cout << "WM_SIZE -> line " << __LINE__ << " Inside if(ID == hCommandId)" <<'\n';
height = rect.top - rect.bottom;
std::cout << "WM_SIZE -> line " << __LINE__ << " Inside if(ID == hCommandId)" <<'\n';
SetWindowPos(childWindows[i], NULL, 0, 0,(int)(width*dHCRWidth),
(int)(height*dHCRHeight), (SWP_NOMOVE|SWP_NOZORDER|SWP_SHOWWINDOW));
}
}
UpdateWindow(hWnd);
std::cout << "WM_SIZE -> line " << __LINE__ << '\n';
break;
//...

The couts are there for debugging. When trying to run my application, it would close after I try to change the size. I found out, with the couts, that the problem was coming from or, at least, seemed to come from:

GetWindowContextHelpId(childWindows[i]);

I set the ContextHelpIds of hEdit(0x00001) which is the main EDIT and for hCommand(0x00002) which is another EDIT, but I didn't for the menus. What's wrong my code? And would there be an easier way to do what I'm trying to do? Thank you very much.

CppMaster