Skip to main content
GameDev.net gamedev.net
🔒 Locked

win api troubles

Started by Hassanbasil Sep 9, 2010 at 1:32 PM 10 replies 2.3k views
Original Post
Hassanbasil
Hassanbasil
Hello everyone,

I'm having a problem that when i create a window as a dialog using a resource (CreateDialog (...)), all other windows can be activated, for example, if i use MessageBox (...), the box shows up but i can't click it, when i hover over a button in it, it glows, but i can click it, same with combo boxes, when i click the arrow to show a list, then i can't click anything in the list, nor the main dialog, why does this happen?

here's some source
//resourceID_DLG DIALOGEX 50, 50, 340, 330STYLE WS_VISIBLE | WS_CAPTION | WS_BORDERFONT 8, "MS Shell Dlg", 400, 0, 0x1BEGIN//....//....END//creation	wnd = CreateDialogA ( hInstance, MAKEINTRESOURCEA ( ID_DLG ), NULL, (DLGPROC)Proc );	SetWindowTextA ( wnd, "Client Configurations" );	SetWindowLongA ( wnd, GWL_STYLE, GetWindowLongA ( wnd, GWL_STYLE ) &~ WS_MAXIMIZEBOX );//loop	MSG msg;	while ( GetMessageA ( &msg, wnd, 0, 0 ) > 0 )	{		TranslateMessage ( &msg );		DispatchMessageA ( &msg );//....updates...	}//procedureLRESULT CALLBACK Proc ( HWND wnd, UINT msg, WPARAM w, LPARAM l ){	switch ( msg )	{//....cases....		default:			return DefWindowProcA ( wnd, msg, w, l );	}	return TRUE;}


what am i doing wrong?

my other question is, how can i get fonts on system? i tried this:
	LOGFONTA f = { 0 };	f.lfCharSet = DEFAULT_CHARSET;	strcpy ( f.lfFaceName, "" );	f.lfPitchAndFamily = 0;	EnumFontFamiliesExA ( GetDC ( wnd ), &f, (FONTENUMPROCA)fontProc, 0, 0 );//procedureint CALLBACK fontProc ( const LOGFONTA *lpelfe, const TEXTMETRICA *lpntme, DWORD FontType, LPARAM lParam ){	if ( FontType & TRUETYPE_FONTTYPE )	{		SendDlgItemMessageA ( wnd, ID_NS_FONTS, CB_ADDSTRING, 0, (LPARAM)lpelfe->lfFaceName );		int x = 0;	}	return 1;}


but it shows a very huge list of fonts, and alot of repeated fonts, plus some of them with names starting with '@', how can i make it give non-repeated fonts, and get rid of those '@' ones? (do i have to check it myself? on msdn:<> how is it showing multiple repeated names then?)

thanks in advance
regards
-Hassan
LessBread
LessBread
CreateDialog Function: "To support keyboard navigation and other dialog box functionality, the message loop for the dialog box must call the IsDialogMessage function."

See also: Tutorial: Modeless Dialogs

Regarding font enumeration see Enumerating Fonts.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
21st Century Moose
21st Century Moose
It sounds to me as though you've set the wrong owner window in your MessageBox call. The first param should be set to the HWND of your dialog box.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
Hassanbasil
Hassanbasil
I think you got me wrong, the dialog itself is getting messages, but other windows aren't

it doesn't matter whether passing the dialog window or NULL as the MessageBox parent window, both doesn't work

as for modeless dialog, why should my dialog be modeless? anyway making it modeless doesn't help

changing my loop to

if ( !IsDialogMessageA ( wnd, &msg ) )
{
TranslateMessage ( &msg );
DispatchMessageA ( &msg );
}

doesnt solve the problem either
Evil Steve
Evil Steve
1. Don't call DefWindowProc() for dialog messages, just return FALSE if you don't process the message (I.e. the default case).

2. Never cast function pointers like that - remove the (FONTENUMPROCA) cast in your EnumFontFamiliesEx call - if it doesn't compile without the cast, then it's wrong and will cause a crash later on.
I'm not sure about the problem of repeated fonts though...
LessBread
LessBread
Quote:
Original post by Hassanbasil
as for modeless dialog, why should my dialog be modeless? anyway making it modeless doesn't help


When you decided to use CreateDialog, you decided your dialog should be modeless.

From MSDN: "The CreateDialog function creates a modeless dialog box from a dialog box template resource."



"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Hassanbasil
Hassanbasil
I see, thanks for the tips LessBread and Steve

For some reason the MessageBox's works now, i dont really know why and how, but it seems that changing "return DefWindowProc()" to "return FALSE" solved it, anyhow, this was not the main problem actually, i have a combo box, which is not responding: when i click it, the list shows up, i can scroll it using mouse wheel, but i cant click it, nor click it's scroll bar, nor click the main dialog, why would that happen? the combo box is created as the following:

COMBOBOX ID_NS_FONTS, 215, 218, 115, 13, CBS_DROPDOWNLIST | WS_VSCROLL | CBS_SORT

EDIT: in case this is useful: i can use all other controls (edittext, pushbutton, radio button, checkbox, listbox)

[Edited by - Hassanbasil on September 9, 2010 4:22:19 PM]
Hassanbasil
Hassanbasil
Alright the problem seems to be in the loop, i replaced "GetMessage ( &msg, wnd, 0, 0 )" with "GetMessage ( &msg, NULL, 0, 0 )"

