* Re: Problem using windres
[not found] <1391725173713-1009189.post@n5.nabble.com>
@ 2014-02-06 22:24 ` Tonyb
2014-02-07 17:19 ` Tonyb
1 sibling, 0 replies; 2+ messages in thread
From: Tonyb @ 2014-02-06 22:24 UTC (permalink / raw)
To: gcc-help
Looks like I didn't embed that code properly. I thought the Embed would do
the trick. Hopefully this will be more readable:
The resource.txt file:
#include "resource.h"
IDR_MYMENU MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&Stuff"
BEGIN
MENUITEM "&Go", ID_STUFF_GO
MENUITEM "G&o somewhere else", 0, GRAYED
END
END
IDI_MYICON ICON "menu_one.ico"
The prog7.c file:
#include <windows.h>
#include <resource.h>
#include <resource.rc>
/* From winprog.org tutorial */
{ // This extra bracket is necessary to insure that g_szClassName remains
defined at line 52
const char g_szClassName[] = "myWindowClass";
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_LBUTTONDOWN:
{
char szFileName[MAX_PATH];
HINSTANCE hInstance = GetModuleHandle(NULL);
GetModuleFileName(hInstance, szFileName, MAX_PATH);
MessageBox(hwnd, szFileName, "This program is:", MB_OK |
MB_ICONINFORMATION);
}
break;
/* Mnu02.rc */
#define IDR_MAIN_MENU 2000
#define IDM_FILE_OPEN 2100
#define IDM_FILE_EXIT 2105
IDR_MAIN_MENU MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Open...", IDM_FILE_OPEN
MENUITEM "E&xit", IDM_FILE_EXIT
END
END
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;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
/* Mnu02.rc */
#define IDR_MAIN_MENU 2000
#define IDM_FILE_OPEN 2100
#define IDM_FILE_EXIT 2105
IDR_MAIN_MENU MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Open...", IDM_FILE_OPEN
MENUITEM "E&xit", IDM_FILE_EXIT
END
END
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDI_MYICON)); // New
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU); // New
wc.lpszClassName = g_szClassName;
wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL),
"menu_one.ico", IMAGE_ICON, 16,16,0); // New
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
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);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
}
--
View this message in context: http://gcc.1065356.n5.nabble.com/Problem-using-windres-tp1009189p1009194.html
Sent from the gcc - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Problem using windres
[not found] <1391725173713-1009189.post@n5.nabble.com>
2014-02-06 22:24 ` Problem using windres Tonyb
@ 2014-02-07 17:19 ` Tonyb
1 sibling, 0 replies; 2+ messages in thread
From: Tonyb @ 2014-02-07 17:19 UTC (permalink / raw)
To: gcc-help
Well, I managed to figure this out. (I think.) I'm compelled to post it
since I had such a hard time and could find the answer I needed in a couple
days of searching.
Can't compile & link in one step. I was trying to use: gcc prog7.c
resource.coff -I.
Couldn't make it work.
This does:
windres resource.rc resource.coff
gcc -c prog7.c -o prog7.o -I.
gcc prog7.o resource.coff -I.
Here's the makefile:
prog7.exe : prog7.o resource.coff
gcc prog7.o resource.coff -I.
resource.coff : resource.rc
windres resource.rc resource.coff
prog7.o : prog7.c
gcc -c prog7.c -o prog7.o -I.
Please forgive my inelegant post; haven't figured out how to put the code in
those nice little scroll boxes others use. (currently the least of my
problems!)
--
View this message in context: http://gcc.1065356.n5.nabble.com/Problem-using-windres-tp1009189p1009401.html
Sent from the gcc - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-02-07 17:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1391725173713-1009189.post@n5.nabble.com>
2014-02-06 22:24 ` Problem using windres Tonyb
2014-02-07 17:19 ` Tonyb
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).