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

Started by
15 comments, last by DarkMerchant 19 years, 2 months ago
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]
Gor435 - My Journal - MySpace - Facebook
Advertisement
Quote:
apparently <source></source> doesnt work like everyone tells me it does blah!!


that's b/c it's [ and ] not < and >

-me
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;...
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
Gor435 - My Journal - MySpace - Facebook
If you just want to write games and forego all of that win32 API garbage, say no more:

libsdl
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
Gor435 - My Journal - MySpace - Facebook
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
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
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.
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.
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.



Gor435 - My Journal - MySpace - Facebook

This topic is closed to new replies.

Advertisement