Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Windows API in C/C++

Name: duh 2008-02-21 13:28

Help, I have no idea how to correctly use the API to create windows and fill them with text and shit.

Give me information, tutorials, etc.

Name: Anonymous 2008-02-22 11:09

>>37
Meme m = MemeFactory.CreateMeme(null);

Name: Anonymous 2008-02-22 11:34

>>41
NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL

Name: Anonymous 2008-02-22 14:32


CreateWindowEx(this, NULL, this, NULL, this,  NULL, this, NULL, this, NULL, this, NULL,
    this, NULL, this, NULL, this, NULL, this, NULL, this, NULL, this, NULL, this, NULL,
this, NULL, this, NULL, this, NULL, this, NULL, this, NULL, this, NULL, this, NULL)
// this NULL is an eyesore.

Name: Anonymous 2008-02-22 16:24

>>43
is not valid Python code

Name: Anonymous 2008-02-22 18:14

>>42
There is no NULL in java, you fail.

Name: Anonymous 2008-02-22 18:20

>>45
You know Java, you fail.

Name: Anonymous 2008-02-22 18:24

>>37
Learn win32api and you will understand

Name: Anonymous 2008-02-22 21:54

Java has no NULL.
How does it handle an invalid memory reference?
Terrible!

Name: Anonymous 2008-02-23 0:55

??48
The null keyword is used for the null reference. It's actually funny, proponents of Java always boast how there's no more null pointer segfaults, however they ignore the fact that there is the common unchecked null reference exception ;)

Name: Anonymous 2008-02-23 4:56

>>48
Nurupo!

Name: Anonymous 2008-02-23 5:20

how does JVM know wut memory is???/

Name: Anonymous 2008-02-23 5:32

>>51
Terrible!

Name: Anonymous 2008-02-23 8:46

how do i programmed windows gui???/

Name: Anonymous 2008-02-23 8:52

>>53
gui-mode

Name: Anonymous 2008-02-23 9:28

>>53
Terrible!

Name: Anonymous 2008-02-23 10:32

>>54
guido-mode

Name: Anonymous 2008-02-23 14:13

UI programming in Windows native C/C++ is so fucking shit that it motivated me to learn Java, so I could at least pretend I was back in the world of X, with sensible event handling and layout.

OP could use C++ on .Net, but they go together like oil and water.

Name: Anonymous 2008-02-23 14:35

No .NET ploz, just halp 2 designed GUI

Name: Anonymous 2008-02-23 14:48

Windows UI programming just too fucking complicated to put into a post like this.  Go and get hold of a copy of Petzold on Windows and work through that like the rest of us had to.

Or use a better set of tools like JRuby on the JVM

   # Valid as of JRuby 1.0
  
   # This is the 'magical Java include line'.
   include Java
  
   # With the 'include Java' above, we can now refer to things that are part of the
   # standard Java platform via their full paths.
   frame = javax.swing.JFrame.new("Window") # Creating a Java JFrame.
   label = javax.swing.JLabel.new("Hello")
  
   # We can transparently call Java methods on Java objects, just as if they were defined in Ruby.
   frame.getContentPane.add(label)  # Invoking the Java method 'getContentPane'.
   frame.setDefaultCloseOperation(javax.swing.JFrame::EXIT_ON_CLOSE)
   frame.pack
   frame.setVisible(true)

Name: Anonymous 2008-02-23 14:56

>>10
Not necessarily. Hint: Nextstep.

Name: Anonymous 2008-02-23 15:15

This is your Hello World in 1995 on Win32 and 'C'

#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd,
             UINT msg,
             WPARAM wparam,
             LPARAM lparam);
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
         LPSTR cmdline, int cmdshow) {
  MSG         msg;
  HWND        hwnd;
  WNDCLASSEX  wndclass = { 0 };
  wndclass.cbSize          = sizeof(WNDCLASSEX);
  wndclass.style           = CS_HREDRAW | CS_VREDRAW;
  wndclass.lpfnWndProc     = WndProc;
  wndclass.hIcon           = LoadIcon(NULL, IDI_APPLICATION);
  wndclass.hCursor         = LoadCursor(NULL, IDC_ARROW);
  wndclass.hbrBackground   = (HBRUSH)GetStockObject(WHITE_BRUSH);
  wndclass.lpszClassName   = TEXT("Window1");
  wndclass.hInstance       = hInstance;
  wndclass.hIconSm         = LoadIcon(NULL, IDI_APPLICATION);
  RegisterClassEx(&wndclass);
  hwnd = CreateWindow(TEXT("Window1"),
        TEXT("Hello World"),
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        0,
        CW_USEDEFAULT,
        0,
        NULL,
        NULL,
        hInstance,
        NULL);

  if( !hwnd )
    return 0;
  ShowWindow(hwnd, SW_SHOWNORMAL);
  UpdateWindow(hwnd);
  while( GetMessage(&msg, NULL, 0, 0) ) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
         WPARAM wparam, LPARAM lparam) {
  switch(msg) {
    case WM_DESTROY:
      PostQuitMessage(WM_QUIT);
      break;
    default:
      return DefWindowProc(hwnd, msg, wparam, lparam);
  }
  return 0;
}

