[Win32 API] Creating classes (error when compiling)

Started by
23 comments, last by 50p 14 years, 10 months ago
Hi there. I moved from MFC to Win32 API because I think it's better (maybe not easier). I made a new dialog (in the dialog editor (VS2005)) and it has a ListControl (ListView) control and to add, remove, edit, etc. items from/to it in the code is a bit messy. So I decided to make a class for it so the code will be more clear and easier to use the control but, I get errors complaining about return data types and some others... I'll show you my class and please tell me why it's not compiling: http://50p.pastebin.com/m47296db3 I don't see anything wrong with the class itself -_-' It compile fine only if I use int, float, double, etc. but not BOOL, LPSTR, etc. why? Here are files that are included in main.cpp
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <gl/gl.h>
#include <gl/glu.h>

#include <commctrl.h>

#include "resource.h"

#include "ListViewCtrl.h"
Advertisement
Try to include windows.h in CListViewCtrl.h. Since it actually uses Windows types you need to have it included anyway.

In this case #pragma once might actually bite you. It is more to type, but try "real" header inclusion guards.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Adding #include <windows.h> got rid of most of the errors but than I had issues with LVCOLUMN, so I added #include <commctrl.h> and it compiles just fine.

I thought that if I'll #include <windows.h> in main.cpp and than #include "ListViewCtrl.h" also in main.cpp than ListViewCtrl.h will have <windows.h> included as well (that's why I posted what I included in main.cpp) but I was wrong.

Thanks a lot.

EDIT:
BTW, does anyone know if there is a message sent when a window is created? I'm not talking about WM_CREATE because it's triggered before the window is shown.
In C# it's OnLoad event but I don't know what it is in Win32 API. Basically, I want to display a new window which will be used to control what's going on in the OpenGL window. So I'd like to display the new window "on top" of the OpenGL window. To do this I used DialogBox() but when I use it, the new window is created but the "main" one isn't, until I close the "sub window". Maybe I should use CreateWindow instead but how would I use the dialog box's ID that is in .rc file?
WM_CREATE is the closest thing to OnLoad for non-dialog HWNDs.

DialogBox opens the dialog modal, this doesn't sound like the behaviour you need. You can use the CreateDialog macro:

hwndDialog = CreateDialog( hInstance, MAKEINTRESOURCE( ID_FROM_DIALOG_RESOURCE ), hwndMain, MyDialogProc );

A dialog sends the WM_INITDIALOG message to its DlgProc, you can use this to do further initialisation.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Thanks. That worked well!
Do you maybe know if it's possible to keep that dialog box always on top of its parent? I don't want it to be always on top of every system windows but just its parent (main window of my application).

Thanks in advance!
I'm not sure if I understand you. Do you want a tool window behaviour as in the window is visible while your app is active, but hides, if your app is not active?

If so, you have to implement that yourself. Check WM_ACTIVATE_APP in your main window proc and call ShowWindow with the HWND of the dialog accordingly.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

AFAIK there is no WM_ACTIVATE_APP but WM_ACTIVATE. Anyway, I tried to ShowWindow with WM_ACTIVATE message but it doesn't seem to work at all. I'd like to achieve this:
http://img40.imageshack.us/img40/2395/mainwndandtoolswnd.png

So that even if my main ("GL WINDOW!") is active (focused) the Tools window would always be on top of that main, as you can see on the screenshot.
But I get this:
http://img42.imageshack.us/img42/1395/mainwndandtoolswnd2.png

So it means that WM_ACTIVATE is not called or ShowWindow doesn't show the Tools window on top of the main window. I tried many SW_xxx to show the window but none of them worked the way I wanted. I'd like the tools window to be on top of main window but if the main window is active (focused) than the Tools window would not active (of course) and that would mean the window would be "grayed" (non active window).
It's actually spelled WM_ACTIVATEAPP.
Ah, i understand now. Sorry for the typo.

You could also try SetWindowPos with setting the z order of the tool window above the main window and SWP_NOMOVE | SWP_NOSIZE set. Do check the flags from WM_ACTIVATEAPP.

That's one of the things that MFC handles nicely. All the tool windows get an active caption (although they're technically are not) and are auto-hidden when the main window loses focus.
This functionality is a monstrous hack. You can look at Catch 22's tutorial, he explains how to do this manually: Clicky

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

It's not possible or you guys don't know what I mean or you don't know how to achieve it :P

I tried: ShowWindow( hToolsWnd, INT )
Where INT was from 1 to 18. Even though there are only 11 values possible for the 2nd param, SW_SHOWNORMAL to SW_MAX (1-11).


http://prdownloads.sourceforge.net/crayzedsgui/CELayoutEditorSetup-0.6.2.exe?download
This is a link to CEGUI Layout Editor which works the way I want. If any of you could download it and see what I mean I'd be grateful.

Thanks

This topic is closed to new replies.

Advertisement