Skip to main content
gamedev.net
🔒 Locked

problem with CreateDialog

Started by BungoMan85 4 replies 400+ views
Original Post
BungoMan85
BungoMan85
ive used the win32 macro create dialog a hundred times before. i copied and pasted some existing code into a new project and tweaked it a little bit (mostly stuff outside WinMain or way after CreateDialog is called). now for some reason the program runs then doesnt do anything, its like it crashes but it doesnt give me an error message. it almost as if somewhere something is calling PostQuitMessage before the program can even show itself here is my WinMain function. I added in some MessageBox calls to narrow it down. this is how i am positive it is CreateDialog and not something else.
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPreviousInstance, LPSTR lpCmdLine, int iShowCmd)
{
	g_hInstance=hInstance;
MessageBox(0,"1","Error",MB_OK);
	HWND hWnd=0;
	hWnd=CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOG_MAIN),0,(DLGPROC)DialogProc);
MessageBox(0,"2","Error",MB_OK);
	if (!hWnd)
	{
		MessageBox(0,"Could not create window.","Error",MB_OK);

		return 0;
	}

	g_hWnd=hWnd;

	ShowWindow(hWnd,SW_SHOWNORMAL);

	UpdateWindow(hWnd);

	MSG Msg;

	while (GetMessage(&Msg,0,0,0))
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}

	return 0;
}
as you can see there isnt much to it at all. IDD_DIALOG_MAIN and DialogProc are valid (it wouldnt compile if they werent). i am at a total loss because i just used this code the other day and it worked, ive included all the right files, made sure the right kind of project was used and made sure i havent made any other newbie mistakes... as far as DialogProc goes it just handles the quit and destroy messages, but that cant be the cause. the program shows the first message box but not the second.... it exits before it even gets to it... Bungo!
Bungo!
Oxyd
Oxyd
Maybe there''s an error in your DialogProc function. Maybe it''s not doing the right things in response to WM_INITIDIALOG message... Post DialogProc too...

Oxyd

---
- Unreadable code is code written on a piece of paper, but not the one, in which the programmer is using a space in the place you don''t.
- Real programmers aren''t afraid of goto
Aprosenf
Aprosenf
Post your dialog message handler. The error is almost certainly in that. As bad as Windows is, I can assure you there''s nothing wrong with CreateDialog.
BungoMan85
BungoMan85

static BOOL CALLBACK DialogProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
static BOOL bHideIcon=FALSE;

switch(uiMsg)
{
case WM_INITDIALOG: {
g_hDriveList=GetDlgItem(hWnd,IDC_LIST_DRIVES);

RECT WindowListRect;

GetWindowRect(g_hDriveList,&WindowListRect);

ZeroMemory(&g_lvColumn,sizeof(LVCOLUMN));

g_lvColumn.mask=LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM;

g_lvColumn.pszText="Drives";

g_lvColumn.cx=WindowListRect.right-WindowListRect.left;

SendMessage(g_hDriveList,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT);

SendMessage(g_hDriveList,LVM_INSERTCOLUMN,0,(LPARAM)&g_lvColumn);

ZeroMemory(&g_lvItem,sizeof(LVITEM));

g_lvItem.mask=LVIF_TEXT;
g_lvItem.cchTextMax=256;


CHAR lpszDrive[4];
INT iItem=0;

for (CHAR cDrive=''A'';cDrive<''Z'';cDrive++)
{
sprintf(lpszDrive,"%c:\\",cDrive);

if (GetDriveType(lpszDrive)==DRIVE_CDROM)
{
g_lvItem.iItem=iItem;

g_lvItem.iSubItem=0;

g_lvItem.pszText=lpszDrive;

SendMessage(g_hDriveList,LVM_INSERTITEM,0,(LPARAM)&g_lvItem);

iItem++;
}
}

}
break;
case WM_COMMAND: {
}
break;
case WM_NOTIFY: {
}
break;
case WM_CLOSE: {
DestroyWindow(hWnd);
}
break;
case WM_DESTROY: {
PostQuitMessage(0);
}
break;
}

return FALSE;
}


not much in it yet, right now all it does is populate a list box with the names of the cd drives on the system. i can comment that all out though and it still behaves the same, also it doesnt matter if i return TRUE or FALSE.

Bungo!
Bungo!
BungoMan85
BungoMan85
ugh! DUH DUH DUH! i knew it was something stupid like that. thank you so much. i wonder why then my old code (from previous projects) works just fine without that. either way, thank you

Bungo!
Bungo!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.