digitalmars.D.learn - Programming with windows api (windows.h)
- monarch_dodra (30/30) Dec 17 2012 I'm a bit confused about how to interface with windows.h.
- Andrej Mitrovic (6/10) Dec 17 2012 std.c.windows.windows is a very thin layer around the API. There are
- monarch_dodra (3/14) Dec 20 2012 Good deal. I was able to get it to work with that. Thanks.
- John Chapman (18/22) Dec 17 2012 Something like this:
- John Chapman (1/2) Dec 17 2012 Oops, should be CF_UNICODETEXT (13)
I'm a bit confused about how to interface with windows.h. All I'm trying to do is retrieve some text from my clipboard to print it. So far, I have this: //---- import std.stdio; import core.sys.windows.windows; extern (Windows) { HWND GetClipboardOwner(); BOOL OpenClipboard(HWND hWndNewOwner); HANDLE GetClipboardData(UINT uFormat); } void main() { HWND hWnd = GetClipboardOwner(); if ( hWnd == null ) {stderr.writeln("Problem."); return;} if ( OpenClipboard(hWnd) == 0 ) {stderr.writeln("Problem 2."); return;} hWnd = cast(HWND)GetClipboardData(CF_TEXT); } //---- This works, but as you can see, I have to declare as "extern (Windows)" all the functions myself. Not pretty, but works I guess. I'm hitting a wall at "CF_TEXT" though: That's an enum. Anyways... Am I doing it wrong, or are is the amount of ported windows interface currently limited... Kinda lost here (The fact that I'm also new to windows programming doesn't help...) :)
Dec 17 2012
On 12/17/12, monarch_dodra <monarchdodra gmail.com> wrote:Am I doing it wrong, or are is the amount of ported windows interface currently limited...std.c.windows.windows is a very thin layer around the API. There are better bindings here: http://dsource.org/projects/bindings/wiki/WindowsApiKinda lost here (The fact that I'm also new to windows programming doesn't help...) :)Take a look here, there are many examples of WinAPI programming: https://github.com/AndrejMitrovic/DWinProgramming
Dec 17 2012
On Monday, 17 December 2012 at 17:24:40 UTC, Andrej Mitrovic wrote:On 12/17/12, monarch_dodra <monarchdodra gmail.com> wrote:Good deal. I was able to get it to work with that. Thanks.Am I doing it wrong, or are is the amount of ported windows interface currently limited...std.c.windows.windows is a very thin layer around the API. There are better bindings here: http://dsource.org/projects/bindings/wiki/WindowsApiKinda lost here (The fact that I'm also new to windows programming doesn't help...) :)Take a look here, there are many examples of WinAPI programming: https://github.com/AndrejMitrovic/DWinProgramming
Dec 20 2012
On Monday, 17 December 2012 at 16:21:09 UTC, monarch_dodra wrote:I'm a bit confused about how to interface with windows.h. All I'm trying to do is retrieve some text from my clipboard to print it.Something like this: HWND hwnd = ... // your window handle (or null) if (OpenClipboard(hwnd)) { HGLOBAL data = GetClipboardData(CF_TEXT); if (data) { auto text = cast(wchar*)GlobalLock(data); writeln(to!string(text[0 .. wcslen(text)])); GlobalUnlock(data); } } You'll have to define GlobalLock/GlobalUnlock, and values for the various clipboard formats (CF_TEXT and co) are documented here: http://msdn.microsoft.com/en-gb/library/windows/desktop/ff729168%28v=vs.85%29.aspxI'm hitting a wall at "CF_TEXT" though: That's an enum.enum : uint { CF_TEXT = 1, CF_BITMAP = 2, // and so on }
Dec 17 2012
HGLOBAL data = GetClipboardData(CF_TEXT);Oops, should be CF_UNICODETEXT (13)
Dec 17 2012