Archived

This topic is now archived and is closed to further replies.

Does Anyone kow whats wrong with this code?

This topic is 5653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

yea, whats wrong with this code ?????? when i run it, the window creation returns (CreateDialog) but the window wont show and the FIRST 'WM_%window_message%' is WM_QUIT so the progy exits, very strange, any help thanx.!
    
#include <windows.h>
#include "resource.h"
#include <stdlib.h>
#include <stdio.h>

BOOL CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil);

char szClassName[ ] = "WindowsApp";
HWND appHwnd;  

int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
             
    MSG msg; 
	BOOL gotMsg;
	appHwnd = CreateDialog(hThisInstance,MAKEINTRESOURCE(IDD_WINMAIN),HWND_DESKTOP,(DLGPROC)WindowProcedure);
	ShowWindow(appHwnd,SW_SHOW);

	PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE );
while( WM_QUIT != msg.message  )
    {
		gotMsg = PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE );

		if( gotMsg )
        {
			TranslateMessage( &msg );
			DispatchMessage( &msg );
        }
		else
		{
			// free CPU time sent here.

		}

    }

	return msg.wParam;
}


BOOL CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)          
    {
		case WM_INITDIALOG:
		break;
        case WM_DESTROY:
            PostQuitMessage (0);   
            break;
        default:             
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return FALSE;
}
    
[edited by - silvermace on June 25, 2002 6:17:51 AM]

Share this post


Link to post
Share on other sites
As currently written, the program does not return, but gets stuck in the while() loop. I mapped IDD_WINMAIN to the default project dialog box, ran the debugger. appWnd is NULL. Check that on your side.

Note: I don''t do Windows

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share this post


Link to post
Share on other sites
From Microsoft MSDN:

The WM_INITDIALOG message is sent to the dialog box procedure immediately before a dialog box is displayed. Dialog box procedures typically use this message to initialize controls and carry out any other initialization tasks that affect the appearance of the dialog box.

A window receives this message through its WindowProc function.

The dialog box procedure should return TRUE to direct the system to set the keyboard focus to the control specified by wParam. Otherwise, it should return FALSE to prevent the system from setting the default keyboard focus.

Then:

switch (message)
{ case WM_INITDIALOG: return TRUE;

Share this post


Link to post
Share on other sites