NO

Author Topic: Dialog Box and Custom Controls  (Read 9695 times)

leandrojardim

  • Guest
Dialog Box and Custom Controls
« on: April 27, 2012, 06:43:15 PM »
I downloaded the hyperlink custom control in John's website but how do I install a new custom control in the dialog editor toolbox? I click on the custom control button and I enter the class name HyperlinkCtrl32 and also link with the correct library hyperlink.lib but it doesnt work. I am using RC2.

Does is possible to use the dialog editor to design a normal overlapped window and after modify its window class and window procedures to make a child window with it?

And what functions and structures I can use to create a custom control and load it in the dialog editor?

Thanks! :)
« Last Edit: April 28, 2012, 09:25:45 PM by leandrojardim »

CommonTater

  • Guest
Re: Dialog Box and Custom Controls
« Reply #1 on: April 27, 2012, 07:43:34 PM »
I did download the hyperlink custom control in John's website but how do I install a new custom control in the dialog editor toolbox? I click on the custom control button and I enter the class name HyperlinkCtrl32 and also link with the correct library hyperlink.lib but it doesnt work. I am using RC2.

Far as I know, you can't add anything to the Dialog Editors toolbox... you have to load custom controls each time. 

Are you including the header (.h) for the control in your resource script?
Are you including the header in your source code (.c) that handles the dialog?
Is there a registration call needed to initialize the control's class name?

Quote
Does is possible to use the dialog editor to design a normal overlapped window and after modify its window class and window procedures to make a child window with it?

Probably... but why would you want to?

I will caution you against over-use of the dialog editor.  It's not really intended as a gui design tool, it's mostly for the creation of pop-up dialogs; child windows that do things like search or ask for passwords and such.  The main GUI for your program is almost always better made in your code... particularly since it's likely you will want the user to be able to resize it.

Quote
And what functions and structures I can use to create a custom control and load it in the dialog editor?

Take a look in the "User Contributions" section... There you will find EasySplitter, a custom control for resizeable windows, which includes the source code. 
 
 

czerny

  • Guest
Re: Dialog Box and Custom Controls
« Reply #2 on: April 28, 2012, 10:58:43 AM »
On Johns side there are two hyperlink controls (hlink and hyperlink) both from Alexander Stoica.
From the second it is said: "but this control can also be used from the Pelles C Dialog Editor. "

czerny

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Dialog Box and Custom Controls
« Reply #3 on: April 28, 2012, 12:08:09 PM »
Load dll before creating dialog for classname "HyperlinkCtrl32".
Code: [Select]
HMODULE hMod = LoadLibrary("HyperLink.dll");for example
Code: [Select]
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
HMODULE hMod = LoadLibrary("HyperLink.dll");
return DialogBox(hInstance, MAKEINTRESOURCE(1001), NULL, (DLGPROC)MainDlgProc);
}
May the source be with you

leandrojardim

  • Guest
Re: Dialog Box and Custom Controls
« Reply #4 on: April 28, 2012, 08:20:26 PM »
The problem was that I did not use the command "Open custom control" in the Dialog menu. :(

leandrojardim

  • Guest
Re: Dialog Box and Custom Controls
« Reply #5 on: April 28, 2012, 09:01:55 PM »
What could be wrong with this control? It show up in the dialog editor but when I rexecute it within a dialog it blocks the executable program from opening the dialog window...

Code: [Select]
#define __STDC_WANT_LIB_EXT1__ 1
#define WINDOWS_LEAN_AND_MEAN 1

#include <windows.h>
#include <commctrl.h>
#include <custcntl.h>

#include <stdbool.h>
#include <string.h>
#include <tchar.h>

#include "main.h"

/* *** MACROS *** */

#define LM_SETCOLOR WM_USER + 100


/* *** VARIABLES *** */

WNDCLASS ControlWindowClass;
HANDLE LabelLibraryHandle;

HDC DeviceContext;
HBRUSH DefaultBrush;

_TCHAR *LabelText;


/* *** FUNCTIONS *** */

static LRESULT CALLBACK LabelProcedure(HWND Window, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message) {
case WM_CREATE:
DeviceContext = GetDC(Window);
DefaultBrush = GetCurrentObject(DeviceContext, OBJ_BRUSH);

return TRUE;

case WM_GETDLGCODE:
return DLGC_STATIC;

case WM_PAINT:
TextOut(DeviceContext, 12, 0, LabelText, _tcslen(LabelText));

return 0;

case LM_SETCOLOR:
SelectObject(DeviceContext, (HBRUSH)wParam);

return TRUE;

case WM_NCDESTROY:
DeleteObject(DefaultBrush);

return 0;

case WM_SETTEXT:
free(LabelText);
LabelText = _tcsdup((_TCHAR *)lParam);
UpdateWindow (Window);

return TRUE;

case WM_GETTEXT:
_tcscpy_s((_TCHAR *)lParam, wParam, LabelText);
return _tcslen((_TCHAR *)lParam);

case WM_GETTEXTLENGTH:
return _tcslen(LabelText) + 1;

default:
return DefWindowProc(Window, Message, wParam, lParam);
};
};

