FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Win32 gui api examples available (no gui framework)

 
Post new topic   Reply to topic     Forum Index -> Tutorials
View previous topic :: View next topic  
Author Message
Lynn



Joined: 27 Aug 2004
Posts: 89

PostPosted: Sat Sep 25, 2004 10:58 am    Post subject: Win32 gui api examples available (no gui framework) Reply with quote

http://dsource.org/tutorials/index.php?show_example=123

Simple Windows GUI example with some additional functionality beyond winsamp.d and winsamp2.d provided with dmd.zip. Uses Win32 api (no gui framework) with several TextEdit controls. Uses WM_SETTEXT and WM_GETTEXT. Only depends on
import std.c.windows.windows;

http://dsource.org/tutorials/index.php?show_example=124

Demonstrates basic usage of Win32 TreeView control. Creates very simple tree, and responds to mouse click selections with confirmation in TextViewer. Only uses Win32 api calls ... no GUI framework. Buttons created, but only 'stubbed' functionality. As of 2004-Sep-25, std.c.windows.windows has only basic 'widgets' supported:
buttons, textedit, checkbox, etc.

It is missing the "advanced" controls, such as TreeView, ListControl, common dialogs, etc. This code depends on installation of the "Core32" library, available at:
http://svn.dsource.org/svn/projects/core32/downloads/

This code assumes core32 files are installed at:
[dmd_dir]\src\phobos\win32

import std.c.windows.windows;
import win32.commctrl;

and win32.lib is installed in
[dmd_dir]\lib
Back to top
View user's profile Send private message
endless



Joined: 11 Jan 2005
Posts: 3

PostPosted: Tue Jan 25, 2005 5:33 pm    Post subject: Reply with quote

Hello. Any ideas on why the relevant code with fail with "ChapSelector Tree not created!"?

Incidentally, the executable itself appears to be running in the task manager. This seems to be the case with all the other win32 GUI examples. No window is being drawn to the screen. This is on a Windows 2003 machine. I must be doing something wrong?
Back to top
View user's profile Send private message
chriss



Joined: 06 Jan 2007
Posts: 2

PostPosted: Sat Jan 06, 2007 5:28 am    Post subject: Reply with quote

The Win32 examples seem to be down. Are there any other places to download them?

Regards Chriss
Back to top
View user's profile Send private message
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Sun Jan 07, 2007 12:01 am    Post subject: Reply with quote

chriss wrote:
The Win32 examples seem to be down. Are there any other places to download them?

Regards Chriss
It's not that the examples are down so much as they moved and didn't leave a forwarding address. These particular examples are now located at: http://www.dsource.org/projects/tutorials/wiki/WindowsGuiCategory

Sorry, for the confusion. I'm sure we could've spent more effort keeping the old links alive by redirecting to the new links, but at the examples are still available.

