Sign in to follow this  

I HATE WIN32 I HATE IT I HATE IT(Major part solved)

This topic is 4713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am having a problem here i have used the forger win32 api tutorial and some others but i cant figure out what i am doing wrong i can seem to get my resource files to work with my .cpp files and i cant even get my windows menus to work right nor can i get the icons to display right nor can i get rid of that annoying little console window that displays with my window oh and btw im poor so i use dev-c++ does this about sum it up here lets try some code to be sure this is what i have
#include <windows.h>

#define ID_FILE_EXIT 1000

const char *ClsName = "BasicApp";
const char *WndName = "HI";

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

{       
        MSG Msg;    
        HWND hWnd;
        WNDCLASSEX WndClsEx;
        
        // Create the app window
        WndClsEx.cbSize = sizeof (WNDCLASSEX);
        WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
        WndClsEx.lpfnWndProc = WndProcedure;
        WndClsEx.cbClsExtra = 0;
        WndClsEx.cbWndExtra = 5;
        WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
        WndClsEx.hInstance = hInstance;
        WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
        WndClsEx.hbrBackground = (HBRUSH)(21); //(HBRUSH) GetStockObject (COLOR_WINDOW);
        WndClsEx.lpszMenuName = NULL;
        WndClsEx.lpszClassName = ClsName;
       
        // register 
       RegisterClassEx(&WndClsEx);
        
        // Create the window object
      hWnd = CreateWindow(ClsName,
			  WndName,
			  WS_OVERLAPPEDWINDOW,
			  CW_USEDEFAULT,
			  CW_USEDEFAULT,
			  CW_USEDEFAULT,
			  CW_USEDEFAULT,
			  NULL,
			  NULL,
			  hInstance,
			  NULL);
       
       if(!hWnd)
       return 0;
       
       ShowWindow(hWnd, SW_SHOWNORMAL);
       UpdateWindow(hWnd);
       
       while( GetMessage(&Msg, NULL, 0, 0))
       {
               TranslateMessage(&Msg);
               DispatchMessage(&Msg);   
       }
       
             
       return Msg.wParam;
       
    }
    
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
        switch(Msg)
        {
            case WM_CREATE:
                {
                 HMENU hMenu, hSubMenu;
                 
                 hMenu = CreateMenu();
                 
                 hSubMenu = CreatePopupMenu();
                 
                 AppendMenu(hSubMenu, 2, ID_FILE_EXIT, "E&xit");
                 AppendMenu(hMenu, 2, (UINT)hSubMenu,"&File");
                 
                 SetMenu(hWnd, hMenu);
               
                }
                break;    
            case WM_DESTROY:
                PostQuitMessage(WM_QUIT);
                break;
            default:
                return DefWindowProc(hWnd, Msg, wParam, lParam);
            }
            return 0;
        }



the problem here is the fact that the program works fine exept i cant seem to get my exit command to show i click file and well nothing happens Thank you Palidine. ok but still need help with win32 [Edited by - Gor435 on January 19, 2005 10:16:27 PM]

Share this post


Link to post
Share on other sites
Add WM_COMMAND case to your switch block.


...
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_FILE_EXIT:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
break;
...



Share this post


Link to post
Share on other sites
and that does absolutly nothing the program runs just the same i still have no exit nothing happens when i click file notta :/

BTW how do these people expect you to learn this stuff when they rarley explain why you need to type some of this stuff

i mean they say IDD_ABOUTDLG is the id of the resource (example word for word from a tutorial forgers to be exact) but wtf does that mean i mean come on people

Share this post


Link to post
Share on other sites
no i dont want to forgo the api and this is not inteneded to be a game accually i want to write this program to extract .rar files (my gf plays the sims 2 and downloads mods which are usually in .rar format) i could write this program in the console but well that would just be crappy now wouldnt it

Share this post


Link to post
Share on other sites
For the Win32 API there was a good book "Windows 98 Programming from the Ground Up" by Herbert Schildt.

I would not recommend to MFC to anyone I did not loathe.

.NET however is very nice, and easier to learn than either of the other options.

But if you don't want .NET then you have pure Win32 API (not done often anymore), ATL/WTL (Active Template Lirbary, Window(s) Template Library?), or the Borland VCL (Visual Class Library) system (which used to be VERY nice compared to MFC) used by Borland C++ Builder.

Share this post


Link to post
Share on other sites
I think I've caught your problem. You pass a plain 2 as a second parameter of the AppendMenu function. That corresponds to macro mnemonic MF_DISABLED. This prevents your menu from appearing. You should pass MF_POPUP instead (or 0x10 which is the same).

Anyway your program won't exit on pressing exit if you don't tell it how to respond on ID_FILE_EXIT message. Which is adding WM_COMMAND branch to switch statement.

