Author Topic: Weird WinAPI problem  (Read 9001 times)

Offline henniez-swisswater

  • Single posting newcomer
  • *
  • Posts: 6
Weird WinAPI problem
« on: March 06, 2006, 05:00:25 pm »
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 

Offline webwraith

  • Single posting newcomer
  • *
  • Posts: 9
Re: Weird WinAPI problem
« Reply #1 on: March 06, 2006, 05:35:27 pm »
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)?

Offline henniez-swisswater

  • Single posting newcomer
  • *
  • Posts: 6
Re: Weird WinAPI problem
« Reply #2 on: March 06, 2006, 05:38:11 pm »
o sry for that. it compiles but the static text is nowhere (the non-working one). and yeah they are in two different projects.


Offline webwraith

  • Single posting newcomer
  • *
  • Posts: 9
Re: Weird WinAPI problem
« Reply #3 on: March 06, 2006, 05:58:28 pm »
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

Offline TDragon

  • Lives here!
  • ****
  • Posts: 936
    • Twilight Dragon Media
Re: Weird WinAPI problem
« Reply #4 on: March 06, 2006, 06:38:29 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...
http://tdm-gcc.tdragon.net/ - TDM-GCC compiler suite for Windows (GCC 5.1.0 2015-06-28, 32/64-bit, no extra DLLs)

sethjackson

  • Guest
Re: Weird WinAPI problem
« Reply #5 on: March 06, 2006, 06:50:30 pm »
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

Offline Vampyre_Dark

  • Regular
  • ***
  • Posts: 255
  • Hello!
    • Somewhere Over The Rainbow...
Re: Weird WinAPI problem
« Reply #6 on: March 06, 2006, 07:54:17 pm »
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

  • Guest
Re: Weird WinAPI problem
« Reply #7 on: March 06, 2006, 07:57:49 pm »
 :lol: I used it for two years, and I still think it was a mess.  :P

Offline henniez-swisswater

  • Single posting newcomer
  • *
  • Posts: 6
Re: Weird WinAPI problem
« Reply #8 on: March 06, 2006, 08:02:45 pm »
@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

  • Guest
Re: Weird WinAPI problem
« Reply #9 on: March 06, 2006, 08:05:37 pm »
Yes.

http://www.amazon.com/exec/obidos/ASIN/157231995X/winprognet-20/102-5163610-7788162

Old, but good. I don't have it anymore. Ditched it after I started using wxWidgets.

Also look here.

http://www.winprog.org/tutorial/references.html

A good Win32 API tutorial is here.

http://www.winprog.org/tutorial/index.html

Offline Vampyre_Dark

  • Regular
  • ***
  • Posts: 255
  • Hello!
    • Somewhere Over The Rainbow...
Re: Weird WinAPI problem
« Reply #10 on: March 06, 2006, 08:10:00 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

  • Guest
Re: Weird WinAPI problem
« Reply #11 on: March 06, 2006, 08:22:38 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: C++
  1. wxFrame* frame = new wxFrame(0, wxID_ANY, _("Test Window"), wxDefaultPosition, wxDefaultSize);
  2.  

Win32 API

Code: C++
  1. // Get the hInstance from somewhere. Generally from the window procedure
  2.  
  3. HWND hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,
  4.                            "myWindowClass",
  5.                            "Test Window",
  6.                            WS_OVERLAPPEDWINDOW,
  7.                            CW_USEDEFAULT,
  8.                            CW_USEDEFAULT,
  9.                            240,
  10.                            120,
  11.                            0,
  12.                            0,
  13.                            hInstance,
  14.                            0);
  15.  
  16.  

Offline henniez-swisswater

  • Single posting newcomer
  • *
  • Posts: 6
Re: Weird WinAPI problem
« Reply #12 on: March 06, 2006, 08:35:13 pm »
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

  • Guest
Re: Weird WinAPI problem
« Reply #13 on: March 06, 2006, 08:39:08 pm »
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


Offline Vampyre_Dark

  • Regular
  • ***
  • Posts: 255
  • Hello!
    • Somewhere Over The Rainbow...
Re: Weird WinAPI problem
« Reply #14 on: March 06, 2006, 08:51:55 pm »
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~