News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Weird WinAPI problem

Started by henniez-swisswater, March 06, 2006, 05:00:25 PM

Previous topic - Next topic

henniez-swisswater

I have twice the same code. once it works fine the other one doesn't work. the code is supposed to show a window with a static text (created with CreateWindow("STATIC","blabla",...)). the reason for me having twice the same code, is that that I worte one from scratch (not working) and the other one is generate by code::blocks. the code::blocks one works, so I copied the working code, generated by code::blocks, and I overwrote my code. Here coms the strange thing, it still doesn't work. It is exactly the same code. Is it possible than some kind of project setting can cause this problem?

regards 

webwraith

Do you have both pieces of code in the same project? If not, perhaps you should check the build options of the non-working code.

Also, you just say that the code isnt working, how do you mean?

Is it not compiling? compiling, but not linking? What are the error messages (if any)?

henniez-swisswater

o sry for that. it compiles but the static text is nowhere (the non-working one). and yeah they are in two different projects.


webwraith

OK, I'm not quite sure I follow you. what do you mean by static text?

CreateWindow takes two character arrays, one is the name of your previously registered class (i.e.;the lpszClassName member of WNDCLASS structure), this must be the same as your registered window class otherwise Windows will be looking for a class that doesn't exist.
Thoe other character array is the 'caption' of the window, or the text that appears in the titlebar. This can be anything you like, but won't put anything into the client area (the main area of the window).

If you want the equivalent of an error message-type window, use MessageBox() instead. otherwise you're looking at window controls, and there are others out there much more knowledgable about those than I. Your best bet is to invest in a decent book on Win32 api programming

TDragon

Quote from: webwraith on March 06, 2006, 05:58:28 PM
CreateWindow takes two character arrays, one is the name of your previously registered class (i.e.;the lpszClassName member of WNDCLASS structure), this must be the same as your registered window class otherwise Windows will be looking for a class that doesn't exist.
Or it may be one of the predefined class names, such as "COMBOBOX" or "STATIC".

Quote
Thoe other character array is the 'caption' of the window, or the text that appears in the titlebar. This can be anything you like, but won't put anything into the client area (the main area of the window).
...unless you're creating a control window as a child window of the main window, or any of a number of similar scenarios.

Quote
otherwise you're looking at window controls, and there are others out there much more knowledgable about those than I.
Indeed...

henniez-swisswater: The Win32 API is a fickle mistress. When I'm forced to use it, I tend to keep the MSDN Library open for reference to any functions I use. When problems like yours show up, it's usually due to some obscure constraint on a Win32 function.

Fortunately, I can usually make use of wxWidgets, which actually makes GUI programming fun.

Good luck...
[url="https://jmeubank.github.io/tdm-gcc/"]https://jmeubank.github.io/tdm-gcc/[/url] - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

sethjackson

Yeah I agree with TDragon. Win32 API programming is a mess. I used to use it..... Until I found wxWidgets. wxWidgets does make GUI programming fun. :D

Vampyre_Dark

I think it's only a mess when you are new to it.  :? You learn to do a cleaner job in time. My first win32 programs were messes all over the place, because I was new to it, and I didn't understand it as much. After you've been usng it awhile, you start to understand more how everything works together, and it becomes more clean and organised as a result.
C::B Wishlist
~BOYCOTT THE EVIL YELLOW BOXES~

sethjackson

 :lol: I used it for two years, and I still think it was a mess.  :P

henniez-swisswater

@TDragon: Indeed I wanted to use the predefined "STATIC" "BUTTON" etc. But I reckon I would be best to get a book too. Does anyone of you know a good one?

sethjackson


Vampyre_Dark

Quote from: sethjackson on March 06, 2006, 07:57:49 PM
:lol: I used it for two years, and I still think it was a mess.  :P
Why not give a side by side example of how wx does the same task easier?  :P The only thing I don't like is filling out structs all the time.
C::B Wishlist
~BOYCOTT THE EVIL YELLOW BOXES~

sethjackson

Quote from: Vampyre_Dark on March 06, 2006, 08:10:00 PM
Quote from: sethjackson on March 06, 2006, 07:57:49 PM
:lol: I used it for two years, and I still think it was a mess.  :P
Why not give a side by side example of how wx does the same task easier?  :P The only thing I don't like is filling out structs all the time.

Do I really need to? It is obvious. wxWidgets is cross-platform Win32 API is not.

Also as for documentation I can actually find what I'm looking for in the wx manual......  :lol:

Anyways as for creating a window here we go.

wx

Code (cpp) Select

wxFrame* frame = new wxFrame(0, wxID_ANY, _("Test Window"), wxDefaultPosition, wxDefaultSize);


Win32 API

Code (cpp) Select

// Get the hInstance from somewhere. Generally from the window procedure

HWND hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,
                           "myWindowClass",
                           "Test Window",
                           WS_OVERLAPPEDWINDOW,
                           CW_USEDEFAULT,
                           CW_USEDEFAULT,
                           240,
                           120,
                           0,
                           0,
                           hInstance,
                           0);



henniez-swisswater

oh by the way I solved the inital problem with the two versions where one showed the text and the other didn't. It was some config of c:b. I deleted all project files except the .cbp. afterward, everything was back to normal:P at last. Now I can go on with my thrilling WinAPI experience:P I'll finish this project with WinAPI. But the next one is gonna be some crossplatform API. Probably wx.Actually, are there any other?  I know this goes a bit off-topic, sry.

sethjackson

Yes there are others. GTK+, Qt, Fox, FLTK.

Here is a page comparing these to wx.

http://www.wxwidgets.org/wiki/index.php/WxWidgets_Compared_To_Other_Toolkits


Vampyre_Dark

What exactly did that prove other than they are very similar calls? One has a few more arguments, so what?  :? (I'm not trying to do a win32 vs WX here, I was just curious). I wanted to see an example of actually getting something done.
C::B Wishlist
~BOYCOTT THE EVIL YELLOW BOXES~