Hope this helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by Decibit
I think I've caught your problem. You pass a plain 2 as a second parameter of the AppendMenu function. That corresponds to macro mnemonic MF_DISABLED. This prevents your menu from appearing. You should pass MF_POPUP instead (or 0x10 which is the same).


sorry to be a spoil sport but the 2 there is what i put after i tried that :(
2 accually enables the menu.

Quote:
Anyway your program won't exit on pressing exit if you don't tell it how to respond on ID_FILE_EXIT message. Which is adding WM_COMMAND branch to switch statement.


ok i already have added the WM_COMMAND to my switch statement

Quote:
and that does absolutly nothing the program runs just the same i still have no exit nothing happens when i click file notta :/


next

Quote:
For the Win32 API there was a good book "Windows 98 Programming from the Ground Up" by Herbert Schildt.

I would not recommend to MFC to anyone I did not loathe.

.NET however is very nice, and easier to learn than either of the other options.

But if you don't want .NET then you have pure Win32 API (not done often anymore), ATL/WTL (Active Template Lirbary, Window(s) Template Library?), or the Borland VCL (Visual Class Library) system (which used to be VERY nice compared to MFC) used by Borland C++ Builder.


Again
Quote:
oh and btw im poor so i use dev-c++


Quote:
use WTL, or MFC if you have Codewarrior/Borland C++ Builder or Visual C++
its easier.

better yet, just write it in Visual Basic or Delphi and use the UnRar.dll


Again
Quote:
oh and btw im poor so i use dev-c++

and i have the UnRar.dll that is accually what i was try to use.
but its not like it matters now the header files that came with UnRar.dll
dont work right with dev-c++ i come up with mulitiple linker errors like (Undefinded reference to RAROpenArchive@4 and RARProcessFile@16) so i give up but still i would like to know how to fix the menu and icon problem for future reference.



Share this post


Link to post
Share on other sites
windows programming is easy but i must say that using resources suck they never seem to do what you intend them to do but Let me say that there are many ways to fix your problem if you check for errors which is what usually happens to me.


All im saying is check to see if any of your resource function are passing back null vaule or somethin

if so they are causing errors for some dumb reason.


i will download dev c++ later but i do want to tell you that microsoft has a free command line compiler and there are many downloads out there for the software.

Share this post


Link to post
Share on other sites
try this it should work but clicking on exti doesnt do any thing untill you tell it to in the WM_COMMAND(windows command message handler which hands commands from button clicks to files this should be located in the WndProcedure function under the switch statement):

#include <windows.h>

#define ID_FILE_EXIT 1000

const char *ClsName = "BasicApp";
const char *WndName = "HI";

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

{
MSG Msg;
HWND hWnd;
WNDCLASSEX WndClsEx;

// Create the app window
WndClsEx.cbSize = sizeof (WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProcedure;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 5;
WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hInstance = hInstance;
WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClsEx.hbrBackground = (HBRUSH)(21); //(HBRUSH) GetStockObject (COLOR_WINDOW);
WndClsEx.lpszMenuName = NULL;
WndClsEx.lpszClassName = ClsName;

// register
RegisterClassEx(&WndClsEx);

// Create the window object
hWnd = CreateWindow(ClsName,
WndName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);

if(!hWnd)
return 0;

ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);

while( GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}


return Msg.wParam;

}

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CREATE:
{
HMENU hMenu, hSubMenu;

hMenu = CreateMenu();

hSubMenu = CreatePopupMenu();

AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu,"&File");

SetMenu(hWnd, hMenu);

}
break;
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
return 0;
}

Share this post


Link to post
Share on other sites
sounds like you can use some real help i can help you get around the basics but the advance techinque is over my head you be sure i can help the other problem is no biggie its just dev c++ don't link .lib they use static libraries or something but there are still ways around this flaw.

Share this post


Link to post
Share on other sites
the book i used (and am still using) is tricks of the windows game programming gurus. it explains everything really well (i thought) and tells you what the different things do, which is nice (i tried theforgers tutorial and didnt understand it at all + nothing would work.) the only problem is that only about a quarter of the book is about windows, and the rest is more about games.
Anyway, i just think that theforgers tutorial isnt cery good cause it doesnt explain stuff and if u really want to learn the stuff u should find a good book for it

Share this post


Link to post
Share on other sites
THANKY YOU OWILEY!!! it works now tyvm

And
Quote:
tricks of the windows game programming gurus

I will have to check that book out but like i said i am poor :P

Throws Forgers tutorial he printed in the trash
because my printed tutorial doesnt have that MF_STRING | MF_POPUP part the only thing it said was MF_STRING

Share this post


Link to post
Share on other sites

This topic is 4713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this