Weegee
Go Weegee!
- Reaction score
- 103
Sup TH, I've been recently learning how to program in WINDOWS API and i've been having fun making menus, dialog boxes, etc. Recently, I've tried to put these skills to the test and make an application that opens up a song, plays it, then when it finishes, it allows the user to open up another song. Currently, I'm having troubles getting to the "playing" part as I cannot seem to find any documentation on how to do this >_>. I'm still a noob so don't expect me to be perfect in my coding ;D
Here's my main.cpp:
The code where I open the file has comments below saying "Want to play song here". It's closer to the top. Anywyas, hopefully I provided enough information. I know this is kind of vauge but I can't find any tutorials online so my explanation of what I want to do is to be expected to be pretty vaugue . +Rep inbound !
Here's my main.cpp:
Code:
#include <Windows.h>
#include "resource.h"
const char g_szClassName[] = "myWindowClass";
char szFileName[MAX_PATH] = "";
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Creating OPEN FILE Dialog
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "WAVE Files (*.wav)\0*.wav\0All Files (*.*)\0*.*\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "wav";
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");
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, ID_LOAD_MUSIC, "&Load");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Music");
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, ID_HELP_ABOUT, "&Help");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&About");
SetMenu(hwnd, hMenu);
}
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case ID_LOAD_MUSIC:
if (GetOpenFileName(&ofn))
{
//
// Want to play the song here
//
}
break;
}
case WM_LBUTTONDOWN:
{
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);
wc.lpszClassName = g_szClassName;
wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Happy Fun Times",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
The code where I open the file has comments below saying "Want to play song here". It's closer to the top. Anywyas, hopefully I provided enough information. I know this is kind of vauge but I can't find any tutorials online so my explanation of what I want to do is to be expected to be pretty vaugue . +Rep inbound !