BOOL WINAPI DllMain(HANDLE Handle, DWORD Reason, LPVOID Reserved)
{
LabelLibraryHandle = Handle;

switch (Reason) {
case DLL_PROCESS_ATTACH:
InitCommonControls();

LabelText = _tcsdup (_T("Label"));
memset (&ControlWindowClass, 0, sizeof (ControlWindowClass));

ControlWindowClass.style = 0;
ControlWindowClass.hInstance = GetModuleHandle(NULL);

ControlWindowClass.lpszClassName = _T("LabelClass");
ControlWindowClass.lpfnWndProc = LabelProcedure;

if (!RegisterClass(&ControlWindowClass)) {
return FALSE;
};

return TRUE;

case DLL_PROCESS_DETACH:
if (!UnregisterClass(_T("LabelClass"), GetModuleHandle(NULL)))
return FALSE;

return TRUE;

default:
return TRUE;
};
};

UINT __declspec(dllexport) CALLBACK CustomControlInfoA(LPCCINFOA CustomControlArguments)
{
if (!CustomControlArguments)
return 2;

memset(&CustomControlArguments[0], 0, sizeof(CustomControlArguments[0]));

CustomControlArguments[0].cxDefault = 80;
CustomControlArguments[0].cyDefault = 8;
CustomControlArguments[0].flStyleDefault = WS_CHILD | WS_VISIBLE;

CustomControlArguments[0].cStyleFlags = 0;
CustomControlArguments[0].aStyleFlags = 0;

CustomControlArguments[0].lpfnStyle = 0;
CustomControlArguments[0].lpfnSizeToText = 0;

lstrcpyn(CustomControlArguments[0].szClass, _T("LabelClass"), CCHCCCLASS);
lstrcpyn(CustomControlArguments[0].szDesc, _T("LabelClass (label.dll)"), CCHCCDESC);
lstrcpyn(CustomControlArguments[0].szTextDefault, _T("Label"), CCHCCTEXT);

return 1;
};
« Last Edit: April 28, 2012, 09:07:58 PM by leandrojardim »

czerny

  • Guest
Re: Dialog Box and Custom Controls
« Reply #6 on: April 28, 2012, 09:11:29 PM »
Quote
The problem was that I did not use the command "Open custom control" in the Dialog menu.

Can you explain this a little bit more detailed. I can not find what you are talking from.
The help says that there are also dialogs

  • new temporary custom control
  • rempve custom control
  • select custom control

which I can not find too.


Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Dialog Box and Custom Controls
« Reply #7 on: April 28, 2012, 09:12:15 PM »
Quote
What could be wrong with this control? It show up in the dialog editor but when I rexecute it within a dialog it blocks the executable program from opening the dialog window...
Read this:
http://forum.pellesc.de/index.php?topic=4473.msg16745#msg16745
« Last Edit: April 28, 2012, 09:34:59 PM by timovjl »
May the source be with you

leandrojardim

  • Guest
Re: Dialog Box and Custom Controls
« Reply #8 on: April 28, 2012, 09:25:07 PM »
Quote
The problem was that I did not use the command "Open custom control" in the Dialog menu.

Can you explain this a little bit more detailed. I can not find what you are talking from.
The help says that there are also dialogs

  • new temporary custom control
  • rempve custom control
  • select custom control

which I can not find too.

The Dialog menu only shows up in the toolbar when you are editing a dialog in the dialog editor. First you must load the dll into memory with that command. After you loaded it, you need to click on the button with a "small head" in the toolbox and select a control from te list.
« Last Edit: April 28, 2012, 09:27:07 PM by leandrojardim »

leandrojardim

  • Guest
Re: Dialog Box and Custom Controls
« Reply #9 on: April 28, 2012, 09:33:45 PM »
Read this:
http://forum.pellesc.de/index.php?topic=4473.msg16745#msg16745

Man, you did it again! It worked like a dream. How I could not understand that?!

czerny

  • Guest
Re: Dialog Box and Custom Controls
« Reply #10 on: April 28, 2012, 10:14:00 PM »
The Dialog menu only shows up in the toolbar when you are editing a dialog in the dialog editor. First you must load the dll into memory with that command. After you loaded it, you need to click on the button with a "small head" in the toolbox and select a control from te list.

Thank you!

leandrojardim

  • Guest
Re: Dialog Box and Custom Controls
« Reply #11 on: April 28, 2012, 10:18:37 PM »
Thank you!

I am glad I could help you! :)