Re: Accessing LPARAM param from SendMessage acts weird.

2018-11-05 Thread Mark Moorhen via Digitalmars-d-learn

Brilliant! Thanks John
!


Accessing LPARAM param from SendMessage acts weird.

2018-11-04 Thread Mark Moorhen via Digitalmars-d-learn

Another Windows challenge:

I'm trying to get the title of the active window even if it is 
from an external application. This is what I've come up with so 
far:



import std.stdio;
import core.sys.windows.windows;

extern (Windows)

void main()
{
HWND foreground = GetForegroundWindow();
const(wchar) title;

int length = SendMessage(foreground, WM_GETTEXTLENGTH, 0, 0);
	SendMessage(foreground, WM_GETTEXT, length, 
LPARAM(title));			//LPARAM is a Long Pointer


writeln(length);
writeln(title);

}


Outputs :

27
  ´┐┐


So the lengt of the foreground windows title should be 27 chars 
long, but the title is only 3 chars (and kinda funny ones too:-(


Anyone ideas?



Re: getting Win32 Messagebox to work

2018-10-26 Thread Mark Moorhen via Digitalmars-d-learn

On Friday, 26 October 2018 at 13:59:17 UTC, Adam D. Ruppe wrote:

On Friday, 26 October 2018 at 12:36:42 UTC, Mark Moorhen wrote:

Can anyone help me out with this?


Yeah, let me make a few general points here:




Welcome to the wonderful world of wide strings and D Windows 
programming! :)


Wow, that's a lot of info, but it makes things a lot clearer. I 
ended up with this:


import core.runtime;
import std.utf;
import core.sys.windows.windows;

extern (Windows)
void WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR 
lpCmdLine, int iCmdShow)

{
const(wchar*)  foo = toUTF16z("hello"w[0 .. 2]);
MessageBoxW(null, foo, "hi", 0);
}

It does compile, but does not run as expected. Any clues?




Re: getting Win32 Messagebox to work

2018-10-26 Thread Mark Moorhen via Digitalmars-d-learn

On Friday, 26 October 2018 at 13:20:17 UTC, Adam D. Ruppe wrote:
If that doesn't compile without casts, you don't want it to 
compile - casting is often a mistake; the compiler is trying to 
tell you something.


Now you've mentioned, I also tried:
{
const(char)* content = "Some random content.";
MessageBox(NULL, content , "Window title", 0);
}

And it compiles like a charm.


Re: getting Win32 Messagebox to work

2018-10-26 Thread Mark Moorhen via Digitalmars-d-learn

On Friday, 26 October 2018 at 13:04:21 UTC, Adam D. Ruppe wrote:
On Friday, 26 October 2018 at 12:56:21 UTC, rikki cattermole 
wrote:
MessageBoxA(null, cast(const(char)*)content.ptr, 
cast(const(char)*)"Window title".ptr, 0);


Get rid of those casts, they are unnecessary.


I got to this:

string content = "Some random content.";
const(char)* content2 =  content.ptr;
MessageBox(NULL, content2 , "Window title", 0);


But how would you do this without casts?


Re: getting Win32 Messagebox to work

2018-10-26 Thread Mark Moorhen via Digitalmars-d-learn
On Friday, 26 October 2018 at 12:56:21 UTC, rikki cattermole 
wrote:

On 27/10/2018 1:46 AM, Mark Moorhen wrote:
On Friday, 26 October 2018 at 12:39:13 UTC, rikki cattermole 
wrote:

On 27/10/2018 1:36 AM, Mark Moorhen wrote:

[...]


alias string = immutable(char)[];

A slice (string in this case) is a length + pointer pair. You 
need to add .ptr on content with a cast to get to 
const(char)*.


Thanks for your quick reply.

However when I do:
cast(const(char)*) content.ptr;

I get a error:


HelloMsg.d(9): Error: 
`cast(const(char)*)cast(immutable(char)*)content` has no effect

This should work:

string content = "Some random content.";
MessageBoxA(null, cast(const(char)*)content.ptr, 
cast(const(char)*)"Window title".ptr, 0);


Thanks again. It does work indeed. Now I'll have to try and get 
my head around it. But that will work out. eventually...


Re: getting Win32 Messagebox to work

2018-10-26 Thread Mark Moorhen via Digitalmars-d-learn
On Friday, 26 October 2018 at 12:39:13 UTC, rikki cattermole 
wrote:

On 27/10/2018 1:36 AM, Mark Moorhen wrote:

[...]


alias string = immutable(char)[];

A slice (string in this case) is a length + pointer pair. You 
need to add .ptr on content with a cast to get to const(char)*.


Thanks for your quick reply.

However when I do:
cast(const(char)*) content.ptr;

I get a error:


HelloMsg.d(9): Error: 
`cast(const(char)*)cast(immutable(char)*)content` has no effect


getting Win32 Messagebox to work

2018-10-26 Thread Mark Moorhen via Digitalmars-d-learn

Hi,

I've recently started looking into D, and I'm afraid i'm gonna 
need some support to get me going.


I work mostly on Windows, so i've downloaded the examples from 
"https://github.com/AndrejMitrovic/DWinProgramming";. Only these 
examples do not work out-of-the-box on my machine (Win10, 64-bit 
/ DMD32 D Compiler v2.082.0)


Now I'm trying to pass the content for a Messagebox as a variable 
like this:


import core.runtime;
import win32.windef;
import win32.winuser;

extern (Windows)
void WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR 
lpCmdLine, int iCmdShow)

{
string content = "Some random content.";
MessageBox(NULL, content , "Window title", 0);
}


When compiling I get the error:

HelloMsg.d(9): Error: function `win32.winuser.MessageBoxA(void*, 
const(char)*, const(char)*, uint)` is not callable using argument 
types `(typeof(null), string, string, int)`
HelloMsg.d(9):cannot pass argument `content` of type 
`string` to parameter `const(char)*`


Can anyone help me out with this?