Thread overview | ||||||
---|---|---|---|---|---|---|
|
April 17, 2009 Encapsulation Win32 SDK with class in DMD2028 problem--Help wanted | ||||
---|---|---|---|---|
| ||||
Hello, After my reading below post: http://d.puremagic.com/issues/show_bug.cgi?id=2580 I can compile the win32 SDK sample in dmd\sample folder.After that I tried to encapsulate all those staff in class.Attached is my chance.Below is a short description about all the 3 classes: WinClass:Encapsulation of WNDCLASSEX WinFrame:Encapsulation of window frame WinApp:Encapsulation of the Gui application Here I have a couple of question.It would be grateful if anybody here kindly let me know,though I do know it is a bit long and it is just an excise of a beginner: 1.The program compiled but runs with an Access Violation error.I can not found the place the error occurred.I tried to comments out the try...catch block,but the program runs invisible and with 100% CPU usage,I have to aborted from the task manager. 2.Is it possible to encapsulate the callback function int WindowProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam) into any of the three classes?Which one should be the ideal place? 3.Is is possible to encapsulate all the framework into just one class,say WinFrame,and then we can call it by auto app=new WinFrame; app.show; If yes,how? 4.Is it possible to use main() other than int WinMain(),if yes,how? And I do know point 3 and 4 may be a longer story and there are a lot of GUI libararies for reference.But I can not gain a clear idea just by reading the other's large project with out short explanation.So really appreciate,if anybody can teach me. Thanks and best regards, Sam |
April 17, 2009 Re: Encapsulation Win32 SDK with class in DMD2028 problem--Help wanted | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sam Hu Attachments: | Forget attachment.Resent.
Sam Hu Wrote:
> Hello,
>
> After my reading below post:
> http://d.puremagic.com/issues/show_bug.cgi?id=2580
> I can compile the win32 SDK sample in dmd\sample folder.After that I tried to encapsulate all those staff in class.Attached is my chance.Below is a short description about all the 3 classes:
> WinClass:Encapsulation of WNDCLASSEX
> WinFrame:Encapsulation of window frame
> WinApp:Encapsulation of the Gui application
>
> Here I have a couple of question.It would be grateful if anybody here kindly let me know,though I do know it is a bit long and it is just an excise of a beginner:
> 1.The program compiled but runs with an Access Violation error.I can not found the place the error occurred.I tried to comments out the try...catch block,but the program runs invisible and with 100% CPU usage,I have to aborted from the task manager.
> 2.Is it possible to encapsulate the callback function
> int WindowProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam)
> into any of the three classes?Which one should be the ideal place?
> 3.Is is possible to encapsulate all the framework into just one class,say WinFrame,and then we can call it by
> auto app=new WinFrame;
> app.show;
> If yes,how?
> 4.Is it possible to use main() other than int WinMain(),if yes,how?
> And I do know point 3 and 4 may be a longer story and there are a lot of GUI libararies for reference.But I can not gain a clear idea just by reading the other's large project with out short explanation.So really appreciate,if anybody can teach me.
>
> Thanks and best regards,
> Sam
>
>
>
|
April 17, 2009 Re: Encapsulation Win32 SDK with class in DMD2028 problem--Help wanted | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sam Hu | On Fri, 17 Apr 2009 13:19:16 +0400, Sam Hu <samhudotsamhu@gmail.com> wrote: > Hello, > > After my reading below post: > http://d.puremagic.com/issues/show_bug.cgi?id=2580 > I can compile the win32 SDK sample in dmd\sample folder.After that I tried to encapsulate all those staff in class.Attached is my chance.Below is a short description about all the 3 classes: > WinClass:Encapsulation of WNDCLASSEX > WinFrame:Encapsulation of window frame > WinApp:Encapsulation of the Gui application > > Here I have a couple of question.It would be grateful if anybody here kindly let me know,though I do know it is a bit long and it is just an excise of a beginner: > 1.The program compiled but runs with an Access Violation error.I can not found the place the error occurred.I tried to comments out the try...catch block,but the program runs invisible and with 100% CPU usage,I have to aborted from the task manager. Need to look at source code to determine the reason. > 2.Is it possible to encapsulate the callback function > int WindowProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam) > into any of the three classes?Which one should be the ideal place? yes. Once you created a window and received a hWnd handle, bind your class and hWnd. One of the two ways: 1) global WinClass[HWND] _hWndToWinClass; _hWndToWinClass[hWnd] = this; 2) SetWindowLong(hWnd, GWL_USERDATA, cast(int)this); WinClass getWinClassByHWND(HWND hWnd) { 1) if (auto ptr = hWnd in _hWndToWinClass) return *ptr; return null; 2) return cast(WinClass)GetWindowLong(hWnd, GWL_USERDATA); } Now when you receive a callback, get a corresponding WinClass reference and redirect to it: extern(Windows) LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { // a lookup from HWND to WinClass here: WinClass win = getWinClassByHWND(hWnd); if (win is null) { return DefWindowProcW(hWnd, message, wParam, lParam); } return win.wndProc(hWnd, message, wParam, lParam); } > 3.Is is possible to encapsulate all the framework into just one class,say WinFrame,and then we can call it by > auto app=new WinFrame; > app.show; > If yes,how? It's possible, of course, but it's a lot of code to write. > 4.Is it possible to use main() other than int WinMain(),if yes,how? > And I do know point 3 and 4 may be a longer story and there are a lot of GUI libararies for reference.But I can not gain a clear idea just by reading the other's large project with out short explanation.So really appreciate,if anybody can teach me. > I am successfully using both and have no problems. Just write void main() {} or follow win32 guide on digitalmars.com I prefer void main() personally as it is shorter to write :) > Thanks and best regards, > Sam > > > |
April 17, 2009 Re: Encapsulation Win32 SDK with class in DMD2028 problem--Help wanted | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sam Hu | On Fri, 17 Apr 2009 13:22:21 +0400, Sam Hu <samhudotsamhu@gmail.com> wrote: > Forget attachment.Resent. > > Sam Hu Wrote: > >> Hello, >> >> After my reading below post: >> http://d.puremagic.com/issues/show_bug.cgi?id=2580 >> I can compile the win32 SDK sample in dmd\sample folder.After that I tried to encapsulate all those staff in class.Attached is my chance.Below is a short description about all the 3 classes: >> WinClass:Encapsulation of WNDCLASSEX >> WinFrame:Encapsulation of window frame >> WinApp:Encapsulation of the Gui application >> >> Here I have a couple of question.It would be grateful if anybody here kindly let me know,though I do know it is a bit long and it is just an excise of a beginner: >> 1.The program compiled but runs with an Access Violation error.I can not found the place the error occurred.I tried to comments out the try...catch block,but the program runs invisible and with 100% CPU usage,I have to aborted from the task manager. >> 2.Is it possible to encapsulate the callback function >> int WindowProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam) >> into any of the three classes?Which one should be the ideal place? >> 3.Is is possible to encapsulate all the framework into just one class,say WinFrame,and then we can call it by >> auto app=new WinFrame; >> app.show; >> If yes,how? >> 4.Is it possible to use main() other than int WinMain(),if yes,how? >> And I do know point 3 and 4 may be a longer story and there are a lot of GUI libararies for reference.But I can not gain a clear idea just by reading the other's large project with out short explanation.So really appreciate,if anybody can teach me. >> >> Thanks and best regards, >> Sam >> >> >> > Here is a nice article: http://www.gamedev.net/reference/programming/features/win32wrapper/page2.asp It's in C++, but still applicable and relevant. |
Copyright © 1999-2021 by the D Language Foundation