Jump to content
Tuts 4 You

wired visual studio problem


deepzero

Recommended Posts

right, so yesterday night i had a native vsc++ 2008 project display a dialogbox using the DialogBox(...) functon. worked perfectly fine.

i then went to bed, and when i got up this morning, the exact same DialogBox call would just return -1 and fail.

I then did some further testing:

1) Creating a dialogbox with a list view on it always fails

2) creating a dialogbox with NO list view on it always succeeds. sometimes the dialog will get display correctly, sometimes the form-background is missing and some dialog items are floating around freely.it always takes up 100% cpu power.

3) creating a new,clean project with a dialog but no list view, it works in the beginning, but after several tries, it might fail, just like that.

at this point i moved to my second pc.same problems.

1) i create a standard Win32 dialog project (visual studio default)

2) it runs fine, about box gets displayed

3) i add a list view to the about box

4) program starts up fine, but the about box wont be displayed

i?ll bluntly admit, i dont have the slightest clue as to what might have failed.

makes no sense to me whatsoever.

Edited by deepzero
Link to comment

InitCommonControls or InitCommonControlsEx will get you out of trouble with that problem, ;)


/>http://www.winprog.org/tutorial/errors.html

HR,

Ghandi

Link to comment

hi,

well, that seems to be one important function... ;)

Didnt have any problems without calling it, up to now, though...

In the meantime i reverted back to a system backup of mid-february and - tada - everything went back to normal... :S

no clue what caused this.

thanks,

deep0 :)

p.s. winpro.org seems to be down...

Link to comment

Not from here, win32pro.org opens fine, o0

Here's the bit on the page i was linking to though:

Dialog does not display when certain controls are added

Controls such as the ListView, TreeView, Hotkey, Progress Bar, and others are classified as Common Controls, as they were added to windows in comctl32.dll and were not available prior to Windows 95. Controls such as BUTTON, EDIT, LISTBOX, etc... while no doubt being common, are not "Common Controls" and I generally refer to them as "Standard Controls".

If you add a Common Control to a dialog and it fails to display, you most likely failed to call InitCommonControls() before running your dialog, or perhaps at all. The best place to call it is first thing in WinMain(). Calling it in WM_INITDIALOG is too late, since the dialog will fail before it reaches this point and it will never get called.

Some people and documentation may tell you that InitCommonControls() is deprecated and you should use InitCommonControlsEx(). Feel free to do this if you want, InitCommonControls() is just simpler and there's nothing wrong with using it.

HR,

Ghandi

Link to comment

page is def. down on my end... :)

thanks for the link and the quote.

i am now calling InitCommonControls() right at the EP and before creating dialog boxes:


InitCommonControls();
HWND subhwnd = CreateDialog(hinstance,(LPCTSTR)DLG_SUB,
MAIN_HWND,(DLGPROC)SUB_DISP);

still, this wont work.

CreateDialog() returns 0, indicating failure.

The problem seems to be that i have a RichTextBox on DLG_SUB.

If i replace it by a normal textobox (EditCOntrol), it works fine.

I am guessing this is related to the InitCommonControls() call?

Link to comment

RichEdit controls are not part of the CommonControls library, instead they are part of their own subsection, you can either link to a .lib file or manually load the appropriate "richedXX.dll" (where XX is the version you want).

If using DialogBoxParam you can wrap it with a call to LoadLibray:


INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nShowCmd )
{
INITCOMMONCONTROLSEX icex = {0};
HMODULE hRichEdit = LoadLibraryA("riched20.dll");
INT ReturnVal; /* Check to see if we loaded the riched20.dll (which registers the RichEdit class in its entrypoint procedure) */
if (!hRichEdit)
{
MessageBox(NULL,"riched20.dll failed to load!",NULL,MB_ICONERROR);
return 0;
}
/* Call InitCommonControlsEx to allow us use of the common controls */
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_USEREX_CLASSES;
InitCommonControlsEx(&icex); /* Get return value of call IF interested */
ReturnVal = DialogBoxParam( hInstance, MAKEINTRESOURCE(IDD_MAIN), HWND_DESKTOP, (DLGPROC)WndProc, 0 ); /* Free library as its no longer needed */
FreeLibrary(hRichEdit); /* Pass on return value of call to DialogBoxParam */
return ReturnVal;}

This type of wrapper could be used around your window creation also, if you didn't want to, or like me, can't get MSVC to link to it explicitly.

HR,

Ghandi

Edited by ghandi
Link to comment

once again you saved me, ghandi. :) thanks :):yes:

note to everyone:

that http://www.winprog.org/ site Ghandi linked me to is extremely helpful.

the tuts are avalanche as a pdf, too, and the problem this thread is about is actually in their FAQs... :^

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...