Re: How to read live output from another process ?
On Friday, 23 June 2023 at 23:37:29 UTC, Vinod K Chandran wrote: Hi all, Hi, I found the solution by myself. We can use Pipe struct for this job. Here is the code looks like. This is for future readers. ```d void onBtnBurnClick(Control c, EventArgs e) { // A button click event handler if (!jobStarted) { jobStarted = true; btnBurn.text = "Stop the job"; string cmd = makeCommand(); ff = spawn(, cmd); // ff is global var } else { ff.send(-1); // Send a signal to stop the job btnBurn.text = "Start the job"; } } void runInAnotherThread(string cmd) { Duration du = dur!"hnsecs"(-2); // Minus value for no waiting auto psin = pipe(); auto psout = pipe(); auto pserr = pipe(); spawnShell(cmd, psin.readEnd, psout.writeEnd, pserr.writeEnd , null, Config.detached); string line; while ((line = pserr.readEnd.readln()) !is null){ receiveTimeout(du, (int dummy) {psin.writeEnd.writeln("q"); psin.writeEnd.flush(); }); // Here, entering "q" is app specific command to stop. writefln("pipe err: %s", line); stdout.flush; } } ``` By this way, you can asynchronously process the output from the child process.
How to read live output from another process ?
Hi all, I am trying to create a program which burns time codes to a video. I am using ffmpeg for this. So far, I can successfully start ffmpeg in another thread and stop it when I need. But I can't read the live outputs from ffmpeg. This is my code. ```d void onBtnBurnClick(Control c, EventArgs e) { if (!burnStarted) { burnStarted = true; btnBurn.text = "Stop Burning"; auto ffCmd = makeFFMPEGCommand(selVideo); // ffPipe is a global ProcessPipes auto tsk = task!runFFMPEG(ffCmd, , frm.handle); tsk.executeInNewThread(); } else { ffPipe.stdin.writeln("q"); ffPipe.stdin.close(); btnBurn.text = "Burn Time Code"; } } ``` This is a button's click event.
Re: How to call a function from a dll created with d ?
On Saturday, 2 July 2022 at 21:36:50 UTC, mw wrote: Actually, can you create a github repo, I'm sure people will send you a working PR. Yes I can. I will inform here once I did it.
Re: How to call a function from a dll created with d ?
On Saturday, 2 July 2022 at 01:05:25 UTC, Ali Çehreli wrote: 3) The users of this dll should import that .di file (declaring the functions themselves won't work): Ali Hi, Thanks for the reply. I have tried your suggestion. First, I compiled my dll's source code with `-H` switch as you said. Then I got the header file with this content. ```d // D import file generated from dimedll.d module dimedll; import core.sys.windows.windows; import core.sys.windows.dll; import std.stdio; mixin SimpleDllMain!(); export void testFunc(); ``` So far so good. Then I change my `dime.d` source file like this. ```d import dimedll; void main() { log("Lets build our own ime"); testFunc(); } ``` Unfortunately, I got this error message. dime.obj : error LNK2019: unresolved external symbol __imp___D7dimedll8testFuncFZv referenced in function __Dmain dime.obj : error LNK2001: unresolved external symbol __D7dimedll12__ModuleInfoZ dime.exe : fatal error LNK1120: 2 unresolved externals Error: linker exited with status 1120 Then I have tested with `dimedll.testFunc()` instead of `testFunc()` at the calling site. Then also I got an error message like this. dime.obj : error LNK2019: unresolved external symbol __imp___D7dimedll8testFuncFZv referenced in function __Dmain dime.obj : error LNK2001: unresolved external symbol __D7dimedll12__ModuleInfoZ dime.exe : fatal error LNK1120: 2 unresolved externals Error: linker exited with status 1120 I want to test this with ddemangle.exe, but there is no proper documentation for that tool. So I don't know how to use that tool. So Actually I am stuck.
Re: How to call a function from a dll created with d ?
On Friday, 1 July 2022 at 22:38:17 UTC, Adam D Ruppe wrote: On Friday, 1 July 2022 at 22:32:24 UTC, Vinod K Chandran wrote: So using a `def` file is a must I think. no it is not. you just need to mark things export and make sure names match (including module name) Thanks for the reply. These are my questions. 1. `mixin` statement in dll file - Do I need to export it ? 2. There is only one function and that is marked with `export`. 3. Name of the module which I wrote the dll code is `dimedll`. So my dll file's name is `dimedll.dll`. And my lib file's name is `dimedll.lib`. No change in names. 4. Name of my exported function is `testFunc`. And the same name is used in `extern` keyword and the calling site. So where do I check again ?
Re: How to call a function from a dll created with d ?
On Friday, 1 July 2022 at 22:22:42 UTC, mw wrote: Try follow instructions here: https://wiki.dlang.org/Win32_DLLs_in_D Thanks. So using a `def` file is a must I think. At first, I thought I can skip that.
Re: How to call a function from a dll created with d ?
On Friday, 1 July 2022 at 21:02:20 UTC, mw wrote: I think the problem is the linker looking for dime.testFunc, while your lib function is dimedll.testFunc Thanks for the reply. What about this `mixin SimpleDllMain;` I suspect this.
Re: How to call a function from a dll created with d ?
On Friday, 1 July 2022 at 20:08:45 UTC, ryuukk_ wrote: I think it is `extern(D) void testFunc();`? Thanks for the reply. But the result is same linker error.
Re: Window created with Windows API is not visible
On Saturday, 18 June 2022 at 21:03:23 UTC, solidstate1991 wrote: It seems that you are created a layered window. So chances are there to it become translucent.
Re: How to call a GDI+ function from D ?
On Sunday, 5 June 2022 at 11:33:14 UTC, Vinod K Chandran wrote: For future readers of this thread, rikki cattermole helped me to findthe solution to this problem. I Do not need the C++ classes or their methods for this. There is a set of C functions in gdiplus.dll. Check this link. https://docs.microsoft.com/en-us/windows/win32/gdiplus/-gdiplus-flatapi-flat
Re: How to call a GDI+ function from D ?
On Sunday, 5 June 2022 at 10:57:16 UTC, rikki cattermole wrote: Bitmap is a class, not a namespace. The function you want is actually a constructor. https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-headers/include/gdiplus/gdiplusheaders.h#L179 Thank you for the reply. Well, I know that it is a CTOR. But I thought this is the D way to call it.
How to call a GDI+ function from D ?
Hi all, I want to call the Bitmap function from gdi+. This is the syntax of the function in C++. ```c++ void Bitmap( [in] const WCHAR *filename, [in] BOOLuseEmbeddedColorManagement ); ``` And this is the mangled name which I got from goldbolt compiler. `?Bitmap@@YAXPEB_WH@Z ` Now, this is my declaration in D. ```d extern (C++, "Bitmap") void * Bitmap(const(wchar)* file, BOOL useClr); ``` And this is my call site. ```d auto imgPath = toUTF16z(r"C:\Users\AcerLap\Pictures\Saved Pictures\d3.png") ; auto pBmp = Bitmap(imgPath, FALSE); ``` But I got this error message. ``` app.obj : error LNK2019: unresolved external symbol "void * __cdecl Bitmap::Bitmap(char16_t const *,int)" (?Bitmap@0@YAPAXPB_SH@Z) referenced in function __D4wing9imagelist9ImageList8addImageMFAyaZv app.exe : fatal error LNK1120: 1 unresolved externals Error: linker exited with status 1120 ``` You see, the mangled names are different. From D - `?Bitmap@0@YAPAXPB_SH@Z` From C++ - `?Bitmap@@YAXPEB_WH@Z` How to fix this ?
Re: How to convert a LPCWSTR aka const(wchar)* to string
On Tuesday, 10 May 2022 at 01:07:37 UTC, Mike Parker wrote: ```d import std.conv : to; string s = to!string(pszUserString); ``` Thanks, it worked. At first, I tried `to!string` but it failed because of this usage-- ```d this(LPCWSTR dtpStr) { this.dateString = to!string(LPCWSTR)(dtpStr) ; } ```
How to convert a LPCWSTR aka const(wchar)* to string
Hi all. I want to convert an LPCWSTR to string. I have a struct like this ```cpp typedef struct tagNMDATETIMESTRINGW { NMHDR nmhdr; LPCWSTRpszUserString; SYSTEMTIME st; DWORD dwFlags; } NMDATETIMESTRINGW, *LPNMDATETIMESTRINGW; ``` I want to convert this `pszUserString` to a string. How to do it. Thanks in advance.
Re: How to remove an element from a dynamic array with given index ?
On Monday, 2 May 2022 at 20:50:17 UTC, H. S. Teoh wrote: should be in the same order. How to do it ? int[] data = [ 10, 20, 30, 40, 50 ]; data = data.remove(2); assert(data == [ 10, 20, 40, 50 ]); T Thanks a lot.
How to remove an element from a dynamic array with given index ?
Hi all, I have dynamic array and I want to remove an element from it. All I have the index of the element to remove. And I want to the array should be in the same order. How to do it ?
Re: How to implement private constructor
On Monday, 25 April 2022 at 07:19:31 UTC, bauss wrote: Yes and in addition to Ali's message then remember it's private for the module only. Oops typo. What I meant is that private is module level, so it's __not__ private in the module, but it is for other modules. Thanks for the reply. Got it. All I wanted to implement more than ctor with different parameters and avoid code duplication.
Re: How to implement private constructor
On Monday, 25 April 2022 at 02:22:42 UTC, Ali Çehreli wrote: Looks good to me. There are other ways as well: Thanks a lot. All I wanted to implement more than ctor with different parameters and avoid code duplication.
How to implement private constructor
Hi all, Please take a look at this code. Is this the right way to use private constructors ? ```d class Foo { int p1 ; string p2 ; bool p3 ; private this(int a, string b, bool c) { this.p1 = a this.p2 = b this.p3 = c } this(int a) { this(a, "some string", true); } this(int a, string b) { this(a, b, true); } } ```
Re: I want to append to lists without using append
On Monday, 4 April 2022 at 13:32:19 UTC, Steven Schveighoffer wrote: This looks more like lisp or scheme. You know this is a forum for the D programming language? This was the same question in my mind.
Re: Help needed to learn typeof(return)
On Sunday, 27 March 2022 at 01:11:02 UTC, Steven Schveighoffer wrote: Not sure what the question here is, Thanks for the reply. Actually, my problem was this, I forgot the presence of `LargerOf!(A, B)` template function in that chapter. When I see it in a function, I thought where is the implementation of this function ? But later I found it. And yes, you can get into paradoxical problems like: ```d auto foo() { typeof(return) x; return x; } ``` which will not compile. Yeah, I got the point. In fact, after reading the `Template` chapter in that book, I am amazed. There are lot of possibilities in D templates.
Re: Help needed to learn typeof(return)
On Saturday, 26 March 2022 at 18:25:54 UTC, Vinod K Chandran wrote: Hi all, The author says `LargerOf!(A, B)` is used instead of `auto` keyword. How did compiler understands the return type from `LargerOf!(A, B)`. Oh Sorry !. I forgot the `LargerOf!(A, B)` definition which is in the same chapter. My fault. Sorry.
Help needed to learn typeof(return)
Hi all, I am reading `Programming in D` online book. There is a paragraph in the chapter `More Templates`. ``` typeof(return) generates the return type of a function, inside that function. For example, instead of defining the calculate() function above as an auto function, we can be more explicit by replacing auto with LargerOf!(A, B) in its definition. (Being more explicit would have the added benefit of obviating at least some part of its function comment.) ``` And it shows this code. ```d LargerOf!(A, B) calculate(A, B)(A a, B b) { typeof(return) result;// The type is either A or B // ... return result; } ``` The author says `LargerOf!(A, B)` is used instead of `auto` keyword. How did compiler understands the return type from `LargerOf!(A, B)`.
Re: Help needed to learn templates
On Saturday, 19 March 2022 at 22:31:19 UTC, Stanislav Blinov wrote: It is appearing not in the `static if`, but in the `is` expression, which I described further in the rest of my first reply. Sorry if that wasn't clear. No, it was my mistake, I missed it. The other template syntax - `template foo(alias T)` can take as `T` any symbol, not just a type. I understand this. It comes from you, the programmer. Like I said before, `is(T == U[], U)` means "is T an array of some type, the type which I (the programmer) would like to refer to as U?". That's all there is to it (well, not quite, but it should suffice for starters). You're simply introducing an identifier. So, when `T` is an `int[][][]`, naturally, `U` becomes an alias to `int[][]` (look at the converse - when `U` is `int[][]`, `U[]` is naturally an `int[][][]`). Okay, got it. You can think of that test as this: ```d import std.traits : isDynamicArray; // ... static if (isDynamicArray!T) { alias U = typeof(T.init[0]); // ... } ``` Yes, in this case everything is simple and clear. ...which would roughly be the same thing - you test if `T` is a dynamic array of some type, and then make an alias for that array's element type. It's just that the `is` expression allows you to create such alias in situ. Okay. Got the point. Thanks. Now, I understand that why Ali suggest me to learn **`is()`** expression.
Re: Help needed to learn templates
On Saturday, 19 March 2022 at 16:08:33 UTC, Ali Çehreli wrote: Here is the clickable url: http://ddili.org/ders/d.en/is_expr.html I just read it again and I still like what I wrote there. :) (Usually it is the other way around.) Ali Thanks. Let me read that chapter.
Re: Help needed to learn templates
On Saturday, 19 March 2022 at 15:58:25 UTC, Ali Çehreli wrote: I wrote a chapter about the is expression but it's still mysterious to me. :) ddili.org/ders/d.en/is_expr.html Thanks for the reply. I think I choose the wrong book. I knew about your book but I thought this one is specially written for templates. I will read the template chapters in **`Programming in D`**. It means "if T matches U[] and U is a type". "a type" because it is just U in the is expression list. So as per the eponymous trick, **`enum size_t rank`** will be executed directly. Right ? But in that case, **`rank`** template doesn't take a parameter. There is only the type parameter which is **`T`**. So I am still in confusion about **`U`**. I believe at least some of the traits have been added since that doc document was written. I would write it in a much simpler way using template constraints today: ```d template rank(T) { import std.traits : isArray; import std.range : ElementType; static if (isArray!T) { enum size_t rank = 1 + rank!(ElementType!T); } else { enum size_t rank = 0; } } ``` This template is very easy to understand and I have no confusions about it. Because, it only takes **`T`** as type parameter and there is no magical **`U`**. However, note how the template constraints had to be repeated as isArray!T and !isArray!T in that case. Yeah, I noted. Not at all! The is expression is the weirdest part of D. Oh I see.
Re: Help needed to learn templates
On Saturday, 19 March 2022 at 08:49:02 UTC, Salih Dincer wrote: Thanks for the reply. You explained the idea very well and it's easy to understand for a novice.
Re: Help needed to learn templates
On Saturday, 19 March 2022 at 11:47:53 UTC, Stanislav Blinov wrote: No. First of all Thanks for the reply. The answer "No" is a wonder to me. Because, from my point of view, `U` is coming from nowhere. My understanding is, we can use any parameter of a template inside the template. So in this case `U` is not in the parameter list. It is suddenly appearing in that `static if`. The test is not `T t == U[]`. It is `is(T t == U[], U)`. Okay, I understand. Actually, the lower case `t` is not needed there, you can simply write `is(T == U[], U)`. So the `T` is not the type. It's the parameter. Right ? So a template doesn't need a type. Only the parameter, right ? (I think I am too dumb to ask this. Please forgive me.) Yes, and `U` then becomes `int[][]`. Which is why the template recurses down and instantiates itself with `U`, until `T` fails the test. In order to understand this, I need to understand from where the `U` comes.
Help needed to learn templates
Hi all, I am trying to learn D templates with Philippe Sigaud's "D Templates: A Tutorial". So far so good. I have completed first 19 pages and in the 20th page, I found an obstacle. This is the code. ```d module rank1; template rank(T) { static if (is(T t == U[], U)) // is T an array of U, for some type U? enum size_t rank = 1 + rank!(U); // then let’s recurse down. else enum size_t rank = 0; // Base case, ending the recursion. } module using_rank1; import rank1; static assert(rank!(int) == 0); static assert(rank!(int[]) == 1); static assert(rank!(int[][]) == 2); static assert(rank!(int[][][]) == 3); ``` Question 1 - `U` is appearing in the first static if statement. But we had to write `U` on the template line, right? Like - `template rank(T, U)` Question 2 - The statif if test is - `T t == U[ ]` What does that mean ? Question 3 - if `T t == U[ ]` is the test, then I think when we pass ```d rank!(int[ ][ ][ ]) ``` The test will be `int[ ][ ][ ] == U[ ]`, Right ?
Re: Documentation generator is not working
On Monday, 6 September 2021 at 01:19:04 UTC, Ali Çehreli wrote: Yes, but it was meant to be a joke. Don't do that. :) Ha ha, okay :)
Re: Documentation generator is not working
On Friday, 3 September 2021 at 20:21:43 UTC, Ali Çehreli wrote: So, change your program to respond to -D and generate the documentation potentially by spawning a dmd instance. :o) I am not sure i get the point correctly. You mean, starting dmd as a new process from my program and pass the file name as parameter ?
Re: Documentation generator is not working
On Thursday, 2 September 2021 at 17:34:59 UTC, Adam D Ruppe wrote: Anything after -run goes to your program not the compiler. Args to the compiler must be before -run. Thanks for the reply. Got the point now. :)
Re: Documentation generator is not working
On Thursday, 2 September 2021 at 16:26:19 UTC, jfondren wrote: What commands are you running? What you describe doing, works: ``` $ dmd -D file $ w3m -dump file.html|grep -A1 function A sample function. Let's check what we will get in documentation. abc - A simple string $ rm -fv file.html removed 'file.html' $ dmd -D file $ w3m -dump file.html|grep -A1 function A sample function. Let's check what we will get in documentation. abc - A simple string $ ``` Thanks for the reply. My command was the problem. I repeatedly used "dmd -run test.d -D" But now, I can see the html file when I use this -- "dmd -D test.d".
Documentation generator is not working
Hi all, I am playing with ddoc. I wrote this code-- ```d import std.stdio : log = writeln; void main() { log("Experimenting with dDoc"); } /// A sample function. /// Let's check what we will get in documentation. /// abc - A simple string void sample(string abc) {log(abc);} ``` And then, compile it with "-D" switch. At first, I saw an html file is generated. But I deleted it and compiled again. This time, no html file is generated. What's wrong with this ?
Re: wanting to try a GUI toolkit: needing some advice on which one to choose
On Saturday, 29 May 2021 at 01:04:02 UTC, Marcone wrote: Win32Api + Metaprogramming? Yes.
Re: wanting to try a GUI toolkit: needing some advice on which one to choose
On Thursday, 27 May 2021 at 01:17:44 UTC, someone wrote: I am learning D by writing a Windows only GUI library. It is taking too much time for me since, I am writing some stuff and then happen to learn some new things about it and re-writing it.Anyhow, so far so good. This is the code now. ```d import winglib ; import std.stdio : log = writeln; void main() { auto frm = new Window() ; frm.text = "Learning D By Writing D"; // C = Control class. Window is derived from Control // E = EventArgs. frm.onMouseHover = (c, e) => log("Mouse is now on ", e.x, ", ", e.y); frm.onMouseLeave = (c, e) => log("Mouse leaved from window") ; frm.onKeyDown = (c, e) => log(e.keyCode, " key is pressed"); frm.create() ; auto btn = new Button(frm) ; btn.font.name = "Calibri" ; btn.width = 150 ; btn.text = "DMD Or LDC" ; btn.font.size = 14 ; btn.create() ; frm.show() ; } ``` I am slowly adding more features to this. Till now, Window & Button are completed.
Re: How to use dub with our own package
On Wednesday, 12 May 2021 at 20:55:07 UTC, Christian Köstlin wrote: if you want to do a separate package later on, you only have to change a little in your project setup, code can stay the same. kind regards, Christian That's nice. :)
Re: How to use dub with our own package
On Wednesday, 12 May 2021 at 15:03:14 UTC, Imperatorn wrote: Check out add-local Thanks. Let me check. :)
Re: How to use dub with our own package
On Wednesday, 12 May 2021 at 17:23:16 UTC, JG wrote: Have a look at [link](https://forum.dlang.org/post/jyxdcotuqhcdfqwwh...@forum.dlang.org). Thanks for the link. :)
Re: How to use dub with our own package
On Wednesday, 12 May 2021 at 18:26:39 UTC, Christian Köstlin wrote: Are you really interested in doing winglib as a separate dub package? If not you could just do a `dub init yourappname` which gives you the basic skeleton. something like: . ├── dub.sdl └── source └── app.d then you replace app.d with your file + put your winglib with package.d into a subfolder under source -> . ├── dub.sdl └── source ├── app.d └── winglib ├── othermodule.d └── package.d then a dub build will just build your project including the submodules ... if you need a separate dub package then the other answers lead the way. https://dub.pm/commandline.html#add-local That's really helpful. All i need to do is re-arrange my folder setup. Thanks a lot. :)
How to use dub with our own package
Hi all, I am creating a hobby project related with win api gui functions. i would like to work with dub. But How do I use dub in my project. 1. All my gui library modules are located in a folder named "winglib". 2. And that folder also conatains a d file called "package.d" 3. "package.d" contains all the public imports. 4. Outside this winglib folder, I have my main file called "app.d" 5. "app.d" imports "winglib". So in this setup, how do I use dub ? Thanks in advance.
Re: Question about property & method access scope.
On Tuesday, 11 May 2021 at 10:48:03 UTC, Mike Parker wrote: On Tuesday, 11 May 2021 at 09:10:02 UTC, Vinod K Chandran wrote: So in many situations, I need to check some boolean properties of Window class and call some functions of Window class in WndProc. But I don't want to expose those props and functions to the user. So if I make them private, I can't access them inside the WndProc function. How do solve this issue. Thanks in advance. Assuming window.d and wndproc.d are in the same package (and not the default global package), then you can use `package` instead of `private`. On Tuesday, 11 May 2021 at 10:48:03 UTC, Mike Parker wrote: > > Assuming window.d and wndproc.d are in the same package (and > not the default global package), then you can use `package` > instead of `private`. Thanks. "package" scope worked. this is the code now. ```d package : bool misBkClrChanged ; void setBkClrInternal(HDC dcHandle) { RECT rct; HBRUSH hBr = CreateSolidBrush(cast(COLORREF) this.mBackColor); GetClientRect(this.mHandle, ) ; FillRect(dcHandle, , hBr) ; DeleteObject(hBr) ; } // And this is the wndproc case WM_ERASEBKGND : { if(win.misBkClrChanged) { auto dch = cast(HDC) wParam ; win.setBkClrInternal(dch) ; return 1 ; } } break ; } ```
Re: Question about property & method access scope.
On Tuesday, 11 May 2021 at 10:47:15 UTC, cc wrote: The `package` protection attribute should work here if the modules reside in the same package (directory)? Thanks. "package" scope worked.
Question about property & method access scope.
Hi all, I am practising D with a win api GUI hobby project. I have a Window class and it resides in module window.d My WndProc function resides in another module named wnd_proc_module.d Inside my WndProc, I get the Window class like this. ```d Window win = cast(Window) (cast(void*) GetWindowLongPtrW(hWnd, GWLP_USERDATA)) ; ``` So in many situations, I need to check some boolean properties of Window class and call some functions of Window class in WndProc. But I don't want to expose those props and functions to the user. So if I make them private, I can't access them inside the WndProc function. How do solve this issue. Thanks in advance.
Re: Is there any bettter solution to Windows wide string
On Sunday, 9 May 2021 at 09:34:00 UTC, FreeSlave wrote: You may try using tempCStringW from std.internal.cstring. It uses small string optimization. However the api is internal, so I'm not sure how valid it is to use this function. The returned struct is a temporary buffer so you must ensure that you don't escape dangling pointers. Thanks for the reply. Let me check. :)
Re: Is there any bettter solution to Windows wide string
On Saturday, 8 May 2021 at 21:26:06 UTC, Imperatorn wrote: iirc that's toUTF16z Thanks. Let me check. :)
Is there any bettter solution to Windows wide string
Hi all, I am planning some win32 hobby projects. Now I have this function to tackle the LPCWSTR data type in win32. ```d private import std.utf; auto toWString(S)(S s) { return toUTFz!(const(wchar)*)(s); } ``` Is there any better way to do this ?
Re: dlang vs crystal-language
On Wednesday, 5 May 2021 at 18:50:05 UTC, Alain De Vos wrote: What's wrong with WSL. I think it is a great idea. What Imperatorn said is the write thing. Sorry for not being clear.
Re: dlang vs crystal-language
On Friday, 30 April 2021 at 19:25:16 UTC, Siemargl wrote: I did this @2014. No problems remembered. May be it's my fault. Let me check once again.
Re: dlang vs crystal-language
On Friday, 30 April 2021 at 17:01:52 UTC, TheGag96 wrote: I used tkD a long time ago. Look through [this repo](https://github.com/thegag96/codewrite) - maybe something in there will help you. Thanks for the link. Let me check.
Re: dlang vs crystal-language
On Friday, 30 April 2021 at 14:49:33 UTC, Alain De Vos wrote: tkd works perfectly. Which O.S. are you using ? I can guide. I am using Windows 10 x64.
Re: dlang vs crystal-language
On Wednesday, 28 April 2021 at 22:41:03 UTC, Alain De Vos wrote: What are the strengths and weaknesses comparing the two languages ? I can name a strength of dlang is the working binding to tk and gtk. Pros of **Crystal** 1. Attractive syntax. I like Ruby like syntax. It's really expressive. Cons of Crystal 1. It doesn't have a compiler for Windows. It uses WSL based compiler and I think it's a bad idea. I don't think I need to tell the pros & cons of **D lang** in it's own forum. BTW, I wonder to see someone says that they have succeeded in compiling a **tkD** example code. I tried it with no luck. So I gave up that idea.
Re: Windows Console and writing Unicode characters
On Tuesday, 30 March 2021 at 08:31:02 UTC, Luhrel wrote: I have been used this trick in C++, so it might also work in D: ``` import core.stdc.stdlib; import std.stdio; void main() { version(Windows) system("chcp 65001 > NUL".ptr); writeln("çéäö"); } ``` Works like a charm in Cmder. But it displayed some squares in CMD.
Re: How to delete dynamic array ?
On Thursday, 18 March 2021 at 21:21:37 UTC, Paul Backus wrote: The source code is here: https://github.com/p0nce/d-idioms/ Thanks for the answer. But it's more complex than I thought. Something like Latex was in my mind.
Re: How to delete dynamic array ?
On Wednesday, 17 March 2021 at 14:30:26 UTC, Guillaume Piolat wrote: I made this article to clear up that point: https://p0nce.github.io/d-idioms/#Slices-.capacity,-the-mysterious-property Sorry for this off-topic question. I am amazed with eye catchy look of that d-idioms page. I want to create a page like it for my ongoing project. I think it's a good form of documentation. How do i create one like it ?
Re: How to change button text color in NM_CUSTOMDRAW (Win32 API question)
On Wednesday, 17 March 2021 at 06:39:26 UTC, Imperatorn wrote: Good that you solved it, that wasn't what I thought the solution would be I was sure about i can solve this through NM_CUSTOMDRAW. Because, in VB .net, we can change back color & fore color of button. On the same time, there is an option to turn on the OwnerDrawStyle. If we set this property true, we need to draw the button on our own. So i am pretty sure that, that property will turn a normal button to an owner drawn button. But if we don't use that property, then also we can change the button colors. So that means, without using BS_OWNERDRAW style, we can change the colors. And that's the NM_CUSTOMDRAW message. Unfortunately, there is not much tutorials or documentation about handling this message in a Button's case. We can find some examples and articles related to ListView & Treeview. But not a single line of documentation about buttons. Was more than 10 years ago since I was "the king of win api" Glad to know that. Can you write an article about how to use Gdi+ in win api apps ? Now I am using gdi. But i want to test how gdi+ works on win32 apps.
Re: How to change button text color in NM_CUSTOMDRAW (Win32 API question)
On Tuesday, 16 March 2021 at 19:42:26 UTC, Imperatorn wrote: At last, i found the answer myself. There is a item called dwDrawStage in NMCUSTOMDRAW structure. If value of dwDrawStage is equal to CDDS_PREERASE, call SetBkMode with transparent and call SetTextColor. Then draw text with DrawText function. And finally, return CDRF_NOTIFYPOSTPAINT. In short, do the color changing process in pre-erase stage and return CDRF_NOTIFYPOSTPAINT constant. As per MSDN, What this constant means is, The control will notify the parent after painting an item. This occurs when the dwDrawStage of the NMCUSTOMDRAW structure equals CDDS_PREPAINT.
Re: How to change button text color in NM_CUSTOMDRAW (Win32 API question)
On Tuesday, 16 March 2021 at 18:35:00 UTC, Imperatorn wrote: I see Do you get CLR_INVALID in return? From that results, second one contains my color value. Set Text color result - 0233FF66 RGB(102, 255, 51) is the color. 66 = 102 FF = 255 33 = 51
Re: How to change button text color in NM_CUSTOMDRAW (Win32 API question)
On Tuesday, 16 March 2021 at 18:35:00 UTC, Imperatorn wrote: I see Do you get CLR_INVALID in return? That results might be wrong. So i printed them in hex. These are the hex results. Set Text color result - Set Text color result - 0233FF66 Set Text color result - Set Text color result - Set Text color result - 0233FF66 Set Text color result - Set Text color result - 0233FF66 Look, the third one is CLR_INVALID.
Re: How to change button text color in NM_CUSTOMDRAW (Win32 API question)
On Tuesday, 16 March 2021 at 18:35:00 UTC, Imperatorn wrote: I see Do you get CLR_INVALID in return? As far as i know this is the value of CLR_INVALID - 4294967295. And these are the results i got from my function. Set Text color result - 0 Set Text color result - 36962150 Set Text color result - -1 Set Text color result - 0 Set Text color result - 36962150 Set Text color result - 0 Set Text color result - 36962150 The first two results got when the form shown. Rest are the results of a mouse hover.
Re: How to change button text color in NM_CUSTOMDRAW (Win32 API question)
On Tuesday, 16 March 2021 at 17:45:09 UTC, Imperatorn wrote: Omg the pain. Are you forced to use raw win api for this? Not at all. It's my hobby project. I choose raw win api. It's a fun.
How to change button text color in NM_CUSTOMDRAW (Win32 API question)
Hi all, I am creating a Button class with Win32 API functions. So far so good. I am using NM_CUSTOMDRAW message to change the back color of my buttons. It's really easy to change the back color in this way. But I can't change the text color of my button. This is my pseudo code. ``` uint setBtnBackColor( LPNMCUSTOMDRAW lp) { SetTextColor(lp.hdc, RGB(102, 255, 51) )// Not working if lp.uItemState & CDIS_SELECTED { //--- btn clicked // Change back color using SelectObject & FillRect // Its Working. No probs. } elseif lp.uItemState & CDIS_HOT { //Mouse over // Change back color using SelectObject & FillRect // Its Working. No probs. } else { // -Default state of button // Change back color using SelectObject & FillRect // Its Working. No probs. } return CDRF_SKIPDEFAULT } ``` What is wrong in my approach ?
Re: How can I make this work?
On Sunday, 28 February 2021 at 13:15:47 UTC, Adam D. Ruppe wrote: And it is the simplest thing, no missing length, no weird property casting. The GC handled with two simple add/remove calls. Perfect example of teaching something. Thank you for this knowledge. Even though, this was not my problem, Its really helpful for me to my future project. :)
Re: How to use dguihub package ?
On Tuesday, 19 January 2021 at 16:52:18 UTC, Paul Backus wrote: On Tuesday, 19 January 2021 at 16:22:35 UTC, Vinod K Chandran wrote: b ? (tbinfo.fsState |= TBSTATE_ENABLED) : (tbinfo.fsState &= ~TBSTATE_ENABLED); This means, "if b is true, set the TBSTATE_ENABLED flag to true; otherwise, set it to false." Hi Paul Backus, Thanks for the detailed reply. After reading your reply, I got the idea. But think there is one silly mistake in your reply. Forgive me if I am wrong. Instead of "if b is true, set the TBSTATE_ENABLED flag to true; otherwise, set it to false." This is the meaning of that code. if (b == true) {tbinfo.fsState = true ; } else {tbinfo.fsState = false;} Because, TBSTATE_ENABLED is a manifest constant and I cannot modify it. What about simply writing this -- "tbinfo.fsState = b ; " This also worked.
Re: How to use dguihub package ?
On Sunday, 17 January 2021 at 14:00:48 UTC, Mike Parker wrote: On Sunday, 17 January 2021 at 13:04:33 UTC, Vinod K Chandran Three of those messages include the solution to fix the errors. The fourth one is a missing import (`import std.conv : to`) in dguihub.core.utils. You could fix these yourself and submit a pull request to the project, or submit an issue. Hi Mike Parker, I just comment out the first area and write an import statement as you said. But I omited the ": to" part. And Suddenly it worked. But I think I should need to work on the commented code because it's the "Enabled" property of toolbar class. But for me, this code looks Chinese. Anyhow, I am planning to study this from beginning. "b ? (tbinfo.fsState |= TBSTATE_ENABLED) : (tbinfo.fsState &= ~TBSTATE_ENABLED);" This is the problem line in that property. "b" is a boolean parameter. But I dont know what this "|="sign means in D.
How to use dguihub package ?
Hi all, I would like to use a gui package called "dguihub". So i did these steps. 1. Downloaded source files from Github. 2. Extract it and copy dguihub folder to my project folder. this folder contains all the source files of this package. 3. Write an import statement in my app.d "import dguihub;" 4. Copy paste the code from "hello" in example folder 5. Compiled with "rdmd app.d" And i got this result. dguihub\toolbar.d(103): Deprecation: integral promotion not done for ~TBSTATE_ENABLED, use '-preview=intpromote' switch or ~cast(int)(TBSTATE_ENABLED) dguihub\core\menu\abstractmenu.d(187): Deprecation: variable mi is shadowing variable dguihub.core.menu.abstractmenu.RootMenu.create.mi. Rename the foreach variable. dguihub\core\menu\abstractmenu.d(209): Deprecation: integral promotion not done for ~enabled, use '-preview=intpromote' switch or ~cast(int)(enabled) dguihub\core\utils.d(130): Error: template instance to!wstring template to is not defined Do i miss something ?
Re: How to work Get & Set text in clipboard in Windows ?
On Monday, 22 June 2020 at 10:26:12 UTC, aberba wrote: It would be a one-liner if it was an api. Such utility APIs are quite missing in D. Um, You are right. How about putting them together into a package? Well, this is an inspiration to me. Let me try. :)
Re: How to work Get & Set text in clipboard in Windows ?
On Saturday, 20 June 2020 at 13:46:05 UTC, Dennis wrote: Thanks a lot. Well, i thought it should be a one liner like- Clipboard.SetText(sText) But after reading your reply, i realized that this is D, not a scripting language. :)
How to work Get & Set text in clipboard in Windows ?
Hi all, I would like to know how to get & set text in clipboard. I am using windows machine. Thanks in advance. --Vinod Chandran
Re: What is the current stage of @property ?
On Wednesday, 10 June 2020 at 22:15:25 UTC, 12345swordy wrote: It can't do binary operations and unary operations. @12345swordy, You mean we can't do such ops inside the property ?
Re: What is the current stage of @property ?
On Wednesday, 10 June 2020 at 21:40:44 UTC, Paul Backus wrote: The current state of @property is that it doesn't really do anything. D allows you to call functions without parentheses, and to use assignment syntax to call a single-argument function, so you can write getters and setters that work like properties even if you don't use the @property annotation: struct Example { private int x_; int x() { return x; } // getter void x(int n) { x = n; } // setter } void main() { Example e; e.x = 123; // calls setter int y = e.x; // calls getter } @Paul Backus, Thanks for the explanation & code sample.
Re: What is the current stage of @property ?
On Wednesday, 10 June 2020 at 21:41:54 UTC, H. S. Teoh wrote: It's stuck in limbo, like many things that people just cannot agree on. There are a few places where it's needed (like satisfying the range API, which implicitly checks for it), but for the most part, you can just ignore it, it doesn't really make a big difference. Life goes on. T @H. S. Teoh, Yeah, got it.
What is the current stage of @property ?
Hi all, I read in an old thread that authors of D wants to eliminate @property. I just roughly read the big thread bu couldn't find a conclusion. After all that thread is a 48 page longer jumbo thread. So out of curiosity, i am asking this. What is the current state of @property ? Is it deprecated ?
Re: How to parse enum from a string ?
On Wednesday, 27 May 2020 at 17:36:35 UTC, Dennis wrote: On Wednesday, 27 May 2020 at 17:33:33 UTC, Vinod K Chandran wrote: I am saving this enum values as string in database. So, when i retrieve them from the database, how can i parse the string into TestEnum ? Use `to` from `std.conv`. ``` import std.conv: to; void main() { assert("Received".to!TestEnum == TestEnum.Received); } ``` Hi, Thanks a lot. It worked. :)
How to parse enum from a string ?
Hi all, Assume that i have an enum like this. enum TestEnum { Received = 1, Started , Finished , Sent } I am saving this enum values as string in database. So, when i retrieve them from the database, how can i parse the string into TestEnum ? In vb. net, i can use [Enum].Parse(GetType( TestEnum), "Started") How to do this in D ?
Re: How to get the pointer of "this" ?
On Tuesday, 26 May 2020 at 14:42:04 UTC, Steven Schveighoffer wrote: On Tuesday, 26 May 2020 at 14:42:04 UTC, Steven Schveighoffer wrote: Hm... According to run.dlang.io, this behavior changed in 2.072 (prior to that it worked). In 2.067.1 to 2.071.2, changing the this reference was actually allowed, but deprecated. Technically, you don't need to do this. Passing an address to a class reference isn't going to benefit anything, as a class reference already is a pointer. This is, of course, unless you want to CHANGE the class reference. Which is disallowed for `this`. Technically speaking, `this` is simply a local parameter. It technically could be changed, but it is not allowed because of the bad code that would likely result. -Steve Hi, Thanks for the reply. I've got the point.
Re: How to get the pointer of "this" ?
On Tuesday, 26 May 2020 at 13:48:52 UTC, ag0aep6g wrote: On 26.05.20 15:43, Vinod K Chandran wrote: So far now, two solutions are very clear for this problem. 1. As per John Chapman's suggestion - use cast(DWORD_PTR)cast(void*)this). 2. Use another varibale to use as an lvalue. - Button dummyBtn = this; cast(DWORD_PTR) Among these two, i think 2nd option is good. Am i right ? No. Use option 1. Could you please tell me why ?
Re: How to get the pointer of "this" ?
On Tuesday, 26 May 2020 at 13:44:24 UTC, Adam D. Ruppe wrote: On Tuesday, 26 May 2020 at 11:35:23 UTC, Vinod K Chandran wrote: Okay, but uint is working perfectly. It won't if you use -m64. Okay. I got it.
Re: How to get the pointer of "this" ?
On Tuesday, 26 May 2020 at 13:37:22 UTC, Vinod K Chandran wrote: On Tuesday, 26 May 2020 at 12:41:20 UTC, John Chapman wrote: On Monday, 25 May 2020 at 16:26:31 UTC, Vinod K Chandran wrote: Here is my full code. Please take a look. https://pastebin.com/av3nrvtT Change line 124 to: SetWindowSubclass(this.mHandle, SUBCLASSPROC(), UINT_PTR(subClsID), cast(DWORD_PTR)cast(void*)this); That is, change `` to `cast(void*)this`. Hi, Thanks for the reply. That will work like charm but we need to change the code in subclassed button's WndProc like this-- extern(Windows) private LRESULT btnWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR scID, DWORD_PTR refData) { try { Button thisBtn = cast(Button)cast(void*)refData; { catch (Exception e) {} So far now, two solutions are very clear for this problem. 1. As per John Chapman's suggestion - use cast(DWORD_PTR)cast(void*)this). 2. Use another varibale to use as an lvalue. - Button dummyBtn = this; cast(DWORD_PTR) Among these two, i think 2nd option is good. Am i right ?
Re: How to get the pointer of "this" ?
On Tuesday, 26 May 2020 at 12:08:29 UTC, Johannes Loher wrote: On Tuesday, 26 May 2020 at 11:44:58 UTC, Vinod K Chandran wrote: [...] [...] It doesn't compile, the line string mt [...] Hi, Sorry for the typos in my code.
Re: How to get the pointer of "this" ?
On Tuesday, 26 May 2020 at 12:41:20 UTC, John Chapman wrote: On Monday, 25 May 2020 at 16:26:31 UTC, Vinod K Chandran wrote: Here is my full code. Please take a look. https://pastebin.com/av3nrvtT Change line 124 to: SetWindowSubclass(this.mHandle, SUBCLASSPROC(), UINT_PTR(subClsID), cast(DWORD_PTR)cast(void*)this); That is, change `` to `cast(void*)this`. Hi, Thanks for the reply. That will work like charm but we need to change the code in subclassed button's WndProc like this-- extern(Windows) private LRESULT btnWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR scID, DWORD_PTR refData) { try { Button thisBtn = cast(Button)cast(void*)refData; { catch (Exception e) {}
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 16:39:30 UTC, Mike Parker wrote: On Monday, 25 May 2020 at 08:39:23 UTC, John Burton wrote: I believe that in D *this* is a reference to the object and not a pointer like in C++. So I think that writing might be what you need? No. A class reference is a pointer under the hood. Getting its address will result in a pointer to the reference variable itself, not to the class instance. When passing a reference to a C API, casting it directly to the C type is correct. Try this code. This will reproduce the same error. import std.stdio : log = writeln; void main() { log("Let's check whether 'this' is an lvalue or not."); Button btn = new Button("A button"); } class Button { this(string btntext){ mtext = btntext; log("button created with the name , ", btntext); log(); } private: string mt }
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 18:42:33 UTC, bauss wrote: On Monday, 25 May 2020 at 17:14:13 UTC, Vinod K Chandran wrote: On Monday, 25 May 2020 at 16:54:11 UTC, Mike Parker wrote: [...] Hi @Mike Parker, Thank you for your valuable suggestions. I will sure follow them. Well, the exact line number where the error showing is the one with the "SetWindowSubclass" function. In pastebin, the line number is 124. Need to see the Control class too. I think the problem might be something you're referencing from there but need to be sure. Here is some code to reproduce the error in your system. https://pastebin.com/rgN3ug1e 'this' is not an lvalue.
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 22:54:32 UTC, Adam D. Ruppe wrote: On Monday, 25 May 2020 at 22:31:00 UTC, Vinod K Chandran wrote: A dword is an unsigned, 32-bit unit of data. We can use uint in D. I have tried that too, but no luck. A DWORD_PTR is *not* the same as a uint. It is more like a size_t or void* depending on context. Okay, but uint is working perfectly.
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 22:04:28 UTC, Adam D. Ruppe wrote: On Monday, 25 May 2020 at 21:45:39 UTC, welkam wrote: Where is DWORD_PTR defined? it is a win32 thing. should be able to directly cast to it most the time if there is opCast on the class it needs another layer of helper function but without opCast it should just work Hi, What is an opCast ?
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 21:45:39 UTC, welkam wrote: On Sunday, 24 May 2020 at 17:05:16 UTC, Vinod K Chandran wrote: cast(DWORD_PTR) this); Where is DWORD_PTR defined? I cant find it in docs. If its an alias of long then you have to cast to a pointer like this cast(long*) this; you need to specify that you want to cast to a pointer of type T. In this case T is long. Hi, Thanks for the reply. Well, DWORD_PTR is a win32 data type. It is defined in the file windows.h. A dword is an unsigned, 32-bit unit of data. We can use uint in D. I have tried that too, but no luck.
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 18:42:33 UTC, bauss wrote: On Monday, 25 May 2020 at 17:14:13 UTC, Vinod K Chandran wrote: On Monday, 25 May 2020 at 16:54:11 UTC, Mike Parker wrote: [...] Hi @Mike Parker, Thank you for your valuable suggestions. I will sure follow them. Well, the exact line number where the error showing is the one with the "SetWindowSubclass" function. In pastebin, the line number is 124. Need to see the Control class too. I think the problem might be something you're referencing from there but need to be sure. @bauss, Here is the code for Control class. https://pastebin.com/Hy9dCNdS
Re: How to get the pointer of "this" ?
On Monday, 25 May 2020 at 16:54:11 UTC, Mike Parker wrote: On Monday, 25 May 2020 at 16:26:31 UTC, Vinod K Chandran wrote: [...] The error has nothing to do with taking a pointer to `this`. It's suggesting that somewhere in your code you're attempting to use the `this` reference like an lvalue, e.g. making an assignment to it. I don't see anywhere that you're doing that. Glancing through the code, I don't see anywhere that you're doing that (and unfortunately this is not a minimal example because of dependencies on some of your other modules, so I can't compile it myself). [...] Hi @Mike Parker, Thank you for your valuable suggestions. I will sure follow them. Well, the exact line number where the error showing is the one with the "SetWindowSubclass" function. In pastebin, the line number is 124.
Re: How to get the pointer of "this" ?
On Sunday, 24 May 2020 at 17:40:10 UTC, bauss wrote: On Sunday, 24 May 2020 at 17:05:16 UTC, Vinod K Chandran wrote: [...] I think your issue might be elsewhere because casting this should be fine and it should not complain about that in your given code. At least you should be able to pass this to another function or even cast it. Please show the full code and the full error which gives you the stacktrace of where it's called and from where. Here is my full code. Please take a look. https://pastebin.com/av3nrvtT
How to get the pointer of "this" ?
Hi all, I have a class like this. class Button : Control { ... HWND createButton(){ ... SetWindowSubclass(this.mHandle, SUBCLASSPROC(), UINT_PTR(subClsID), cast(DWORD_PTR) this); } } But compiler says that - "Error: 'this' is not an lvalue and cannot be modified" I've seen many cpp code which uses pointer to 'this' as the last parameter in SetWindowSubclass(). Is there something wrong with my approach ?
Re: How to use base class & child class as parameter in one function ?
On Friday, 22 May 2020 at 22:44:17 UTC, H. S. Teoh wrote: On Fri, May 22, 2020 at 09:39:16PM +, Vinod K Chandran via Digitalmars-d-learn wrote: [...] So in the same manner, i want void function(Base) = fnPtr wiil work with void function(Child) You cannot, because that's type unsafe: class Base {} class Derived : Base { void derivedFunc() {} } class Another : Base {} void derivedFunc(Derived d) { d.derivedFunc(); } void function(Base) funPtr; funPtr = derivedFunc; // suppose this was allowed Base obj = new Another; funPtr(obj); // crash: obj does not have derivedFunc() T Yeah, I understand that. And i just changed my code. Thanks for the guidance. :)
Re: How to use base class & child class as parameter in one function ?
On Friday, 22 May 2020 at 22:40:50 UTC, Steven Schveighoffer wrote: On 5/22/20 5:39 PM, Vinod K Chandran wrote: [...] That is the opposite of what you are thinking. A function pointer has to be valid based on its parameter types. Covariant functions are allowed. This is OK: void function(Child) fptr; void foo(Base) {} fptr = // OK! it's fine to call fptr with a Child, because it is a Base as well void function(Base) fptr2; void foo2(Child) {} fptr2 = // Error! if you called fptr2 with a Base that is NOT a Child, bad things will happen. This is more clear if you actually try calling them: fptr2(new Base); // the compiler should allow this foo2(new Base); // but would not allow this So why should fptr2 be allowed to point at foo2? -Steve Thank you for the guidance. I got the point. :)
Re: How to use base class & child class as parameter in one function ?
On Friday, 22 May 2020 at 20:51:20 UTC, Steven Schveighoffer wrote: On 5/22/20 4:04 PM, Vinod K Chandran wrote: [...] Yes. What you cannot do is this (which I hope doesn't compile in VB.net, but I wouldn't be surprised): Dim sampleList As New List(Of Child) sampleList.Add(New Base(10)) Which is the equivalent of what you were requesting. -Steve Nope-- List(Of Base) will contain an instance of a Child. So in the same manner, i want void function(Base) = fnPtr wiil work with void function(Child)
Re: How to use base class & child class as parameter in one function ?
On Friday, 22 May 2020 at 20:06:20 UTC, Adam D. Ruppe wrote: On Friday, 22 May 2020 at 20:04:24 UTC, Vinod K Chandran wrote: sampleList.Add(New Child(10.5)) Is this possible in D without casting ? Direct translation of this code works just fine in D. Yeah, my bad. I just checked in D. But think inherited type difference is a problem in function pointer's parameters only. alias EvtFuncPtr = void function(EventArgs); Now, this EvtFuncPtr won't allow any derived classes of EventArgs as parameter. That's the problem i am facing. What about a template ? alias EvtFuncPtr = void function(T)(T = EventArgs); This is not compiled.
Re: How to use base class & child class as parameter in one function ?
On Friday, 22 May 2020 at 16:12:12 UTC, Steven Schveighoffer wrote: On 5/22/20 9:10 AM, Vinod K Chandran wrote: On Friday, 22 May 2020 at 12:21:25 UTC, rikki cattermole wrote: if (Child child = cast(Child)parent) { assert(child !is null); } Actually, problem occurs in addHandler function. It expects an argument of type "EventArgs", not MouseEventArgs. Yes, because what if you did this with your function: fnp(new EventArgs(...)); It would be called with the type being implicitly cast to the child type without that being true. What Rikki was recommending is that you write your handler like this: void onClick(EventArgs e){ if(auto me = cast(MouseEventArgs)e) { log("form clicked on x = ", me.x, ", and y = ", me.y); } } Actually, if you are certain it's a programming error for onClick to be called with a different type of event args, I'd do: void onClick(EventArgs e){ auto me = cast(MouseEventArgs)e; assert(me !is null, "Error, onClick called with invalid event type"); log("form clicked on x = ", me.x, ", and y = ", me.y); } Thanks for the answer. I understand that, in D, derived class and base class are not the same as in vb.net or any other language. (Please correct me if i am wrong). In vb.net, assume that i have a class setup like this-- Public Class Base Public Property SampleInt As Integer End Class Public Class Child : Inherits Base Public Property SampleDouble As Double End Class //Assume that i have a list of Base class like this-- Dim sampleList As New List(Of Base) // Now, i can use this list like this-- sampleList.Add(New Child(10.5)) Is this possible in D without casting ?
Re: How to use base class & child class as parameter in one function ?
On Friday, 22 May 2020 at 12:21:25 UTC, rikki cattermole wrote: if (Child child = cast(Child)parent) { assert(child !is null); } Actually, problem occurs in addHandler function. It expects an argument of type "EventArgs", not MouseEventArgs.
How to use base class & child class as parameter in one function ?
Hi all, I have a windows gui setup like this; class EventArgs {} \\ Base class for all messages class MouseEventArgs : EventArgs { // child class for handling mouse messages ... int x; int y; this(WPARAM wpm, LPARAM lpm){ this.x = xFromLparam(lpm); this.y = yFromLparam(lpm); } } alias EvtFuncPtr = void function(EventArgs); // function pointer struct MsgHandler { uint message ; HWND handle ; bool isActive ; EvtFuncPtr fnPtr; } // Then in my window class... void addHandler(uint we, EvtFuncPtr fnp){ // This is error point. auto mh = MsgHandler(); mh.handle = this.mHandle; mh.message = we; mh.fnPtr = fnp; mh.isActive = true; this.msgHandlerList ~= mh; // This is a list in window class. } // And in the WndProc... auto thisWin = findWindowClass(hWnd); // get the window class with hWnd. auto mh = thisWin.findHandler(hWnd, message);// get the event handler for this message & hWnd if(mh.isActive) { // if there is an event handler fixed, switch (message){ case 512 : .. case 526 : // if it's a Mouse messages auto ea = new MouseEventArgs(wParam, lParam); mh.fnPtr(ea); // execute that event handler function break; default : break; } } // And this is the window creation site... auto app = new Application() ; auto frm = new Window(app) ; frm.createWindow() ; frm.addHandler(frm.load, ); frm.addHandler(frm.Click, ); void onLoad(EventArgs e){ log("form is loaded..."); } void onClick(MouseEventArgs e){ // Compiler wants to change the MouseEventArgs with EventArgs. log("form clicked on x = ", e.x, ", and y = ", e.y); } I wrote EventArgs as the parameter type in function pointer but i want to use it's child classes also. But i can't.
Re: How to use GET_X_LPARAM in D ?
On Thursday, 21 May 2020 at 20:12:13 UTC, Harry Gillanders wrote: On Thursday, 21 May 2020 at 18:42:47 UTC, Vinod K Chandran wrote: Hi all, I need to use the macro GET_X_LPARAM. But compiler says that "undefined identifier GET_X_LPARAM". I cant find any modules with GET_X_LPARAM defined. Do i miss something ? GET_X_LPARAM isn't defined in Phobos's Windows bindings, so you'll need to provide the definition yourself. GET_X_LPARAM is defined as a macro in the windowsx.h header of the Windows SDK, as: #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) Which can trivially be translated to D as a function, like so: int GET_X_LPARAM (T) (T lp) { import core.sys.windows.windef : LOWORD; return cast(int) cast(short) LOWORD(lp); } Hope this helps :) Thank you for the code and guidance. Let me check it. :)
Re: How to use GET_X_LPARAM in D ?
On Thursday, 21 May 2020 at 18:42:47 UTC, Vinod K Chandran wrote: Hi all, I need to use the macro GET_X_LPARAM. But compiler says that "undefined identifier GET_X_LPARAM". I cant find any modules with GET_X_LPARAM defined. Do i miss something ? I search all modules in " C:\D\dmd2\src\druntime\src\core\sys\windows ". But no luck.
How to use GET_X_LPARAM in D ?
Hi all, I need to use the macro GET_X_LPARAM. But compiler says that "undefined identifier GET_X_LPARAM". I cant find any modules with GET_X_LPARAM defined. Do i miss something ?