Thanks for your help and tips.
21st Century Moose
21st Century Moose
You were correct, I had you wrong.

Check your MSDN for the correct values to return from DialogProc, by the way:
Quote:
Typically, the dialog box procedure should return TRUE if it processed the message, and FALSE if it did not. If the dialog box procedure returns FALSE, the dialog manager performs the default dialog operation in response to the message.

If the dialog box procedure processes a message that requires a specific return value, the dialog box procedure should set the desired return value by calling SetWindowLong(hwndDlg, DWL_MSGRESULT, lResult) immediately before returning TRUE. Note that you must call SetWindowLong immediately before returning TRUE; doing so earlier may result in the DWL_MSGRESULT value being overwritten by a nested dialog box message.

and
Quote:
You should use the dialog box procedure only if you use the dialog box class for the dialog box. This is the default class and is used when no explicit class is specified in the dialog box template. Although the dialog box procedure is similar to a window procedure, it must not call the DefWindowProc function to process unwanted messages. Unwanted messages are processed internally by the dialog box window procedure.
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
Hassanbasil
Hassanbasil
Sorry for bumping, but as my questions are in the same topic i'd rather have them here than making a new thread

I got two more problems, first one is:
void PlayVideo ( HWND hwnd_ParentWindow, LPSTR lpstr, int OriginX, int OriginY, int Width, int Height, UINT* length ) {		MCIWnd = MCIWndCreate ( hwnd_ParentWindow, GetModuleHandle(NULL),		WS_CHILD | WS_VISIBLE | MCIWNDF_NOTIFYMODE | MCIWNDF_NOPLAYBAR, NULL );	MCIWndOpen ( MCIWnd, lpstr, NULL ); // new device in window	SetWindowPos ( MCIWnd, HWND_TOPMOST, OriginX, OriginY, Width, Height,  SWP_NOZORDER | SWP_NOACTIVATE );    MCIWndPlay ( MCIWnd ); // plays device	if ( length )		*length = MCIWndGetLength ( MCIWnd );}


As you can see, MCIWnd is a global variable, a handle to the window playing a video, this function simply doesnt work because MCIWndOpen says it cannot find the specified file (throws a box saying "the specified file could not be found...."), even though i use the FindFirstFileA to get the file name, well i also tried passing -1 as the sz parameter, it shows the expander, and i see the video (with the same name i passed..) if i click it, it plays fine, but why it doesnt work when passing the name? (i have used this function in some previous projects and it worked fine, i dont really know whats up with this problem)

Second question is: how can i dynamically change the text of a listbox control item? i have tried this:
//listbox creation (in .rc file)LISTBOX ID_SENTENCES, 10, 205, 180, 85, WS_VSCROLL | LBS_HASSTRINGS//message (there is an item with the index 0)SendDlgItemMessageA ( wnd, ID_SENTENCES, LB_SETITEMDATA, 0, (LPARAM)"test" );


this simply does nothing, the function returns 1 and GetLastError () returns 0, what's wrong there?

Thanks
Regards
-Hassan
jwezorek
jwezorek
On the mci problem, I don't know ... make sure the path is right. Try hard coding in an absolute path and see if that works, etc.

For the list box thing, ummm, this is kind of crazy but as far as I know there is no way to change the text of a list box item in Win32. LB_SETITEMDATA is for associating some data with an item that is useful for your program e.g. a pointer to some object or something. It doesn't have anything to do with the item text. What you need is a message called LB_SETITEMTEXT -- unfortunately this message doesn't exist. So as a work around you can create a new item and delete the old one, as in:
void SetListBoxItemText(HWND list_box, int n, char* text) {      SendMessage(list_box, LB_INSERTSTRING, (WPARAM) n, (LPARAM) text);      SendMessage(list_box, LB_DELETESTRING, (WPARAM)(n+1), 0L);}

but realistically since list box's interface isn't rich enough for your needs you should really consider using a list view instead. A list view with the LVS_REPORT style is pretty much the same thing as a list box but a lot more powerful. Personally I pretty much never use list boxes.
Hassanbasil
Hassanbasil
Quote:
Original post by jwezorek
On the mci problem, I don't know ... make sure the path is right. Try hard coding in an absolute path and see if that works, etc.

For the list box thing, ummm, this is kind of crazy but as far as I know there is no way to change the text of a list box item in Win32. LB_SETITEMDATA is for associating some data with an item that is useful for your program e.g. a pointer to some object or something. It doesn't have anything to do with the item text. What you need is a message called LB_SETITEMTEXT -- unfortunately this message doesn't exist. So as a work around you can create a new item and delete the old one, as in:
*** Source Snippet Removed ***
but realistically since list box's interface isn't rich enough for your needs you should really consider using a list view instead. A list view with the LVS_REPORT style is pretty much the same thing as a list box but a lot more powerful. Personally I pretty much never use list boxes.


i tried writing the path myself, no hope, i tried putting the video everywhere the function could expect, it just cant find it unless i use the built-in explorer (and using it is not an option..)

as for the list view, i will try it, it's sad that i can change the list box's string

thanks for your help!

Topic Locked

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

Sign in to reply to this topic.