Qbasicnews.com

Full Version: Icon in main window
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to have an icon (for example fblogo.ico) in the main window of a program.

I've read the FB-WIN ICON tutorial and tested it in the following manner:

Make a text file testicon.rc with the following text:
FB_PROGRAM_ICON ICON fblogo.ico

Then renamed it to testicon.rc

I placed fblogo.ico and testicon.rc in the same dir as the program test.bas

Then compiled the program with this option:
fbc testicon.rc -s gui test.bas

Then test.exe has the icon but not the window in the program itself?

Do i have to change something in winmain (see <------- next to the code of the program).

I replaced MAINICON with FBICON and compiled again with fbc testicon.rc -s gui test.bas but with no result.

Anyone a suggestion?

The following code is test.bas (just a window, nothing fancy)

OPTION Explicit

' $INCLUDE: 'win\kernel32.bi'
' $INCLUDE: 'win\user32.bi'
' $INCLUDE: 'win\GDI32.bi'

DECLARE FUNCTION WinMain (byval hInstance as long, _
byval hPrevInstance as long, _
szCmdLine as string, _
byval iCmdShow as long) as long

dim OS AS OSVERSIONINFO
dim Oss AS STRING
OS.dwOSVersionInfoSize = LEN(OS)
IF GetVersionEx(OS) THEN
SELECT CASE OS.dwPlatformId
CASE VER_PLATFORM_WIN32_WINDOWS
IF OS.dwMajorVersion = 4 AND OS.dwMinorVersion = 0 THEN Oss ="95"
IF OS.dwMajorVersion = 4 AND OS.dwMinorVersion = 10 THEN Oss = "98"
IF OS.dwMajorVersion = 4 AND OS.dwMinorVersion = 90 THEN Oss = "ME"
END SELECT
END IF

DIM SHARED hInst AS LONG

IF Oss <>"95" OR Oss <> "98" OR Oss <> "ME" THEN
END WinMain(GetModuleHandle(null), null, Command$, SW_NORMAL) 'XP entry point
Else
hInst=GetModuleHandle(null)
END WinMain(hInst, null, COMMAND$, SW_NORMAL) '9x entry point
END IF

FUNCTION ProcessWindow (BYVAL hDlg AS Uinteger, BYVAL wMsg AS Uinteger, BYVAL wParam _
AS Uinteger, BYVAL lParam AS LONG) AS Long

STATIC hStBrush1 AS LONG
DIM wmID AS LONG, wmEvent AS Long
DIM StBgColor1 AS Long, StFgColor1 AS LONG
DIM Lt1 AS STRING
DIM hCtrl AS Long
STfgColor1 = &H4080FF ' Selected foreground color for a Static control
STbgColor1 = &HC7CFD3


IF wMsg = WM_CREATE Then 'Messages that Initializes Controls and
'tasks that affects the Appearance of Dialogs

ELSEIF wMsg = WM_DESTROY Then
DeleteObject hStBrush1 ' Frees all system resources associated with this brush
' a control sends notification messages to its Parent
ELSEIF wMsg = WM_CLOSE THEN ' Message from Clicking on system close Icon
PostQuitMessage 0
END If
ProcessWindow = DefWindowProc(hdlg, wMsg, wParam, lParam)
END Function


FUNCTION WINMAIN (BYVAL hInstance AS LONG, _
BYVAL hPrevInstance AS LONG, _
szCmdLine AS STRING, _
BYVAL iCmdShow AS LONG) AS LONG

DIM wMsg As Msg
DIM wcls AS wndclass
DIM hWnd AS Unsigned LONG, hMenu AS LONG
DIM szpgmname AS STRING, style as long


szpgmname = "FreeBasic GUI Samples"
WITH wcls
.style = CS_HREDRAW OR CS_VREDRAW OR CS_DBLCLKS
.lpfnWndProc = @ProcessWindow 'point to callback code
.cbClsExtra = 0
.cbWndExtra = 0
.hInstance = hInstance
.hIcon = LoadIcon( hInstance, "MAINICON" ) <-------
.hCursor = LoadCursor( NULL, BYVAL IDC_ARROW )
.hbrBackground = COLOR_MENU +1
.lpszMenuName = NULL
.lpszClassName = Sadd(szpgmname)
END WITH
RegisterClass wcls
style = WS_VISIBLE OR WS_OVERLAPPEDWINDOW OR DS_MODALFRAME

hWnd = CreateWindowEx(0, szpgmname, "Example window", _
Style, 0, 45, 800, 573, _
HWND_DESKTOP, hMenu, hInstance, BYVAL NULL)

ShowWindow hWnd, iCmdShow
UpdateWindow hWnd
WHILE (GetMessage(wMsg, NULL, 0, 0) <> false )
TranslateMessage wMsg
DispatchMessage wMsg
Wend
WinMain = wMsg.wParam
END Function
This line:
Code:
.hIcon = LoadIcon( hInstance, "MAINICON" )
has to be changed to use the name of the icon (or the integer ID)... for example, "FB_PROGRAM_ICON".
Darn! DrV got there first. . . Tongue
It works!

Thanx to DrV for helping and rpgfan3233 for trying to help

Think we can close this topic now