(By the way, do let me know if you get compile errors running these examples, and I'll try to fix them up. Many of the examples haven't been tested in a while, and D has gone through some changes. Now that D 1.0 has been released, I'd like to declare as many of them as possible as "D 1.0"-enabled.)
Back to top
View user's profile Send private message AIM Address
chriss



Joined: 06 Jan 2007
Posts: 2

PostPosted: Sun Jan 07, 2007 7:00 am    Post subject: Reply with quote

Hi, sorry but i wrote something wrong.

The Tutorial itself is available. But the downloadfiles are not!

Like this one
http://www.dsource.org/tutorials/index.php?show_example=123

If i compile the code as it is on the tutorial i get some errors.

But with a few changes i works very well.
Here is my working code (Example 'WinCalc')
Code:

import std.string;
import std.c.windows.windows;

const int IDC_BTN_PLUS = 103;
const int IDC_BTN_MINUS = 104;
const int IDC_EDIT_FIRST_NUMBER = 105;
const int IDC_EDIT_SECOND_NUMBER = 106;
const int IDC_EDIT_RESULT_NUMBER = 107;

static HINSTANCE ghInstance;
static HWND      ghPlusBtn;
static HWND      ghMinusBtn;
static HWND      ghFirstNumberEdit;
static HWND      ghSecondNumberEdit;
static HWND      ghResultNumberEdit;
static HWND      ghWndMain;

void CreateControls()
{
  HWND hChapSelectorTree;
 
  ghPlusBtn = CreateWindowA("BUTTON", "Plus",
                 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_TEXT,
                 5, 5, 53, 25, ghWndMain, cast(HMENU) IDC_BTN_PLUS,
                 ghInstance, null);

  ghMinusBtn = CreateWindowA("BUTTON", "Minus",
                 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_TEXT,
                 60, 5, 53, 25, ghWndMain,
                 cast(HMENU) IDC_BTN_MINUS,
                 ghInstance, null);

  ghFirstNumberEdit = CreateWindowA("EDIT", "0",
                 WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT,
                 5, 32, 110, 25, ghWndMain,
                 cast(HMENU) IDC_EDIT_FIRST_NUMBER, ghInstance, null);

  ghSecondNumberEdit = CreateWindowA("EDIT", "20",
                 WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT,
                 5, 60, 110, 25, ghWndMain,
                 cast(HMENU) IDC_EDIT_SECOND_NUMBER, ghInstance, null);
 
  ghResultNumberEdit = CreateWindowA("EDIT", "",
                 WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT,
                 5, 87, 110, 25, ghWndMain,
                 cast(HMENU) IDC_EDIT_RESULT_NUMBER,
                 ghInstance, null);
}

void DoMessagePump()
{
  MSG msg;
  while (GetMessageA(&msg, cast(HWND) null, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessageA(&msg);
  }
}

void CreateMainWindow()
{
  HWND hWnd;
  hWnd = CreateWindowA("DWndClass",
               "MiniCalc",
               WS_THICKFRAME | WS_MAXIMIZEBOX
               | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE,
               CW_USEDEFAULT, CW_USEDEFAULT,
               125, 150, HWND_DESKTOP,
               cast(HMENU) null, ghInstance, null);
  assert(hWnd);
  ghWndMain = hWnd;
}

void InitApplication()
{
  WNDCLASS wc;
  wc.lpszClassName = "DWndClass";
  wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc = &WindowProc;
  wc.hInstance = ghInstance;
  wc.hIcon = LoadIconA(cast(HINSTANCE) null, IDI_APPLICATION);
  wc.hCursor = LoadCursorA(cast(HINSTANCE) null, IDC_CROSS);
  wc.hbrBackground = cast(HBRUSH) (COLOR_WINDOW + 1);
  wc.lpszMenuName = null;
  wc.cbClsExtra = wc.cbWndExtra = 0;

  assert(RegisterClassA(&wc));
}

void InitInstance()
{
  ghInstance = GetModuleHandleA(null);
  InitApplication();

  CreateMainWindow();

  CreateControls();
}

/**********************************************************/

/* Note the similarity of this code to the console D startup
 * code in \dmd\src\phobos\dmain2.d
 * You'll also need a .def file with at least the following in it:
 *  EXETYPE NT
 *  SUBSYSTEM WINDOWS
 */

extern (C) void gc_init();
extern (C) void gc_term();
extern (C) void _minit();
extern (C) void _moduleCtor();
extern (C) void _moduleUnitTests();

extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
            LPSTR lpCmdLine, int nCmdShow)
{
  int result = 1;

  gc_init();      // initialize garbage collector
  _minit();     // initialize module constructor table

  try {
    _moduleCtor();    // call module constructors
    _moduleUnitTests(); // run unit tests (optional)

    InitInstance();
    DoMessagePump();
  }
  catch (Object o) {    // catch any uncaught exceptions
    MessageBoxA(null, cast(char *)o.toString(), "Error",
                MB_OK | MB_ICONEXCLAMATION);
    result = 0;   // failed
  }
  gc_term();      // run finalizers; terminate garbage collector
  return result;
}

extern(Windows)
int WindowProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam)
{
  char[8] firstNumber;
  char[8] secondNumber;
  int count;
  long num1;
  long num2;

  switch (uMsg) {
    case WM_COMMAND: {
      switch (LOWORD(wParam)) {
        case IDC_BTN_PLUS:
          if (HIWORD(wParam) == BN_CLICKED) {
            count = SendMessageA(ghFirstNumberEdit, WM_GETTEXT,
                                 6, cast(int)cast(char*)firstNumber);
            count = SendMessageA(ghSecondNumberEdit, WM_GETTEXT,
                                 6, cast(int)cast(char*)secondNumber);
            num1 = atoi(cast(char[])firstNumber);
            num2 = atoi(cast(char[])secondNumber);
            SendMessageA(ghResultNumberEdit, WM_SETTEXT,
                         8, cast(int)cast(char*)toString(num1 + num2));
          }
          break;
        case IDC_BTN_MINUS:
          if (HIWORD(wParam) == BN_CLICKED) {
            count = SendMessageA(ghFirstNumberEdit,
                                 WM_GETTEXT, 8,
                                 cast(int)cast(char*)firstNumber);
            count = SendMessageA(ghSecondNumberEdit,
                                 WM_GETTEXT, 8,
                                 cast(int)cast(char*)secondNumber);
            num1 = atoi(cast(char[])firstNumber);
            num2 = atoi(cast(char[])secondNumber);
            SendMessageA(ghResultNumberEdit,
                         WM_SETTEXT, 8,
                         cast(int)cast(char*)toString(num1 - num2));
          }
          break;
        case IDC_EDIT_FIRST_NUMBER:

          break;
        case IDC_EDIT_SECOND_NUMBER:
          break;
        case IDC_EDIT_RESULT_NUMBER:
          break;
      }
      break;
    }
    case WM_DESTROY:
      PostQuitMessage(0);
      break;

    case WM_NOTIFY:
      break;

    default:
      break;
  }
  return DefWindowProcA(hWnd, uMsg, wParam, lParam);
}


It has a little output issue by using the "Plus" function but i'm sure that this is not a big thing and everybody should be able to fix it.
Back to top
View user's profile Send private message
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Sun Jan 07, 2007 9:51 am    Post subject: Reply with quote

chriss wrote:
Hi, sorry but i wrote something wrong.

The Tutorial itself is available. But the downloadfiles are not!
Oh, the link to those changed, too: http://svn.dsource.org/projects/core32/downloads/

We should probably revise the example though to eliminate the necessity of using theCore32 core though, since Core32 isn't really being maintained any more.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Tutorials All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group