This is your Hello World in 2008 on C# and WPF

using System.Windows;
using System;

class Program {
  [STAThread]
  static void Main() {
    Window f = new Window();
    f.Title  = "Hello World";
    new Application().Run(f);
  }
}

Anyone who wants to do the former needs their heads examined.

Name: NULL NULL NULL 2008-02-23 15:20

  wndclass.hIcon           = LoadIcon(NULL, IDI_APPLICATION);
  wndclass.hCursor         = LoadCursor(NULL, IDC_ARROW);
  wndclass.hIconSm         = LoadIcon(NULL, IDI_APPLICATION);
        0,
        0,
        NULL,
        NULL,
        NULL);
  while( GetMessage(&msg, NULL, 0, 0) ) {

NULL NULL NULL

Name: Anonymous 2008-02-23 15:36

It's not really that hard;

wm title . "C++ WinAPI hello world app"
label .hwlabel -text "Behold, a button:"
button .hwbutton -text "Click me" -command {
    tk_messageBox -title "Hi" -message "Hello, world!"
}
pack .hwlabel .hwbutton

Name: Anonymous 2008-02-23 16:05

If you must use native C++, then the Fox Toolkit (http://www.fox-toolkit.org/) is probably the best way to ease your pain.  Here's "Hello world":

#include "fx.h"
 
int main(int argc, char *argv[]) {
  FXApp application("Hello", "FoxTest");
  application.init(argc, argv);
  FXMainWindow *main=new FXMainWindow(&application, "Hello", NULL, NULL, DECOR_ALL);
  new FXButton(main, "&Hello, World!", NULL, &application, FXApp::ID_QUIT);
  application.create();
  main->show(PLACEMENT_SCREEN);
  return application.run();
}

Name: Anonymous 2008-02-23 16:08

>>63
Tcl/Tk is cheating.  Even if that itself is written in C.

Name: Anonymous 2008-02-23 16:40

>>65
Yes, clearly using a language designed for the job in question is cheating. After all, that would be easy and painless, and we wouldn't want that, now would we?

Name: Anonymous 2008-02-24 1:03

>>61
#include <windows.h>
#include <winuser.h>

main() {
 MessageBox(0,"Hello world!","Hello world!",0);
}


and you forgot to mention that the second one creates a binary several times bigger than the first.

Name: Anonymous 2008-02-24 3:34

>>67
I'm sure you'll be severely worried by the difference in binary size on your half-terabyte HD.

Name: Anonymous 2008-02-24 9:22

>>68
It's indicative of a crappier compiler all the same.

Name: Anonymous 2008-02-24 12:25

>>67
I just built both those programs, and the WPF executable is smaller by almost a factor of 2.

HelloWin32 = 7.50 KB (7,680 bytes)

HelloWPF = 4.00 KB (4,096 bytes)

So, which is the crappier?

Name: Anonymous 2008-02-24 12:33

>>70
HelloWin32 = 7.50 KiB (7,680 bytes)

HelloWPF = 4.00 KiB (4,096 bytes) + (DotNetFx = 23.1 MiB (24,265,736 bytes))

Name: Anonymous 2008-02-24 12:59

>>71
HelloWin32 = 7.50 KiB (7,680 bytes)

HelloWPF = 4.00 KiB (4,096 bytes) + (DotNetFx = 23.1 MiB (24,265,736 bytes))/Number of WPF programs.

I'll let you argue with
>>66
Yes, clearly using a language designed for the job in question is cheating. After all, that would be easy and painless, and we wouldn't want that, now would we?

Name: Anonymous 2008-02-24 13:02

>>71
The Win32 API + C/C++ runtime take up some space as well.

Name: Anonymous 2008-02-24 13:25

The Win32 API [..] take(s) up some space as well.

Name: Anonymous 2008-02-24 14:34

>>61
hello.cs(1,7): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
hello.cs(1,1): error CS0246: The type or namespace name `System.Windows' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 2 error(s), 0 warnings


Name: Anonymous 2008-02-24 14:39

Fuck that noise.  Just need to design some GUIs, ya dig?

Name: Anonymous 2008-02-24 15:49

>>72
You fail at rounding file size to block size

Name: Anonymous 2008-02-24 16:01

>>76
PROTIP: Don't do it

Name: Anonymous 2008-02-24 16:02

>>75
Could you fail any harder?

How do I use WPF?

Name: Anonymous 2008-02-24 16:34

>>72
Enjoy your 6771 WPF programs.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List