NO

Author Topic: GUI programming: how to use resource?  (Read 4985 times)

andre104

  • Guest
GUI programming: how to use resource?
« on: May 22, 2009, 07:30:11 AM »
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

  • Guest
Re: GUI programming: how to use resource?
« Reply #1 on: May 22, 2009, 11:12:43 AM »
Look at followings API that best suit your case:

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

Bye.

andre104

  • Guest
Re: GUI programming: how to use resource?
« Reply #2 on: May 22, 2009, 05:44:01 PM »
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?

Offline DMac

  • Member
  • *
  • Posts: 272
Re: GUI programming: how to use resource?
« Reply #3 on: May 22, 2009, 07:06:37 PM »
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.

Offline DMac

  • Member
  • *
  • Posts: 272
Re: GUI programming: how to use resource?
« Reply #4 on: May 22, 2009, 07:39:47 PM »
Now for some specifics from your project:

Make sure you include every thing you need
Code: [Select]
#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
Code: [Select]
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
Code: [Select]
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.