Hi,
I’m trying to find a couple functions along the lines of the GetWindowLong(), SetWindowLong() variety except for dialog boxes. It’s my understanding that there’s no HWND created for a dialog box until runtime so I don’t know how to SetWindowLong() without it. For whatever reason I believed that the dialog box’s HWND would inherit the GetWindowLong() that I have set for my main window… nope. I didn’t get any compiler errors (understandable) so when errors started cropping up I started thinking there was a memory leak, after a couple hours I figured out my use of GetWindowLong() was incorrect inside of the dialog box.
What I’m doing is creating a map maker. I have a class that stores all the information for the map as well as all the functions to manipulate it. The intent for dialog box I’m creating is to change the Width/Height of the map (64x64 pixel tiles). I’ve got the dialog box giving me the correct data upon entry but I can’t change the map without either making the “Info” data global or finding a GetWindowLong() workaround.
Here’s some code in case I’m doing something stupid, it’s just my callback function for my dialog box. I’m not sure if it’s necessary to show more… I’ve got a lot of code so far and a lot of it is a pretty jumbled mess. It’s my first try taking on something this size by myself.
Thanks for any insight anyone can give. I’ve been searching the internet for a while but I have a feeling I’m probably looking for the wrong type of solution.Code:// Message handler for Height/Width Option box. LRESULT CALLBACK Options(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { char height[4]; char width[4]; WORD sizeOfInput; DisplayInfo* Info = (DisplayInfo*)(DWORD_PTR)GetWindowLongPtr(hDlg, GWLP_USERDATA); switch (message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: switch( LOWORD(wParam) ) { case IDCANCEL: { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; case IDOK: { // Getting Height Value // Get number of characters. sizeOfInput = (WORD) SendDlgItemMessage(hDlg, IDC_HEIGHT, EM_LINELENGTH, (WPARAM) 0, (LPARAM) 0); if (sizeOfInput == 0) { MessageBox(hDlg, "No characters entered for Height.", "Error", MB_OK); break; } else if (sizeOfInput == 1) { MessageBox(hDlg, "Height must be greater than or equal to 10.", "Error", MB_OK); break; } // Put the number of characters into first word of buffer. *((LPWORD)height) = sizeOfInput; // Get the characters. SendDlgItemMessage(hDlg, IDC_HEIGHT, EM_GETLINE, (WPARAM) 0, // line 0 (LPARAM) height); // Null-terminate the string. height[sizeOfInput] = 0; // Getting Width Value sizeOfInput = (WORD) SendDlgItemMessage(hDlg, IDC_WIDTH, EM_LINELENGTH, (WPARAM) 0, (LPARAM) 0); if (sizeOfInput == 0) { MessageBox(hDlg, "No characters entered for Width.", "Error", MB_OK); break; } else if (sizeOfInput == 1) { MessageBox(hDlg, "Width must be greater than or equal to 10.", "Error", MB_OK); break; } // Put the number of characters into first word of buffer. *((LPWORD)width) = sizeOfInput; // Get the characters. SendDlgItemMessage(hDlg, IDC_WIDTH, EM_GETLINE, (WPARAM) 0, // line 0 (LPARAM) width); // Null-terminate the string. width[sizeOfInput] = 0; Info->SetWidthHeight(atoi(height), atoi(width)); EndDialog(hDlg, TRUE); return TRUE; } } } return FALSE; }
-Peter
PS sorry for the weird formatting of my code, not sure what's going on there. I'm using VS 2005
*******EDIT*******
As a side note I just tried my code with "Info" being a global and everything appears to work fine.



LinkBack URL
About LinkBacks


