Click to See Complete Forum and Search --> : error creating edit control


roguecoder
November 25th, 2006, 10:03 AM
I have the following lines of code in my win api program.

I am getting the following error:: error C2440: '=' : cannot convert from 'HGDIOBJ' to 'HFONT'

case WM_CREATE:
{
HFONT hfDefault;
HWND hEdit;

hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
0, 0, 100, 100, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
if(hEdit == NULL)
{
MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
}
hfDefault = GetStockObject(DEFAULT_GUI_FONT);
SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
}
break;
case WM_SIZE:
{
HWND hEdit;
RECT rcClient;

GetClientRect(hwnd, &rcClient);

hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT);
SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
}
break;

roguecoder
November 25th, 2006, 10:10 AM
Also is there a editor like the one to create dialogs in windows visual C++
For the main Window of the program your creating ?

i can't seem to find one :S.. is there a 3rd party ? (no .net or mfc... all win api)

ovidiucucu
November 25th, 2006, 10:38 AM
[ Redirected thread ]

miteshpandey
November 25th, 2006, 10:50 AM
Are you by the way using

#define STRICT


Did you try casting?

roguecoder
November 26th, 2006, 06:34 AM
Sorry yes i have #define

Sample with the IDC_MAIN_EDIT
#define ID_FILE_EXIT 40012
#define ID_HELP_HELP 40013
#define IC_MAIN_EDIT 104

i'm still new to this. what is casting ?

ovidiucucu
November 26th, 2006, 06:57 AM
As miteshpandey already suggested, you have to cast (convert) from HGDIOBJ type which is returned by GetStockObject to to your actual type HFONT.
hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
Why need to cast a handle type? Take a look at THIS (http://www.codeguru.com/forum/showpost.php?p=1424531).

ovidiucucu
November 26th, 2006, 07:25 AM
Also is there a editor like the one to create dialogs in windows visual C++
For the main Window of the program your creating ?

i can't seem to find one :S.. is there a 3rd party ? (no .net or mfc... all win api)

In Visual C++ you don't need any third party stuff to add a dialog template resource to a Win32 Application, add controls on it, then call DialogBox.

Here are examples:
ProgressBar.zip (http://www.codeguru.com/forum/attachment.php?attachmentid=12801)
ComboTest.zip (http://www.codeguru.com/forum/attachment.php?attachmentid=12736)

roguecoder
November 26th, 2006, 08:13 AM
So most programs just use dialog box's instead of CreateWindowEx ??????


see there is alot i don't know :P

ovidiucucu
November 26th, 2006, 09:52 AM
So most programs just use dialog box's instead of CreateWindowEx ??????


see there is alot i don't know :P
Not very clear what you want to say, so let's try tu un-shuffle it a little:

A dialog (box) is also a window of a particular (pre-defined) window class.
You can also create a dialog box by a call of CreateWindowEx.
DialogBox (http://msdn2.microsoft.com/en-us/library/ms645452.aspx) is a macro that uses DialogBoxParam (http://msdn2.microsoft.com/en-us/library/ms645465.aspx) function to create a modal dialog based on a dialog template resource.
DialogBoxParam calls itself CreateWindowEx function.