GUI programming: how to use resource?

Started by andre104, May 22, 2009, 07:30:11 AM

Previous topic - Next topic

andre104

My first attempt to do GUI programming using Pelles C



I've made the resource. Then how can I load the resource, and add some functionalities, e.g:
- the progress bar value changed accordingly when the slider is moved
- when the button is clicked, a message box will apper

::)

Alessio

Look at followings API that best suit your case:

- DialogBox
- DialogBoxIndirect
- DialogBoxIndirectParam
- DialogBoxParam
- CreateDialog
- CreateDialogIndirect
- CreateDialogIndirectParam
- CreateDialogParam

Bye.

andre104

Err... OK. Thanks for your hint.
I use CreateDialog()

Anyway, this is my attempt so far, based on these explanations:
http://winprog.org/tutorial/start.html
http://www.codeguru.com/forum/archive/index.php/t-267384.html

Maybe someone could elabore more, e.g on adding event handler for the slider?

DMac

There are a number of errors in your project so things aren't hooking up right.  That's why the dialog doesn't even show.

Your best bet is to start your dialog project using the Pelles C project wizard.

"File>New>Project>Win32 Application Wizard" and select the option to create a dialog based application.

You can modify the main dialog created to suit your needs.

Then look at the code Pelles generates in Main()

Also look at the properties of the dialog and specifically the class name property.

There are a lot of things to keep in mind when setting up a dialog project.  I always use the wizard to get started and then modify to suit my needs.
No one cares how much you know,
until they know how much you care.

DMac

Now for some specifics from your project:

Make sure you include every thing you need

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <commctrl.h> //<-Gotta have this
#include "GUITest.h"


Make sure you register all of the window components you'll need and load the windows class struct from the built in dialog definition

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){

InitCommonControls(); //<- Don't forget
   
WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;
int error;

    wc.cbSize        = sizeof(WNDCLASSEX);
    if (!GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wc)) //<-Must do this for dialog app
        return 0;
wc.hInstance = hInstance;

wc.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(ID_MAINICON));
wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, MAKEINTRESOURCE(ID_MAINICON));

    if(!RegisterClassEx(&wc))    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }


Use the proper CALLBACK for Dialogs

BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
    switch(msg)    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return FALSE;
    }
return FALSE;
}


Make sure to assign the class name to the dialog in the properties
No one cares how much you know,
until they know how much you care.